When disabling legacy private browsing for testing, change the SessionID back to...
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Sep 2019 16:19:50 +0000 (16:19 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Sep 2019 16:19:50 +0000 (16:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=201480

Reviewed by Youenn Fablet.

Source/WebCore:

No change in behavior, but this blocks bug 200050 which will make WebKitTestRunner use a persistent, non-default session.
Without this change, that change causes lots of test failures because we are switching from the legacy private browsing session
to the default session instead of the session we were using.

* page/Page.cpp:
(WebCore::Page::enableLegacyPrivateBrowsing): Deleted.
* page/Page.h:
* page/PageGroup.cpp:
(WebCore::PageGroup::addPage):
(WebCore::PageGroup::setSessionIDForTesting):
(WebCore::PageGroup::enableLegacyPrivateBrowsingForTesting): Deleted.
* page/PageGroup.h:
* storage/StorageNamespaceProvider.cpp:
(WebCore::StorageNamespaceProvider::setSessionIDForTesting):
(WebCore::StorageNamespaceProvider::enableLegacyPrivateBrowsingForTesting): Deleted.
* storage/StorageNamespaceProvider.h:

Source/WebKit:

* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::setPrivateBrowsingEnabled):
* WebProcess/InjectedBundle/InjectedBundle.h:

Source/WebKitLegacy/mac:

* WebView/WebView.mm:
(-[WebView _preferencesChanged:]):

Source/WebKitLegacy/win:

* WebView.cpp:
(WebView::notifyPreferencesChanged):

Tools:

* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::beginTesting):
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::setPrivateBrowsingEnabled):

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

20 files changed:
Source/WebCore/ChangeLog
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebCore/page/PageGroup.cpp
Source/WebCore/page/PageGroup.h
Source/WebCore/storage/StorageNamespaceProvider.cpp
Source/WebCore/storage/StorageNamespaceProvider.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp
Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h
Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.cpp
Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.h
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebView/WebView.mm
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/WebView.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/glib/CMakeLists.txt
Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

index 3ba6be8..f857f38 100644 (file)
@@ -1,3 +1,27 @@
+2019-09-06  Alex Christensen  <achristensen@webkit.org>
+
+        When disabling legacy private browsing for testing, change the SessionID back to what it was, not the defaultSessionID
+        https://bugs.webkit.org/show_bug.cgi?id=201480
+
+        Reviewed by Youenn Fablet.
+
+        No change in behavior, but this blocks bug 200050 which will make WebKitTestRunner use a persistent, non-default session.
+        Without this change, that change causes lots of test failures because we are switching from the legacy private browsing session
+        to the default session instead of the session we were using.
+
+        * page/Page.cpp:
+        (WebCore::Page::enableLegacyPrivateBrowsing): Deleted.
+        * page/Page.h:
+        * page/PageGroup.cpp:
+        (WebCore::PageGroup::addPage):
+        (WebCore::PageGroup::setSessionIDForTesting):
+        (WebCore::PageGroup::enableLegacyPrivateBrowsingForTesting): Deleted.
+        * page/PageGroup.h:
+        * storage/StorageNamespaceProvider.cpp:
+        (WebCore::StorageNamespaceProvider::setSessionIDForTesting):
+        (WebCore::StorageNamespaceProvider::enableLegacyPrivateBrowsingForTesting): Deleted.
+        * storage/StorageNamespaceProvider.h:
+
 2019-09-06  Youenn Fablet  <youenn@apple.com>
 
         Remove MediaStreamPrivate::scheduleDeferredTask
index 3f58183..37ee7ed 100644 (file)
@@ -1676,14 +1676,6 @@ void Page::storageBlockingStateChanged()
         view->storageBlockingStateChanged();
 }
 
-void Page::enableLegacyPrivateBrowsing(bool privateBrowsingEnabled)
-{
-    // Don't allow changing the legacy private browsing state if we have set a session ID.
-    ASSERT(m_sessionID == PAL::SessionID::defaultSessionID() || m_sessionID == PAL::SessionID::legacyPrivateSessionID());
-
-    setSessionID(privateBrowsingEnabled ? PAL::SessionID::legacyPrivateSessionID() : PAL::SessionID::defaultSessionID());
-}
-
 void Page::updateIsPlayingMedia(uint64_t sourceElementID)
 {
     MediaProducer::MediaStateFlags state = MediaProducer::IsNotPlaying;
index 7c86502..269e6fd 100644 (file)
@@ -607,7 +607,6 @@ public:
 
     WEBCORE_EXPORT PAL::SessionID sessionID() const;
     WEBCORE_EXPORT void setSessionID(PAL::SessionID);
-    WEBCORE_EXPORT void enableLegacyPrivateBrowsing(bool privateBrowsingEnabled);
     bool usesEphemeralSession() const { return m_sessionID.isEphemeral(); }
 
     MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }
index 128c18f..d4c54c4 100644 (file)
@@ -95,7 +95,7 @@ void PageGroup::addPage(Page& page)
     m_pages.add(&page);
     
     if (m_isLegacyPrivateBrowsingEnabledForTesting)
-        page.enableLegacyPrivateBrowsing(true);
+        page.setSessionID(PAL::SessionID::legacyPrivateSessionID());
 }
 
 void PageGroup::removePage(Page& page)
@@ -126,15 +126,16 @@ CaptionUserPreferences& PageGroup::captionPreferences()
 }
 #endif
 
-void PageGroup::enableLegacyPrivateBrowsingForTesting(bool enabled)
+void PageGroup::setSessionIDForTesting(const PAL::SessionID& sessionID)
 {
-    if (m_isLegacyPrivateBrowsingEnabledForTesting == enabled)
+    bool legacyPrivate = sessionID == PAL::SessionID::legacyPrivateSessionID();
+    if (m_isLegacyPrivateBrowsingEnabledForTesting == legacyPrivate)
         return;
 
-    m_isLegacyPrivateBrowsingEnabledForTesting = enabled;
+    m_isLegacyPrivateBrowsingEnabledForTesting = legacyPrivate;
     
     for (auto* page : m_pages)
-        page->enableLegacyPrivateBrowsing(enabled);
+        page->setSessionID(sessionID);
 }
 
 } // namespace WebCore
index 6baf0a1..863b296 100644 (file)
 #include <wtf/Noncopyable.h>
 #include <wtf/text/WTFString.h>
 
+namespace PAL {
+class SessionID;
+}
+
 namespace WebCore {
 
 class Page;
@@ -58,7 +62,7 @@ public:
     WEBCORE_EXPORT CaptionUserPreferences& captionPreferences();
 #endif
 
-    WEBCORE_EXPORT void enableLegacyPrivateBrowsingForTesting(bool);
+    WEBCORE_EXPORT void setSessionIDForTesting(const PAL::SessionID&);
 
 private:
     String m_name;
index 6c5a8de..a3e35d1 100644 (file)
@@ -82,9 +82,8 @@ StorageNamespace& StorageNamespaceProvider::transientLocalStorageNamespace(Secur
     return *slot;
 }
 
-void StorageNamespaceProvider::enableLegacyPrivateBrowsingForTesting(bool enabled)
+void StorageNamespaceProvider::setSessionIDForTesting(const PAL::SessionID& newSessionID)
 {
-    auto newSessionID = enabled ? PAL::SessionID::legacyPrivateSessionID() : PAL::SessionID::defaultSessionID();
     if (m_localStorageNamespace && newSessionID != m_localStorageNamespace->sessionID())
         m_localStorageNamespace->setSessionIDForTesting(newSessionID);
     
index 01d064b..269ece7 100644 (file)
@@ -52,7 +52,7 @@ public:
 
     Ref<StorageArea> localStorageArea(Document&);
 
-    WEBCORE_EXPORT void enableLegacyPrivateBrowsingForTesting(bool enabled);
+    WEBCORE_EXPORT void setSessionIDForTesting(const PAL::SessionID&);
 
 protected:
     StorageNamespace* optionalLocalStorageNamespace() { return m_localStorageNamespace.get(); }
index 07959ca..cb24398 100644 (file)
@@ -1,3 +1,14 @@
+2019-09-06  Alex Christensen  <achristensen@webkit.org>
+
+        When disabling legacy private browsing for testing, change the SessionID back to what it was, not the defaultSessionID
+        https://bugs.webkit.org/show_bug.cgi?id=201480
+
+        Reviewed by Youenn Fablet.
+
+        * WebProcess/InjectedBundle/InjectedBundle.cpp:
+        (WebKit::InjectedBundle::setPrivateBrowsingEnabled):
+        * WebProcess/InjectedBundle/InjectedBundle.h:
+
 2019-09-06  Patrick Griffis  <pgriffis@igalia.com>
 
         [GTK][WPE] Do not enable the sandbox in Snap
index ca85d58..e34777e 100644 (file)
@@ -166,9 +166,9 @@ void WKBundleSetJavaScriptCanAccessClipboard(WKBundleRef bundleRef, WKBundlePage
     WebKit::toImpl(bundleRef)->setJavaScriptCanAccessClipboard(WebKit::toImpl(pageGroupRef), enabled);
 }
 
-void WKBundleSetPrivateBrowsingEnabled(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, bool enabled)
+void WKBundleSetPrivateBrowsingEnabled(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, WKBundlePageRef pageRef, bool enabled)
 {
-    WebKit::toImpl(bundleRef)->setPrivateBrowsingEnabled(WebKit::toImpl(pageGroupRef), enabled);
+    WebKit::toImpl(bundleRef)->setPrivateBrowsingEnabled(WebKit::toImpl(pageGroupRef), WebKit::toImpl(pageRef), enabled);
 }
 
 void WKBundleSetPopupBlockingEnabled(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, bool enabled)
index c98ab79..14d7d5c 100644 (file)
@@ -49,7 +49,7 @@ WK_EXPORT void WKBundleSetAllowStorageAccessFromFileURLS(WKBundleRef bundle, WKB
 WK_EXPORT void WKBundleSetMinimumLogicalFontSize(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, int size);
 WK_EXPORT void WKBundleSetFrameFlatteningEnabled(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled);
 WK_EXPORT void WKBundleSetJavaScriptCanAccessClipboard(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled);
-WK_EXPORT void WKBundleSetPrivateBrowsingEnabled(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled);
+WK_EXPORT void WKBundleSetPrivateBrowsingEnabled(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKBundlePageRef pageRef, bool enabled);
 WK_EXPORT void WKBundleSetPopupBlockingEnabled(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled);
 WK_EXPORT void WKBundleSetAuthorAndUserStylesEnabled(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled);
 WK_EXPORT void WKBundleSetSpatialNavigationEnabled(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled);
index ab89687..1f68d24 100644 (file)
@@ -346,16 +346,27 @@ void InjectedBundle::setJavaScriptCanAccessClipboard(WebPageGroupProxy* pageGrou
         (*iter)->settings().setJavaScriptCanAccessClipboard(enabled);
 }
 
-void InjectedBundle::setPrivateBrowsingEnabled(WebPageGroupProxy* pageGroup, bool enabled)
+void InjectedBundle::setPrivateBrowsingEnabled(WebPageGroupProxy* pageGroup, WebPage* page, bool enabled)
 {
     ASSERT(!hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-    if (enabled)
+
+    PAL::SessionID newSessionID = PAL::SessionID::legacyPrivateSessionID();
+    if (enabled) {
+        auto currentSessionID = page->corePage()->sessionID();
+        if (currentSessionID == PAL::SessionID::legacyPrivateSessionID())
+            return;
+        m_initialSessionID = currentSessionID;
         WebProcess::singleton().ensureLegacyPrivateBrowsingSessionInNetworkProcess();
+    } else {
+        if (!m_initialSessionID)
+            return;
+        newSessionID = *std::exchange(m_initialSessionID, WTF::nullopt);
+    }
 
-    PageGroup::pageGroup(pageGroup->identifier())->enableLegacyPrivateBrowsingForTesting(enabled);
+    PageGroup::pageGroup(pageGroup->identifier())->setSessionIDForTesting(newSessionID);
 
     auto webStorageNameSpaceProvider = WebStorageNamespaceProvider::getOrCreate(*pageGroup);
-    webStorageNameSpaceProvider->enableLegacyPrivateBrowsingForTesting(enabled);
+    webStorageNameSpaceProvider->setSessionIDForTesting(newSessionID);
 }
 
 void InjectedBundle::setPopupBlockingEnabled(WebPageGroupProxy* pageGroup, bool enabled)
index f3e2744..66299a4 100644 (file)
@@ -31,6 +31,7 @@
 #include <JavaScriptCore/JavaScript.h>
 #include <WebCore/UserContentTypes.h>
 #include <WebCore/UserScriptTypes.h>
+#include <pal/SessionID.h>
 #include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/text/WTFString.h>
@@ -104,7 +105,7 @@ public:
     void setAsyncFrameScrollingEnabled(WebPageGroupProxy*, bool);
     void setPluginsEnabled(WebPageGroupProxy*, bool);
     void setJavaScriptCanAccessClipboard(WebPageGroupProxy*, bool);
-    void setPrivateBrowsingEnabled(WebPageGroupProxy*, bool);
+    void setPrivateBrowsingEnabled(WebPageGroupProxy*, WebPage*, bool);
     void setPopupBlockingEnabled(WebPageGroupProxy*, bool);
     void setAuthorAndUserStylesEnabled(WebPageGroupProxy*, bool);
     void setSpatialNavigationEnabled(WebPageGroupProxy*, bool);
@@ -173,6 +174,8 @@ private:
 
     std::unique_ptr<API::InjectedBundle::Client> m_client;
 
+    Optional<PAL::SessionID> m_initialSessionID;
+
 #if PLATFORM(COCOA)
     RetainPtr<WKWebProcessBundleParameters> m_bundleParameters;
     RetainPtr<NSSet> m_classesForCoder;
index 5ab4f9e..3826468 100644 (file)
@@ -1,3 +1,13 @@
+2019-09-06  Alex Christensen  <achristensen@webkit.org>
+
+        When disabling legacy private browsing for testing, change the SessionID back to what it was, not the defaultSessionID
+        https://bugs.webkit.org/show_bug.cgi?id=201480
+
+        Reviewed by Youenn Fablet.
+
+        * WebView/WebView.mm:
+        (-[WebView _preferencesChanged:]):
+
 2019-09-06  Rob Buis  <rbuis@igalia.com>
 
         Add runtime flag for lazy image loading
index 3392970..fb40ce8 100644 (file)
@@ -2888,8 +2888,8 @@ static bool needsSelfRetainWhileLoadingQuirk()
     settings.setPluginsEnabled([preferences arePlugInsEnabled]);
     settings.setLocalStorageEnabled([preferences localStorageEnabled]);
 
-    _private->page->enableLegacyPrivateBrowsing([preferences privateBrowsingEnabled]);
-    _private->group->storageNamespaceProvider().enableLegacyPrivateBrowsingForTesting([preferences privateBrowsingEnabled]);
+    _private->page->setSessionID([preferences privateBrowsingEnabled] ? PAL::SessionID::legacyPrivateSessionID() : PAL::SessionID::defaultSessionID());
+    _private->group->storageNamespaceProvider().setSessionIDForTesting([preferences privateBrowsingEnabled] ? PAL::SessionID::legacyPrivateSessionID() : PAL::SessionID::defaultSessionID());
     settings.setSansSerifFontFamily([preferences sansSerifFontFamily]);
     settings.setSerifFontFamily([preferences serifFontFamily]);
     settings.setStandardFontFamily([preferences standardFontFamily]);
index 286a304..3fc7f59 100644 (file)
@@ -1,3 +1,13 @@
+2019-09-06  Alex Christensen  <achristensen@webkit.org>
+
+        When disabling legacy private browsing for testing, change the SessionID back to what it was, not the defaultSessionID
+        https://bugs.webkit.org/show_bug.cgi?id=201480
+
+        Reviewed by Youenn Fablet.
+
+        * WebView.cpp:
+        (WebView::notifyPreferencesChanged):
+
 2019-09-06  Rob Buis  <rbuis@igalia.com>
 
         Add runtime flag for lazy image loading
index c3ec7f9..026cfc0 100644 (file)
@@ -5307,7 +5307,7 @@ HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification)
     else
         WebFrameNetworkingContext::destroyPrivateBrowsingSession();
 #endif
-    m_page->enableLegacyPrivateBrowsing(!!enabled);
+    m_page->setSessionID(!!enabled ? PAL::SessionID::legacyPrivateSessionID() : PAL::SessionID::defaultSessionID());
 
     hr = preferences->sansSerifFontFamily(&str);
     if (FAILED(hr))
index 2df5dfc..406e838 100644 (file)
@@ -1,3 +1,15 @@
+2019-09-06  Alex Christensen  <achristensen@webkit.org>
+
+        When disabling legacy private browsing for testing, change the SessionID back to what it was, not the defaultSessionID
+        https://bugs.webkit.org/show_bug.cgi?id=201480
+
+        Reviewed by Youenn Fablet.
+
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::beginTesting):
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::setPrivateBrowsingEnabled):
+
 2019-09-06  Rob Buis  <rbuis@igalia.com>
 
         Add runtime flag for lazy image loading
index 6f1d5a0..b6ed370 100644 (file)
@@ -7,8 +7,6 @@ set(WebKitGLibAPITests_SOURCES
 )
 
 set(WebKitGLibAPITests_INCLUDE_DIRECTORIES
-    ${CMAKE_SOURCE_DIR}/Source
-    ${CMAKE_SOURCE_DIR}/Source/WTF
     ${FORWARDING_HEADERS_DIR}
     ${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGLib
     ${TOOLS_DIR}/TestWebKitAPI/glib/WebKitGLib
index aebdd69..ac149a5 100644 (file)
@@ -497,7 +497,7 @@ void InjectedBundle::beginTesting(WKDictionaryRef settings, BegingTestingMode te
     // Don't change experimental or internal features here; those should be set in TestController::resetPreferencesToConsistentValues().
     WKBundleSetAllowUniversalAccessFromFileURLs(m_bundle, m_pageGroup, true);
     WKBundleSetJavaScriptCanAccessClipboard(m_bundle, m_pageGroup, true);
-    WKBundleSetPrivateBrowsingEnabled(m_bundle, m_pageGroup, false);
+    WKBundleSetPrivateBrowsingEnabled(m_bundle, m_pageGroup, page()->page(), false);
     WKBundleSetAuthorAndUserStylesEnabled(m_bundle, m_pageGroup, true);
     WKBundleSetFrameFlatteningEnabled(m_bundle, m_pageGroup, false);
     WKBundleSetMinimumLogicalFontSize(m_bundle, m_pageGroup, 9);
index 2b310a4..06524a3 100644 (file)
@@ -534,7 +534,7 @@ void TestRunner::setJavaScriptCanAccessClipboard(bool enabled)
 void TestRunner::setPrivateBrowsingEnabled_DEPRECATED(bool enabled)
 {
     auto& injectedBundle = InjectedBundle::singleton();
-    WKBundleSetPrivateBrowsingEnabled(injectedBundle.bundle(), injectedBundle.pageGroup(), enabled);
+    WKBundleSetPrivateBrowsingEnabled(injectedBundle.bundle(), injectedBundle.pageGroup(), injectedBundle.page()->page(), enabled);
 }
 
 void TestRunner::setPopupBlockingEnabled(bool enabled)