WebKit should throw when trying to create a WKWebView with a related view that is...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 20:31:19 +0000 (20:31 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 20:31:19 +0000 (20:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196041
<rdar://problem/49083230>

Reviewed by Alex Christensen.

Source/WebKit:

WebKit should throw when trying to create a WKWebView with a related view that is using a different data store.
We do not support having several WebsiteDataStores sharing the same WebProcess.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::createWebPage):

Tools:

Add API test coverage.

* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewConfiguration.mm:
(TEST):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/WebProcessPool.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewConfiguration.mm

index cf4e27a..d6dbc1d 100644 (file)
@@ -1,3 +1,19 @@
+2019-03-21  Chris Dumez  <cdumez@apple.com>
+
+        WebKit should throw when trying to create a WKWebView with a related view that is using a different data store
+        https://bugs.webkit.org/show_bug.cgi?id=196041
+        <rdar://problem/49083230>
+
+        Reviewed by Alex Christensen.
+
+        WebKit should throw when trying to create a WKWebView with a related view that is using a different data store.
+        We do not support having several WebsiteDataStores sharing the same WebProcess.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::createWebPage):
+
 2019-03-21  Alex Christensen  <achristensen@webkit.org>
 
         Add SPI to inform applications of WKContentRuleList actions
index 9e41e57..2219785 100644 (file)
@@ -552,6 +552,8 @@ static void validate(WKWebViewConfiguration *configuration)
         WKProcessPool *relatedWebViewProcessPool = [relatedWebView->_configuration processPool];
         if (processPool && processPool != relatedWebViewProcessPool)
             [NSException raise:NSInvalidArgumentException format:@"Related web view %@ has process pool %@ but configuration specifies a different process pool %@", relatedWebView, relatedWebViewProcessPool, configuration.processPool];
+        if ([relatedWebView->_configuration websiteDataStore] != [_configuration websiteDataStore])
+            [NSException raise:NSInvalidArgumentException format:@"Related web view %@ has data store %@ but configuration specifies a different data store %@", relatedWebView, [relatedWebView->_configuration websiteDataStore], [_configuration websiteDataStore]];
 
         [_configuration setProcessPool:relatedWebViewProcessPool];
     }
index 6954490..407e873 100644 (file)
@@ -1215,6 +1215,9 @@ Ref<WebPageProxy> WebProcessPool::createWebPage(PageClient& pageClient, Ref<API:
     if (pageConfiguration->relatedPage()) {
         // Sharing processes, e.g. when creating the page via window.open().
         process = &pageConfiguration->relatedPage()->process();
+        // We do not support several WebsiteDataStores sharing a single process.
+        ASSERT(process.get() == m_dummyProcessProxy || &pageConfiguration->websiteDataStore()->websiteDataStore() == &process->websiteDataStore());
+        ASSERT(&pageConfiguration->relatedPage()->websiteDataStore() == &pageConfiguration->websiteDataStore()->websiteDataStore());
     } else if (WebKit::isInspectorProcessPool(*this)) {
         // Do not delay process launch for inspector pages as inspector pages do not know how to transition from a terminated process.
         process = &processForRegistrableDomain(pageConfiguration->websiteDataStore()->websiteDataStore(), nullptr, { });
index 7ec2c50..5201c77 100644 (file)
@@ -1,3 +1,16 @@
+2019-03-21  Chris Dumez  <cdumez@apple.com>
+
+        WebKit should throw when trying to create a WKWebView with a related view that is using a different data store
+        https://bugs.webkit.org/show_bug.cgi?id=196041
+        <rdar://problem/49083230>
+
+        Reviewed by Alex Christensen.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewConfiguration.mm:
+        (TEST):
+
 2019-03-21  Alex Christensen  <achristensen@webkit.org>
 
         Add SPI to inform applications of WKContentRuleList actions
index 550671a..a308518 100644 (file)
@@ -28,6 +28,7 @@
 #import "PlatformUtilities.h"
 #import <WebKit/WKWebView.h>
 #import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WKWebsiteDataStore.h>
 #import <wtf/Function.h>
 #import <wtf/RetainPtr.h>
 
@@ -62,6 +63,14 @@ TEST(WebKit, InvalidConfiguration)
         [configuration _setVisitedLinkStore:nil];
     });
 #pragma clang diagnostic pop
+
+    // Related WebViews cannot use different data stores.
+    auto configurationForEphemeralView = adoptNS([[WKWebViewConfiguration alloc] init]);
+    configurationForEphemeralView.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
+    auto ephemeralWebView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configurationForEphemeralView.get()]);
+    shouldThrowExceptionWhenUsed([&](WKWebViewConfiguration *configuration) {
+        [configuration _setRelatedWebView:ephemeralWebView.get()];
+    });
 }
 
 TEST(WebKit, ConfigurationGroupIdentifierIsCopied)