Index: webkit/glue/webworker.cc |
=================================================================== |
--- webkit/glue/webworker.cc (revision 0) |
+++ webkit/glue/webworker.cc (revision 0) |
@@ -0,0 +1,118 @@ |
+// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <ctype.h> |
+#include "config.h" |
+ |
+#include "base/compiler_specific.h" |
+ |
+MSVC_PUSH_WARNING_LEVEL(0); |
+#include "Frame.h" |
+#include "FrameLoaderClient.h" |
+#include "WorkerContextProxy.h" |
+#include "Worker.h" |
+MSVC_POP_WARNING(); |
+ |
+#undef LOG |
+ |
+#include "webkit/glue/webworker.h" |
+ |
+#include "base/string_util.h" |
+#include "webkit/glue/glue_util.h" |
+#include "webkit/glue/webframeloaderclient_impl.h" |
+#include "webkit/glue/webframe_impl.h" |
+#include "webkit/glue/webview_delegate.h" |
+#include "webkit/glue/webview_impl.h" |
+ |
+namespace WebCore { |
+ |
+// The purpose of this class is to provide a WorkerContextProxy |
+// implementation that we can give to WebKit. Internally, it converts the |
+// data types to Chrome compatible ones so that renderer code can use it over |
+// IPC. |
+class ChromiumWorkerContextProxy : public WorkerContextProxy { |
+ public: |
+ ChromiumWorkerContextProxy(Worker* worker, WebWorkerContextProxy* webworker) |
+ : worker_(worker), webworker_(webworker) { |
+ } |
+ virtual ~ChromiumWorkerContextProxy() { |
+ } |
+ virtual void startWorkerContext(const KURL& scriptURL, |
+ const String& userAgent, |
+ const String& sourceCode) { |
+ webworker_->StartWorkerContext(webkit_glue::KURLToGURL(scriptURL), |
+ webkit_glue::StringToStdString(userAgent), |
+ webkit_glue::StringToStdString(sourceCode)); |
+ } |
+ virtual void terminateWorkerContext() { |
+ } |
+ virtual void postMessageToWorkerContext(const String&) { |
+ } |
+ virtual bool hasPendingActivity() const { |
+ return true; |
+ } |
+ virtual void workerObjectDestroyed() { |
+ } |
+ |
+ private: |
+ Worker* worker_; |
+ WebWorkerContextProxy* webworker_; |
+}; |
+ |
+// When WebKit creates a WorkerContextProxy object, we give it this |
+// implementation that uses the glue provided Chrome interface |
+// WebWorkerContextProxy to go over IPC to the worker process. |
+WorkerContextProxy* WebCore::WorkerContextProxy::create(Worker* worker) { |
+ // Get to the RenderView, so that we can tell the browser to create a |
+ // worker process. |
+ WebFrameLoaderClient* frame_loader_client = |
+ static_cast<WebFrameLoaderClient*>( |
+ worker->document()->frame()->loader()->client()); |
+ WebViewDelegate* webview_delegate = |
+ frame_loader_client->webframe()->webview_impl()->delegate(); |
+ WebWorkerContextProxy* webworker = webview_delegate->CreateWebWorker(); |
+ return new ChromiumWorkerContextProxy(worker, webworker); |
+} |
+ |
+} |
+ |
+ |
+ |
+// *****TODO***** |
+// This class should be calling the WorkerContextProxy implementation from |
+// WebKit. Right now this is part of WorkerMessagingProxy but it needs to be |
+// factored out so that we can reuse it. |
+ |
+// The purpose of this class is to convert the Chrome data types that were sent |
+// over IPC to WebKit compatible ones, and then pass them on to the WebKit |
+// implementation of WorkerContextProxy. |
+class WebWorkerContextWrapper: public WebWorkerContextProxy { |
+ public: |
+ WebWorkerContextWrapper() { |
+ } |
+ virtual ~WebWorkerContextWrapper() { |
+ } |
+ virtual void StartWorkerContext(const GURL& script_url, |
+ const std::string& user_agent, |
+ const std::string& source_code) { |
+ |
+ } |
+ virtual void TerminateWorkerContext() { |
+ } |
+ virtual void PostMessageToWorkerContext(const std::string&) { |
+ } |
+ virtual bool HasPendingActivity() const { |
+ return true; |
+ } |
+ virtual void WorkerObjectDestroyed() { |
+ } |
+ |
+ private: |
+ DISALLOW_EVIL_CONSTRUCTORS(WebWorkerContextWrapper); |
+}; |
+ |
+ |
+WebWorkerContextProxy* CreateWebWorkerContextWrapper() { |
+ return new WebWorkerContextWrapper(); |
+} |