Title: [234236] branches/safari-606-branch
Revision
234236
Author
[email protected]
Date
2018-07-26 00:14:43 -0700 (Thu, 26 Jul 2018)

Log Message

Cherry-pick r234111. rdar://problem/42604691

    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.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234111 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-606-branch/Source/WebCore/ChangeLog (234235 => 234236)


--- branches/safari-606-branch/Source/WebCore/ChangeLog	2018-07-26 07:14:37 UTC (rev 234235)
+++ branches/safari-606-branch/Source/WebCore/ChangeLog	2018-07-26 07:14:43 UTC (rev 234236)
@@ -1,5 +1,98 @@
 2018-07-25  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r234111. rdar://problem/42604691
+
+    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.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234111 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-07-23  Chris Dumez  <[email protected]>
+
+            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-25  Babak Shafiei  <[email protected]>
+
         Cherry-pick r234098. rdar://problem/42507862
 
     fullscreen env() variables should have initial values

Modified: branches/safari-606-branch/Source/WebCore/testing/Internals.cpp (234235 => 234236)


--- branches/safari-606-branch/Source/WebCore/testing/Internals.cpp	2018-07-26 07:14:37 UTC (rev 234235)
+++ branches/safari-606-branch/Source/WebCore/testing/Internals.cpp	2018-07-26 07:14:43 UTC (rev 234236)
@@ -4633,4 +4633,9 @@
     return contextDocument()->page()->pluginData().webVisiblePlugins().size();
 }
 
+void Internals::notifyResourceLoadObserver()
+{
+    ResourceLoadObserver::shared().notifyObserver();
+}
+
 } // namespace WebCore

Modified: branches/safari-606-branch/Source/WebCore/testing/Internals.h (234235 => 234236)


--- branches/safari-606-branch/Source/WebCore/testing/Internals.h	2018-07-26 07:14:37 UTC (rev 234235)
+++ branches/safari-606-branch/Source/WebCore/testing/Internals.h	2018-07-26 07:14:43 UTC (rev 234236)
@@ -718,6 +718,8 @@
 
     size_t pluginCount();
 
+    void notifyResourceLoadObserver();
+
 private:
     explicit Internals(Document&);
     Document* contextDocument() const;

Modified: branches/safari-606-branch/Source/WebCore/testing/Internals.idl (234235 => 234236)


--- branches/safari-606-branch/Source/WebCore/testing/Internals.idl	2018-07-26 07:14:37 UTC (rev 234235)
+++ branches/safari-606-branch/Source/WebCore/testing/Internals.idl	2018-07-26 07:14:43 UTC (rev 234236)
@@ -654,4 +654,6 @@
     void setUseSystemAppearance(boolean value);
 
     unsigned long pluginCount();
+
+    void notifyResourceLoadObserver();
 };

Modified: branches/safari-606-branch/Source/WebKit/ChangeLog (234235 => 234236)


--- branches/safari-606-branch/Source/WebKit/ChangeLog	2018-07-26 07:14:37 UTC (rev 234235)
+++ branches/safari-606-branch/Source/WebKit/ChangeLog	2018-07-26 07:14:43 UTC (rev 234236)
@@ -1,5 +1,132 @@
 2018-07-25  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r234111. rdar://problem/42604691
+
+    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.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234111 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-07-23  Chris Dumez  <[email protected]>
+
+            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-25  Babak Shafiei  <[email protected]>
+
         Cherry-pick r234067. rdar://problem/42451597
 
     Occasional crash under -[WKFormInputSession setSuggestions:]

Modified: branches/safari-606-branch/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp (234235 => 234236)


--- branches/safari-606-branch/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp	2018-07-26 07:14:37 UTC (rev 234235)
+++ branches/safari-606-branch/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp	2018-07-26 07:14:43 UTC (rev 234236)
@@ -327,17 +327,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: branches/safari-606-branch/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h (234235 => 234236)


--- branches/safari-606-branch/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h	2018-07-26 07:14:37 UTC (rev 234235)
+++ branches/safari-606-branch/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h	2018-07-26 07:14:43 UTC (rev 234236)
@@ -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: branches/safari-606-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (234235 => 234236)


--- branches/safari-606-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2018-07-26 07:14:37 UTC (rev 234235)
+++ branches/safari-606-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2018-07-26 07:14:43 UTC (rev 234236)
@@ -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;
@@ -1526,6 +1549,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: branches/safari-606-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (234235 => 234236)


--- branches/safari-606-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2018-07-26 07:14:37 UTC (rev 234235)
+++ branches/safari-606-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2018-07-26 07:14:43 UTC (rev 234236)
@@ -202,6 +202,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: branches/safari-606-branch/Tools/ChangeLog (234235 => 234236)


--- branches/safari-606-branch/Tools/ChangeLog	2018-07-26 07:14:37 UTC (rev 234235)
+++ branches/safari-606-branch/Tools/ChangeLog	2018-07-26 07:14:43 UTC (rev 234236)
@@ -1,5 +1,99 @@
 2018-07-25  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r234111. rdar://problem/42604691
+
+    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.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234111 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-07-23  Chris Dumez  <[email protected]>
+
+            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-25  Babak Shafiei  <[email protected]>
+
         Cherry-pick r234064. rdar://problem/42451634
 
     Picking a color from the color panel for typing attributes needs to inverse transform through color-filter

Modified: branches/safari-606-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (234235 => 234236)


--- branches/safari-606-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-07-26 07:14:37 UTC (rev 234235)
+++ branches/safari-606-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-07-26 07:14:43 UTC (rev 234236)
@@ -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 */; };
@@ -1091,6 +1092,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 */,
@@ -1394,6 +1396,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>"; };
@@ -2570,6 +2573,7 @@
 				51C8E1A81F27F47300BF731B /* EmptyGrandfatheredResourceLoadStatistics.plist */,
 				F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */,
 				F407FE381F1D0DE60017CF25 /* enormous.svg */,
+				CDA29B2A20FD344E00F15CED /* ExitFullscreenOnEnterPiP.html */,
 				F41AB99B1EF4692C0083FA08 /* file-uploading.html */,
 				A17EAC542083056E0084B41B /* find.pdf */,
 				F43E3BC020DADB8000A4E7ED /* fixed-nav-bar.html */,
@@ -2637,6 +2641,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 */,
@@ -3660,6 +3665,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 */,

Modified: branches/safari-606-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm (234235 => 234236)


--- branches/safari-606-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm	2018-07-26 07:14:37 UTC (rev 234235)
+++ branches/safari-606-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm	2018-07-26 07:14:43 UTC (rev 234236)
@@ -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: branches/safari-606-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/notify-resourceLoadObserver.html (0 => 234236)


--- branches/safari-606-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/notify-resourceLoadObserver.html	                        (rev 0)
+++ branches/safari-606-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/notify-resourceLoadObserver.html	2018-07-26 07:14:43 UTC (rev 234236)
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script>
+    internals.notifyResourceLoadObserver();
+</script>
+</body>
+</html>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to