API::PageConfiguration's sessionID needs to be set whenever the API::WebsiteDataStore...
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Aug 2015 21:50:24 +0000 (21:50 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Aug 2015 21:50:24 +0000 (21:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148097

Reviewed by Anders Carlsson.

Source/WebKit2:

We were getting an empty SessionID set on the WebPageProxy (and crashing asserting down the line)
when using a WKPageConfiguration with a WKWebsiteDataStore set on it.

Tests:
    WebKit2.WKPageConfigurationBasicWithDataStore
    WebKit2.WKPageConfigurationBasicWithNonPersistentDataStore

* UIProcess/API/APIPageConfiguration.cpp:
(API::PageConfiguration::setWebsiteDataStore):
Set the sessionID member whenever changing the WebsiteDataStore.

* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
(WKWebsiteDataStoreGetDefaultDataStore):
(WKWebsiteDataStoreCreateNonPersistentDataStore):
* UIProcess/API/C/WKWebsiteDataStoreRef.h:
Expose functions for getting default and new non-persistent data stores via the C-SPI. Useful
for testing and transitioning users of the C-SPI to the new model.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView initWithFrame:configuration:]):
Remove explicit setting of the sessionID. This is handled by the above call to setWebsiteDataStore().

Tools:

* TestWebKitAPI/Tests/WebKit2/WKPageConfiguration.cpp:
Add tests for WebsiteDataStores in the WKPageConfiguration.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/APIPageConfiguration.cpp
Source/WebKit2/UIProcess/API/C/WKWebsiteDataStoreRef.cpp
Source/WebKit2/UIProcess/API/C/WKWebsiteDataStoreRef.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2/WKPageConfiguration.cpp

index c4acc7f..e1ff61c 100644 (file)
@@ -1,3 +1,32 @@
+2015-08-17  Sam Weinig  <sam@webkit.org>
+
+        API::PageConfiguration's sessionID needs to be set whenever the API::WebsiteDataStore is set
+        https://bugs.webkit.org/show_bug.cgi?id=148097
+
+        Reviewed by Anders Carlsson.
+
+        We were getting an empty SessionID set on the WebPageProxy (and crashing asserting down the line)
+        when using a WKPageConfiguration with a WKWebsiteDataStore set on it.
+
+        Tests:
+            WebKit2.WKPageConfigurationBasicWithDataStore
+            WebKit2.WKPageConfigurationBasicWithNonPersistentDataStore
+
+        * UIProcess/API/APIPageConfiguration.cpp:
+        (API::PageConfiguration::setWebsiteDataStore):
+        Set the sessionID member whenever changing the WebsiteDataStore.
+
+        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
+        (WKWebsiteDataStoreGetDefaultDataStore):
+        (WKWebsiteDataStoreCreateNonPersistentDataStore):
+        * UIProcess/API/C/WKWebsiteDataStoreRef.h:
+        Expose functions for getting default and new non-persistent data stores via the C-SPI. Useful
+        for testing and transitioning users of the C-SPI to the new model.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView initWithFrame:configuration:]):
+        Remove explicit setting of the sessionID. This is handled by the above call to setWebsiteDataStore().
+
 2015-08-17  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Cannot change WKWebView scrollView deceleration rate
index e441a72..8af64a8 100644 (file)
@@ -141,6 +141,11 @@ API::WebsiteDataStore* PageConfiguration::websiteDataStore()
 void PageConfiguration::setWebsiteDataStore(API::WebsiteDataStore* websiteDataStore)
 {
     m_websiteDataStore = websiteDataStore;
+
+    if (m_websiteDataStore)
+        m_sessionID = m_websiteDataStore->websiteDataStore().sessionID();
+    else
+        m_sessionID = WebCore::SessionID();
 }
 
 WebCore::SessionID PageConfiguration::sessionID()
index b4bfeed..e9e907b 100644 (file)
@@ -33,3 +33,13 @@ WKTypeID WKWebsiteDataStoreGetTypeID()
 {
     return WebKit::toAPI(API::WebsiteDataStore::APIType);
 }
+
+WKWebsiteDataStoreRef WKWebsiteDataStoreGetDefaultDataStore()
+{
+    return WebKit::toAPI(API::WebsiteDataStore::defaultDataStore().get());
+}
+
+WKWebsiteDataStoreRef WKWebsiteDataStoreCreateNonPersistentDataStore()
+{
+    return WebKit::toAPI(&API::WebsiteDataStore::createNonPersistentDataStore().leakRef());
+}
index aed3eb6..36990e3 100644 (file)
@@ -34,6 +34,9 @@ extern "C" {
 
 WK_EXPORT WKTypeID WKWebsiteDataStoreGetTypeID();
 
+WK_EXPORT WKWebsiteDataStoreRef WKWebsiteDataStoreGetDefaultDataStore();
+WK_EXPORT WKWebsiteDataStoreRef WKWebsiteDataStoreCreateNonPersistentDataStore();
+
 #ifdef __cplusplus
 }
 #endif
index f140783..1a78f2b 100644 (file)
@@ -312,7 +312,6 @@ static bool shouldAllowPictureInPictureMediaPlayback()
     pageConfiguration->setUserContentController([_configuration userContentController]->_userContentControllerProxy.get());
     pageConfiguration->setVisitedLinkProvider([_configuration _visitedLinkProvider]->_visitedLinkProvider.get());
     pageConfiguration->setWebsiteDataStore([_configuration websiteDataStore]->_websiteDataStore.get());
-    pageConfiguration->setSessionID(pageConfiguration->websiteDataStore()->websiteDataStore().sessionID());
     pageConfiguration->setTreatsSHA1SignedCertificatesAsInsecure([_configuration _treatsSHA1SignedCertificatesAsInsecure]);
 
     RefPtr<WebKit::WebPageGroup> pageGroup;
index b787099..bee2920 100644 (file)
@@ -1,3 +1,13 @@
+2015-08-17  Sam Weinig  <sam@webkit.org>
+
+        API::PageConfiguration's sessionID needs to be set whenever the API::WebsiteDataStore is set
+        https://bugs.webkit.org/show_bug.cgi?id=148097
+
+        Reviewed by Anders Carlsson.
+
+        * TestWebKitAPI/Tests/WebKit2/WKPageConfiguration.cpp:
+        Add tests for WebsiteDataStores in the WKPageConfiguration.
+
 2015-08-17  Brian Burg  <bburg@apple.com>
 
         Web Inspector: load ProtocolTestStub from the WebInspectorUI bundle
index b5b8509..d041eea 100644 (file)
@@ -31,6 +31,8 @@
 #include "PlatformWebView.h"
 #include "Test.h"
 
+#include <WebKit/WKWebsiteDataStoreRef.h>
+
 namespace TestWebKitAPI {
 
 TEST(WebKit2, WKPageConfigurationEmpty)
@@ -70,10 +72,58 @@ TEST(WebKit2, WKPageConfigurationBasic)
     
     PlatformWebView webView(configuration.get());
     setPageLoaderClient(webView.page());
+    
+    WKRetainPtr<WKPageConfigurationRef> copiedConfiguration = adoptWK(WKPageCopyPageConfiguration(webView.page()));
+    ASSERT_EQ(context.get(), WKPageConfigurationGetContext(copiedConfiguration.get()));
+
+    WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("simple", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+
+    didFinishLoad = false;
+    Util::run(&didFinishLoad);
+}
+
+TEST(WebKit2, WKPageConfigurationBasicWithDataStore)
+{
+    WKRetainPtr<WKPageConfigurationRef> configuration = adoptWK(WKPageConfigurationCreate());
+    WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
+    WKPageConfigurationSetContext(configuration.get(), context.get());
+    WKRetainPtr<WKWebsiteDataStoreRef> websiteDataStore = WKWebsiteDataStoreGetDefaultDataStore();
+    WKPageConfigurationSetWebsiteDataStore(configuration.get(), websiteDataStore.get());
+    
+    PlatformWebView webView(configuration.get());
+    setPageLoaderClient(webView.page());
+
+    WKRetainPtr<WKPageConfigurationRef> copiedConfiguration = adoptWK(WKPageCopyPageConfiguration(webView.page()));
+    ASSERT_EQ(context.get(), WKPageConfigurationGetContext(copiedConfiguration.get()));
+    ASSERT_EQ(WKWebsiteDataStoreGetDefaultDataStore(), WKPageConfigurationGetWebsiteDataStore(copiedConfiguration.get()));
+
+    WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("simple", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+
+    didFinishLoad = false;
+    Util::run(&didFinishLoad);
+}
+
+TEST(WebKit2, WKPageConfigurationBasicWithNonPersistentDataStore)
+{
+    WKRetainPtr<WKPageConfigurationRef> configuration = adoptWK(WKPageConfigurationCreate());
+    WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
+    WKPageConfigurationSetContext(configuration.get(), context.get());
+    WKRetainPtr<WKWebsiteDataStoreRef> websiteDataStore = adoptWK(WKWebsiteDataStoreCreateNonPersistentDataStore());
+    WKPageConfigurationSetWebsiteDataStore(configuration.get(), websiteDataStore.get());
+    
+    PlatformWebView webView(configuration.get());
+    setPageLoaderClient(webView.page());
+
+    WKRetainPtr<WKPageConfigurationRef> copiedConfiguration = adoptWK(WKPageCopyPageConfiguration(webView.page()));
+    ASSERT_EQ(context.get(), WKPageConfigurationGetContext(copiedConfiguration.get()));
+    ASSERT_EQ(websiteDataStore.get(), WKPageConfigurationGetWebsiteDataStore(copiedConfiguration.get()));
 
     WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("simple", "html"));
     WKPageLoadURL(webView.page(), url.get());
 
+    didFinishLoad = false;
     Util::run(&didFinishLoad);
 }