Enable Session API.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jan 2014 00:28:20 +0000 (00:28 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jan 2014 00:28:20 +0000 (00:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=127255

Patch by Martin Hock <mhock@apple.com> on 2014-01-22
Reviewed by Alexey Proskuryakov.

* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::storageSession):
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::NetworkResourceLoader):
(WebKit::NetworkResourceLoader::start):
* NetworkProcess/NetworkResourceLoader.h:
* NetworkProcess/RemoteNetworkingContext.h:
* NetworkProcess/mac/RemoteNetworkingContext.mm:
(WebKit::RemoteNetworkingContext::storageSession):
(WebKit::RemoteNetworkingContext::ensurePrivateBrowsingSession):
* Shared/Network/NetworkResourceLoadParameters.cpp:
(WebKit::NetworkResourceLoadParameters::NetworkResourceLoadParameters):
(WebKit::NetworkResourceLoadParameters::encode):
(WebKit::NetworkResourceLoadParameters::decode):
* Shared/Network/NetworkResourceLoadParameters.h:
* Shared/SessionTracker.cpp:
(WebKit::staticSessionMap):
(WebKit::SessionTracker::sessionMap):
(WebKit::SessionTracker::session):
(WebKit::SessionTracker::setSession):
(WebKit::SessionTracker::destroySession):
* Shared/SessionTracker.h:
* UIProcess/API/C/WKPage.cpp:
(WKPageSetSession):
* UIProcess/API/C/WKPage.h:
* UIProcess/API/C/WKSessionRef.cpp:
(WKSessionCreate):
* UIProcess/API/C/WKSessionRef.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
(WebKit::WebPageProxy::setSession):
* UIProcess/WebPageProxy.h:
* WebProcess/Network/WebResourceLoadScheduler.cpp:
(WebKit::WebResourceLoadScheduler::scheduleLoad):
* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::loadResourceSynchronously):
* WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm:
(WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession):
(WebKit::WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts):
(WebKit::WebFrameNetworkingContext::storageSession):
* WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp:
(WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession):
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::startDownload):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
(WebKit::WebPage::sessionID):
(WebKit::WebPage::updatePreferences):
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::setSessionID):
* WebProcess/WebPage/WebPage.messages.in:

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

25 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit2/NetworkProcess/NetworkResourceLoader.h
Source/WebKit2/NetworkProcess/RemoteNetworkingContext.h
Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.mm
Source/WebKit2/Shared/Network/NetworkResourceLoadParameters.cpp
Source/WebKit2/Shared/Network/NetworkResourceLoadParameters.h
Source/WebKit2/Shared/SessionTracker.cpp
Source/WebKit2/Shared/SessionTracker.h
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPage.h
Source/WebKit2/UIProcess/API/C/WKSessionRef.cpp
Source/WebKit2/UIProcess/API/C/WKSessionRef.h
Source/WebKit2/UIProcess/APISession.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm
Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp
Source/WebKit2/WebProcess/WebPage/WebFrame.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index 211032b..463af28 100644 (file)
@@ -1,3 +1,62 @@
+2014-01-22  Martin Hock  <mhock@apple.com>
+
+        Enable Session API.
+        https://bugs.webkit.org/show_bug.cgi?id=127255
+
+        Reviewed by Alexey Proskuryakov.
+
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::storageSession):
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::NetworkResourceLoader):
+        (WebKit::NetworkResourceLoader::start):
+        * NetworkProcess/NetworkResourceLoader.h:
+        * NetworkProcess/RemoteNetworkingContext.h:
+        * NetworkProcess/mac/RemoteNetworkingContext.mm:
+        (WebKit::RemoteNetworkingContext::storageSession):
+        (WebKit::RemoteNetworkingContext::ensurePrivateBrowsingSession):
+        * Shared/Network/NetworkResourceLoadParameters.cpp:
+        (WebKit::NetworkResourceLoadParameters::NetworkResourceLoadParameters):
+        (WebKit::NetworkResourceLoadParameters::encode):
+        (WebKit::NetworkResourceLoadParameters::decode):
+        * Shared/Network/NetworkResourceLoadParameters.h:
+        * Shared/SessionTracker.cpp:
+        (WebKit::staticSessionMap):
+        (WebKit::SessionTracker::sessionMap):
+        (WebKit::SessionTracker::session):
+        (WebKit::SessionTracker::setSession):
+        (WebKit::SessionTracker::destroySession):
+        * Shared/SessionTracker.h:
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetSession):
+        * UIProcess/API/C/WKPage.h:
+        * UIProcess/API/C/WKSessionRef.cpp:
+        (WKSessionCreate):
+        * UIProcess/API/C/WKSessionRef.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::WebPageProxy):
+        (WebKit::WebPageProxy::setSession):
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/Network/WebResourceLoadScheduler.cpp:
+        (WebKit::WebResourceLoadScheduler::scheduleLoad):
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
+        (WebKit::WebPlatformStrategies::loadResourceSynchronously):
+        * WebProcess/WebCoreSupport/mac/WebFrameNetworkingContext.mm:
+        (WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession):
+        (WebKit::WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts):
+        (WebKit::WebFrameNetworkingContext::storageSession):
+        * WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp:
+        (WebKit::WebFrameNetworkingContext::ensurePrivateBrowsingSession):
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::startDownload):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage):
+        (WebKit::WebPage::sessionID):
+        (WebKit::WebPage::updatePreferences):
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::setSessionID):
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2014-01-21  Brady Eidson  <beidson@apple.com>
 
         IDB: "Put" support
index b1dd56a..1fee498 100644 (file)
@@ -151,7 +151,7 @@ void NetworkConnectionToWebProcess::setSerialLoadingEnabled(bool enabled)
 static NetworkStorageSession& storageSession(uint64_t sessionID)
 {
     if (SessionTracker::isEphemeralID(sessionID)) {
-        NetworkStorageSession* privateSession = SessionTracker::session(sessionID).get();
+        NetworkStorageSession* privateSession = SessionTracker::session(sessionID);
         if (privateSession)
             return *privateSession;
         // Some requests with private browsing mode requested may still be coming shortly after NetworkProcess was told to destroy its session.
index f2c40f8..a6fa006 100644 (file)
@@ -59,12 +59,12 @@ NetworkResourceLoader::NetworkResourceLoader(const NetworkResourceLoadParameters
     , m_identifier(parameters.identifier)
     , m_webPageID(parameters.webPageID)
     , m_webFrameID(parameters.webFrameID)
+    , m_sessionID(parameters.sessionID)
     , m_request(parameters.request)
     , m_priority(parameters.priority)
     , m_contentSniffingPolicy(parameters.contentSniffingPolicy)
     , m_allowStoredCredentials(parameters.allowStoredCredentials)
     , m_clientCredentialPolicy(parameters.clientCredentialPolicy)
-    , m_inPrivateBrowsingMode(parameters.inPrivateBrowsingMode)
     , m_shouldClearReferrerOnHTTPSToHTTPRedirect(parameters.shouldClearReferrerOnHTTPSToHTTPRedirect)
     , m_isLoadingMainResource(parameters.isMainResource)
     , m_sandboxExtensionsAreConsumed(false)
@@ -127,7 +127,7 @@ void NetworkResourceLoader::start()
     ref();
 
     // FIXME (NetworkProcess): Set platform specific settings.
-    m_networkingContext = RemoteNetworkingContext::create(m_inPrivateBrowsingMode, m_shouldClearReferrerOnHTTPSToHTTPRedirect);
+    m_networkingContext = RemoteNetworkingContext::create(m_sessionID, m_shouldClearReferrerOnHTTPSToHTTPRedirect);
 
     consumeSandboxExtensions();
 
index eeb2cc0..7b69a59 100644 (file)
@@ -174,12 +174,12 @@ private:
     ResourceLoadIdentifier m_identifier;
     uint64_t m_webPageID;
     uint64_t m_webFrameID;
+    uint64_t m_sessionID;
     WebCore::ResourceRequest m_request;
     WebCore::ResourceLoadPriority m_priority;
     WebCore::ContentSniffingPolicy m_contentSniffingPolicy;
     WebCore::StoredCredentials m_allowStoredCredentials;
     WebCore::ClientCredentialPolicy m_clientCredentialPolicy;
-    bool m_inPrivateBrowsingMode;
     bool m_shouldClearReferrerOnHTTPSToHTTPRedirect;
     bool m_isLoadingMainResource;
 
index 5f3bf70..da6b37a 100644 (file)
@@ -33,20 +33,20 @@ namespace WebKit {
 
 class RemoteNetworkingContext final : public WebCore::NetworkingContext {
 public:
-    static PassRefPtr<RemoteNetworkingContext> create(bool privateBrowsingEnabled, bool shouldClearReferrerOnHTTPSToHTTPRedirect)
+    static PassRefPtr<RemoteNetworkingContext> create(uint64_t sessionID, bool shouldClearReferrerOnHTTPSToHTTPRedirect)
     {
-        return adoptRef(new RemoteNetworkingContext(privateBrowsingEnabled, shouldClearReferrerOnHTTPSToHTTPRedirect));
+        return adoptRef(new RemoteNetworkingContext(sessionID, shouldClearReferrerOnHTTPSToHTTPRedirect));
     }
     virtual ~RemoteNetworkingContext();
 
-    // FIXME: remove platform-specific code and use SessionTracker
+    // FIXME: Remove platform-specific code and use SessionTracker.
     static void ensurePrivateBrowsingSession(uint64_t sessionID);
 
     virtual bool shouldClearReferrerOnHTTPSToHTTPRedirect() const override { return m_shouldClearReferrerOnHTTPSToHTTPRedirect; }
 
 private:
-    RemoteNetworkingContext(bool privateBrowsingEnabled, bool shouldClearReferrerOnHTTPSToHTTPRedirect)
-        : m_privateBrowsingEnabled(privateBrowsingEnabled)
+    RemoteNetworkingContext(uint64_t sessionID, bool shouldClearReferrerOnHTTPSToHTTPRedirect)
+        : m_sessionID(sessionID)
         , m_shouldClearReferrerOnHTTPSToHTTPRedirect(shouldClearReferrerOnHTTPSToHTTPRedirect)
 #if PLATFORM(MAC)
         , m_needsSiteSpecificQuirks(false)
@@ -70,7 +70,7 @@ private:
     virtual uint64_t initiatingPageID() const;
 #endif
 
-    bool m_privateBrowsingEnabled;
+    uint64_t m_sessionID;
     bool m_shouldClearReferrerOnHTTPSToHTTPRedirect;
 
 #if PLATFORM(MAC)
index 1059b88..f60e5db 100644 (file)
@@ -59,15 +59,11 @@ bool RemoteNetworkingContext::localFileContentSniffingEnabled() const
 
 NetworkStorageSession& RemoteNetworkingContext::storageSession() const
 {
-    if (m_privateBrowsingEnabled) {
-        NetworkStorageSession* privateSession = SessionTracker::session(SessionTracker::legacyPrivateSessionID).get();
-        if (privateSession)
-            return *privateSession;
-        // Some requests with private browsing mode requested may still be coming shortly after NetworkProcess was told to destroy its session.
-        // FIXME: Find a way to track private browsing sessions more rigorously.
-        LOG_ERROR("Private browsing was requested, but there was no session for it. Please file a bug unless you just disabled private browsing, in which case it's an expected race.");
-    }
-
+    NetworkStorageSession* session = SessionTracker::session(m_sessionID);
+    if (session)
+        return *session;
+    // Some requests may still be coming shortly after NetworkProcess was told to destroy its session.
+    LOG_ERROR("Invalid session ID. Please file a bug unless you just disabled private browsing, in which case it's an expected race.");
     return NetworkStorageSession::defaultStorageSession();
 }
 
@@ -87,7 +83,7 @@ void RemoteNetworkingContext::ensurePrivateBrowsingSession(uint64_t sessionID)
         return;
 
     ASSERT(!SessionTracker::getIdentifierBase().isNull());
-    SessionTracker::session(sessionID) = NetworkStorageSession::createPrivateBrowsingSession(SessionTracker::getIdentifierBase() + '.' + String::number(sessionID));
+    SessionTracker::setSession(sessionID, NetworkStorageSession::createPrivateBrowsingSession(SessionTracker::getIdentifierBase() + '.' + String::number(sessionID)));
 }
 
 }
index 57a0571..54cabf4 100644 (file)
@@ -41,11 +41,11 @@ NetworkResourceLoadParameters::NetworkResourceLoadParameters()
     : identifier(0)
     , webPageID(0)
     , webFrameID(0)
+    , sessionID(0)
     , priority(ResourceLoadPriorityVeryLow)
     , contentSniffingPolicy(SniffContent)
     , allowStoredCredentials(DoNotAllowStoredCredentials)
     , clientCredentialPolicy(DoNotAskClientForAnyCredentials)
-    , inPrivateBrowsingMode(false)
     , shouldClearReferrerOnHTTPSToHTTPRedirect(true)
     , isMainResource(false)
 {
@@ -56,6 +56,7 @@ void NetworkResourceLoadParameters::encode(IPC::ArgumentEncoder& encoder) const
     encoder << identifier;
     encoder << webPageID;
     encoder << webFrameID;
+    encoder << sessionID;
     encoder << request;
 
     encoder << static_cast<bool>(request.httpBody());
@@ -94,7 +95,6 @@ void NetworkResourceLoadParameters::encode(IPC::ArgumentEncoder& encoder) const
     encoder.encodeEnum(contentSniffingPolicy);
     encoder.encodeEnum(allowStoredCredentials);
     encoder.encodeEnum(clientCredentialPolicy);
-    encoder << inPrivateBrowsingMode;
     encoder << shouldClearReferrerOnHTTPSToHTTPRedirect;
     encoder << isMainResource;
 }
@@ -110,6 +110,9 @@ bool NetworkResourceLoadParameters::decode(IPC::ArgumentDecoder& decoder, Networ
     if (!decoder.decode(result.webFrameID))
         return false;
 
+    if (!decoder.decode(result.sessionID))
+        return false;
+
     if (!decoder.decode(result.request))
         return false;
 
@@ -141,8 +144,6 @@ bool NetworkResourceLoadParameters::decode(IPC::ArgumentDecoder& decoder, Networ
         return false;
     if (!decoder.decodeEnum(result.clientCredentialPolicy))
         return false;
-    if (!decoder.decode(result.inPrivateBrowsingMode))
-        return false;
     if (!decoder.decode(result.shouldClearReferrerOnHTTPSToHTTPRedirect))
         return false;
     if (!decoder.decode(result.isMainResource))
index ace0634..cbf4531 100644 (file)
@@ -52,6 +52,7 @@ public:
     ResourceLoadIdentifier identifier;
     uint64_t webPageID;
     uint64_t webFrameID;
+    uint64_t sessionID;
     WebCore::ResourceRequest request;
     SandboxExtension::HandleArray requestBodySandboxExtensions; // Created automatically for the sender.
     SandboxExtension::Handle resourceSandboxExtension; // Created automatically for the sender.
@@ -59,7 +60,6 @@ public:
     WebCore::ContentSniffingPolicy contentSniffingPolicy;
     WebCore::StoredCredentials allowStoredCredentials;
     WebCore::ClientCredentialPolicy clientCredentialPolicy;
-    bool inPrivateBrowsingMode;
     bool shouldClearReferrerOnHTTPSToHTTPRedirect;
     bool isMainResource;
 };
index cec3aa3..baaff9b 100644 (file)
@@ -33,7 +33,7 @@ using namespace WebCore;
 
 namespace WebKit {
 
-static HashMap<uint64_t, std::unique_ptr<NetworkStorageSession>>& sessionMap()
+static HashMap<uint64_t, std::unique_ptr<NetworkStorageSession>>& staticSessionMap()
 {
     ASSERT(isMainThread());
 
@@ -49,9 +49,9 @@ static String& identifierBase()
     return base;
 }
 
-const HashMap<uint64_t, std::unique_ptr<NetworkStorageSession>>& SessionTracker::getSessionMap()
+const HashMap<uint64_t, std::unique_ptr<NetworkStorageSession>>& SessionTracker::sessionMap()
 {
-    return sessionMap();
+    return staticSessionMap();
 }
 
 const String& SessionTracker::getIdentifierBase()
@@ -59,16 +59,24 @@ const String& SessionTracker::getIdentifierBase()
     return identifierBase();
 }
 
-std::unique_ptr<NetworkStorageSession>& SessionTracker::session(uint64_t sessionID)
+NetworkStorageSession* SessionTracker::session(uint64_t sessionID)
 {
-    return sessionMap().add(sessionID, nullptr).iterator->value;
+    if (sessionID == defaultSessionID)
+        return &NetworkStorageSession::defaultStorageSession();
+    return staticSessionMap().add(sessionID, nullptr).iterator->value.get();
+}
+
+void SessionTracker::setSession(uint64_t sessionID, std::unique_ptr<NetworkStorageSession> session)
+{
+    ASSERT(sessionID != defaultSessionID);
+    staticSessionMap().add(sessionID, nullptr).iterator->value = std::move(session);
 }
 
 void SessionTracker::destroySession(uint64_t sessionID)
 {
     ASSERT(isMainThread());
 
-    sessionMap().remove(sessionID);
+    staticSessionMap().remove(sessionID);
 }
 
 void SessionTracker::setIdentifierBase(const String& identifier)
index 52c6e20..5d38f10 100644 (file)
@@ -39,9 +39,11 @@ public:
     static const uint64_t defaultSessionID = 1;
     static const uint64_t legacyPrivateSessionID = 2;
     static bool isEphemeralID(uint64_t sessionID) { return sessionID != SessionTracker::defaultSessionID; }
-    static const HashMap<uint64_t, std::unique_ptr<WebCore::NetworkStorageSession>>& getSessionMap();
+    // FIXME: sessionMap()'s returned map does not include default session.
+    static const HashMap<uint64_t, std::unique_ptr<WebCore::NetworkStorageSession>>& sessionMap();
     static const String& getIdentifierBase();
-    static std::unique_ptr<WebCore::NetworkStorageSession>& session(uint64_t sessionID);
+    static WebCore::NetworkStorageSession* session(uint64_t sessionID);
+    static void setSession(uint64_t sessionID, std::unique_ptr<WebCore::NetworkStorageSession>);
     static void destroySession(uint64_t sessionID);
     static void setIdentifierBase(const String&);
 };
index 847b43c..bb139bc 100644 (file)
@@ -680,6 +680,11 @@ void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient
     toImpl(pageRef)->initializeUIClient(wkClient);
 }
 
+void WKPageSetSession(WKPageRef pageRef, WKSessionRef session)
+{
+    toImpl(pageRef)->setSession(*toImpl(session));
+}
+
 void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback)
 {
     toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), ScriptValueCallback::create(context, callback));
index a3e4062..216a8ff 100644 (file)
@@ -41,6 +41,7 @@
 #include <WebKit2/WKPagePolicyClient.h>
 #include <WebKit2/WKPageUIClient.h>
 #include <WebKit2/WKPageVisibilityTypes.h>
+#include <WebKit2/WKSessionRef.h>
 
 #ifndef __cplusplus
 #include <stdbool.h>
@@ -201,6 +202,8 @@ WK_EXPORT void WKPageSetPageLoaderClient(WKPageRef page, const WKPageLoaderClien
 WK_EXPORT void WKPageSetPagePolicyClient(WKPageRef page, const WKPagePolicyClientBase* client);
 WK_EXPORT void WKPageSetPageUIClient(WKPageRef page, const WKPageUIClientBase* client);
 
+WK_EXPORT void WKPageSetSession(WKPageRef page, WKSessionRef session);
+
 typedef void (*WKPageRunJavaScriptFunction)(WKSerializedScriptValueRef, WKErrorRef, void*);
 WK_EXPORT void WKPageRunJavaScriptInMainFrame(WKPageRef page, WKStringRef script, void* context, WKPageRunJavaScriptFunction function);
 #ifdef __BLOCKS__
index 44aa37a..4af2f7b 100644 (file)
 
 using namespace WebKit;
 
+WKSessionRef WKSessionCreate(bool isEphemeral)
+{
+    RefPtr<API::Session> session = API::Session::create(isEphemeral);
+    return toAPI(session.release().leakRef());
+}
+
 WKTypeID WKSessionGetTypeID()
 {
     return toAPI(API::Session::APIType);
index e42d8c5..63fa542 100644 (file)
@@ -32,6 +32,9 @@
 extern "C" {
 #endif
 
+/* FIXME: We can create sessions on demand, because we hardcode the fact that all sessions but the default one are ephemeral. We'll need to create them explicitly once sessions have more configuration options. */
+WK_EXPORT WKSessionRef WKSessionCreate(bool isEphemeral);
+
 WK_EXPORT WKTypeID WKSessionGetTypeID();
 
 WK_EXPORT bool WKSessionIsEphemeral(WKSessionRef session);
index df716e5..bd604b2 100644 (file)
@@ -34,6 +34,7 @@ namespace API {
 
 class Session : public API::ObjectImpl<API::Object::Type::Session> {
 public:
+    // FIXME: We can create sessions on demand, because we hardcode the fact that all sessions but the default one are ephemeral. We'll need to create them explicitly once sessions have more configuration options.
     static PassRefPtr<Session> create(bool isEphemeral);
     static Session& defaultSession();
     static Session& legacyPrivateSession();
index d23df27..6d11fd1 100644 (file)
 #include <wtf/RefCountedLeakCounter.h>
 #endif
 
+#if ENABLE(NETWORK_PROCESS)
+#include "NetworkProcessMessages.h"
+#endif
+
 // This controls what strategy we use for mouse wheel coalescing.
 #define MERGE_WHEEL_EVENTS 1
 
@@ -341,6 +345,7 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, Web
 
     // FIXME: If we ever expose the session storage size as a preference, we need to pass it here.
     m_process->context().storageManager().createSessionStorageNamespace(m_pageID, m_process->isValid() ? m_process->connection() : 0, std::numeric_limits<unsigned>::max());
+    setSession(session);
 }
 
 WebPageProxy::~WebPageProxy()
@@ -497,6 +502,16 @@ void WebPageProxy::reattachToWebProcessWithItem(WebBackForwardListItem* item)
     m_process->responsivenessTimer()->start();
 }
 
+void WebPageProxy::setSession(API::Session& session)
+{
+    m_session = session;
+    m_process->send(Messages::WebPage::SetSessionID(session.getID()), m_pageID);
+
+#if ENABLE(NETWORK_PROCESS)
+    m_process->context().sendToNetworkingProcess(Messages::NetworkProcess::EnsurePrivateBrowsingSession(session.getID()));
+#endif
+}
+
 void WebPageProxy::initializeWebPage()
 {
     ASSERT(isValid());
index 7240dc2..fca2102 100644 (file)
@@ -332,6 +332,8 @@ public:
     static PassRefPtr<WebPageProxy> create(PageClient&, WebProcessProxy&, WebPageGroup&, API::Session&, uint64_t pageID);
     virtual ~WebPageProxy();
 
+    void setSession(API::Session&);
+
     uint64_t pageID() const { return m_pageID; }
     uint64_t sessionID() const { return m_session->getID(); }
 
index 45163e0..eabd654 100644 (file)
@@ -30,6 +30,7 @@
 #include "NetworkConnectionToWebProcessMessages.h"
 #include "NetworkProcessConnection.h"
 #include "NetworkResourceLoadParameters.h"
+#include "SessionTracker.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebErrors.h"
 #include "WebFrame.h"
@@ -105,7 +106,6 @@ void WebResourceLoadScheduler::scheduleLoad(ResourceLoader* resourceLoader, Cach
 
     ContentSniffingPolicy contentSniffingPolicy = resourceLoader->shouldSniffContent() ? SniffContent : DoNotSniffContent;
     StoredCredentials allowStoredCredentials = resourceLoader->shouldUseCredentialStorage() ? AllowStoredCredentials : DoNotAllowStoredCredentials;
-    bool privateBrowsingEnabled = resourceLoader->frameLoader()->frame().settings().privateBrowsingEnabled();
 
     // FIXME: Some entities in WebCore use WebCore's "EmptyFrameLoaderClient" instead of having a proper WebFrameLoaderClient.
     // EmptyFrameLoaderClient shouldn't exist and everything should be using a WebFrameLoaderClient,
@@ -118,13 +118,13 @@ void WebResourceLoadScheduler::scheduleLoad(ResourceLoader* resourceLoader, Cach
     loadParameters.identifier = identifier;
     loadParameters.webPageID = webPage ? webPage->pageID() : 0;
     loadParameters.webFrameID = webFrame ? webFrame->frameID() : 0;
+    loadParameters.sessionID = webPage ? webPage->sessionID() : SessionTracker::defaultSessionID;
     loadParameters.request = resourceLoader->request();
     loadParameters.priority = priority;
     loadParameters.contentSniffingPolicy = contentSniffingPolicy;
     loadParameters.allowStoredCredentials = allowStoredCredentials;
     // If there is no WebFrame then this resource cannot be authenticated with the client.
     loadParameters.clientCredentialPolicy = (webFrame && webPage) ? resourceLoader->clientCredentialPolicy() : DoNotAskClientForAnyCredentials;
-    loadParameters.inPrivateBrowsingMode = privateBrowsingEnabled;
     loadParameters.shouldClearReferrerOnHTTPSToHTTPRedirect = shouldClearReferrerOnHTTPSToHTTPRedirect;
     loadParameters.isMainResource = resource && resource->type() == CachedResource::MainResource;
 
index 45f68dc..a7d32c3 100644 (file)
@@ -270,12 +270,12 @@ void WebPlatformStrategies::loadResourceSynchronously(NetworkingContext* context
     loadParameters.identifier = resourceLoadIdentifier;
     loadParameters.webPageID = webPage ? webPage->pageID() : 0;
     loadParameters.webFrameID = webFrame ? webFrame->frameID() : 0;
+    loadParameters.sessionID = webPage ? webPage->sessionID() : SessionTracker::defaultSessionID;
     loadParameters.request = request;
     loadParameters.priority = ResourceLoadPriorityHighest;
     loadParameters.contentSniffingPolicy = SniffContent;
     loadParameters.allowStoredCredentials = storedCredentials;
     loadParameters.clientCredentialPolicy = clientCredentialPolicy;
-    loadParameters.inPrivateBrowsingMode = context->storageSession().isPrivateBrowsingSession();
     loadParameters.shouldClearReferrerOnHTTPSToHTTPRedirect = context->shouldClearReferrerOnHTTPSToHTTPRedirect();
 
     data.resize(0);
index 4762de4..6b59ac4 100644 (file)
@@ -28,6 +28,7 @@
 #include "SessionTracker.h"
 #include "WebCookieManager.h"
 #include "WebFrameNetworkingContext.h"
+#include "WebPage.h"
 #include <WebCore/Frame.h>
 #include <WebCore/FrameLoader.h>
 #include <WebCore/FrameLoaderClient.h>
@@ -52,7 +53,7 @@ void WebFrameNetworkingContext::ensurePrivateBrowsingSession(uint64_t sessionID)
     else
         base = SessionTracker::getIdentifierBase();
 
-    SessionTracker::session(sessionID) = NetworkStorageSession::createPrivateBrowsingSession(base + '.' + String::number(sessionID));
+    SessionTracker::setSession(sessionID, NetworkStorageSession::createPrivateBrowsingSession(base + '.' + String::number(sessionID)));
 }
 
 void WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts(HTTPCookieAcceptPolicy policy)
@@ -62,7 +63,7 @@ void WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts(HTTPCookieAc
     if (RetainPtr<CFHTTPCookieStorageRef> cookieStorage = NetworkStorageSession::defaultStorageSession().cookieStorage())
         WKSetHTTPCookieAcceptPolicy(cookieStorage.get(), policy);
 
-    for (const auto& session : SessionTracker::getSessionMap().values()) {
+    for (const auto& session : SessionTracker::sessionMap().values()) {
         if (session)
             WKSetHTTPCookieAcceptPolicy(session->cookieStorage().get(), policy);
     }
@@ -99,11 +100,11 @@ NetworkStorageSession& WebFrameNetworkingContext::storageSession() const
 {
     ASSERT(isMainThread());
 
-    if (frame() && frame()->settings().privateBrowsingEnabled())
-        return *SessionTracker::session(SessionTracker::legacyPrivateSessionID);
-
+    if (frame())
+        return *SessionTracker::session(webFrameLoaderClient()->webFrame()->page()->sessionID());
     return NetworkStorageSession::defaultStorageSession();
 }
+
 WebFrameLoaderClient* WebFrameNetworkingContext::webFrameLoaderClient() const
 {
     if (!frame())
index 4aa96ca..2450743 100644 (file)
@@ -44,7 +44,7 @@ void WebFrameNetworkingContext::ensurePrivateBrowsingSession(uint64_t sessionID)
     if (SessionTracker::session(sessionID))
         return;
 
-    SessionTracker::session(sessionID) = NetworkStorageSession::createPrivateBrowsingSession(String::number(sessionID));
+    SessionTracker::setSession(sessionID, NetworkStorageSession::createPrivateBrowsingSession(String::number(sessionID)));
 }
 
 WebFrameNetworkingContext::WebFrameNetworkingContext(WebFrame* frame)
index 64ba5e9..c49a41c 100644 (file)
@@ -234,8 +234,7 @@ void WebFrame::startDownload(const WebCore::ResourceRequest& request)
 
 #if ENABLE(NETWORK_PROCESS)
     if (WebProcess::shared().usesNetworkProcess()) {
-        bool privateBrowsingEnabled = m_coreFrame->loader().networkingContext()->storageSession().isPrivateBrowsingSession();
-        WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::StartDownload(privateBrowsingEnabled, policyDownloadID, request), 0);
+        WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::StartDownload(page()->sessionID(), policyDownloadID, request), 0);
         return;
     }
 #endif
index 3a6b99b..66dee8b 100644 (file)
@@ -223,6 +223,7 @@ PassRefPtr<WebPage> WebPage::create(uint64_t pageID, const WebPageCreationParame
 
 WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
     : m_pageID(pageID)
+    , m_sessionID(0)
     , m_viewSize(parameters.viewSize)
     , m_hasSeenPlugin(false)
     , m_useFixedLayout(false)
@@ -2121,6 +2122,14 @@ void WebPage::setLayerHostingMode(unsigned layerHostingMode)
         pluginView->setLayerHostingMode(m_layerHostingMode);
 }
 
+uint64_t WebPage::sessionID() const
+{
+    if (m_sessionID)
+        return m_sessionID;
+
+    return m_page->settings().privateBrowsingEnabled() ? SessionTracker::legacyPrivateSessionID : SessionTracker::defaultSessionID;
+}
+
 void WebPage::didReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction, uint64_t downloadID)
 {
     WebFrame* frame = WebProcess::shared().webFrame(frameID);
@@ -2423,7 +2432,10 @@ void WebPage::updatePreferences(const WebPreferencesStore& store)
     settings.setLocalStorageEnabled(store.getBoolValueForKey(WebPreferencesKey::localStorageEnabledKey()));
     settings.setXSSAuditorEnabled(store.getBoolValueForKey(WebPreferencesKey::xssAuditorEnabledKey()));
     settings.setFrameFlatteningEnabled(store.getBoolValueForKey(WebPreferencesKey::frameFlatteningEnabledKey()));
-    settings.setPrivateBrowsingEnabled(store.getBoolValueForKey(WebPreferencesKey::privateBrowsingEnabledKey()));
+    if (m_sessionID)
+        settings.setPrivateBrowsingEnabled(SessionTracker::isEphemeralID(m_sessionID));
+    else
+        settings.setPrivateBrowsingEnabled(store.getBoolValueForKey(WebPreferencesKey::privateBrowsingEnabledKey()));
     settings.setDeveloperExtrasEnabled(store.getBoolValueForKey(WebPreferencesKey::developerExtrasEnabledKey()));
     settings.setJavaScriptExperimentsEnabled(store.getBoolValueForKey(WebPreferencesKey::javaScriptExperimentsEnabledKey()));
     settings.setTextAreasAreResizable(store.getBoolValueForKey(WebPreferencesKey::textAreasAreResizableKey()));
index fe301b1..8735a2d 100644 (file)
@@ -179,6 +179,8 @@ public:
 
     WebCore::Page* corePage() const { return m_page.get(); }
     uint64_t pageID() const { return m_pageID; }
+    uint64_t sessionID() const;
+    void setSessionID(uint64_t sessionID) { m_sessionID = sessionID; }
 
     void setSize(const WebCore::IntSize&);
     const WebCore::IntSize& size() const { return m_viewSize; }
@@ -873,6 +875,7 @@ private:
     void reportUsedFeatures();
 
     uint64_t m_pageID;
+    uint64_t m_sessionID;
 
     OwnPtr<WebCore::Page> m_page;
     RefPtr<WebFrame> m_mainFrame;
index 21bcb5f..400fb4f 100644 (file)
@@ -25,6 +25,8 @@ messages -> WebPage LegacyReceiver {
     SetViewState(unsigned viewState, bool wantsDidUpdateViewState)
     SetLayerHostingMode(unsigned layerHostingMode)
 
+    SetSessionID(uint64_t sessionID)
+
     SetDrawsBackground(bool drawsBackground)
     SetDrawsTransparentBackground(bool drawsTransparentBackground)