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 "config.h" |
| 6 |
| 7 #if ENABLE(WORKERS) |
| 8 |
| 9 #include "base/compiler_specific.h" |
| 10 |
| 11 #include "Frame.h" |
| 12 #include "FrameLoaderClient.h" |
| 13 #include "WorkerMessagingProxy.h" |
| 14 #include "Worker.h" |
| 15 |
| 16 #undef LOG |
| 17 |
| 18 #include "webkit/glue/webworkerclient_impl.h" |
| 19 |
| 20 #include "webkit/glue/glue_util.h" |
| 21 #include "webkit/glue/webframeloaderclient_impl.h" |
| 22 #include "webkit/glue/webframe_impl.h" |
| 23 #include "webkit/glue/webview_delegate.h" |
| 24 #include "webkit/glue/webview_impl.h" |
| 25 #include "webkit/glue/webworker.h" |
| 26 |
| 27 |
| 28 // When WebKit creates a WorkerContextProxy object, we check if we're in the |
| 29 // renderer or worker process. If the latter, then we just use |
| 30 // WebCore::WorkerMessagingProxy. |
| 31 // |
| 32 // If we're in the renderer process, then we need use the glue provided |
| 33 // WebWorker object to talk to the worker process over IPC. The worker process |
| 34 // talks to WebCore::Worker* using WorkerObjectProxy, which we implement on |
| 35 // WebWorkerClientImpl. |
| 36 WebCore::WorkerContextProxy* WebCore::WorkerContextProxy::create( |
| 37 WebCore::Worker* worker) { |
| 38 if (!worker->scriptExecutionContext()->isDocument()) |
| 39 return new WebCore::WorkerMessagingProxy(worker); |
| 40 |
| 41 WebWorkerClientImpl* proxy = new WebWorkerClientImpl(worker); |
| 42 |
| 43 // Get to the RenderView, so that we can tell the browser to create a |
| 44 // worker process if necessary. |
| 45 WebCore::Document* document = static_cast<WebCore::Document*>( |
| 46 worker->scriptExecutionContext()); |
| 47 WebFrameLoaderClient* frame_loader_client = |
| 48 static_cast<WebFrameLoaderClient*>(document->frame()->loader()->client()); |
| 49 WebViewDelegate* webview_delegate = |
| 50 frame_loader_client->webframe()->webview_impl()->delegate(); |
| 51 WebWorker* webworker = webview_delegate->CreateWebWorker(proxy); |
| 52 proxy->set_webworker(webworker); |
| 53 return proxy; |
| 54 } |
| 55 |
| 56 |
| 57 WebWorkerClientImpl::WebWorkerClientImpl(WebCore::Worker* worker) |
| 58 : worker_(worker) { |
| 59 } |
| 60 |
| 61 WebWorkerClientImpl::~WebWorkerClientImpl() { |
| 62 } |
| 63 |
| 64 void WebWorkerClientImpl::set_webworker(WebWorker* webworker) { |
| 65 webworker_.reset(webworker); |
| 66 } |
| 67 |
| 68 void WebWorkerClientImpl::startWorkerContext( |
| 69 const WebCore::KURL& scriptURL, |
| 70 const WebCore::String& userAgent, |
| 71 const WebCore::String& sourceCode) { |
| 72 webworker_->StartWorkerContext(webkit_glue::KURLToGURL(scriptURL), |
| 73 webkit_glue::StringToString16(userAgent), |
| 74 webkit_glue::StringToString16(sourceCode)); |
| 75 } |
| 76 |
| 77 void WebWorkerClientImpl::terminateWorkerContext() { |
| 78 webworker_->TerminateWorkerContext(); |
| 79 } |
| 80 |
| 81 void WebWorkerClientImpl::postMessageToWorkerContext( |
| 82 const WebCore::String& message) { |
| 83 webworker_->PostMessageToWorkerContext( |
| 84 webkit_glue::StringToString16(message)); |
| 85 } |
| 86 |
| 87 bool WebWorkerClientImpl::hasPendingActivity() const { |
| 88 // TODO(jianli): we should use the same logic from WorkerMessagingProxy |
| 89 // here, so that we don't do a synchronous IPC. |
| 90 // Until then, always return true. |
| 91 return true; |
| 92 } |
| 93 |
| 94 void WebWorkerClientImpl::workerObjectDestroyed() { |
| 95 webworker_->WorkerObjectDestroyed(); |
| 96 } |
| 97 |
| 98 void WebWorkerClientImpl::PostMessageToWorkerObject(const string16& message) { |
| 99 // TODO(jianli): this method, and the ones below, need to implement |
| 100 // WorkerObjectProxy. |
| 101 } |
| 102 |
| 103 void WebWorkerClientImpl::PostExceptionToWorkerObject( |
| 104 const string16& error_message, |
| 105 int line_number, |
| 106 const string16& source_url) { |
| 107 } |
| 108 |
| 109 void WebWorkerClientImpl::PostConsoleMessageToWorkerObject( |
| 110 int destination, |
| 111 int source, |
| 112 int level, |
| 113 const string16& message, |
| 114 int line_number, |
| 115 const string16& source_url) { |
| 116 } |
| 117 |
| 118 void WebWorkerClientImpl::ConfirmMessageFromWorkerObject(bool has_pending_activi
ty) { |
| 119 } |
| 120 |
| 121 void WebWorkerClientImpl::ReportPendingActivity(bool has_pending_activity) { |
| 122 } |
| 123 |
| 124 void WebWorkerClientImpl::WorkerContextDestroyed() { |
| 125 delete this; |
| 126 } |
| 127 |
| 128 #endif |
OLD | NEW |