WebPageGroup's should keep track of what processes they are being used by
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Nov 2013 04:09:24 +0000 (04:09 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Nov 2013 04:09:24 +0000 (04:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=124556

Reviewed by Dan Bernstein.

* Scripts/webkit2/messages.py:
(struct_or_class):
Mark WebPageGroupData as a struct.

* Shared/UserMessageCoders.h:
* Shared/mac/ObjCObjectGraphCoders.h:
* Shared/mac/ObjCObjectGraphCoders.mm:
* WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h:
* UIProcess/WebConnectionToWebProcess.cpp:
* UIProcess/WebContext.cpp:
* UIProcess/WebContextUserMessageCoders.h:
* UIProcess/WebPageProxy.cpp:
* UIProcess/WebPageProxy.h:
Pass the WebProcess/WebProcessProxy to both encode and decode.

* Shared/WebPageCreationParameters.h:
Pass the page group by ID when creating a page, as it will have had its own
creation message sent already.

* UIProcess/WebPageGroup.cpp:
* UIProcess/WebPageGroup.h:
Keep track of processes.

* UIProcess/WebProcessProxy.cpp:
* UIProcess/WebProcessProxy.h:
Keep track of the page groups used by the process.

* WebProcess/WebPage/WebPage.cpp:
Get the already created page group on creation.

* WebProcess/WebProcess.cpp:
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:
Explicitly create page groups in the WebProcess.

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

21 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/Scripts/webkit2/messages.py
Source/WebKit2/Shared/UserMessageCoders.h
Source/WebKit2/Shared/WebPageCreationParameters.cpp
Source/WebKit2/Shared/WebPageCreationParameters.h
Source/WebKit2/Shared/mac/ObjCObjectGraphCoders.h
Source/WebKit2/Shared/mac/ObjCObjectGraphCoders.mm
Source/WebKit2/UIProcess/WebConnectionToWebProcess.cpp
Source/WebKit2/UIProcess/WebContext.cpp
Source/WebKit2/UIProcess/WebContextUserMessageCoders.h
Source/WebKit2/UIProcess/WebPageGroup.cpp
Source/WebKit2/UIProcess/WebPageGroup.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebProcessProxy.cpp
Source/WebKit2/UIProcess/WebProcessProxy.h
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebProcess.cpp
Source/WebKit2/WebProcess/WebProcess.h
Source/WebKit2/WebProcess/WebProcess.messages.in

index 68156f1..39b8b4a 100644 (file)
@@ -1,3 +1,45 @@
+2013-11-18  Sam Weinig  <sam@webkit.org>
+
+        WebPageGroup's should keep track of what processes they are being used by
+        https://bugs.webkit.org/show_bug.cgi?id=124556
+
+        Reviewed by Dan Bernstein.
+
+        * Scripts/webkit2/messages.py:
+        (struct_or_class):
+        Mark WebPageGroupData as a struct.
+
+        * Shared/UserMessageCoders.h:
+        * Shared/mac/ObjCObjectGraphCoders.h:
+        * Shared/mac/ObjCObjectGraphCoders.mm:
+        * WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h:
+        * UIProcess/WebConnectionToWebProcess.cpp:
+        * UIProcess/WebContext.cpp:
+        * UIProcess/WebContextUserMessageCoders.h:
+        * UIProcess/WebPageProxy.cpp:
+        * UIProcess/WebPageProxy.h:
+        Pass the WebProcess/WebProcessProxy to both encode and decode.
+
+        * Shared/WebPageCreationParameters.h:
+        Pass the page group by ID when creating a page, as it will have had its own
+        creation message sent already.
+
+        * UIProcess/WebPageGroup.cpp:
+        * UIProcess/WebPageGroup.h:
+        Keep track of processes.
+
+        * UIProcess/WebProcessProxy.cpp:
+        * UIProcess/WebProcessProxy.h:
+        Keep track of the page groups used by the process.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        Get the already created page group on creation.
+
+        * WebProcess/WebProcess.cpp:
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+        Explicitly create page groups in the WebProcess.
+
 2013-11-20  Brady Eidson  <beidson@apple.com>
 
         IDB related cleanup in WebKit2
index 9aa976a..f448293 100644 (file)
@@ -213,6 +213,7 @@ def struct_or_class(namespace, type):
         'WebKit::TextCheckerState',
         'WebKit::WebNavigationDataStore',
         'WebKit::WebPageCreationParameters',
+        'WebKit::WebPageGroupData',
         'WebKit::WebPreferencesStore',
         'WebKit::WebProcessCreationParameters',
         'WebKit::WindowGeometry',
index 2d79a52..570f18e 100644 (file)
@@ -71,7 +71,7 @@ namespace WebKit {
 template<typename Owner>
 class UserMessageEncoder {
 public:
-    bool baseEncode(CoreIPC::ArgumentEncoder& encoder, API::Object::Type& type) const
+    bool baseEncode(CoreIPC::ArgumentEncoder& encoder, const Owner& coder, API::Object::Type& type) const
     {
         if (!m_root) {
             encoder << static_cast<uint32_t>(API::Object::Type::Null);
@@ -86,7 +86,7 @@ public:
             API::Array* array = static_cast<API::Array*>(m_root);
             encoder << static_cast<uint64_t>(array->size());
             for (size_t i = 0; i < array->size(); ++i)
-                encoder << Owner(array->at(i));
+                encoder << Owner(coder, array->at(i));
             return true;
         }
         case API::Object::Type::Dictionary: {
@@ -98,7 +98,7 @@ public:
             ImmutableDictionary::MapType::const_iterator end = map.end();
             for (; it != end; ++it) {
                 encoder << it->key;
-                encoder << Owner(it->value.get());
+                encoder << Owner(coder, it->value.get());
             }
             return true;
         }
@@ -149,15 +149,15 @@ public:
         }
         case API::Object::Type::RenderLayer: {
             WebRenderLayer* renderLayer = static_cast<WebRenderLayer*>(m_root);
-            encoder << Owner(renderLayer->renderer());
+            encoder << Owner(coder, renderLayer->renderer());
             encoder << renderLayer->isReflection();
             encoder << renderLayer->isClipping();
             encoder << renderLayer->isClipped();
             encoder << static_cast<uint32_t>(renderLayer->compositingLayerType());
             encoder << renderLayer->absoluteBoundingBox();
-            encoder << Owner(renderLayer->negativeZOrderList());
-            encoder << Owner(renderLayer->normalFlowList());
-            encoder << Owner(renderLayer->positiveZOrderList());
+            encoder << Owner(coder, renderLayer->negativeZOrderList());
+            encoder << Owner(coder, renderLayer->normalFlowList());
+            encoder << Owner(coder, renderLayer->positiveZOrderList());
             return true;
         }
         case API::Object::Type::RenderObject: {
@@ -165,10 +165,10 @@ public:
             encoder << renderObject->name();
             encoder << renderObject->elementTagName();
             encoder << renderObject->elementID();
-            encoder << Owner(renderObject->elementClassNames());
+            encoder << Owner(coder, renderObject->elementClassNames());
             encoder << renderObject->absolutePosition();
             encoder << renderObject->frameRect();
-            encoder << Owner(renderObject->children());
+            encoder << Owner(coder, renderObject->children());
             return true;
         }
         case API::Object::Type::URL: {
index 1dbf95b..22c5b62 100644 (file)
@@ -37,7 +37,7 @@ void WebPageCreationParameters::encode(CoreIPC::ArgumentEncoder& encoder) const
 
     encoder << store;
     encoder.encodeEnum(drawingAreaType);
-    encoder << pageGroupData;
+    encoder << pageGroupID;
     encoder << drawsBackground;
     encoder << drawsTransparentBackground;
     encoder << underlayColor;
@@ -76,7 +76,7 @@ bool WebPageCreationParameters::decode(CoreIPC::ArgumentDecoder& decoder, WebPag
         return false;
     if (!decoder.decodeEnum(parameters.drawingAreaType))
         return false;
-    if (!decoder.decode(parameters.pageGroupData))
+    if (!decoder.decode(parameters.pageGroupID))
         return false;
     if (!decoder.decode(parameters.drawsBackground))
         return false;
index cfb0f39..a730c87 100644 (file)
@@ -60,7 +60,7 @@ struct WebPageCreationParameters {
     
     WebPreferencesStore store;
     DrawingAreaType drawingAreaType;
-    WebPageGroupData pageGroupData;
+    uint64_t pageGroupID;
 
     bool drawsBackground;
     bool drawsTransparentBackground;
index 4191e57..b6db2e7 100644 (file)
@@ -38,11 +38,12 @@ class WebProcessProxy;
 
 class WebContextObjCObjectGraphEncoder {
 public:
-    explicit WebContextObjCObjectGraphEncoder(ObjCObjectGraph*);
+    explicit WebContextObjCObjectGraphEncoder(ObjCObjectGraph*, WebProcessProxy*);
     void encode(CoreIPC::ArgumentEncoder&) const;
 
 private:
     ObjCObjectGraph* m_objectGraph;
+    WebProcessProxy* m_process;
 };
 
 class WebContextObjCObjectGraphDecoder {
index 5a91cca..8158ad0 100644 (file)
@@ -92,7 +92,7 @@ static WebKitNSType typeFromObject(id object)
 template<typename Owner>
 class ObjCObjectGraphEncoder {
 public:
-    bool baseEncode(CoreIPC::ArgumentEncoder& encoder, WebKitNSType& type) const
+    bool baseEncode(CoreIPC::ArgumentEncoder& encoder, const Owner& coder, WebKitNSType& type) const
     {
         if (!m_root) {
             encoder << static_cast<uint32_t>(NullType);
@@ -118,7 +118,7 @@ public:
             encoder << static_cast<uint64_t>(size);
 
             for (NSUInteger i = 0; i < size; ++i)
-                encoder << Owner([array objectAtIndex:i]);
+                encoder << Owner(coder, [array objectAtIndex:i]);
             return true;
         }
         case NSDictionaryType: {
@@ -130,8 +130,8 @@ public:
             NSArray *keys = [dictionary allKeys];
             NSArray *values = [dictionary allValues];
             for (NSUInteger i = 0; i < size; ++i) {
-                encoder << Owner([keys objectAtIndex:i]);
-                encoder << Owner([values objectAtIndex:i]);
+                encoder << Owner(coder, [keys objectAtIndex:i]);
+                encoder << Owner(coder, [values objectAtIndex:i]);
             }
 
             return true;
@@ -269,15 +269,22 @@ class WebContextObjCObjectGraphEncoderImpl : public ObjCObjectGraphEncoder<WebCo
 public:
     typedef ObjCObjectGraphEncoder<WebContextObjCObjectGraphEncoderImpl> Base;
 
-    explicit WebContextObjCObjectGraphEncoderImpl(id root)
+    explicit WebContextObjCObjectGraphEncoderImpl(id root, WebProcessProxy* process)
         : Base(root)
+        , m_process(process)
+    {
+    }
+
+    WebContextObjCObjectGraphEncoderImpl(const WebContextObjCObjectGraphEncoderImpl& userMessageEncoder, id root)
+        : Base(root)
+        , m_process(userMessageEncoder.m_process)
     {
     }
 
     void encode(CoreIPC::ArgumentEncoder& encoder) const
     {
         WebKitNSType type = NullType;
-        if (baseEncode(encoder, type))
+        if (baseEncode(encoder, *this, type))
             return;
 
         switch (type) {
@@ -290,7 +297,7 @@ public:
         }
         case WKTypeRefWrapperType: {
             WKTypeRefWrapper *wrapper = static_cast<WKTypeRefWrapper *>(m_root);
-            encoder << WebContextUserMessageEncoder(toImpl(wrapper.object));
+            encoder << WebContextUserMessageEncoder(toImpl(wrapper.object), m_process);
             break;
         }
 #endif
@@ -299,6 +306,9 @@ public:
             break;
         }
     }
+
+private:
+    WebProcessProxy* m_process;
 };
 
 
@@ -378,10 +388,15 @@ public:
     {
     }
 
+    explicit InjectedBundleObjCObjectGraphEncoderImpl(const InjectedBundleObjCObjectGraphEncoderImpl&, id root)
+        : Base(root)
+    {
+    }
+
     void encode(CoreIPC::ArgumentEncoder& encoder) const
     {
         WebKitNSType type = NullType;
-        if (baseEncode(encoder, type))
+        if (baseEncode(encoder, *this, type))
             return;
 
         switch (type) {
@@ -471,14 +486,15 @@ private:
 
 // Adaptors
 
-WebContextObjCObjectGraphEncoder::WebContextObjCObjectGraphEncoder(ObjCObjectGraph* objectGraph)
+WebContextObjCObjectGraphEncoder::WebContextObjCObjectGraphEncoder(ObjCObjectGraph* objectGraph, WebProcessProxy* process)
     : m_objectGraph(objectGraph)
+    , m_process(process)
 {
 }
 
 void WebContextObjCObjectGraphEncoder::encode(CoreIPC::ArgumentEncoder& encoder) const
 {
-    encoder << WebContextObjCObjectGraphEncoderImpl(m_objectGraph->rootObject());
+    encoder << WebContextObjCObjectGraphEncoderImpl(m_objectGraph->rootObject(), m_process);
 }
 
 WebContextObjCObjectGraphDecoder::WebContextObjCObjectGraphDecoder(RefPtr<ObjCObjectGraph>& objectGraph, WebProcessProxy* process)
index 886573f..12e520e 100644 (file)
@@ -52,7 +52,7 @@ void WebConnectionToWebProcess::invalidate()
 
 void WebConnectionToWebProcess::encodeMessageBody(CoreIPC::ArgumentEncoder& encoder, API::Object* messageBody)
 {
-    encoder << WebContextUserMessageEncoder(messageBody);
+    encoder << WebContextUserMessageEncoder(messageBody, m_process);
 }
 
 bool WebConnectionToWebProcess::decodeMessageBody(CoreIPC::ArgumentDecoder& decoder, RefPtr<API::Object>& messageBody)
index dcd7a16..c6c9c7c 100644 (file)
@@ -573,7 +573,7 @@ WebProcessProxy* WebContext::createNewWebProcess()
     RefPtr<API::Object> injectedBundleInitializationUserData = m_injectedBundleClient.getInjectedBundleInitializationUserData(this);
     if (!injectedBundleInitializationUserData)
         injectedBundleInitializationUserData = m_injectedBundleInitializationUserData;
-    process->send(Messages::WebProcess::InitializeWebProcess(parameters, WebContextUserMessageEncoder(injectedBundleInitializationUserData.get())), 0);
+    process->send(Messages::WebProcess::InitializeWebProcess(parameters, WebContextUserMessageEncoder(injectedBundleInitializationUserData.get(), process.get())), 0);
 
     if (WebPreferences::anyPageGroupsAreUsingPrivateBrowsing())
         process->send(Messages::WebProcess::EnsurePrivateBrowsingSession(), 0);
@@ -587,7 +587,7 @@ WebProcessProxy* WebContext::createNewWebProcess()
             CoreIPC::ArgumentEncoder messageData;
 
             messageData.encode(message.first);
-            messageData.encode(WebContextUserMessageEncoder(message.second.get()));
+            messageData.encode(WebContextUserMessageEncoder(message.second.get(), process.get()));
             process->send(Messages::WebProcess::PostInjectedBundleMessage(CoreIPC::DataReference(messageData.buffer(), messageData.bufferSize())), 0);
         }
         m_messagesToInjectedBundlePostedToEmptyContext.clear();
@@ -738,7 +738,7 @@ PassRefPtr<WebPageProxy> WebContext::createWebPage(PageClient* pageClient, WebPa
     if (!pageGroup)
         pageGroup = m_defaultPageGroup.get();
 
-    return process->createWebPage(pageClient, this, pageGroup);
+    return process->createWebPage(pageClient, *pageGroup);
 }
 
 DownloadProxy* WebContext::download(WebPageProxy* initiatingPage, const ResourceRequest& request)
@@ -768,12 +768,13 @@ void WebContext::postMessageToInjectedBundle(const String& messageName, API::Obj
 
     // FIXME: Return early if the message body contains any references to WKPageRefs/WKFrameRefs etc. since they're local to a process.
 
-    CoreIPC::ArgumentEncoder messageData;
-    messageData.encode(messageName);
-    messageData.encode(WebContextUserMessageEncoder(messageBody));
+    for (size_t i = 0; i < m_processes.size(); ++i) {
+        CoreIPC::ArgumentEncoder messageData;
+        messageData.encode(messageName);
+        messageData.encode(WebContextUserMessageEncoder(messageBody, m_processes[i].get()));
 
-    for (size_t i = 0; i < m_processes.size(); ++i)
         m_processes[i]->send(Messages::WebProcess::PostInjectedBundleMessage(CoreIPC::DataReference(messageData.buffer(), messageData.bufferSize())), 0);
+    }
 }
 
 // InjectedBundle client
@@ -971,7 +972,7 @@ void WebContext::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC:
 
         RefPtr<API::Object> returnData;
         didReceiveSynchronousMessageFromInjectedBundle(messageName, messageBody.get(), returnData);
-        replyEncoder->encode(WebContextUserMessageEncoder(returnData.get()));
+        replyEncoder->encode(WebContextUserMessageEncoder(returnData.get(), WebProcessProxy::fromConnection(connection)));
         return;
     }
 
index 79bef0f..aea73a7 100644 (file)
@@ -45,15 +45,22 @@ class WebContextUserMessageEncoder : public UserMessageEncoder<WebContextUserMes
 public:
     typedef UserMessageEncoder<WebContextUserMessageEncoder> Base;
 
-    explicit WebContextUserMessageEncoder(API::Object* root
+    explicit WebContextUserMessageEncoder(API::Object* root, WebProcessProxy* process)
         : Base(root)
+        , m_process(process)
+    {
+    }
+
+    WebContextUserMessageEncoder(const WebContextUserMessageEncoder& userMessageEncoder, API::Object* root)
+        : Base(root)
+        , m_process(userMessageEncoder.m_process)
     {
     }
 
     void encode(CoreIPC::ArgumentEncoder& encoder) const
     {
         API::Object::Type type = API::Object::Type::Null;
-        if (baseEncode(encoder, type))
+        if (baseEncode(encoder, *this, type))
             return;
 
         switch (type) {
@@ -69,13 +76,21 @@ public:
         }
         case API::Object::Type::PageGroup: {
             WebPageGroup* pageGroup = static_cast<WebPageGroup*>(m_root);
-            encoder << pageGroup->data();
+            if (pageGroup->addProcess(*m_process)) {
+                m_process->addWebPageGroup(*pageGroup);
+            
+                encoder << true;
+                encoder << pageGroup->data();
+            } else {
+                encoder << false;
+                encoder << pageGroup->pageGroupID();
+            }
             break;
         }
 #if PLATFORM(MAC)
         case API::Object::Type::ObjCObjectGraph: {
             ObjCObjectGraph* objectGraph = static_cast<ObjCObjectGraph*>(m_root);
-            encoder << WebContextObjCObjectGraphEncoder(objectGraph);
+            encoder << WebContextObjCObjectGraphEncoder(objectGraph, m_process);
             break;
         }
 #endif
@@ -84,6 +99,9 @@ public:
             break;
         }
     }
+
+private:
+    WebProcessProxy* m_process;
 };
 
 // Adds
@@ -135,7 +153,7 @@ public:
             uint64_t pageGroupID;
             if (!decoder.decode(pageGroupID))
                 return false;
-            coder.m_root = WebPageGroup::get(pageGroupID);
+            coder.m_root = coder.m_process->webPageGroup(pageGroupID);
             break;
         }
 #if PLATFORM(MAC)
index e64073d..bcbc0eb 100644 (file)
@@ -30,6 +30,7 @@
 #include "WebPageGroupProxyMessages.h"
 #include "WebPageProxy.h"
 #include "WebPreferences.h"
+#include "WebProcessMessages.h"
 #include <wtf/HashMap.h>
 #include <wtf/text/StringConcatenate.h>
 
@@ -191,4 +192,14 @@ void WebPageGroup::removeAllUserContent()
     sendToAllProcessesInGroup(Messages::WebPageGroupProxy::RemoveAllUserContent(), m_data.pageGroupID);
 }
 
+bool WebPageGroup::addProcess(WebProcessProxy& process)
+{
+    return m_processes.add(&process).isNewEntry;
+}
+
+void WebPageGroup::disconnectProcess(WebProcessProxy& process)
+{
+    m_processes.remove(&process);
+}
+
 } // namespace WebKit
index 24ccd09..7b1d73b 100644 (file)
@@ -35,8 +35,8 @@
 
 namespace WebKit {
 
-class WebPreferences;
 class WebPageProxy;
+class WebPreferences;
 
 class WebPageGroup : public API::TypedObject<API::Object::Type::PageGroup> {
 public:
@@ -56,13 +56,16 @@ public:
     void setPreferences(WebPreferences*);
     WebPreferences* preferences() const;
     void preferencesDidChange();
-    
+
     void addUserStyleSheet(const String& source, const String& baseURL, API::Array* whitelist, API::Array* blacklist, WebCore::UserContentInjectedFrames, WebCore::UserStyleLevel);
     void addUserScript(const String& source, const String& baseURL, API::Array* whitelist, API::Array* blacklist, WebCore::UserContentInjectedFrames, WebCore::UserScriptInjectionTime);
     void removeAllUserStyleSheets();
     void removeAllUserScripts();
     void removeAllUserContent();
 
+    bool addProcess(WebProcessProxy&);
+    void disconnectProcess(WebProcessProxy&);
+
 private:
     WebPageGroup(const String& identifier, bool visibleToInjectedBundle, bool visibleToHistoryClient);
 
@@ -71,20 +74,13 @@ private:
     WebPageGroupData m_data;
     mutable RefPtr<WebPreferences> m_preferences;
     HashSet<WebPageProxy*> m_pages;
+    HashSet<WebProcessProxy*> m_processes;
 };
     
 template<typename T>
 void WebPageGroup::sendToAllProcessesInGroup(const T& message, uint64_t destinationID)
 {
-    HashSet<WebProcessProxy*> processesSeen;
-
-    for (WebPageProxy* webPageProxy : m_pages) {
-        WebProcessProxy* webProcessProxy = webPageProxy->process();
-        ASSERT(webProcessProxy);
-
-        if (!processesSeen.add(webProcessProxy).isNewEntry)
-            continue;
-
+    for (auto webProcessProxy : m_processes) {
         if (webProcessProxy->canSendMessage())
             webProcessProxy->send(T(message), destinationID);
     }
index 8e8d595..244fa9a 100644 (file)
@@ -222,15 +222,15 @@ static const char* webKeyboardEventTypeString(WebEvent::Type type)
 }
 #endif // !LOG_DISABLED
 
-PassRefPtr<WebPageProxy> WebPageProxy::create(PageClient* pageClient, PassRefPtr<WebProcessProxy> process, WebPageGroup* pageGroup, uint64_t pageID)
+PassRefPtr<WebPageProxy> WebPageProxy::create(PageClient* pageClient, PassRefPtr<WebProcessProxy> process, WebPageGroup& pageGroup, uint64_t pageID)
 {
     return adoptRef(new WebPageProxy(pageClient, process, pageGroup, pageID));
 }
 
-WebPageProxy::WebPageProxy(PageClient* pageClient, PassRefPtr<WebProcessProxy> process, WebPageGroup* pageGroup, uint64_t pageID)
+WebPageProxy::WebPageProxy(PageClient* pageClient, PassRefPtr<WebProcessProxy> process, WebPageGroup& pageGroup, uint64_t pageID)
     : m_pageClient(pageClient)
     , m_process(process)
-    , m_pageGroup(pageGroup)
+    , m_pageGroup(&pageGroup)
     , m_mainFrame(0)
     , m_userAgent(standardUserAgent())
     , m_geolocationPermissionRequestManager(this)
@@ -524,6 +524,11 @@ void WebPageProxy::initializeWebPage()
         inspector()->enableRemoteInspection();
 #endif
 
+    if (m_pageGroup->addProcess(*m_process)) {
+        m_process->addWebPageGroup(*m_pageGroup);
+        m_process->send(Messages::WebProcess::CreateWebPageGroup(m_pageGroup->pageGroupID(), m_pageGroup->data()), 0);
+    }
+
     initializeCreationParameters();
     m_process->send(Messages::WebProcess::CreateWebPage(m_pageID, m_creationParameters), 0);
 
@@ -612,7 +617,7 @@ void WebPageProxy::loadURL(const String& url, API::Object* userData)
     bool createdExtension = maybeInitializeSandboxExtensionHandle(URL(URL(), url), sandboxExtensionHandle);
     if (createdExtension)
         m_process->willAcquireUniversalFileReadSandboxExtension();
-    m_process->send(Messages::WebPage::LoadURL(url, sandboxExtensionHandle, WebContextUserMessageEncoder(userData)), m_pageID);
+    m_process->send(Messages::WebPage::LoadURL(url, sandboxExtensionHandle, WebContextUserMessageEncoder(userData, m_process.get())), m_pageID);
     m_process->responsivenessTimer()->start();
 }
 
@@ -627,7 +632,7 @@ void WebPageProxy::loadURLRequest(WebURLRequest* urlRequest, API::Object* userDa
     bool createdExtension = maybeInitializeSandboxExtensionHandle(urlRequest->resourceRequest().url(), sandboxExtensionHandle);
     if (createdExtension)
         m_process->willAcquireUniversalFileReadSandboxExtension();
-    m_process->send(Messages::WebPage::LoadURLRequest(urlRequest->resourceRequest(), sandboxExtensionHandle, WebContextUserMessageEncoder(userData)), m_pageID);
+    m_process->send(Messages::WebPage::LoadURLRequest(urlRequest->resourceRequest(), sandboxExtensionHandle, WebContextUserMessageEncoder(userData, m_process.get())), m_pageID);
     m_process->responsivenessTimer()->start();
 }
 
@@ -654,7 +659,7 @@ void WebPageProxy::loadFile(const String& fileURLString, const String& resourceD
     SandboxExtension::Handle sandboxExtensionHandle;
     SandboxExtension::createHandle(resourceDirectoryPath, SandboxExtension::ReadOnly, sandboxExtensionHandle);
     m_process->assumeReadAccessToBaseURL(resourceDirectoryURL);
-    m_process->send(Messages::WebPage::LoadURL(fileURL, sandboxExtensionHandle, WebContextUserMessageEncoder(userData)), m_pageID);
+    m_process->send(Messages::WebPage::LoadURL(fileURL, sandboxExtensionHandle, WebContextUserMessageEncoder(userData, m_process.get())), m_pageID);
     m_process->responsivenessTimer()->start();
 }
 
@@ -664,7 +669,7 @@ void WebPageProxy::loadData(WebData* data, const String& MIMEType, const String&
         reattachToWebProcess();
 
     m_process->assumeReadAccessToBaseURL(baseURL);
-    m_process->send(Messages::WebPage::LoadData(data->dataReference(), MIMEType, encoding, baseURL, WebContextUserMessageEncoder(userData)), m_pageID);
+    m_process->send(Messages::WebPage::LoadData(data->dataReference(), MIMEType, encoding, baseURL, WebContextUserMessageEncoder(userData, m_process.get())), m_pageID);
     m_process->responsivenessTimer()->start();
 }
 
@@ -674,7 +679,7 @@ void WebPageProxy::loadHTMLString(const String& htmlString, const String& baseUR
         reattachToWebProcess();
 
     m_process->assumeReadAccessToBaseURL(baseURL);
-    m_process->send(Messages::WebPage::LoadHTMLString(htmlString, baseURL, WebContextUserMessageEncoder(userData)), m_pageID);
+    m_process->send(Messages::WebPage::LoadHTMLString(htmlString, baseURL, WebContextUserMessageEncoder(userData, m_process.get())), m_pageID);
     m_process->responsivenessTimer()->start();
 }
 
@@ -689,7 +694,7 @@ void WebPageProxy::loadAlternateHTMLString(const String& htmlString, const Strin
         m_mainFrame->setUnreachableURL(unreachableURL);
 
     m_process->assumeReadAccessToBaseURL(baseURL);
-    m_process->send(Messages::WebPage::LoadAlternateHTMLString(htmlString, baseURL, unreachableURL, WebContextUserMessageEncoder(userData)), m_pageID);
+    m_process->send(Messages::WebPage::LoadAlternateHTMLString(htmlString, baseURL, unreachableURL, WebContextUserMessageEncoder(userData, m_process.get())), m_pageID);
     m_process->responsivenessTimer()->start();
 }
 
@@ -698,7 +703,7 @@ void WebPageProxy::loadPlainTextString(const String& string, API::Object* userDa
     if (!isValid())
         reattachToWebProcess();
 
-    m_process->send(Messages::WebPage::LoadPlainTextString(string, WebContextUserMessageEncoder(userData)), m_pageID);
+    m_process->send(Messages::WebPage::LoadPlainTextString(string, WebContextUserMessageEncoder(userData, m_process.get())), m_pageID);
     m_process->responsivenessTimer()->start();
 }
 
@@ -707,7 +712,7 @@ void WebPageProxy::loadWebArchiveData(const WebData* webArchiveData, API::Object
     if (!isValid())
         reattachToWebProcess();
 
-    m_process->send(Messages::WebPage::LoadWebArchiveData(webArchiveData->dataReference(), WebContextUserMessageEncoder(userData)), m_pageID);
+    m_process->send(Messages::WebPage::LoadWebArchiveData(webArchiveData->dataReference(), WebContextUserMessageEncoder(userData, m_process.get())), m_pageID);
     m_process->responsivenessTimer()->start();
 }
 
@@ -3105,7 +3110,7 @@ NativeWebMouseEvent* WebPageProxy::currentlyProcessedMouseDownEvent()
 
 void WebPageProxy::postMessageToInjectedBundle(const String& messageName, API::Object* messageBody)
 {
-    process()->send(Messages::WebPage::PostInjectedBundleMessage(messageName, WebContextUserMessageEncoder(messageBody)), m_pageID);
+    process()->send(Messages::WebPage::PostInjectedBundleMessage(messageName, WebContextUserMessageEncoder(messageBody, process())), m_pageID);
 }
 
 #if PLATFORM(GTK)
@@ -3862,7 +3867,7 @@ void WebPageProxy::initializeCreationParameters()
     m_creationParameters.viewState = m_viewState;
     m_creationParameters.drawingAreaType = m_drawingArea->type();
     m_creationParameters.store = m_pageGroup->preferences()->store();
-    m_creationParameters.pageGroupData = m_pageGroup->data();
+    m_creationParameters.pageGroupID = m_pageGroup->pageGroupID();
     m_creationParameters.drawsBackground = m_drawsBackground;
     m_creationParameters.drawsTransparentBackground = m_drawsTransparentBackground;
     m_creationParameters.underlayColor = m_underlayColor;
index e247bf7..6bf0cd0 100644 (file)
@@ -228,7 +228,7 @@ class WebPageProxy
     , public CoreIPC::MessageReceiver {
 public:
 
-    static PassRefPtr<WebPageProxy> create(PageClient*, PassRefPtr<WebProcessProxy>, WebPageGroup*, uint64_t pageID);
+    static PassRefPtr<WebPageProxy> create(PageClient*, PassRefPtr<WebProcessProxy>, WebPageGroup&, uint64_t pageID);
     virtual ~WebPageProxy();
 
     uint64_t pageID() const { return m_pageID; }
@@ -742,7 +742,7 @@ public:
     WebCore::ScrollPinningBehavior scrollPinningBehavior() { return m_scrollPinningBehavior; }
         
 private:
-    WebPageProxy(PageClient*, PassRefPtr<WebProcessProxy>, WebPageGroup*, uint64_t pageID);
+    WebPageProxy(PageClient*, PassRefPtr<WebProcessProxy>, WebPageGroup&, uint64_t pageID);
     void platformInitialize();
     void initializeCreationParameters();
 
index be1bd74..161c72d 100644 (file)
@@ -37,6 +37,7 @@
 #include "WebContext.h"
 #include "WebNavigationDataStore.h"
 #include "WebNotificationManagerProxy.h"
+#include "WebPageGroup.h"
 #include "WebPageProxy.h"
 #include "WebPluginSiteDataManager.h"
 #include "WebProcessMessages.h"
@@ -152,6 +153,12 @@ void WebProcessProxy::disconnect()
     if (m_downloadProxyMap)
         m_downloadProxyMap->processDidClose();
 
+    Vector<WebPageGroup*> pageGroups;
+    copyValuesToVector(m_pageGroups, pageGroups);
+    for (size_t i = 0, size = frames.size(); i < size; ++i)
+        pageGroups[i]->disconnectProcess(*this);
+    m_pageGroups.clear();
+
     m_context->disconnectProcess(this);
 }
 
@@ -160,7 +167,7 @@ WebPageProxy* WebProcessProxy::webPage(uint64_t pageID)
     return globalPageMap().get(pageID);
 }
 
-PassRefPtr<WebPageProxy> WebProcessProxy::createWebPage(PageClient* pageClient, WebContext*, WebPageGroup* pageGroup)
+PassRefPtr<WebPageProxy> WebProcessProxy::createWebPage(PageClient* pageClient, WebPageGroup& pageGroup)
 {
     uint64_t pageID = generatePageID();
     RefPtr<WebPageProxy> webPage = WebPageProxy::create(pageClient, this, pageGroup, pageID);
@@ -209,6 +216,19 @@ Vector<WebPageProxy*> WebProcessProxy::pages() const
     return result;
 }
 
+WebPageGroup* WebProcessProxy::webPageGroup(uint64_t pageGroupID)
+{
+    if (!HashMap<uint64_t, WebPageGroup*>::isValidKey(pageGroupID))
+        return nullptr;
+
+    return m_pageGroups.get(pageGroupID);
+}
+
+void WebProcessProxy::addWebPageGroup(WebPageGroup& pageGroup)
+{
+    m_pageGroups.add(pageGroup.pageGroupID(), &pageGroup);
+}
+
 WebBackForwardListItem* WebProcessProxy::webBackForwardItem(uint64_t itemID) const
 {
     return m_backForwardListItemMap.get(itemID);
index 83dd395..0969ac9 100644 (file)
@@ -77,11 +77,14 @@ public:
     WebContext* context() const { return m_context.get(); }
 
     static WebPageProxy* webPage(uint64_t pageID);
-    PassRefPtr<WebPageProxy> createWebPage(PageClient*, WebContext*, WebPageGroup*);
+    PassRefPtr<WebPageProxy> createWebPage(PageClient*, WebPageGroup&);
     void addExistingWebPage(WebPageProxy*, uint64_t pageID);
     void removeWebPage(uint64_t pageID);
     Vector<WebPageProxy*> pages() const;
 
+    WebPageGroup* webPageGroup(uint64_t pageGroupID);
+    void addWebPageGroup(WebPageGroup&);
+
     WebBackForwardListItem* webBackForwardItem(uint64_t itemID) const;
 
     ResponsivenessTimer* responsivenessTimer() { return &m_responsivenessTimer; }
@@ -194,6 +197,7 @@ private:
     WebPageProxyMap m_pageMap;
     WebFrameProxyMap m_frameMap;
     WebBackForwardListItemMap m_backForwardListItemMap;
+    HashMap<uint64_t, WebPageGroup*> m_pageGroups;
 
     OwnPtr<DownloadProxyMap> m_downloadProxyMap;
 
index 72ebfbc..be6e357 100644 (file)
@@ -53,10 +53,15 @@ public:
     {
     }
 
+    InjectedBundleUserMessageEncoder(const InjectedBundleUserMessageEncoder&, API::Object* root)
+        : Base(root)
+    {
+    }
+
     void encode(CoreIPC::ArgumentEncoder& encoder) const
     {
         API::Object::Type type = API::Object::Type::Null;
-        if (baseEncode(encoder, type))
+        if (baseEncode(encoder, *this, type))
             return;
 
         switch (type) {
@@ -133,10 +138,21 @@ public:
             break;
         }
         case API::Object::Type::PageGroup: {
-            WebPageGroupData pageGroupData;
-            if (!decoder.decode(pageGroupData))
+            bool isNewPageGroup;
+            if (!decoder.decode(isNewPageGroup))
                 return false;
-            coder.m_root = WebProcess::shared().webPageGroup(pageGroupData);
+            
+            if (isNewPageGroup) {
+                WebPageGroupData pageGroupData;
+                if (!decoder.decode(pageGroupData))
+                    return false;
+                coder.m_root = WebProcess::shared().createWebPageGroup(pageGroupData.pageGroupID, pageGroupData);
+            } else {
+                uint64_t pageGroupID;
+                if (!decoder.decode(pageGroupID))
+                    return false;
+                coder.m_root = WebProcess::shared().webPageGroup(pageGroupID);
+            }
             break;
         }
 #if PLATFORM(MAC)
index 355eb9b..d282923 100644 (file)
@@ -344,7 +344,9 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
     m_page->setCanStartMedia(false);
     m_mayStartMediaWhenInWindow = parameters.mayStartMediaWhenInWindow;
 
-    m_pageGroup = WebProcess::shared().webPageGroup(parameters.pageGroupData);
+    m_pageGroup = WebProcess::shared().webPageGroup(parameters.pageGroupID);
+    ASSERT(m_pageGroup);
+
     m_page->setGroupName(m_pageGroup->identifier());
     m_page->setDeviceScaleFactor(parameters.deviceScaleFactor);
 
index cad9ac5..b72353d 100644 (file)
@@ -704,6 +704,12 @@ void WebProcess::removeWebFrame(uint64_t frameID)
     parentProcessConnection()->send(Messages::WebProcessProxy::DidDestroyFrame(frameID), 0);
 }
 
+WebPageGroupProxy* WebProcess::createWebPageGroup(uint64_t pageGroupID, const WebPageGroupData& pageGroupData)
+{
+    ASSERT(!m_pageGroupMap.contains(pageGroupID));
+    return m_pageGroupMap.add(pageGroupID, WebPageGroupProxy::create(pageGroupData)).iterator->value.get();
+}
+
 WebPageGroupProxy* WebProcess::webPageGroup(PageGroup* pageGroup)
 {
     for (HashMap<uint64_t, RefPtr<WebPageGroupProxy>>::const_iterator it = m_pageGroupMap.begin(), end = m_pageGroupMap.end(); it != end; ++it) {
@@ -719,17 +725,6 @@ WebPageGroupProxy* WebProcess::webPageGroup(uint64_t pageGroupID)
     return m_pageGroupMap.get(pageGroupID);
 }
 
-WebPageGroupProxy* WebProcess::webPageGroup(const WebPageGroupData& pageGroupData)
-{
-    HashMap<uint64_t, RefPtr<WebPageGroupProxy>>::AddResult result = m_pageGroupMap.add(pageGroupData.pageGroupID, nullptr);
-    if (result.isNewEntry) {
-        ASSERT(!result.iterator->value);
-        result.iterator->value = WebPageGroupProxy::create(pageGroupData);
-    }
-
-    return result.iterator->value.get();
-}
-
 void WebProcess::clearResourceCaches(ResourceCachesToClear resourceCachesToClear)
 {
     platformClearResourceCaches(resourceCachesToClear);
index 96e4ec8..f83ad44 100644 (file)
@@ -127,9 +127,9 @@ public:
     void addWebFrame(uint64_t, WebFrame*);
     void removeWebFrame(uint64_t);
 
+    WebPageGroupProxy* createWebPageGroup(uint64_t pageGroupID, const WebPageGroupData&);
     WebPageGroupProxy* webPageGroup(WebCore::PageGroup*);
     WebPageGroupProxy* webPageGroup(uint64_t pageGroupID);
-    WebPageGroupProxy* webPageGroup(const WebPageGroupData&);
 
 #if PLATFORM(MAC)
     pid_t presenterApplicationPid() const { return m_presenterApplicationPid; }
index 532b4c2..1127d01 100644 (file)
@@ -27,6 +27,9 @@ messages -> WebProcess LegacyReceiver {
     # Create a new page.
     CreateWebPage(uint64_t newPageID, WebKit::WebPageCreationParameters pageCreationParameters)
 
+    # Create a new page group.
+    CreateWebPageGroup(uint64_t newPageGroupID, WebKit::WebPageGroupData pageGroupData)
+
     # Visited link tracking.
     SetVisitedLinkTable(WebKit::SharedMemory::Handle handle)
     VisitedLinkStateChanged(Vector<WebCore::LinkHash> linkHashes)