| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/webworker_proxy.h" | 5 #include "content/renderer/webworker_proxy.h" |
| 6 | 6 |
| 7 #include "content/common/child_thread.h" | 7 #include "content/common/child_thread.h" |
| 8 #include "content/common/content_client.h" |
| 8 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
| 9 #include "content/common/webmessageportchannel_impl.h" | 10 #include "content/common/webmessageportchannel_impl.h" |
| 10 #include "content/common/worker_messages.h" | 11 #include "content/common/worker_messages.h" |
| 12 #include "content/worker/content_worker_client.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerClient.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerClient.h" |
| 13 | 15 |
| 14 using WebKit::WebCommonWorkerClient; | 16 using WebKit::WebCommonWorkerClient; |
| 15 using WebKit::WebMessagePortChannel; | 17 using WebKit::WebMessagePortChannel; |
| 16 using WebKit::WebMessagePortChannelArray; | 18 using WebKit::WebMessagePortChannelArray; |
| 17 using WebKit::WebString; | 19 using WebKit::WebString; |
| 18 using WebKit::WebURL; | 20 using WebKit::WebURL; |
| 19 using WebKit::WebWorkerClient; | 21 using WebKit::WebWorkerClient; |
| 20 | 22 |
| 21 WebWorkerProxy::WebWorkerProxy( | 23 WebWorkerProxy::WebWorkerProxy( |
| 22 WebWorkerClient* client, | 24 WebWorkerClient* client, |
| 23 ChildThread* child_thread, | 25 ChildThread* child_thread, |
| 24 int render_view_route_id, | 26 int render_view_route_id, |
| 25 int parent_appcache_host_id) | 27 int parent_appcache_host_id) |
| 26 : WebWorkerBase(child_thread, 0, MSG_ROUTING_NONE, render_view_route_id, | 28 : WebWorkerBase(child_thread, 0, MSG_ROUTING_NONE, render_view_route_id, |
| 27 parent_appcache_host_id), | 29 parent_appcache_host_id), |
| 28 client_(client) { | 30 client_(client) { |
| 29 // TODO(atwilson): Change to pass in a real document_id when we support nested | 31 // TODO(atwilson): Change to pass in a real document_id when we support nested |
| 30 // workers. | 32 // workers. |
| 33 content::GetContentClient()->worker()->WebWorkerProxyCreated(this, route_id_, |
| 34 client_); |
| 31 } | 35 } |
| 32 | 36 |
| 33 WebWorkerProxy::~WebWorkerProxy() { | 37 WebWorkerProxy::~WebWorkerProxy() { |
| 34 // If we're midway through starting a worker, cancel it. | 38 // If we're midway through starting a worker, cancel it. |
| 35 CancelCreation(); | 39 CancelCreation(); |
| 36 } | 40 } |
| 37 | 41 |
| 38 void WebWorkerProxy::CancelCreation() { | 42 void WebWorkerProxy::CancelCreation() { |
| 39 if (route_id_ == MSG_ROUTING_NONE) | 43 if (route_id_ == MSG_ROUTING_NONE) |
| 40 return; | 44 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 81 } |
| 78 | 82 |
| 79 void WebWorkerProxy::workerObjectDestroyed() { | 83 void WebWorkerProxy::workerObjectDestroyed() { |
| 80 Send(new WorkerMsg_WorkerObjectDestroyed(route_id_)); | 84 Send(new WorkerMsg_WorkerObjectDestroyed(route_id_)); |
| 81 delete this; | 85 delete this; |
| 82 } | 86 } |
| 83 | 87 |
| 84 void WebWorkerProxy::clientDestroyed() { | 88 void WebWorkerProxy::clientDestroyed() { |
| 85 } | 89 } |
| 86 | 90 |
| 91 void WebWorkerProxy::attachDevTools() |
| 92 { |
| 93 if (devtools_delegate_) |
| 94 devtools_delegate_->AttachDevTools(); |
| 95 } |
| 96 |
| 97 void WebWorkerProxy::detachDevTools() |
| 98 { |
| 99 if (devtools_delegate_) |
| 100 devtools_delegate_->DetachDevTools(); |
| 101 } |
| 102 |
| 103 void WebWorkerProxy::dispatchDevToolsMessage(const WebString& message) |
| 104 { |
| 105 if (devtools_delegate_) |
| 106 devtools_delegate_->SendDevToolsMessage(message.utf8()); |
| 107 } |
| 108 |
| 87 bool WebWorkerProxy::OnMessageReceived(const IPC::Message& message) { | 109 bool WebWorkerProxy::OnMessageReceived(const IPC::Message& message) { |
| 88 if (!client_) | 110 if (!client_) |
| 89 return false; | 111 return false; |
| 90 | 112 |
| 113 if (devtools_delegate_ && |
| 114 devtools_delegate_->OnMessageReceived(message)) |
| 115 return true; |
| 116 |
| 91 bool handled = true; | 117 bool handled = true; |
| 92 IPC_BEGIN_MESSAGE_MAP(WebWorkerProxy, message) | 118 IPC_BEGIN_MESSAGE_MAP(WebWorkerProxy, message) |
| 93 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) | 119 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) |
| 94 IPC_MESSAGE_HANDLER(WorkerMsg_PostMessage, OnPostMessage) | 120 IPC_MESSAGE_HANDLER(WorkerMsg_PostMessage, OnPostMessage) |
| 95 IPC_MESSAGE_FORWARD(WorkerHostMsg_PostExceptionToWorkerObject, | 121 IPC_MESSAGE_FORWARD(WorkerHostMsg_PostExceptionToWorkerObject, |
| 96 client_, | 122 client_, |
| 97 WebWorkerClient::postExceptionToWorkerObject) | 123 WebWorkerClient::postExceptionToWorkerObject) |
| 98 IPC_MESSAGE_HANDLER(WorkerHostMsg_PostConsoleMessageToWorkerObject, | 124 IPC_MESSAGE_HANDLER(WorkerHostMsg_PostConsoleMessageToWorkerObject, |
| 99 OnPostConsoleMessageToWorkerObject) | 125 OnPostConsoleMessageToWorkerObject) |
| 100 IPC_MESSAGE_FORWARD(WorkerHostMsg_ConfirmMessageFromWorkerObject, | 126 IPC_MESSAGE_FORWARD(WorkerHostMsg_ConfirmMessageFromWorkerObject, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 131 client_->postMessageToWorkerObject(message, channels); | 157 client_->postMessageToWorkerObject(message, channels); |
| 132 } | 158 } |
| 133 | 159 |
| 134 void WebWorkerProxy::OnPostConsoleMessageToWorkerObject( | 160 void WebWorkerProxy::OnPostConsoleMessageToWorkerObject( |
| 135 const WorkerHostMsg_PostConsoleMessageToWorkerObject_Params& params) { | 161 const WorkerHostMsg_PostConsoleMessageToWorkerObject_Params& params) { |
| 136 client_->postConsoleMessageToWorkerObject(params.source_identifier, | 162 client_->postConsoleMessageToWorkerObject(params.source_identifier, |
| 137 params.message_type, params.message_level, | 163 params.message_type, params.message_level, |
| 138 params.message, params.line_number, params.source_url); | 164 params.message, params.line_number, params.source_url); |
| 139 } | 165 } |
| 140 | 166 |
| OLD | NEW |