OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <ctype.h> |
| 6 #include "config.h" |
| 7 |
| 8 #include "base/compiler_specific.h" |
| 9 |
| 10 MSVC_PUSH_WARNING_LEVEL(0); |
| 11 #include "Frame.h" |
| 12 #include "FrameLoaderClient.h" |
| 13 #include "WorkerContextProxy.h" |
| 14 #include "Worker.h" |
| 15 MSVC_POP_WARNING(); |
| 16 |
| 17 #undef LOG |
| 18 |
| 19 #include "webkit/glue/webworker.h" |
| 20 |
| 21 #include "base/string_util.h" |
| 22 #include "webkit/glue/glue_util.h" |
| 23 #include "webkit/glue/webframeloaderclient_impl.h" |
| 24 #include "webkit/glue/webframe_impl.h" |
| 25 #include "webkit/glue/webview_delegate.h" |
| 26 #include "webkit/glue/webview_impl.h" |
| 27 |
| 28 namespace WebCore { |
| 29 |
| 30 // The purpose of this class is to provide a WorkerContextProxy |
| 31 // implementation that we can give to WebKit. Internally, it converts the |
| 32 // data types to Chrome compatible ones so that renderer code can use it over |
| 33 // IPC. |
| 34 class ChromiumWorkerContextProxy : public WorkerContextProxy { |
| 35 public: |
| 36 ChromiumWorkerContextProxy(Worker* worker, WebWorkerContextProxy* webworker) |
| 37 : worker_(worker), webworker_(webworker) { |
| 38 } |
| 39 virtual ~ChromiumWorkerContextProxy() { |
| 40 } |
| 41 virtual void startWorkerContext(const KURL& scriptURL, |
| 42 const String& userAgent, |
| 43 const String& sourceCode) { |
| 44 webworker_->StartWorkerContext(webkit_glue::KURLToGURL(scriptURL), |
| 45 webkit_glue::StringToStdString(userAgent), |
| 46 webkit_glue::StringToStdString(sourceCode)); |
| 47 } |
| 48 virtual void terminateWorkerContext() { |
| 49 } |
| 50 virtual void postMessageToWorkerContext(const String&) { |
| 51 } |
| 52 virtual bool hasPendingActivity() const { |
| 53 return true; |
| 54 } |
| 55 virtual void workerObjectDestroyed() { |
| 56 } |
| 57 |
| 58 private: |
| 59 Worker* worker_; |
| 60 WebWorkerContextProxy* webworker_; |
| 61 }; |
| 62 |
| 63 // When WebKit creates a WorkerContextProxy object, we give it this |
| 64 // implementation that uses the glue provided Chrome interface |
| 65 // WebWorkerContextProxy to go over IPC to the worker process. |
| 66 WorkerContextProxy* WebCore::WorkerContextProxy::create(Worker* worker) { |
| 67 // Get to the RenderView, so that we can tell the browser to create a |
| 68 // worker process. |
| 69 WebFrameLoaderClient* frame_loader_client = |
| 70 static_cast<WebFrameLoaderClient*>( |
| 71 worker->document()->frame()->loader()->client()); |
| 72 WebViewDelegate* webview_delegate = |
| 73 frame_loader_client->webframe()->webview_impl()->delegate(); |
| 74 WebWorkerContextProxy* webworker = webview_delegate->CreateWebWorker(); |
| 75 return new ChromiumWorkerContextProxy(worker, webworker); |
| 76 } |
| 77 |
| 78 } |
| 79 |
| 80 |
| 81 |
| 82 // *****TODO***** |
| 83 // This class should be calling the WorkerContextProxy implementation from |
| 84 // WebKit. Right now this is part of WorkerMessagingProxy but it needs to be |
| 85 // factored out so that we can reuse it. |
| 86 |
| 87 // The purpose of this class is to convert the Chrome data types that were sent |
| 88 // over IPC to WebKit compatible ones, and then pass them on to the WebKit |
| 89 // implementation of WorkerContextProxy. |
| 90 class WebWorkerContextWrapper: public WebWorkerContextProxy { |
| 91 public: |
| 92 WebWorkerContextWrapper() { |
| 93 } |
| 94 virtual ~WebWorkerContextWrapper() { |
| 95 } |
| 96 virtual void StartWorkerContext(const GURL& script_url, |
| 97 const std::string& user_agent, |
| 98 const std::string& source_code) { |
| 99 |
| 100 } |
| 101 virtual void TerminateWorkerContext() { |
| 102 } |
| 103 virtual void PostMessageToWorkerContext(const std::string&) { |
| 104 } |
| 105 virtual bool HasPendingActivity() const { |
| 106 return true; |
| 107 } |
| 108 virtual void WorkerObjectDestroyed() { |
| 109 } |
| 110 |
| 111 private: |
| 112 DISALLOW_EVIL_CONSTRUCTORS(WebWorkerContextWrapper); |
| 113 }; |
| 114 |
| 115 |
| 116 WebWorkerContextProxy* CreateWebWorkerContextWrapper() { |
| 117 return new WebWorkerContextWrapper(); |
| 118 } |
OLD | NEW |