WebResourceLoadStatisticsStore fails to unregister itself as a MessageReceiver in...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Jul 2018 20:59:58 +0000 (20:59 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Jul 2018 20:59:58 +0000 (20:59 +0000)
commit78d5b7201d9b8525a1debfb841f0eeb0c0d1abe1
tree1d309d99dcf52b61434875b0a26992e5f9a1a3e8
parent3f4185478182d11f2e15cb86ab19ab355e82c094
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
13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp
Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/notify-resourceLoadObserver.html [new file with mode: 0644]