Changeset 233915 in webkit
- Timestamp:
- Jul 18, 2018 10:08:46 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r233910 r233915 1 2018-07-18 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Add SPI to defer running async script until after document load 4 https://bugs.webkit.org/show_bug.cgi?id=187748 5 <rdar://problem/42317378> 6 7 Reviewed by Ryosuke Niwa and Tim Horton. 8 9 On watchOS, we currently observe that time-consuming async scripts can block the first paint of Reader, leaving 10 the user with a blank screen for tens of seconds. One way to mitigate this is to defer async script execution 11 until after document load (i.e. the same timing as DOMContentLoaded). 12 13 This patch introduces an SPI configuration allowing internal clients to defer execution of asynchronous script 14 until after document load; this, in combination with the parser yielding token introduced in r233891, allows 15 Safari on watchOS to avoid being blocked on slow script execution before the first paint of the Reader page on 16 most article-like pages. See below for more details. 17 18 Test: RunScriptAfterDocumentLoad.ExecutionOrderOfScriptsInDocument 19 20 * dom/Document.cpp: 21 (WebCore::Document::shouldDeferAsynchronousScriptsUntilParsingFinishes const): 22 (WebCore::Document::finishedParsing): 23 24 Notify ScriptRunner when the Document has finished parsing, and is about to fire DOMContentLoaded. 25 26 * dom/Document.h: 27 * dom/ScriptRunner.cpp: 28 (WebCore::ScriptRunner::documentFinishedParsing): 29 30 When the document is finished parsing, kick off the script execution timer if needed to run any async script 31 that has been deferred. 32 33 (WebCore::ScriptRunner::notifyFinished): 34 (WebCore::ScriptRunner::timerFired): 35 36 Instead of always taking from the list of async scripts to execute, check our document to see whether we should 37 defer this until after document load. If so, ignore `m_scriptsToExecuteSoon`. 38 39 * dom/ScriptRunner.h: 40 * page/Settings.yaml: 41 42 Add a WebCore setting for this behavior. 43 1 44 2018-07-18 Zan Dobersek <zdobersek@igalia.com> 2 45 -
trunk/Source/WebCore/dom/Document.cpp
r233891 r233915 5194 5194 } 5195 5195 5196 bool Document::shouldDeferAsynchronousScriptsUntilParsingFinishes() const 5197 { 5198 return parsing() && settings().shouldDeferAsynchronousScriptsUntilAfterDocumentLoad(); 5199 } 5200 5196 5201 #if ENABLE(XSLT) 5197 5202 … … 5429 5434 5430 5435 Ref<Document> protectedThis(*this); 5436 5437 scriptRunner()->documentFinishedParsing(); 5431 5438 5432 5439 if (!m_documentTiming.domContentLoadedEventStart) -
trunk/Source/WebCore/dom/Document.h
r233891 r233915 992 992 void popCurrentScript(); 993 993 994 bool shouldDeferAsynchronousScriptsUntilParsingFinishes() const; 995 994 996 #if ENABLE(XSLT) 995 997 void scheduleToApplyXSLTransforms(); -
trunk/Source/WebCore/dom/ScriptRunner.cpp
r233891 r233915 87 87 } 88 88 89 void ScriptRunner::documentFinishedParsing() 90 { 91 if (!m_scriptsToExecuteSoon.isEmpty() && !m_timer.isActive()) 92 resume(); 93 } 94 89 95 void ScriptRunner::notifyFinished(PendingScript& pendingScript) 90 96 { … … 106 112 107 113 Vector<RefPtr<PendingScript>> scripts; 108 scripts.swap(m_scriptsToExecuteSoon); 114 115 if (!m_document.shouldDeferAsynchronousScriptsUntilParsingFinishes()) 116 scripts.swap(m_scriptsToExecuteSoon); 109 117 110 118 size_t numInOrderScriptsToExecute = 0; -
trunk/Source/WebCore/dom/ScriptRunner.h
r233891 r233915 54 54 void didEndYieldingParser() { resume(); } 55 55 56 void documentFinishedParsing(); 57 56 58 private: 57 59 void timerFired(); -
trunk/Source/WebCore/page/Settings.yaml
r233869 r233915 759 759 incompleteImageBorderEnabled: 760 760 initial: false 761 762 shouldDeferAsynchronousScriptsUntilAfterDocumentLoad: 763 initial: false -
trunk/Source/WebKit/ChangeLog
r233909 r233915 1 2018-07-18 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Add SPI to defer running async script until after document load 4 https://bugs.webkit.org/show_bug.cgi?id=187748 5 <rdar://problem/42317378> 6 7 Reviewed by Ryosuke Niwa and Tim Horton. 8 9 Add plumbing for a new ShouldDeferAsynchronousScriptsUntilAfterDocumentLoad configuration that determines 10 whether async script execution should be deferred until document load (i.e. DOMContentLoaded). This 11 configuration defaults to NO on all platforms. See WebCore ChangeLog for more detail. 12 13 * Shared/WebPreferences.yaml: 14 * UIProcess/API/Cocoa/WKWebView.mm: 15 (-[WKWebView _initializeWithConfiguration:]): 16 * UIProcess/API/Cocoa/WKWebViewConfiguration.mm: 17 (-[WKWebViewConfiguration init]): 18 (-[WKWebViewConfiguration copyWithZone:]): 19 (-[WKWebViewConfiguration _shouldDeferAsynchronousScriptsUntilAfterDocumentLoad]): 20 (-[WKWebViewConfiguration _setShouldDeferAsynchronousScriptsUntilAfterDocumentLoad:]): 21 * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h: 22 1 23 2018-07-18 Zan Dobersek <zdobersek@igalia.com> 2 24 -
trunk/Source/WebKit/Shared/WebPreferences.yaml
r233869 r233915 1090 1090 1091 1091 IncompleteImageBorderEnabled: 1092 type: bool 1093 defaultValue: false 1094 1095 ShouldDeferAsynchronousScriptsUntilAfterDocumentLoad: 1092 1096 type: bool 1093 1097 defaultValue: false -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r233905 r233915 548 548 pageConfiguration->setControlledByAutomation([_configuration _isControlledByAutomation]); 549 549 pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::incompleteImageBorderEnabledKey(), WebKit::WebPreferencesStore::Value(!![_configuration _incompleteImageBorderEnabled])); 550 pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::shouldDeferAsynchronousScriptsUntilAfterDocumentLoadKey(), WebKit::WebPreferencesStore::Value(!![_configuration _shouldDeferAsynchronousScriptsUntilAfterDocumentLoad])); 550 551 551 552 #if ENABLE(APPLICATION_MANIFEST) -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm
r233828 r233915 165 165 BOOL _colorFilterEnabled; 166 166 BOOL _incompleteImageBorderEnabled; 167 BOOL _shouldDeferAsynchronousScriptsUntilAfterDocumentLoad; 167 168 BOOL _drawsBackground; 168 169 … … 251 252 _colorFilterEnabled = NO; 252 253 _incompleteImageBorderEnabled = NO; 254 _shouldDeferAsynchronousScriptsUntilAfterDocumentLoad = NO; 253 255 _drawsBackground = YES; 254 256 … … 415 417 configuration->_colorFilterEnabled = self->_colorFilterEnabled; 416 418 configuration->_incompleteImageBorderEnabled = self->_incompleteImageBorderEnabled; 419 configuration->_shouldDeferAsynchronousScriptsUntilAfterDocumentLoad = self->_shouldDeferAsynchronousScriptsUntilAfterDocumentLoad; 417 420 configuration->_drawsBackground = self->_drawsBackground; 418 421 … … 783 786 { 784 787 _incompleteImageBorderEnabled = incompleteImageBorderEnabled; 788 } 789 790 - (BOOL)_shouldDeferAsynchronousScriptsUntilAfterDocumentLoad 791 { 792 return _shouldDeferAsynchronousScriptsUntilAfterDocumentLoad; 793 } 794 795 - (void)_setShouldDeferAsynchronousScriptsUntilAfterDocumentLoad:(BOOL)shouldDeferAsynchronousScriptsUntilAfterDocumentLoad 796 { 797 _shouldDeferAsynchronousScriptsUntilAfterDocumentLoad = shouldDeferAsynchronousScriptsUntilAfterDocumentLoad; 785 798 } 786 799 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h
r233828 r233915 74 74 @property (nonatomic, setter=_setIncompleteImageBorderEnabled:) BOOL _incompleteImageBorderEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 75 75 @property (nonatomic, setter=_setDrawsBackground:) BOOL _drawsBackground WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 76 @property (nonatomic, setter=_setShouldDeferAsynchronousScriptsUntilAfterDocumentLoad:) BOOL _shouldDeferAsynchronousScriptsUntilAfterDocumentLoad WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 76 77 77 78 #if TARGET_OS_IPHONE -
trunk/Tools/ChangeLog
r233914 r233915 1 2018-07-18 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Add SPI to defer running async script until after document load 4 https://bugs.webkit.org/show_bug.cgi?id=187748 5 <rdar://problem/42317378> 6 7 Reviewed by Ryosuke Niwa and Tim Horton. 8 9 Add an API test to verify that when the deferred async script configuration is set, async scripts will be 10 executed after the DOMContentLoaded event. 11 12 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 13 * TestWebKitAPI/Tests/WebKitCocoa/RunScriptAfterDocumentLoad.mm: Added. 14 (TEST): 15 1 16 2018-07-18 Charlie Turner <cturner@igalia.com> 2 17 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r233891 r233915 817 817 F4CD74C620FDACFA00DE3794 /* text-with-async-script.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4CD74C520FDACF500DE3794 /* text-with-async-script.html */; }; 818 818 F4CD74C920FDB49600DE3794 /* TestURLSchemeHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4CD74C820FDB49600DE3794 /* TestURLSchemeHandler.mm */; }; 819 F4D2986E20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D2986D20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm */; }; 819 820 F4D4F3B61E4E2BCB00BB2767 /* DataInteractionSimulator.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B41E4E2BCB00BB2767 /* DataInteractionSimulator.mm */; }; 820 821 F4D4F3B91E4E36E400BB2767 /* DataInteractionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B71E4E36E400BB2767 /* DataInteractionTests.mm */; }; … … 2025 2026 F4CD74C720FDB49600DE3794 /* TestURLSchemeHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestURLSchemeHandler.h; sourceTree = "<group>"; }; 2026 2027 F4CD74C820FDB49600DE3794 /* TestURLSchemeHandler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TestURLSchemeHandler.mm; sourceTree = "<group>"; }; 2028 F4D2986D20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RunScriptAfterDocumentLoad.mm; sourceTree = "<group>"; }; 2027 2029 F4D4F3B41E4E2BCB00BB2767 /* DataInteractionSimulator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataInteractionSimulator.mm; sourceTree = "<group>"; }; 2028 2030 F4D4F3B51E4E2BCB00BB2767 /* DataInteractionSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataInteractionSimulator.h; sourceTree = "<group>"; }; … … 2313 2315 51C8E1A41F26AC5400BF731B /* ResourceLoadStatistics.mm */, 2314 2316 A180C0F91EE67DF000468F47 /* RunOpenPanel.mm */, 2317 F4D2986D20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm */, 2315 2318 CE0947362063223B003C9BA0 /* SchemeRegistry.mm */, 2316 2319 51EB12931FDF050500A5A1BD /* ServiceWorkerBasic.mm */, … … 3825 3828 F418BE151F71B7DC001970E6 /* RoundedRectTests.cpp in Sources */, 3826 3829 A180C0FA1EE67DF000468F47 /* RunOpenPanel.mm in Sources */, 3830 F4D2986E20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm in Sources */, 3827 3831 CDCFA7AA1E45183200C2433D /* SampleMap.cpp in Sources */, 3828 3832 CE0947372063223B003C9BA0 /* SchemeRegistry.mm in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.