Title: [234111] trunk
Revision
234111
Author
cdu...@apple.com
Date
2018-07-23 13:59:58 -0700 (Mon, 23 Jul 2018)

Log Message

WebResourceLoadStatisticsStore fails to unregister itself as a MessageReceiver in its destructor
https://bugs.webkit.org/show_bug.cgi?id=187910
<rdar://problem/42356526>

Reviewed by Brent Fulgham.

Source/WebCore:

Add internals API that causes the ResourceLoadObserver to notify its observer, and avoid waiting
for the 5 second delay.

* testing/Internals.cpp:
(WebCore::Internals::notifyResourceLoadObserver):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

The WebResourceLoadStatisticsStore was only removing itself as a MessageReceiver from the WebProcessProxy
and that WebProcessProxy's connection was getting closed. However, it is possible for the
WebResourceLoadStatisticsStore to get destroyed before this happens. This would lead to crashes such as
the one in <rdar://problem/42356526>.

To address the issue, we let the WebsiteDataStore take care of registering / unregistering the
WebResourceLoadStatisticsStore as a MessageReceiver with the WebProcessProxy. This is more reliable since
the WebsiteDataStore is the one that subclasses WebProcessLifetimeObserver. Make sure the
WebResourceLoadStatisticsStore is removed as a MessageReceiver whenever the WebsiteDataStore is destroyed
or WebsiteDataStore::m_resourceLoadStatistics gets cleared.

* UIProcess/WebResourceLoadStatisticsStore.cpp:
* UIProcess/WebResourceLoadStatisticsStore.h:
Drop logic to add / remove the WebResourceLoadStatisticsStore as a receiver now that the
WebsiteDataStore takes care of it.

* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::~WebsiteDataStore):
Make sure the WebResourceLoadStatisticsStore gets unregistered as a MessageReceiver from all associated
WebProcessProxy objects when the WebsiteDataStore gets destroyed.

(WebKit::WebsiteDataStore::webProcessWillOpenConnection):
(WebKit::WebsiteDataStore::webProcessDidCloseConnection):
Register / Unregister the WebResourceLoadStatisticsStore as a MessageReceiver with the WebProcessProxy.

(WebKit::WebsiteDataStore::setResourceLoadStatisticsEnabled):
Make sure we unregister the WebResourceLoadStatisticsStore as a MessageReceiver with all associated
WebProcessProxy objects before we clear m_resourceLoadStatistics as this will causes the
WebResourceLoadStatisticsStore to get destroyed.

(WebKit::WebsiteDataStore::unregisterWebResourceLoadStatisticsStoreAsMessageReceiver):
(WebKit::WebsiteDataStore::registerWebResourceLoadStatisticsStoreAsMessageReceiver):
Add utility functions to register / unregister WebResourceLoadStatisticsStore as a MessageReceiver with
all associated WebProcessProxy objects.

(WebKit::WebsiteDataStore::enableResourceLoadStatisticsAndSetTestingCallback):
Register the new WebResourceLoadStatisticsStore as a MessageReceiver with all associated WebProcessProxy
objects in case setResourceLoadStatisticsEnabled(true) gets called *after* we've already started
WebProcesses.

* UIProcess/WebsiteData/WebsiteDataStore.h:

Tools:

Add API test coverage.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm:
(-[DisableITPDuringNavigationDelegate webView:didCommitNavigation:]):
(-[DisableITPDuringNavigationDelegate webView:didFinishNavigation:]):
(TEST):
* TestWebKitAPI/Tests/WebKitCocoa/notify-resourceLoadObserver.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (234110 => 234111)


--- trunk/Source/WebCore/ChangeLog	2018-07-23 20:30:35 UTC (rev 234110)
+++ trunk/Source/WebCore/ChangeLog	2018-07-23 20:59:58 UTC (rev 234111)
@@ -1,3 +1,19 @@
+2018-07-23  Chris Dumez  <cdu...@apple.com>
+
+        WebResourceLoadStatisticsStore fails to unregister itself as a MessageReceiver in its destructor
+        https://bugs.webkit.org/show_bug.cgi?id=187910
+        <rdar://problem/42356526>
+
+        Reviewed by Brent Fulgham.
+
+        Add internals API that causes the ResourceLoadObserver to notify its observer, and avoid waiting
+        for the 5 second delay.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::notifyResourceLoadObserver):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2018-07-23  Zalan Bujtas  <za...@apple.com>
 
         [LCF][IFC] Add support for hyphenation.

Modified: trunk/Source/WebCore/testing/Internals.cpp (234110 => 234111)


--- trunk/Source/WebCore/testing/Internals.cpp	2018-07-23 20:30:35 UTC (rev 234110)
+++ trunk/Source/WebCore/testing/Internals.cpp	2018-07-23 20:59:58 UTC (rev 234111)
@@ -4633,4 +4633,9 @@
     return contextDocument()->page()->pluginData().webVisiblePlugins().size();
 }
 
+void Internals::notifyResourceLoadObserver()
+{
+    ResourceLoadObserver::shared().notifyObserver();
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/testing/Internals.h (234110 => 234111)


--- trunk/Source/WebCore/testing/Internals.h	2018-07-23 20:30:35 UTC (rev 234110)
+++ trunk/Source/WebCore/testing/Internals.h	2018-07-23 20:59:58 UTC (rev 234111)
@@ -718,6 +718,8 @@
 
     size_t pluginCount();
 
+    void notifyResourceLoadObserver();
+
 private:
     explicit Internals(Document&);
     Document* contextDocument() const;

Modified: trunk/Source/WebCore/testing/Internals.idl (234110 => 234111)


--- trunk/Source/WebCore/testing/Internals.idl	2018-07-23 20:30:35 UTC (rev 234110)
+++ trunk/Source/WebCore/testing/Internals.idl	2018-07-23 20:59:58 UTC (rev 234111)
@@ -654,4 +654,6 @@
     void setUseSystemAppearance(boolean value);
 
     unsigned long pluginCount();
+
+    void notifyResourceLoadObserver();
 };

Modified: trunk/Source/WebKit/ChangeLog (234110 => 234111)


--- trunk/Source/WebKit/ChangeLog	2018-07-23 20:30:35 UTC (rev 234110)
+++ trunk/Source/WebKit/ChangeLog	2018-07-23 20:59:58 UTC (rev 234111)
@@ -1,3 +1,53 @@
+2018-07-23  Chris Dumez  <cdu...@apple.com>
+
+        WebResourceLoadStatisticsStore fails to unregister itself as a MessageReceiver in its destructor
+        https://bugs.webkit.org/show_bug.cgi?id=187910
+        <rdar://problem/42356526>
+
+        Reviewed by Brent Fulgham.
+
+        The WebResourceLoadStatisticsStore was only removing itself as a MessageReceiver from the WebProcessProxy
+        and that WebProcessProxy's connection was getting closed. However, it is possible for the
+        WebResourceLoadStatisticsStore to get destroyed before this happens. This would lead to crashes such as
+        the one in <rdar://problem/42356526>.
+
+        To address the issue, we let the WebsiteDataStore take care of registering / unregistering the
+        WebResourceLoadStatisticsStore as a MessageReceiver with the WebProcessProxy. This is more reliable since
+        the WebsiteDataStore is the one that subclasses WebProcessLifetimeObserver. Make sure the
+        WebResourceLoadStatisticsStore is removed as a MessageReceiver whenever the WebsiteDataStore is destroyed
+        or WebsiteDataStore::m_resourceLoadStatistics gets cleared.
+
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        * UIProcess/WebResourceLoadStatisticsStore.h:
+        Drop logic to add / remove the WebResourceLoadStatisticsStore as a receiver now that the
+        WebsiteDataStore takes care of it.
+
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::~WebsiteDataStore):
+        Make sure the WebResourceLoadStatisticsStore gets unregistered as a MessageReceiver from all associated
+        WebProcessProxy objects when the WebsiteDataStore gets destroyed.
+
+        (WebKit::WebsiteDataStore::webProcessWillOpenConnection):
+        (WebKit::WebsiteDataStore::webProcessDidCloseConnection):
+        Register / Unregister the WebResourceLoadStatisticsStore as a MessageReceiver with the WebProcessProxy.
+
+        (WebKit::WebsiteDataStore::setResourceLoadStatisticsEnabled):
+        Make sure we unregister the WebResourceLoadStatisticsStore as a MessageReceiver with all associated
+        WebProcessProxy objects before we clear m_resourceLoadStatistics as this will causes the
+        WebResourceLoadStatisticsStore to get destroyed.
+
+        (WebKit::WebsiteDataStore::unregisterWebResourceLoadStatisticsStoreAsMessageReceiver):
+        (WebKit::WebsiteDataStore::registerWebResourceLoadStatisticsStoreAsMessageReceiver):
+        Add utility functions to register / unregister WebResourceLoadStatisticsStore as a MessageReceiver with
+        all associated WebProcessProxy objects.
+
+        (WebKit::WebsiteDataStore::enableResourceLoadStatisticsAndSetTestingCallback):
+        Register the new WebResourceLoadStatisticsStore as a MessageReceiver with all associated WebProcessProxy
+        objects in case setResourceLoadStatisticsEnabled(true) gets called *after* we've already started
+        WebProcesses.
+
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+
 2018-07-23  John Wilander  <wilan...@apple.com>
 
         Resource Load Statistics: Add logging of Storage Access API use in experimental debug mode

Modified: trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp (234110 => 234111)


--- trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp	2018-07-23 20:30:35 UTC (rev 234110)
+++ trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp	2018-07-23 20:59:58 UTC (rev 234111)
@@ -343,17 +343,6 @@
 #endif
 }
 
-
-void WebResourceLoadStatisticsStore::processWillOpenConnection(WebProcessProxy& process, IPC::Connection&)
-{
-    process.addMessageReceiver(Messages::WebResourceLoadStatisticsStore::messageReceiverName(), *this);
-}
-
-void WebResourceLoadStatisticsStore::processDidCloseConnection(WebProcessProxy& process, IPC::Connection&)
-{
-    process.removeMessageReceiver(Messages::WebResourceLoadStatisticsStore::messageReceiverName());
-}
-
 void WebResourceLoadStatisticsStore::applicationWillTerminate()
 {
     flushAndDestroyPersistentStore();

Modified: trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h (234110 => 234111)


--- trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h	2018-07-23 20:30:35 UTC (rev 234110)
+++ trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h	2018-07-23 20:59:58 UTC (rev 234111)
@@ -60,7 +60,7 @@
     HasAccess
 };
 
-class WebResourceLoadStatisticsStore final : public ThreadSafeRefCounted<WebResourceLoadStatisticsStore, WTF::DestructionThread::Main>, private IPC::MessageReceiver {
+class WebResourceLoadStatisticsStore final : public ThreadSafeRefCounted<WebResourceLoadStatisticsStore, WTF::DestructionThread::Main>, public IPC::MessageReceiver {
 public:
     static Ref<WebResourceLoadStatisticsStore> create(WebsiteDataStore& websiteDataStore)
     {
@@ -82,8 +82,6 @@
     void grantStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool userWasPromptedNow, CompletionHandler<void(bool)>&&);
     void requestStorageAccessCallback(bool wasGranted, uint64_t contextId);
 
-    void processWillOpenConnection(WebProcessProxy&, IPC::Connection&);
-    void processDidCloseConnection(WebProcessProxy&, IPC::Connection&);
     void applicationWillTerminate();
 
     void logFrameNavigation(const WebFrameProxy&, const WebCore::URL& pageURL, const WebCore::ResourceRequest&, const WebCore::URL& redirectURL);

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (234110 => 234111)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2018-07-23 20:30:35 UTC (rev 234110)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2018-07-23 20:59:58 UTC (rev 234111)
@@ -121,6 +121,8 @@
 
     platformDestroy();
 
+    unregisterWebResourceLoadStatisticsStoreAsMessageReceiver();
+
     if (m_sessionID.isValid() && m_sessionID != PAL::SessionID::defaultSessionID()) {
         ASSERT(nonDefaultDataStores().get(m_sessionID) == this);
         nonDefaultDataStores().remove(m_sessionID);
@@ -1349,7 +1351,7 @@
         m_storageManager->processWillOpenConnection(webProcessProxy, connection);
 
     if (m_resourceLoadStatistics)
-        m_resourceLoadStatistics->processWillOpenConnection(webProcessProxy, connection);
+        webProcessProxy.addMessageReceiver(Messages::WebResourceLoadStatisticsStore::messageReceiverName(), *m_resourceLoadStatistics);
 }
 
 void WebsiteDataStore::webPageWillOpenConnection(WebPageProxy& webPageProxy, IPC::Connection& connection)
@@ -1367,7 +1369,7 @@
 void WebsiteDataStore::webProcessDidCloseConnection(WebProcessProxy& webProcessProxy, IPC::Connection& connection)
 {
     if (m_resourceLoadStatistics)
-        m_resourceLoadStatistics->processDidCloseConnection(webProcessProxy, connection);
+        webProcessProxy.removeMessageReceiver(Messages::WebResourceLoadStatisticsStore::messageReceiverName());
 
     if (m_storageManager)
         m_storageManager->processDidCloseConnection(webProcessProxy, connection);
@@ -1494,6 +1496,8 @@
         return;
     }
 
+
+    unregisterWebResourceLoadStatisticsStoreAsMessageReceiver();
     m_resourceLoadStatistics = nullptr;
 
     auto existingProcessPools = processPools(std::numeric_limits<size_t>::max(), false);
@@ -1501,6 +1505,25 @@
         processPool->setResourceLoadStatisticsEnabled(false);
 }
 
+void WebsiteDataStore::unregisterWebResourceLoadStatisticsStoreAsMessageReceiver()
+{
+    if (!m_resourceLoadStatistics)
+        return;
+
+    for (auto* webProcessProxy : processes())
+        webProcessProxy->removeMessageReceiver(Messages::WebResourceLoadStatisticsStore::messageReceiverName());
+}
+
+void WebsiteDataStore::registerWebResourceLoadStatisticsStoreAsMessageReceiver()
+{
+    ASSERT(m_resourceLoadStatistics);
+    if (!m_resourceLoadStatistics)
+        return;
+
+    for (auto* webProcessProxy : processes())
+        webProcessProxy->addMessageReceiver(Messages::WebResourceLoadStatisticsStore::messageReceiverName(), *m_resourceLoadStatistics);
+}
+
 bool WebsiteDataStore::resourceLoadStatisticsDebugMode() const
 {
     return m_resourceLoadStatisticsDebugMode;
@@ -1533,6 +1556,8 @@
     m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(*this);
     m_resourceLoadStatistics->setStatisticsTestingCallback(WTFMove(callback));
 
+    registerWebResourceLoadStatisticsStoreAsMessageReceiver();
+
     for (auto& processPool : processPools(std::numeric_limits<size_t>::max(), false))
         processPool->setResourceLoadStatisticsEnabled(true);
 }

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (234110 => 234111)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2018-07-23 20:30:35 UTC (rev 234110)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2018-07-23 20:59:58 UTC (rev 234111)
@@ -203,6 +203,9 @@
     void platformDestroy();
     static void platformRemoveRecentSearches(WallTime);
 
+    void registerWebResourceLoadStatisticsStoreAsMessageReceiver();
+    void unregisterWebResourceLoadStatisticsStoreAsMessageReceiver();
+
     HashSet<RefPtr<WebProcessPool>> processPools(size_t count = std::numeric_limits<size_t>::max(), bool ensureAPoolExists = true) const;
 
 #if ENABLE(NETSCAPE_PLUGIN_API)

Modified: trunk/Tools/ChangeLog (234110 => 234111)


--- trunk/Tools/ChangeLog	2018-07-23 20:30:35 UTC (rev 234110)
+++ trunk/Tools/ChangeLog	2018-07-23 20:59:58 UTC (rev 234111)
@@ -1,3 +1,20 @@
+2018-07-23  Chris Dumez  <cdu...@apple.com>
+
+        WebResourceLoadStatisticsStore fails to unregister itself as a MessageReceiver in its destructor
+        https://bugs.webkit.org/show_bug.cgi?id=187910
+        <rdar://problem/42356526>
+
+        Reviewed by Brent Fulgham.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm:
+        (-[DisableITPDuringNavigationDelegate webView:didCommitNavigation:]):
+        (-[DisableITPDuringNavigationDelegate webView:didFinishNavigation:]):
+        (TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/notify-resourceLoadObserver.html: Added.
+
 2018-07-23  Daniel Bates  <daba...@apple.com>
 
         test-webkitpy should take configuration command line options

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (234110 => 234111)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-07-23 20:30:35 UTC (rev 234110)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-07-23 20:59:58 UTC (rev 234111)
@@ -159,6 +159,7 @@
 		448D7E471EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */; };
 		46397B951DC2C850009A78AE /* DOMNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46397B941DC2C850009A78AE /* DOMNode.mm */; };
 		4647B1261EBA3B850041D7EF /* ProcessDidTerminate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4647B1251EBA3B730041D7EF /* ProcessDidTerminate.cpp */; };
+		466C3843210637DE006A88DE /* notify-resourceLoadObserver.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 466C3842210637CE006A88DE /* notify-resourceLoadObserver.html */; };
 		46AE5A3720F9066D00E0873E /* SimpleServiceWorkerRegistrations-3.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4656A75720F9054F0002E21F /* SimpleServiceWorkerRegistrations-3.sqlite3 */; };
 		46C519DA1D355AB200DAA51A /* LocalStorageNullEntries.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46C519D81D355A7300DAA51A /* LocalStorageNullEntries.mm */; };
 		46C519E61D3563FD00DAA51A /* LocalStorageNullEntries.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 46C519E21D35629600DAA51A /* LocalStorageNullEntries.html */; };
@@ -1094,6 +1095,7 @@
 				9BF356CD202D458500F71160 /* mso-list.html in Copy Resources */,
 				5797FE331EB15AB100B2F4A0 /* navigation-client-default-crypto.html in Copy Resources */,
 				C99B675F1E39736F00FC6C80 /* no-autoplay-with-controls.html in Copy Resources */,
+				466C3843210637DE006A88DE /* notify-resourceLoadObserver.html in Copy Resources */,
 				93E2D2761ED7D53200FA76F6 /* offscreen-iframe-of-media-document.html in Copy Resources */,
 				CEA6CF2819CCF69D0064F5A7 /* open-and-close-window.html in Copy Resources */,
 				7CCB99231D3B4A46003922F6 /* open-multiple-external-url.html in Copy Resources */,
@@ -1397,6 +1399,7 @@
 		46397B941DC2C850009A78AE /* DOMNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMNode.mm; sourceTree = "<group>"; };
 		4647B1251EBA3B730041D7EF /* ProcessDidTerminate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProcessDidTerminate.cpp; sourceTree = "<group>"; };
 		4656A75720F9054F0002E21F /* SimpleServiceWorkerRegistrations-3.sqlite3 */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SimpleServiceWorkerRegistrations-3.sqlite3"; sourceTree = "<group>"; };
+		466C3842210637CE006A88DE /* notify-resourceLoadObserver.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "notify-resourceLoadObserver.html"; sourceTree = "<group>"; };
 		46C519D81D355A7300DAA51A /* LocalStorageNullEntries.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalStorageNullEntries.mm; sourceTree = "<group>"; };
 		46C519E21D35629600DAA51A /* LocalStorageNullEntries.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = LocalStorageNullEntries.html; sourceTree = "<group>"; };
 		46C519E31D35629600DAA51A /* LocalStorageNullEntries.localstorage */ = {isa = PBXFileReference; lastKnownFileType = file; path = LocalStorageNullEntries.localstorage; sourceTree = "<group>"; };
@@ -2574,9 +2577,9 @@
 				9984FACD1CFFB038008D198C /* editable-body.html */,
 				F44D06441F395C0D001A0E29 /* editor-state-test-harness.html */,
 				51C8E1A81F27F47300BF731B /* EmptyGrandfatheredResourceLoadStatistics.plist */,
-				CDA29B2A20FD344E00F15CED /* ExitFullscreenOnEnterPiP.html */,
 				F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */,
 				F407FE381F1D0DE60017CF25 /* enormous.svg */,
+				CDA29B2A20FD344E00F15CED /* ExitFullscreenOnEnterPiP.html */,
 				F41AB99B1EF4692C0083FA08 /* file-uploading.html */,
 				A17EAC542083056E0084B41B /* find.pdf */,
 				F43E3BC020DADB8000A4E7ED /* fixed-nav-bar.html */,
@@ -2644,6 +2647,7 @@
 				9B59F12920340854009E63D5 /* mso-list-compat-mode.html */,
 				9BCD4119206D5ED7001D71BE /* mso-list-on-h4.html */,
 				9BF356CC202D44F200F71160 /* mso-list.html */,
+				466C3842210637CE006A88DE /* notify-resourceLoadObserver.html */,
 				93E2D2751ED7D51700FA76F6 /* offscreen-iframe-of-media-document.html */,
 				7CCB99221D3B44E7003922F6 /* open-multiple-external-url.html */,
 				CEBCA1341E3A803400C73293 /* page-with-csp-iframe.html */,
@@ -3667,6 +3671,7 @@
 				7CCE7EEF1A411AE600447C4C /* EphemeralSessionPushStateNoHistoryCallback.cpp in Sources */,
 				7CCE7EF01A411AE600447C4C /* EvaluateJavaScript.cpp in Sources */,
 				5C7964101EB0278D0075D74C /* EventModifiers.cpp in Sources */,
+				CDA29B2920FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm in Sources */,
 				315118101DB1AE4000176304 /* ExtendedColor.cpp in Sources */,
 				7CCE7EF11A411AE600447C4C /* FailedLoad.cpp in Sources */,
 				7A32D74A1F02151500162C44 /* FileMonitor.cpp in Sources */,
@@ -3814,7 +3819,6 @@
 				518C1153205B0504001FF4AE /* ProcessSwapOnNavigation.mm in Sources */,
 				7C83E0C11D0A652F00FEBCF3 /* ProvisionalURLNotChange.mm in Sources */,
 				7CCE7EC81A411A7E00447C4C /* PublicSuffix.mm in Sources */,
-				CDA29B2920FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm in Sources */,
 				7C83E0C21D0A653500FEBCF3 /* QuickLook.mm in Sources */,
 				7CCE7F0D1A411AE600447C4C /* ReloadPageAfterCrash.cpp in Sources */,
 				7C83E0C31D0A653A00FEBCF3 /* RemoteObjectRegistry.mm in Sources */,

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm (234110 => 234111)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm	2018-07-23 20:30:35 UTC (rev 234110)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm	2018-07-23 20:59:58 UTC (rev 234111)
@@ -28,6 +28,7 @@
 #import "PlatformUtilities.h"
 #import <WebKit/WKFoundation.h>
 #import <WebKit/WKProcessPoolPrivate.h>
+#import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/WKWebsiteDataRecordPrivate.h>
 #import <WebKit/WKWebsiteDataStorePrivate.h>
 #import <wtf/RetainPtr.h>
@@ -34,6 +35,26 @@
 
 #if WK_API_ENABLED
 
+static bool finishedNavigation = false;
+
+@interface DisableITPDuringNavigationDelegate : NSObject <WKNavigationDelegate>
+@end
+
+@implementation DisableITPDuringNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation
+{
+    // Disable ITP so that the WebResourceLoadStatisticsStore gets destroyed before its has a chance to receive the notification from the page.
+    [[WKWebsiteDataStore defaultDataStore] _setResourceLoadStatisticsEnabled:NO];
+}
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    finishedNavigation = true;
+}
+
+@end
+
 TEST(ResourceLoadStatistics, GrandfatherCallback)
 {
     auto *dataStore = [WKWebsiteDataStore defaultDataStore];
@@ -152,5 +173,27 @@
     EXPECT_EQ((size_t)0, [sharedProcessPool _pluginProcessCount]);
 }
 
+TEST(ResourceLoadStatistics, IPCAfterStoreDestruction)
+{
+    [[WKWebsiteDataStore defaultDataStore] _setResourceLoadStatisticsEnabled:YES];
+
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+
+    // Test page requires window.internals.
+#if WK_HAVE_C_SPI
+    WKRetainPtr<WKContextRef> context(AdoptWK, TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
+    configuration.get().processPool = (WKProcessPool *)context.get();
 #endif
 
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    auto navigationDelegate = adoptNS([[DisableITPDuringNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:navigationDelegate.get()];
+
+    [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"notify-resourceLoadObserver" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+
+    TestWebKitAPI::Util::run(&finishedNavigation);
+}
+
+#endif
+

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/notify-resourceLoadObserver.html (0 => 234111)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/notify-resourceLoadObserver.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/notify-resourceLoadObserver.html	2018-07-23 20:59:58 UTC (rev 234111)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script>
+    internals.notifyResourceLoadObserver();
+</script>
+</body>
+</html>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to