fix_font_face_resolution_when_renderer_is_blocked.patch 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Shelley Vohr <[email protected]>
  3. Date: Tue, 4 Jun 2024 15:29:10 +0200
  4. Subject: Fix font face resolution when renderer is blocked
  5. Backports https://chromium-review.googlesource.com/c/chromium/src/+/5584820
  6. As a result of https://chromium-review.googlesource.com/c/chromium/src/+/5290838,
  7. the FontFaceSet promise in e.g. contentWindow.document.fonts.ready will never resolve
  8. while the renderer is blocked. This Cl takes an approach similar to that taken in
  9. MediaQueryList in order to enable the promise to be resolved.
  10. diff --git a/third_party/blink/renderer/core/css/font_face_set_document.cc b/third_party/blink/renderer/core/css/font_face_set_document.cc
  11. index a477f3364122643cd79305adf86bb3cbbbded37e..479778c0118c7813ab424f4adb4f424f89ce3596 100644
  12. --- a/third_party/blink/renderer/core/css/font_face_set_document.cc
  13. +++ b/third_party/blink/renderer/core/css/font_face_set_document.cc
  14. @@ -27,6 +27,7 @@
  15. #include "base/metrics/histogram_functions.h"
  16. #include "third_party/blink/public/common/features.h"
  17. +#include "third_party/blink/public/common/metrics/document_update_reason.h"
  18. #include "third_party/blink/renderer/bindings/core/v8/dictionary.h"
  19. #include "third_party/blink/renderer/core/css/css_font_face.h"
  20. #include "third_party/blink/renderer/core/css/css_font_selector.h"
  21. @@ -141,21 +142,27 @@ FontFaceSetDocument::CSSConnectedFontFaceList() const {
  22. }
  23. void FontFaceSetDocument::FireDoneEventIfPossible() {
  24. - if (should_fire_loading_event_) {
  25. + Document* d = GetDocument();
  26. + if (!d || !d->View()) {
  27. return;
  28. }
  29. +
  30. if (!ShouldSignalReady()) {
  31. return;
  32. }
  33. - Document* d = GetDocument();
  34. - if (!d) {
  35. +
  36. + // FireDoneEventIfPossible gets scheduled via PostTask at the end of a
  37. + // successful style+layout update. An invalidation may have occurred in
  38. + // the interim, so update style and layout synchronously here.
  39. + d->UpdateStyleAndLayout(DocumentUpdateReason::kUnknown);
  40. +
  41. + // These values can change during style+layout update, so check them
  42. + // *after* the call to UpdateStyleAndLayout.
  43. + if (should_fire_loading_event_) {
  44. return;
  45. }
  46. - // If the layout was invalidated in between when we thought layout
  47. - // was updated and when we're ready to fire the event, just wait
  48. - // until after the next layout before firing events.
  49. - if (!d->View() || d->View()->NeedsLayout()) {
  50. + if (!ShouldSignalReady()) {
  51. return;
  52. }