Resource Load Statistics: Make WebsiteDataStore::getAllStorageAccessEntries() call...
authorwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jul 2018 18:25:36 +0000 (18:25 +0000)
committerwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jul 2018 18:25:36 +0000 (18:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187277
<rdar://problem/41745510>

Reviewed by Chris Dumez.

Source/WebKit:

Existing tests use this code. The change is for correctness.

* UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
(-[WKWebsiteDataStore _getAllStorageAccessEntriesFor:completionHandler:]):
    Now receives a WKWebView from its caller and gets the page ID from it.
(-[WKWebsiteDataStore _getAllStorageAccessEntries:]): Deleted.
* UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::getAllStorageAccessEntries):
    Now gets a page ID from its caller and gets the right network process
    through it.
* UIProcess/WebsiteData/WebsiteDataStore.h:

Tools:

* WebKitTestRunner/cocoa/TestControllerCocoa.mm:
(WTR::TestController::getAllStorageAccessEntries):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
Tools/ChangeLog
Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm

index f3d0f2f..f65f4e2 100644 (file)
@@ -1,3 +1,24 @@
+2018-07-03  John Wilander  <wilander@apple.com>
+
+        Resource Load Statistics: Make WebsiteDataStore::getAllStorageAccessEntries() call the right network process instead of iterating over the process pools
+        https://bugs.webkit.org/show_bug.cgi?id=187277
+        <rdar://problem/41745510>
+
+        Reviewed by Chris Dumez.
+
+        Existing tests use this code. The change is for correctness.
+
+        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
+        (-[WKWebsiteDataStore _getAllStorageAccessEntriesFor:completionHandler:]):
+            Now receives a WKWebView from its caller and gets the page ID from it.
+        (-[WKWebsiteDataStore _getAllStorageAccessEntries:]): Deleted.
+        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::getAllStorageAccessEntries):
+            Now gets a page ID from its caller and gets the right network process
+            through it.
+        * UIProcess/WebsiteData/WebsiteDataStore.h:
+
 2018-07-03  Jonathan Bedard  <jbedard@apple.com>
 
         Unreviewed, rolling out r233461.
index 872ba3d..8252322 100644 (file)
@@ -31,7 +31,9 @@
 #import "APIString.h"
 #import "WKHTTPCookieStoreInternal.h"
 #import "WKNSArray.h"
+#import "WKWebViewInternal.h"
 #import "WKWebsiteDataRecordInternal.h"
+#import "WebPageProxy.h"
 #import "WebResourceLoadStatisticsStore.h"
 #import "WebResourceLoadStatisticsTelemetry.h"
 #import "WebsiteDataFetchOption.h"
@@ -343,14 +345,24 @@ static Vector<WebKit::WebsiteDataRecord> toWebsiteDataRecords(NSArray *dataRecor
     WebKit::WebsiteDataStore::allowWebsiteDataRecordsForAllOrigins();
 }
 
-- (void)_getAllStorageAccessEntries:(void (^)(NSArray<NSString *> *domains))completionHandler
+- (void)_getAllStorageAccessEntriesFor:(WKWebView *)webView completionHandler:(void (^)(NSArray<NSString *> *domains))completionHandler
 {
-    _websiteDataStore->websiteDataStore().getAllStorageAccessEntries([completionHandler = makeBlockPtr(completionHandler)](auto domains) {
+    if (!webView) {
+        completionHandler({ });
+        return;
+    }
+
+    auto* webPageProxy = [webView _page];
+    if (!webPageProxy) {
+        completionHandler({ });
+        return;
+    }
+
+    _websiteDataStore->websiteDataStore().getAllStorageAccessEntries(webPageProxy->pageID(), [completionHandler = makeBlockPtr(completionHandler)](auto domains) {
         Vector<RefPtr<API::Object>> apiDomains;
         apiDomains.reserveInitialCapacity(domains.size());
         for (auto& domain : domains)
             apiDomains.uncheckedAppend(API::String::create(domain));
-
         completionHandler(wrapper(API::Array::create(WTFMove(apiDomains))));
     });
 }
index dda7cde..36944fc 100644 (file)
@@ -30,6 +30,7 @@
 NS_ASSUME_NONNULL_BEGIN
 
 @class _WKWebsiteDataStoreConfiguration;
+@class WKWebView;
 
 typedef NS_OPTIONS(NSUInteger, _WKWebsiteDataStoreFetchOptions) {
     _WKWebsiteDataStoreFetchOptionComputeSizes = 1 << 0,
@@ -56,7 +57,7 @@ typedef NS_OPTIONS(NSUInteger, _WKWebsiteDataStoreFetchOptions) {
 
 - (void)_resourceLoadStatisticsSetShouldSubmitTelemetry:(BOOL)value WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 - (void)_setResourceLoadStatisticsTestingCallback:(nullable void (^)(WKWebsiteDataStore *, NSString *))callback WK_API_AVAILABLE(macosx(10.13), ios(11.0));
-- (void)_getAllStorageAccessEntries:(void (^)(NSArray<NSString *> *domains))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_getAllStorageAccessEntriesFor:(WKWebView *)webView completionHandler:(void (^)(NSArray<NSString *> *domains))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 + (void)_allowWebsiteDataRecordsForAllOrigins WK_API_AVAILABLE(macosx(10.13.4), ios(11.3));
 - (bool)_hasRegisteredServiceWorker WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
index 50da10a..06fc505 100644 (file)
@@ -1230,11 +1230,16 @@ void WebsiteDataStore::hasStorageAccessForFrameHandler(const String& resourceDom
     networkProcess.hasStorageAccessForFrame(m_sessionID, resourceDomain, firstPartyDomain, frameID, pageID, WTFMove(completionHandler));
 }
 
-void WebsiteDataStore::getAllStorageAccessEntries(CompletionHandler<void(Vector<String>&& domains)>&& completionHandler)
+void WebsiteDataStore::getAllStorageAccessEntries(uint64_t pageID, CompletionHandler<void(Vector<String>&& domains)>&& completionHandler)
 {
-    // FIXME: Although this is only used for testing, it should not iterate and WTFMove the completion handler.
-    for (auto& processPool : processPools())
-        processPool->networkProcess()->getAllStorageAccessEntries(m_sessionID, WTFMove(completionHandler));
+    auto* webPage = WebProcessProxy::webPage(pageID);
+    if (!webPage) {
+        completionHandler({ });
+        return;
+    }
+    
+    auto& networkProcess = webPage->process().processPool().ensureNetworkProcess();
+    networkProcess.getAllStorageAccessEntries(m_sessionID, WTFMove(completionHandler));
 }
 
 void WebsiteDataStore::grantStorageAccessHandler(const String& resourceDomain, const String& firstPartyDomain, std::optional<uint64_t> frameID, uint64_t pageID, CompletionHandler<void(bool wasGranted)>&& completionHandler)
index b9066ae..02de18e 100644 (file)
@@ -132,7 +132,7 @@ public:
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
     void updatePrevalentDomainsToPartitionOrBlockCookies(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, ShouldClearFirst, CompletionHandler<void()>&&);
     void hasStorageAccessForFrameHandler(const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID, CompletionHandler<void(bool hasAccess)>&&);
-    void getAllStorageAccessEntries(CompletionHandler<void(Vector<String>&& domains)>&&);
+    void getAllStorageAccessEntries(uint64_t pageID, CompletionHandler<void(Vector<String>&& domains)>&&);
     void grantStorageAccessHandler(const String& resourceDomain, const String& firstPartyDomain, std::optional<uint64_t> frameID, uint64_t pageID, CompletionHandler<void(bool wasGranted)>&&);
     void removeAllStorageAccessHandler();
     void removePrevalentDomains(const Vector<String>& domains);
index d6a9e19..1ae2378 100644 (file)
@@ -1,3 +1,14 @@
+2018-07-03  John Wilander  <wilander@apple.com>
+
+        Resource Load Statistics: Make WebsiteDataStore::getAllStorageAccessEntries() call the right network process instead of iterating over the process pools
+        https://bugs.webkit.org/show_bug.cgi?id=187277
+        <rdar://problem/41745510>
+
+        Reviewed by Chris Dumez.
+
+        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
+        (WTR::TestController::getAllStorageAccessEntries):
+
 2018-07-02  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Fix a leak in ActionSheetTests.DismissingActionSheetShouldNotDismissPresentingViewController
index e6efb27..c7b7adc 100644 (file)
@@ -266,7 +266,11 @@ void TestController::removeAllSessionCredentials()
 void TestController::getAllStorageAccessEntries()
 {
 #if WK_API_ENABLED
-    [globalWebViewConfiguration.websiteDataStore _getAllStorageAccessEntries:^(NSArray<NSString *> *nsDomains) {
+    auto* parentView = mainWebView();
+    if (!parentView)
+        return;
+
+    [globalWebViewConfiguration.websiteDataStore _getAllStorageAccessEntriesFor:parentView->platformView() completionHandler:^(NSArray<NSString *> *nsDomains) {
         Vector<String> domains;
         domains.reserveInitialCapacity(nsDomains.count);
         for (NSString *domain : nsDomains)