[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
weinig at apple.com
weinig at apple.com
Wed Dec 22 12:57:19 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit 3971b9e144e8770e602cecc9aa947679b7448efd
Author: weinig at apple.com <weinig at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Thu Sep 2 22:52:18 2010 +0000
Share the common parts of UserMessage coding between both processes.
https://bugs.webkit.org/show_bug.cgi?id=45139
Reviewed by Anders Carlsson.
Add base classes UserMessageEncoder and UserMessageDecoder which implement
encoding/decoding of ImmutableArray and String (soon to be others as well, such
as ImmutableDictionary, Data, etc.) and add derived classes which implement the
process specific bits such as Page -> BundlePage conversion.
* Shared/UserMessageCoders.h: Copied from WebProcess/InjectedBundle/InjectedBundle.cpp.
(WebKit::UserMessageEncoder::baseEncode):
(WebKit::UserMessageEncoder::UserMessageEncoder):
(WebKit::UserMessageDecoder::baseDecode):
(WebKit::UserMessageDecoder::UserMessageDecoder):
* UIProcess/WebContext.cpp:
(WebKit::WebContext::postMessageToInjectedBundle):
(WebKit::WebContext::didReceiveMessage):
* UIProcess/WebContextUserMessageCoders.h: Copied from UIProcess/WebContext.cpp.
(WebKit::WebContextUserMessageEncoder::WebContextUserMessageEncoder):
(WebKit::WebContextUserMessageEncoder::encode):
(WebKit::WebContextUserMessageDecoder::WebContextUserMessageDecoder):
(WebKit::WebContextUserMessageDecoder::decode):
* WebKit2.pro:
* WebKit2.xcodeproj/project.pbxproj:
* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::postMessage):
(WebKit::InjectedBundle::didReceiveMessage):
* WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h: Copied from WebProcess/InjectedBundle/InjectedBundle.cpp.
(WebKit::InjectedBundleUserMessageEncoder::InjectedBundleUserMessageEncoder):
(WebKit::InjectedBundleUserMessageEncoder::encode):
(WebKit::InjectedBundleUserMessageDecoder::InjectedBundleUserMessageDecoder):
(WebKit::InjectedBundleUserMessageDecoder::decode):
* win/WebKit2.vcproj:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66688 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog
index 85d5e61..b5a373b 100644
--- a/WebKit2/ChangeLog
+++ b/WebKit2/ChangeLog
@@ -2,6 +2,43 @@
Reviewed by Anders Carlsson.
+ Share the common parts of UserMessage coding between both processes.
+ https://bugs.webkit.org/show_bug.cgi?id=45139
+
+ Add base classes UserMessageEncoder and UserMessageDecoder which implement
+ encoding/decoding of ImmutableArray and String (soon to be others as well, such
+ as ImmutableDictionary, Data, etc.) and add derived classes which implement the
+ process specific bits such as Page -> BundlePage conversion.
+
+ * Shared/UserMessageCoders.h: Copied from WebProcess/InjectedBundle/InjectedBundle.cpp.
+ (WebKit::UserMessageEncoder::baseEncode):
+ (WebKit::UserMessageEncoder::UserMessageEncoder):
+ (WebKit::UserMessageDecoder::baseDecode):
+ (WebKit::UserMessageDecoder::UserMessageDecoder):
+ * UIProcess/WebContext.cpp:
+ (WebKit::WebContext::postMessageToInjectedBundle):
+ (WebKit::WebContext::didReceiveMessage):
+ * UIProcess/WebContextUserMessageCoders.h: Copied from UIProcess/WebContext.cpp.
+ (WebKit::WebContextUserMessageEncoder::WebContextUserMessageEncoder):
+ (WebKit::WebContextUserMessageEncoder::encode):
+ (WebKit::WebContextUserMessageDecoder::WebContextUserMessageDecoder):
+ (WebKit::WebContextUserMessageDecoder::decode):
+ * WebKit2.pro:
+ * WebKit2.xcodeproj/project.pbxproj:
+ * WebProcess/InjectedBundle/InjectedBundle.cpp:
+ (WebKit::InjectedBundle::postMessage):
+ (WebKit::InjectedBundle::didReceiveMessage):
+ * WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h: Copied from WebProcess/InjectedBundle/InjectedBundle.cpp.
+ (WebKit::InjectedBundleUserMessageEncoder::InjectedBundleUserMessageEncoder):
+ (WebKit::InjectedBundleUserMessageEncoder::encode):
+ (WebKit::InjectedBundleUserMessageDecoder::InjectedBundleUserMessageDecoder):
+ (WebKit::InjectedBundleUserMessageDecoder::decode):
+ * win/WebKit2.vcproj:
+
+2010-09-02 Sam Weinig <sam at webkit.org>
+
+ Reviewed by Anders Carlsson.
+
Simplify ownership semantics of some WebKit2 types
https://bugs.webkit.org/show_bug.cgi?id=45120
diff --git a/WebKit2/Shared/UserMessageCoders.h b/WebKit2/Shared/UserMessageCoders.h
new file mode 100644
index 0000000..ca6c0b3
--- /dev/null
+++ b/WebKit2/Shared/UserMessageCoders.h
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "ArgumentEncoder.h"
+#include "ArgumentDecoder.h"
+#include "ImmutableArray.h"
+#include "WebString.h"
+
+namespace WebKit {
+
+// - Array -> Array
+// - String -> String
+
+template<typename Owner>
+class UserMessageEncoder {
+public:
+ bool baseEncode(CoreIPC::ArgumentEncoder* encoder, APIObject::Type type) const
+ {
+ switch (type) {
+ case APIObject::TypeArray: {
+ ImmutableArray* array = static_cast<ImmutableArray*>(m_root);
+ encoder->encode(static_cast<uint64_t>(array->size()));
+ for (size_t i = 0; i < array->size(); ++i)
+ encoder->encode(Owner(array->at(i)));
+ return true;
+ }
+ case APIObject::TypeString: {
+ WebString* string = static_cast<WebString*>(m_root);
+ encoder->encode(string->string());
+ return true;
+ }
+ default:
+ break;
+ }
+
+ return false;
+ }
+
+protected:
+ UserMessageEncoder(APIObject* root)
+ : m_root(root)
+ {
+ }
+
+ APIObject* m_root;
+};
+
+
+// Handles
+// - Array -> Array
+// - String -> String
+
+template<typename Owner>
+class UserMessageDecoder {
+public:
+ static bool baseDecode(CoreIPC::ArgumentDecoder* decoder, Owner& coder, APIObject::Type type)
+ {
+ switch (type) {
+ case APIObject::TypeArray: {
+ uint64_t size;
+ if (!decoder->decode(size))
+ return false;
+
+ Vector<RefPtr<APIObject> > vector;
+ for (size_t i = 0; i < size; ++i) {
+ RefPtr<APIObject> element;
+ Owner messageCoder(coder, element);
+ if (!decoder->decode(messageCoder))
+ return false;
+ vector.append(element.release());
+ }
+
+ coder.m_root = ImmutableArray::adopt(vector);
+ break;
+ }
+ case APIObject::TypeString: {
+ String string;
+ if (!decoder->decode(string))
+ return false;
+ coder.m_root = WebString::create(string);
+ break;
+ }
+ default:
+ break;
+ }
+
+ return true;
+ }
+
+protected:
+ UserMessageDecoder(RefPtr<APIObject>& root)
+ : m_root(root)
+ {
+ }
+
+ RefPtr<APIObject>& m_root;
+};
+
+} // namespace WebKit
diff --git a/WebKit2/UIProcess/WebContext.cpp b/WebKit2/UIProcess/WebContext.cpp
index 6ca35ac..abbe72a 100644
--- a/WebKit2/UIProcess/WebContext.cpp
+++ b/WebKit2/UIProcess/WebContext.cpp
@@ -29,6 +29,7 @@
#include "InjectedBundleMessageKinds.h"
#include "RunLoop.h"
#include "WebContextMessageKinds.h"
+#include "WebContextUserMessageCoders.h"
#include "WebCoreArgumentCoders.h"
#include "WebPageNamespace.h"
#include "WebPreferences.h"
@@ -50,123 +51,6 @@ using namespace WebCore;
namespace WebKit {
-namespace {
-
-// FIXME: We should try to abstract out the shared logic from these and
-// and the PostMessageEncoder/PostMessageDecoders in InjectedBundle.cpp into
-// a shared baseclass.
-
-// Encodes postMessage messages from the UIProcess -> InjectedBundle
-
-// - Array -> Array
-// - String -> String
-// - Page -> BundlePage
-
-class PostMessageEncoder {
-public:
- PostMessageEncoder(APIObject* root)
- : m_root(root)
- {
- }
-
- void encode(CoreIPC::ArgumentEncoder* encoder) const
- {
- APIObject::Type type = m_root->type();
- encoder->encode(static_cast<uint32_t>(type));
- switch (type) {
- case APIObject::TypeArray: {
- ImmutableArray* array = static_cast<ImmutableArray*>(m_root);
- encoder->encode(static_cast<uint64_t>(array->size()));
- for (size_t i = 0; i < array->size(); ++i)
- encoder->encode(PostMessageEncoder(array->at(i)));
- break;
- }
- case APIObject::TypeString: {
- WebString* string = static_cast<WebString*>(m_root);
- encoder->encode(string->string());
- break;
- }
- case APIObject::TypePage: {
- WebPageProxy* page = static_cast<WebPageProxy*>(m_root);
- encoder->encode(page->pageID());
- break;
- }
- default:
- ASSERT_NOT_REACHED();
- break;
- }
- }
-
-private:
- APIObject* m_root;
-};
-
-// Decodes postMessage messages going from the InjectedBundle -> UIProcess
-
-// - Array -> Array
-// - String -> String
-// - BundlePage -> Page
-
-class PostMessageDecoder {
-public:
- PostMessageDecoder(RefPtr<APIObject>& root, WebContext* context)
- : m_root(root)
- , m_context(context)
- {
- }
-
- static bool decode(CoreIPC::ArgumentDecoder* decoder, PostMessageDecoder& coder)
- {
- uint32_t type;
- if (!decoder->decode(type))
- return false;
-
- switch (type) {
- case APIObject::TypeArray: {
- uint64_t size;
- if (!decoder->decode(size))
- return false;
-
- Vector<RefPtr<APIObject> > vector;
- for (size_t i = 0; i < size; ++i) {
- RefPtr<APIObject> element;
- PostMessageDecoder messageCoder(element, coder.m_context);
- if (!decoder->decode(messageCoder))
- return false;
- vector.append(element.release());
- }
-
- coder.m_root = ImmutableArray::adopt(vector);
- break;
- }
- case APIObject::TypeString: {
- String string;
- if (!decoder->decode(string))
- return false;
- coder.m_root = WebString::create(string);
- break;
- }
- case APIObject::TypeBundlePage: {
- uint64_t pageID;
- if (!decoder->decode(pageID))
- return false;
- coder.m_root = coder.m_context->process()->webPage(pageID);
- break;
- }
- default:
- return false;
- }
-
- return true;
- }
-
-private:
- RefPtr<APIObject>& m_root;
- WebContext* m_context;
-};
-
-}
-
#ifndef NDEBUG
static WTF::RefCountedLeakCounter webContextCounter("WebContext");
#endif
@@ -318,7 +202,7 @@ void WebContext::postMessageToInjectedBundle(const String& messageName, APIObjec
// FIXME: We should consider returning false from this function if the messageBody cannot
// be encoded.
- m_process->send(InjectedBundleMessage::PostMessage, 0, CoreIPC::In(messageName, PostMessageEncoder(messageBody)));
+ m_process->send(InjectedBundleMessage::PostMessage, 0, CoreIPC::In(messageName, WebContextUserMessageEncoder(messageBody)));
}
// InjectedBundle client
@@ -407,8 +291,8 @@ void WebContext::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::Mes
case WebContextMessage::PostMessage: {
String messageName;
RefPtr<APIObject> messageBody;
- PostMessageDecoder messageCoder(messageBody, this);
- if (!arguments->decode(CoreIPC::Out(messageName, messageCoder)))
+ WebContextUserMessageDecoder messageDecoder(messageBody, this);
+ if (!arguments->decode(CoreIPC::Out(messageName, messageDecoder)))
return;
didReceiveMessageFromInjectedBundle(messageName, messageBody.get());
diff --git a/WebKit2/UIProcess/WebContextUserMessageCoders.h b/WebKit2/UIProcess/WebContextUserMessageCoders.h
new file mode 100644
index 0000000..178ea0e
--- /dev/null
+++ b/WebKit2/UIProcess/WebContextUserMessageCoders.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "UserMessageCoders.h"
+#include "WebContext.h"
+#include "WebPageProxy.h"
+
+namespace WebKit {
+
+// Adds
+// - Page -> BundlePage
+
+class WebContextUserMessageEncoder : public UserMessageEncoder<WebContextUserMessageEncoder> {
+public:
+ typedef UserMessageEncoder<WebContextUserMessageEncoder> Base;
+
+ WebContextUserMessageEncoder(APIObject* root)
+ : Base(root)
+ {
+ }
+
+ void encode(CoreIPC::ArgumentEncoder* encoder) const
+ {
+ APIObject::Type type = m_root->type();
+ encoder->encode(static_cast<uint32_t>(type));
+
+ if (baseEncode(encoder, type))
+ return;
+
+ switch (type) {
+ case APIObject::TypePage: {
+ WebPageProxy* page = static_cast<WebPageProxy*>(m_root);
+ encoder->encode(page->pageID());
+ break;
+ }
+ default:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+ }
+};
+
+// Adds
+// - Page -> BundlePage
+
+class WebContextUserMessageDecoder : public UserMessageDecoder<WebContextUserMessageDecoder> {
+public:
+ typedef UserMessageDecoder<WebContextUserMessageDecoder> Base;
+
+ WebContextUserMessageDecoder(RefPtr<APIObject>& root, WebContext* context)
+ : Base(root)
+ , m_context(context)
+ {
+ }
+
+ WebContextUserMessageDecoder(WebContextUserMessageDecoder& userMessageDecoder, RefPtr<APIObject>& root)
+ : Base(root)
+ , m_context(userMessageDecoder.m_context)
+ {
+ }
+
+ static bool decode(CoreIPC::ArgumentDecoder* decoder, WebContextUserMessageDecoder& coder)
+ {
+ uint32_t type;
+ if (!decoder->decode(type))
+ return false;
+
+ if (!Base::baseDecode(decoder, coder, static_cast<APIObject::Type>(type)))
+ return false;
+
+ // If the base decoded something into root, we are done.
+ if (coder.m_root)
+ return true;
+
+ switch (type) {
+ case APIObject::TypeBundlePage: {
+ uint64_t pageID;
+ if (!decoder->decode(pageID))
+ return false;
+ coder.m_root = coder.m_context->process()->webPage(pageID);
+ break;
+ }
+ default:
+ return false;
+ }
+
+ return true;
+ }
+
+private:
+ WebContext* m_context;
+};
+
+} // namespace WebKit
diff --git a/WebKit2/WebKit2.pro b/WebKit2/WebKit2.pro
index 2c65036..43beafd 100644
--- a/WebKit2/WebKit2.pro
+++ b/WebKit2/WebKit2.pro
@@ -162,6 +162,7 @@ HEADERS += \
Shared/MutableDictionary.h \
Shared/NotImplemented.h \
Shared/qt/WebEventFactoryQt.h \
+ Shared/UserMessageCoders.h \
Shared/VisitedLinkTable.h \
Shared/WebEventConversion.h \
Shared/WebEvent.h \
@@ -204,6 +205,7 @@ HEADERS += \
UIProcess/VisitedLinkProvider.h \
UIProcess/WebContext.h \
UIProcess/WebContextInjectedBundleClient.h \
+ UIProcess/WebContextUserMessageCoders.h \
UIProcess/WebFormClient.h \
UIProcess/WebFormSubmissionListenerProxy.h \
UIProcess/WebFrameListenerProxy.h \
@@ -226,6 +228,7 @@ HEADERS += \
WebProcess/InjectedBundle/InjectedBundlePageFormClient.h \
WebProcess/InjectedBundle/InjectedBundlePageUIClient.h \
WebProcess/InjectedBundle/InjectedBundleScriptWorld.h \
+ WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h \
WebProcess/Plugins/JSNPObject.h \
WebProcess/Plugins/JSNPMethod.h \
WebProcess/Plugins/NPJSObject.h \
diff --git a/WebKit2/WebKit2.xcodeproj/project.pbxproj b/WebKit2/WebKit2.xcodeproj/project.pbxproj
index 388f476..c782296 100644
--- a/WebKit2/WebKit2.xcodeproj/project.pbxproj
+++ b/WebKit2/WebKit2.xcodeproj/project.pbxproj
@@ -255,6 +255,9 @@
BCB0AEEA122F53E300B1341E /* MutableDictionary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCB0AEE8122F53E300B1341E /* MutableDictionary.cpp */; };
BCB0AF3512301DFB00B1341E /* WKMutableDictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB0AF3312301DFB00B1341E /* WKMutableDictionary.h */; settings = {ATTRIBUTES = (Public, ); }; };
BCB0AF3612301DFB00B1341E /* WKMutableDictionary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCB0AF3412301DFB00B1341E /* WKMutableDictionary.cpp */; };
+ BCB0B0DC12305A2500B1341E /* WebContextUserMessageCoders.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB0B0DB12305A2500B1341E /* WebContextUserMessageCoders.h */; };
+ BCB0B0DE12305A8C00B1341E /* InjectedBundleUserMessageCoders.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB0B0DD12305A8C00B1341E /* InjectedBundleUserMessageCoders.h */; };
+ BCB0B0E012305AB100B1341E /* UserMessageCoders.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB0B0DF12305AB100B1341E /* UserMessageCoders.h */; };
BCB28CC0120233D9007D99BC /* InjectedBundleMessageKinds.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB28CBF120233D9007D99BC /* InjectedBundleMessageKinds.h */; };
BCB63478116BF10600603215 /* WebKit2.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB63477116BF10600603215 /* WebKit2.h */; settings = {ATTRIBUTES = (Public, ); }; };
BCB7346E11CEE3FF00EC5002 /* WebProcessProxyMessageKinds.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB7346D11CEE3FF00EC5002 /* WebProcessProxyMessageKinds.h */; };
@@ -618,6 +621,9 @@
BCB0AEE8122F53E300B1341E /* MutableDictionary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MutableDictionary.cpp; sourceTree = "<group>"; };
BCB0AF3312301DFB00B1341E /* WKMutableDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKMutableDictionary.h; sourceTree = "<group>"; };
BCB0AF3412301DFB00B1341E /* WKMutableDictionary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKMutableDictionary.cpp; sourceTree = "<group>"; };
+ BCB0B0DB12305A2500B1341E /* WebContextUserMessageCoders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextUserMessageCoders.h; sourceTree = "<group>"; };
+ BCB0B0DD12305A8C00B1341E /* InjectedBundleUserMessageCoders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundleUserMessageCoders.h; sourceTree = "<group>"; };
+ BCB0B0DF12305AB100B1341E /* UserMessageCoders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserMessageCoders.h; sourceTree = "<group>"; };
BCB28CBF120233D9007D99BC /* InjectedBundleMessageKinds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundleMessageKinds.h; sourceTree = "<group>"; };
BCB63477116BF10600603215 /* WebKit2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKit2.h; sourceTree = "<group>"; };
BCB7346D11CEE3FF00EC5002 /* WebProcessProxyMessageKinds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebProcessProxyMessageKinds.h; sourceTree = "<group>"; };
@@ -911,6 +917,7 @@
BCB0AEE8122F53E300B1341E /* MutableDictionary.cpp */,
BCB0AEE7122F53E300B1341E /* MutableDictionary.h */,
BCC57161115ADB42001CCAF9 /* NotImplemented.h */,
+ BCB0B0DF12305AB100B1341E /* UserMessageCoders.h */,
1A0F29C9120B37160053D1B9 /* VisitedLinkTable.cpp */,
1A0F29CA120B37160053D1B9 /* VisitedLinkTable.h */,
BC1DD7B1114DC396005ADAF3 /* WebCoreArgumentCoders.h */,
@@ -1073,6 +1080,7 @@
BCB9E2411120DACA00A137E0 /* WebContext.h */,
BCDE059A11CDA8AE00E41AF1 /* WebContextInjectedBundleClient.cpp */,
BCDE059911CDA8AE00E41AF1 /* WebContextInjectedBundleClient.h */,
+ BCB0B0DB12305A2500B1341E /* WebContextUserMessageCoders.h */,
BCE4694F1214E6CB000B98EB /* WebFormClient.cpp */,
BCE469501214E6CB000B98EB /* WebFormClient.h */,
BCE469511214E6CB000B98EB /* WebFormSubmissionListenerProxy.cpp */,
@@ -1265,6 +1273,7 @@
BCA8C6AE11E3C08700812FB7 /* InjectedBundlePageUIClient.h */,
BC14DF76120B5B7900826C0C /* InjectedBundleScriptWorld.cpp */,
BC14DF75120B5B7900826C0C /* InjectedBundleScriptWorld.h */,
+ BCB0B0DD12305A8C00B1341E /* InjectedBundleUserMessageCoders.h */,
);
path = InjectedBundle;
sourceTree = "<group>";
@@ -1584,6 +1593,9 @@
BCB0AD34122F285800B1341E /* MutableArray.h in Headers */,
BCB0AEE9122F53E300B1341E /* MutableDictionary.h in Headers */,
BCB0AF3512301DFB00B1341E /* WKMutableDictionary.h in Headers */,
+ BCB0B0DC12305A2500B1341E /* WebContextUserMessageCoders.h in Headers */,
+ BCB0B0DE12305A8C00B1341E /* InjectedBundleUserMessageCoders.h in Headers */,
+ BCB0B0E012305AB100B1341E /* UserMessageCoders.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp b/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp
index fa12d4b..1d4b863 100644
--- a/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp
+++ b/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp
@@ -29,6 +29,7 @@
#include "ImmutableArray.h"
#include "InjectedBundleMessageKinds.h"
#include "InjectedBundleScriptWorld.h"
+#include "InjectedBundleUserMessageCoders.h"
#include "WKAPICast.h"
#include "WKBundleAPICast.h"
#include "WebContextMessageKinds.h"
@@ -50,122 +51,6 @@ using namespace JSC;
namespace WebKit {
-namespace {
-
-// FIXME: We should try to abstract out the shared logic from these and
-// and the PostMessageEncoder/PostMessageDecoders in WebContext.cpp into
-// a shared baseclass.
-
-// Encodes postMessage messages from the InjectedBundle -> UIProcess
-
-// - Array -> Array
-// - String -> String
-// - BundlePage -> Page
-
-class PostMessageEncoder {
-public:
- PostMessageEncoder(APIObject* root)
- : m_root(root)
- {
- }
-
- void encode(CoreIPC::ArgumentEncoder* encoder) const
- {
- APIObject::Type type = m_root->type();
- encoder->encode(static_cast<uint32_t>(type));
- switch (type) {
- case APIObject::TypeArray: {
- ImmutableArray* array = static_cast<ImmutableArray*>(m_root);
- encoder->encode(static_cast<uint64_t>(array->size()));
- for (size_t i = 0; i < array->size(); ++i)
- encoder->encode(PostMessageEncoder(array->at(i)));
- break;
- }
- case APIObject::TypeString: {
- WebString* string = static_cast<WebString*>(m_root);
- encoder->encode(string->string());
- break;
- }
- case APIObject::TypeBundlePage: {
- WebPage* page = static_cast<WebPage*>(m_root);
- encoder->encode(page->pageID());
- break;
- }
- default:
- ASSERT_NOT_REACHED();
- break;
- }
- }
-
-private:
- APIObject* m_root;
-};
-
-
-// Decodes postMessage messages going from the UIProcess -> InjectedBundle
-
-// - Array -> Array
-// - String -> String
-// - Page -> BundlePage
-
-class PostMessageDecoder {
-public:
- PostMessageDecoder(RefPtr<APIObject>& root)
- : m_root(root)
- {
- }
-
- static bool decode(CoreIPC::ArgumentDecoder* decoder, PostMessageDecoder& coder)
- {
- uint32_t type;
- if (!decoder->decode(type))
- return false;
-
- switch (type) {
- case APIObject::TypeArray: {
- uint64_t size;
- if (!decoder->decode(size))
- return false;
-
- Vector<RefPtr<APIObject> > vector;
- for (size_t i = 0; i < size; ++i) {
- RefPtr<APIObject> element;
- PostMessageDecoder messageCoder(element);
- if (!decoder->decode(messageCoder))
- return false;
- vector.append(element.release());
- }
-
- coder.m_root = ImmutableArray::adopt(vector);
- break;
- }
- case APIObject::TypeString: {
- String string;
- if (!decoder->decode(string))
- return false;
- coder.m_root = WebString::create(string);
- break;
- }
- case APIObject::TypePage: {
- uint64_t pageID;
- if (!decoder->decode(pageID))
- return false;
- coder.m_root = WebProcess::shared().webPage(pageID);
- break;
- }
- default:
- return false;
- }
-
- return true;
- }
-
-private:
- RefPtr<APIObject>& m_root;
-};
-
-}
-
InjectedBundle::InjectedBundle(const String& path)
: m_path(path)
, m_platformBundle(0)
@@ -187,7 +72,7 @@ void InjectedBundle::initializeClient(WKBundleClient* client)
void InjectedBundle::postMessage(const String& messageName, APIObject* messageBody)
{
- WebProcess::shared().connection()->send(WebContextMessage::PostMessage, 0, CoreIPC::In(messageName, PostMessageEncoder(messageBody)));
+ WebProcess::shared().connection()->send(WebContextMessage::PostMessage, 0, CoreIPC::In(messageName, InjectedBundleUserMessageEncoder(messageBody)));
}
void InjectedBundle::setShouldTrackVisitedLinks(bool shouldTrackVisitedLinks)
@@ -307,8 +192,8 @@ void InjectedBundle::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC:
case InjectedBundleMessage::PostMessage: {
String messageName;
RefPtr<APIObject> messageBody;
- PostMessageDecoder messageCoder(messageBody);
- if (!arguments->decode(CoreIPC::Out(messageName, messageCoder)))
+ InjectedBundleUserMessageDecoder messageDecoder(messageBody);
+ if (!arguments->decode(CoreIPC::Out(messageName, messageDecoder)))
return;
didReceiveMessage(messageName, messageBody.get());
diff --git a/WebKit2/WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h b/WebKit2/WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h
new file mode 100644
index 0000000..0ec4c3a
--- /dev/null
+++ b/WebKit2/WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "UserMessageCoders.h"
+#include "WebPage.h"
+#include "WebProcess.h"
+
+namespace WebKit {
+
+// Adds
+// - BundlePage -> Page
+
+class InjectedBundleUserMessageEncoder : public UserMessageEncoder<InjectedBundleUserMessageEncoder> {
+public:
+ typedef UserMessageEncoder<InjectedBundleUserMessageEncoder> Base;
+
+ InjectedBundleUserMessageEncoder(APIObject* root)
+ : Base(root)
+ {
+ }
+
+ void encode(CoreIPC::ArgumentEncoder* encoder) const
+ {
+ APIObject::Type type = m_root->type();
+ encoder->encode(static_cast<uint32_t>(type));
+
+ if (baseEncode(encoder, type))
+ return;
+
+ switch (type) {
+ case APIObject::TypeBundlePage: {
+ WebPage* page = static_cast<WebPage*>(m_root);
+ encoder->encode(page->pageID());
+ break;
+ }
+ default:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+ }
+};
+
+// Adds
+// - Page -> BundlePage
+
+class InjectedBundleUserMessageDecoder : public UserMessageDecoder<InjectedBundleUserMessageDecoder> {
+public:
+ typedef UserMessageDecoder<InjectedBundleUserMessageDecoder> Base;
+
+ InjectedBundleUserMessageDecoder(RefPtr<APIObject>& root)
+ : Base(root)
+ {
+ }
+
+ InjectedBundleUserMessageDecoder(InjectedBundleUserMessageDecoder&, RefPtr<APIObject>& root)
+ : Base(root)
+ {
+ }
+
+ static bool decode(CoreIPC::ArgumentDecoder* decoder, InjectedBundleUserMessageDecoder& coder)
+ {
+ uint32_t type;
+ if (!decoder->decode(type))
+ return false;
+
+ if (!Base::baseDecode(decoder, coder, static_cast<APIObject::Type>(type)))
+ return false;
+
+ // If the base created something in root, we are done.
+ if (coder.m_root)
+ return true;
+
+ switch (type) {
+ case APIObject::TypePage: {
+ uint64_t pageID;
+ if (!decoder->decode(pageID))
+ return false;
+ coder.m_root = WebProcess::shared().webPage(pageID);
+ break;
+ }
+ default:
+ return false;
+ }
+
+ return true;
+ }
+};
+
+} // namespace WebKit
diff --git a/WebKit2/win/WebKit2.vcproj b/WebKit2/win/WebKit2.vcproj
index d796557..0a6c55b 100755
--- a/WebKit2/win/WebKit2.vcproj
+++ b/WebKit2/win/WebKit2.vcproj
@@ -445,6 +445,10 @@
>
</File>
<File
+ RelativePath="..\Shared\UserMessageCoders.h"
+ >
+ </File>
+ <File
RelativePath="..\Shared\VisitedLinkTable.cpp"
>
</File>
@@ -803,6 +807,10 @@
RelativePath="..\WebProcess\InjectedBundle\InjectedBundleScriptWorld.h"
>
</File>
+ <File
+ RelativePath="..\WebProcess\InjectedBundle\InjectedBundleUserMessageCoders.h"
+ >
+ </File>
<Filter
Name="API"
>
@@ -1101,6 +1109,10 @@
>
</File>
<File
+ RelativePath="..\UIProcess\WebContextUserMessageCoders.h"
+ >
+ </File>
+ <File
RelativePath="..\UIProcess\WebData.h"
>
</File>
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list