Initial checkin of the out of process worker implementation.
WebWorkerClient/WebWorker are parallel interfaces of WebCore::{WorkerObjectProxy, WorkerContextProxy} that use Chrome data types. When WebKit requests a WorkerObjectProxy, we create an instance of WebWorkerClientImpl. This class creates an object that implements a Chromium version of WorkerObjectProxy (i.e. with Chrome data types) through WebViewDelegate. That object is a WebWorkerProxy and talks over IPC to a WebWorker object in the worker process. The WebWorker object creates the actual WebCore::Worker object using another class in glue: WebWorkerImpl.
When the WebCore::Worker object running in the worker process wants to talk back to the code running in the renderer, it talks to WebWorkerImpl which implements WebCore::WorkerObjectProxy. WebWorkerImpl converts the data types to Chrome compatible ones, and then calls the WebWorkerClient version which does IPC to get to the renderer process. This ends up at WebWorkerProxy, which calls WebWorkerClientImpl (the original class).
In future changes, sandboxing, multiple worker processes etc will be added. Note that I also had to make two small changes to WebKit, since WorkerMessagingProxy couldn't be created as is for the nested worker case. I'll either check it in myself or work with Jian to do so.
Review URL: http://codereview.chromium.org/27157
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10847 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/common/ipc_message_utils.h b/chrome/common/ipc_message_utils.h
index 8f813f6a..61243f53 100644
--- a/chrome/common/ipc_message_utils.h
+++ b/chrome/common/ipc_message_utils.h
@@ -11,6 +11,7 @@
#include "base/file_path.h"
#include "base/string_util.h"
+#include "base/string16.h"
#include "base/tuple.h"
#if defined(OS_POSIX)
#include "chrome/common/file_descriptor_set_posix.h"
@@ -56,6 +57,10 @@
TestMsgStart,
DevToolsAgentMsgStart,
DevToolsClientMsgStart,
+ WorkerProcessMsgStart,
+ WorkerProcessHostMsgStart,
+ WorkerMsgStart,
+ WorkerHostMsgStart,
// NOTE: When you add a new message class, also update
// IPCStatusView::IPCStatusView to ensure logging works.
// NOTE: this enum is used by IPC_MESSAGE_MACRO to generate a unique message
@@ -492,6 +497,7 @@
}
};
+
template <>
struct ParamTraits<std::wstring> {
typedef std::wstring param_type;
@@ -506,6 +512,34 @@
}
};
+
+// If WCHAR_T_IS_UTF16 is defined, then string16 is a std::wstring so we don't
+// need this trait.
+#if !defined(WCHAR_T_IS_UTF16)
+
+template <>
+struct ParamTraits<string16> {
+ typedef string16 param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteData(reinterpret_cast<const char*>(p.data()),
+ static_cast<int>(p.size() * sizeof(char16)));
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ const char *data;
+ int data_size = 0;
+ if (!m->ReadData(iter, &data, &data_size))
+ return false;
+ r->assign(reinterpret_cast<const char16*>(data),
+ data_size / sizeof(char16));
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(UTF16ToWide(p));
+ }
+};
+
+#endif
+
template <>
struct ParamTraits<GURL> {
typedef GURL param_type;
@@ -893,6 +927,66 @@
}
};
+
+template <>
+struct ParamTraits<webkit_glue::WebApplicationInfo> {
+ typedef webkit_glue::WebApplicationInfo param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, void** iter, param_type* r);
+ static void Log(const param_type& p, std::wstring* l);
+};
+
+
+#if defined(OS_WIN)
+template<>
+struct ParamTraits<TransportDIB::Id> {
+ typedef TransportDIB::Id param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.handle);
+ WriteParam(m, p.sequence_num);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return (ReadParam(m, iter, &r->handle) &&
+ ReadParam(m, iter, &r->sequence_num));
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(L"TransportDIB(");
+ LogParam(p.handle, l);
+ l->append(L", ");
+ LogParam(p.sequence_num, l);
+ l->append(L")");
+ }
+};
+#endif
+
+template<typename A>
+struct ParamTraits<Maybe<A> > {
+ typedef struct Maybe<A> param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.valid);
+ if (p.valid)
+ WriteParam(m, p.value);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ if (!ReadParam(m, iter, &r->valid))
+ return false;
+
+ if (r->valid)
+ return ReadParam(m, iter, &r->value);
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ if (p.valid) {
+ l->append(L"Just ");
+ ParamTraits<A>::Log(p.value, l);
+ } else {
+ l->append(L"Nothing");
+ }
+
+ }
+};
+
+
template <>
struct ParamTraits<Message> {
static void Write(Message* m, const Message& p) {
@@ -914,6 +1008,7 @@
}
};
+
template <>
struct ParamTraits<Tuple0> {
typedef Tuple0 param_type;
@@ -1070,62 +1165,6 @@
}
};
-#if defined(OS_WIN)
-template<>
-struct ParamTraits<TransportDIB::Id> {
- typedef TransportDIB::Id param_type;
- static void Write(Message* m, const param_type& p) {
- WriteParam(m, p.handle);
- WriteParam(m, p.sequence_num);
- }
- static bool Read(const Message* m, void** iter, param_type* r) {
- return (ReadParam(m, iter, &r->handle) &&
- ReadParam(m, iter, &r->sequence_num));
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(L"TransportDIB(");
- LogParam(p.handle, l);
- l->append(L", ");
- LogParam(p.sequence_num, l);
- l->append(L")");
- }
-};
-#endif
-
-template<typename A>
-struct ParamTraits<Maybe<A> > {
- typedef struct Maybe<A> param_type;
- static void Write(Message* m, const param_type& p) {
- WriteParam(m, p.valid);
- if (p.valid)
- WriteParam(m, p.value);
- }
- static bool Read(const Message* m, void** iter, param_type* r) {
- if (!ReadParam(m, iter, &r->valid))
- return false;
-
- if (r->valid)
- return ReadParam(m, iter, &r->value);
- return true;
- }
- static void Log(const param_type& p, std::wstring* l) {
- if (p.valid) {
- l->append(L"Just ");
- ParamTraits<A>::Log(p.value, l);
- } else {
- l->append(L"Nothing");
- }
-
- }
-};
-
-template <>
-struct ParamTraits<webkit_glue::WebApplicationInfo> {
- typedef webkit_glue::WebApplicationInfo param_type;
- static void Write(Message* m, const param_type& p);
- static bool Read(const Message* m, void** iter, param_type* r);
- static void Log(const param_type& p, std::wstring* l);
-};
//-----------------------------------------------------------------------------