Bug 154101

Summary: Extend CSSFontSelector's lifetime to be longer than the Document's lifetime
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: New BugsAssignee: Myles C. Maxfield <mmaxfield>
Status: RESOLVED FIXED    
Severity: Normal CC: buildbot, commit-queue, kling, koivisto, manian, rniwa, ryanhaddad, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 154921    
Bug Blocks: 153346, 158450    
Attachments:
Description Flags
WIP
none
WIP
none
WIP
none
Patch
none
Archive of layout-test-results from ews117 for mac-yosemite
none
Patch for Committing
buildbot: commit-queue-
Archive of layout-test-results from ews103 for mac-yosemite
none
Archive of layout-test-results from ews114 for mac-yosemite
none
Patch for committing
none
Rebased patch
none
srcset sizes fix
none
Updated patch none

Myles C. Maxfield
Reported 2016-02-10 23:45:38 PST
Extend CSSFontSelector's lifetime to be longer than the Document's lifetime
Attachments
WIP (8.81 KB, patch)
2016-02-10 23:45 PST, Myles C. Maxfield
no flags
WIP (9.85 KB, patch)
2016-02-23 21:18 PST, Myles C. Maxfield
no flags
WIP (11.51 KB, patch)
2016-02-23 22:17 PST, Myles C. Maxfield
no flags
Patch (11.80 KB, patch)
2016-02-23 22:51 PST, Myles C. Maxfield
no flags
Archive of layout-test-results from ews117 for mac-yosemite (1.59 MB, application/zip)
2016-02-24 00:08 PST, Build Bot
no flags
Patch for Committing (12.61 KB, patch)
2016-02-27 21:29 PST, Myles C. Maxfield
buildbot: commit-queue-
Archive of layout-test-results from ews103 for mac-yosemite (824.12 KB, application/zip)
2016-02-27 22:20 PST, Build Bot
no flags
Archive of layout-test-results from ews114 for mac-yosemite (890.75 KB, application/zip)
2016-02-27 22:42 PST, Build Bot
no flags
Patch for committing (12.65 KB, patch)
2016-02-29 22:14 PST, Myles C. Maxfield
no flags
Rebased patch (31.53 KB, patch)
2016-06-07 00:26 PDT, Myles C. Maxfield
no flags
srcset sizes fix (2.40 KB, patch)
2016-06-07 22:29 PDT, Myles C. Maxfield
no flags
Updated patch (13.00 KB, patch)
2016-06-07 23:04 PDT, Myles C. Maxfield
no flags
Myles C. Maxfield
Comment 1 2016-02-10 23:45:59 PST
Myles C. Maxfield
Comment 2 2016-02-23 21:18:56 PST
Myles C. Maxfield
Comment 3 2016-02-23 22:17:34 PST
Myles C. Maxfield
Comment 4 2016-02-23 22:51:13 PST
Build Bot
Comment 5 2016-02-24 00:08:06 PST
Comment on attachment 272098 [details] Patch Attachment 272098 [details] did not pass mac-debug-ews (mac): Output: http://webkit-queues.webkit.org/results/875175 New failing tests: editing/execCommand/insert-line-break-onload.html editing/editability/empty-document-justify-right.html editing/selection/selection-modify-crash.html editing/execCommand/insert-image-with-selecting-document.html editing/selection/extend-by-line-in-empty-document.html editing/editability/empty-document-stylewithcss.html editing/execCommand/delete-empty-container.html editing/execCommand/insert-html-to-document-element-crash.html imported/blink/editing/selection/contains-node-cleared-document.html editing/selection/deleteFromDocument-after-document-open-crash.html imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/sizes/parse-a-sizes-attribute.html editing/editability/empty-document-delete.html
Build Bot
Comment 6 2016-02-24 00:08:08 PST
Created attachment 272103 [details] Archive of layout-test-results from ews117 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews117 Port: mac-yosemite Platform: Mac OS X 10.10.5
Darin Adler
Comment 7 2016-02-24 09:12:58 PST
Comment on attachment 272098 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=272098&action=review The design here is a little bit oblique and peculiar. I understand that there’s this state where we are changing the fonts quickly and so want to optimize by not updating m_cssFontFaceSet. But isn’t there some cleaner way to make that laziness rather than these explicit calls. The particular function which calls buildCompleted doesn’t seem clear. > Source/WebCore/css/CSSFontSelector.cpp:258 > + ASSERT(m_status == Status::Built); For maximum safety, I think this should call buildCompleted. > Source/WebCore/css/CSSFontSelector.h:91 > + enum class Status { > + Building, > + Built > + }; Something like this normally reads better on a single line. Might also be clearer as a boolean rather than am enum. > Source/WebCore/css/CSSFontSelector.h:106 > + PendingFontFaceRule(StyleRuleFontFace& styleRuleFontFace, bool isInitiatingElementInUserAgentShadowTree) > + : styleRuleFontFace(styleRuleFontFace) > + , isInitiatingElementInUserAgentShadowTree(isInitiatingElementInUserAgentShadowTree) > + { > + } Constructor seems unnecessary. Can just use struct initialization syntax. > Source/WebCore/css/CSSFontSelector.h:124 > + Status m_status { Status::Building }; Seems the status should start out as Built, not Building. I would have this be a boolean and call it something m_buildIsUnderway and have it default to false. > Source/WebCore/css/StyleResolver.cpp:289 > + // FIXME: We need a way to make sure that the first call to appendAuthorStyleSheets() is the one which > + // is rebuilding the CSSFontSelector's constituent fonts. > + document().fontSelector().buildCompleted(); Wow, this seems indirect. Is there any cleaner way to do this? Maybe we can just wait until someone calls fontRangesForFamily and do the work on demand then? Or is the earlier timing here important?
Myles C. Maxfield
Comment 8 2016-02-24 15:37:42 PST
I was talking with Ryosuke about this, and I'm no longer sure that this is the best way to go. Another alternative is to make CSSFontFace and FontFace have different lifetimes.
Myles C. Maxfield
Comment 9 2016-02-24 15:38:54 PST
The case Ryosuke brought up is when a page enters the page cache, we want to destroy as much as possible, including all these CSSFontFace objects (but the FontFace objects must stick around).
Myles C. Maxfield
Comment 10 2016-02-24 15:40:20 PST
If they have different lifetimes, there needs to be a discovery mechanism where a FontFace can find a CSSFontFace to route its calls to.
Myles C. Maxfield
Comment 11 2016-02-24 15:48:34 PST
It also means that newly recreated CSSFontFace objects need to discover what state they were in last. This seems difficult.
Myles C. Maxfield
Comment 12 2016-02-24 15:50:44 PST
This state rediscovery may actually cause an illegal state transition (if, for example, the backing bytes of the font are purged from the cache, it may make a font go from Success -> Pending)
Myles C. Maxfield
Comment 13 2016-02-24 16:37:53 PST
Maybe I should partition the CSSFontFaces into "purgeable" and "nonpurgeable" and put a CSSFontFace into the "nonpurgeable" bucket when it is accessed from script.
Myles C. Maxfield
Comment 14 2016-02-25 12:50:07 PST
Adding document.ensureStyleResolver() to resolveForDocument() may be necessary in this patch.
Myles C. Maxfield
Comment 15 2016-02-27 17:54:05 PST
Comment on attachment 272098 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=272098&action=review >> Source/WebCore/css/StyleResolver.cpp:289 >> + document().fontSelector().buildCompleted(); > > Wow, this seems indirect. Is there any cleaner way to do this? Maybe we can just wait until someone calls fontRangesForFamily and do the work on demand then? Or is the earlier timing here important? Actually, now that I look harder, it is now provable that the first call to appendAuthorStyleSheets is the one which is rebuilding the CSSFontSelector's constituent fonts.
Myles C. Maxfield
Comment 16 2016-02-27 21:13:04 PST
Comment on attachment 272098 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=272098&action=review >>> Source/WebCore/css/StyleResolver.cpp:289 >>> + document().fontSelector().buildCompleted(); >> >> Wow, this seems indirect. Is there any cleaner way to do this? Maybe we can just wait until someone calls fontRangesForFamily and do the work on demand then? Or is the earlier timing here important? > > Actually, now that I look harder, it is now provable that the first call to appendAuthorStyleSheets is the one which is rebuilding the CSSFontSelector's constituent fonts. The earlier timing is important to preserve the state of the FontFace JavaScript objects.
Myles C. Maxfield
Comment 17 2016-02-27 21:29:06 PST
Created attachment 272436 [details] Patch for Committing
Build Bot
Comment 18 2016-02-27 22:20:46 PST
Comment on attachment 272436 [details] Patch for Committing Attachment 272436 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/893855 New failing tests: editing/selection/drag-to-contenteditable-iframe.html
Build Bot
Comment 19 2016-02-27 22:20:49 PST
Created attachment 272438 [details] Archive of layout-test-results from ews103 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews103 Port: mac-yosemite Platform: Mac OS X 10.10.5
Build Bot
Comment 20 2016-02-27 22:42:32 PST
Comment on attachment 272436 [details] Patch for Committing Attachment 272436 [details] did not pass mac-debug-ews (mac): Output: http://webkit-queues.webkit.org/results/893867 New failing tests: editing/selection/drag-to-contenteditable-iframe.html
Build Bot
Comment 21 2016-02-27 22:42:36 PST
Created attachment 272440 [details] Archive of layout-test-results from ews114 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews114 Port: mac-yosemite Platform: Mac OS X 10.10.5
Myles C. Maxfield
Comment 22 2016-02-29 22:14:49 PST
Created attachment 272550 [details] Patch for committing
Myles C. Maxfield
Comment 23 2016-03-01 18:34:43 PST
WebKit Commit Bot
Comment 24 2016-03-02 10:49:16 PST
Re-opened since this is blocked by bug 154921
Ryan Haddad
Comment 25 2016-03-02 10:54:29 PST
Myles C. Maxfield
Comment 26 2016-06-07 00:26:37 PDT
Created attachment 280682 [details] Rebased patch
Myles C. Maxfield
Comment 27 2016-06-07 00:26:55 PDT
The crash can be reproduced by simply opening the following page: <style></style> <img sizes='1ex'>
Myles C. Maxfield
Comment 28 2016-06-07 21:55:43 PDT
(In reply to comment #27) > The crash can be reproduced by simply opening the following page: > > <style></style> > <img sizes='1ex'> The lengths in the "sizes" attribute are resolved against the document's style, which is hardcoded in resolveForDocument(). The size is hardcoded to "medium" (which equates to 16) and the family is hardcoded to "-webkit-standard". Therefore, using em's and ex's as units here is useless.
Myles C. Maxfield
Comment 29 2016-06-07 22:29:33 PDT
Created attachment 280772 [details] srcset sizes fix
Myles C. Maxfield
Comment 30 2016-06-07 23:04:49 PDT
Created attachment 280773 [details] Updated patch
WebKit Commit Bot
Comment 31 2016-06-08 00:58:54 PDT
Comment on attachment 280773 [details] Updated patch Clearing flags on attachment: 280773 Committed r201799: <http://trac.webkit.org/changeset/201799>
WebKit Commit Bot
Comment 32 2016-06-08 00:58:59 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 33 2017-06-19 14:17:49 PDT
Note You need to log in before you can comment on or make changes to this bug.