| 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 "chrome/renderer/webworker_proxy.h" | 5 #include "chrome/renderer/webworker_proxy.h" |
| 6 | 6 |
| 7 #include "chrome/common/child_thread.h" | 7 #include "chrome/common/child_thread.h" |
| 8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
| 9 #include "chrome/common/webmessageportchannel_impl.h" | 9 #include "chrome/common/webmessageportchannel_impl.h" |
| 10 #include "chrome/common/worker_messages.h" | 10 #include "chrome/common/worker_messages.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebWorkerClient.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebWorkerClient.h" |
| 13 | 13 |
| 14 using WebKit::WebCommonWorkerClient; | 14 using WebKit::WebCommonWorkerClient; |
| 15 using WebKit::WebMessagePortChannel; | 15 using WebKit::WebMessagePortChannel; |
| 16 using WebKit::WebMessagePortChannelArray; | 16 using WebKit::WebMessagePortChannelArray; |
| 17 using WebKit::WebString; | 17 using WebKit::WebString; |
| 18 using WebKit::WebURL; | 18 using WebKit::WebURL; |
| 19 using WebKit::WebWorkerClient; | 19 using WebKit::WebWorkerClient; |
| 20 | 20 |
| 21 WebWorkerProxy::WebWorkerProxy( | 21 WebWorkerProxy::WebWorkerProxy( |
| 22 WebWorkerClient* client, | 22 WebWorkerClient* client, |
| 23 ChildThread* child_thread, | 23 ChildThread* child_thread, |
| 24 int render_view_route_id) | 24 int render_view_route_id) |
| 25 : WebWorkerBase(child_thread, MSG_ROUTING_NONE, render_view_route_id), | 25 : WebWorkerBase(child_thread, MSG_ROUTING_NONE, render_view_route_id), |
| 26 client_(client) { | 26 client_(client) { |
| 27 } | 27 } |
| 28 | 28 |
| 29 void WebWorkerProxy::Disconnect() { | 29 WebWorkerProxy::~WebWorkerProxy() { |
| 30 // If we're midway through starting a worker, cancel it. |
| 31 CancelCreation(); |
| 32 } |
| 33 |
| 34 void WebWorkerProxy::CancelCreation() { |
| 30 if (route_id_ == MSG_ROUTING_NONE) | 35 if (route_id_ == MSG_ROUTING_NONE) |
| 31 return; | 36 return; |
| 32 | 37 |
| 33 // Tell the browser to not start our queued worker. | 38 // Tell the browser to not start our queued worker. |
| 34 if (!IsStarted()) | 39 if (!IsStarted()) |
| 35 child_thread_->Send(new ViewHostMsg_CancelCreateDedicatedWorker(route_id_)); | 40 child_thread_->Send(new ViewHostMsg_CancelCreateDedicatedWorker(route_id_)); |
| 36 | |
| 37 // Call our superclass to shutdown the routing | |
| 38 WebWorkerBase::Disconnect(); | |
| 39 } | 41 } |
| 40 | 42 |
| 41 void WebWorkerProxy::startWorkerContext( | 43 void WebWorkerProxy::startWorkerContext( |
| 42 const WebURL& script_url, | 44 const WebURL& script_url, |
| 43 const WebString& user_agent, | 45 const WebString& user_agent, |
| 44 const WebString& source_code) { | 46 const WebString& source_code) { |
| 45 CreateWorkerContext(script_url, false, string16(), user_agent, source_code); | 47 CreateWorkerContext(script_url, false, string16(), user_agent, source_code); |
| 46 } | 48 } |
| 47 | 49 |
| 48 void WebWorkerProxy::terminateWorkerContext() { | 50 void WebWorkerProxy::terminateWorkerContext() { |
| 49 if (route_id_ != MSG_ROUTING_NONE) { | 51 if (route_id_ != MSG_ROUTING_NONE) { |
| 50 Send(new WorkerMsg_TerminateWorkerContext(route_id_)); | 52 Send(new WorkerMsg_TerminateWorkerContext(route_id_)); |
| 53 CancelCreation(); |
| 51 Disconnect(); | 54 Disconnect(); |
| 52 } | 55 } |
| 53 } | 56 } |
| 54 | 57 |
| 55 void WebWorkerProxy::postMessageToWorkerContext( | 58 void WebWorkerProxy::postMessageToWorkerContext( |
| 56 const WebString& message, const WebMessagePortChannelArray& channels) { | 59 const WebString& message, const WebMessagePortChannelArray& channels) { |
| 57 std::vector<int> message_port_ids(channels.size()); | 60 std::vector<int> message_port_ids(channels.size()); |
| 58 std::vector<int> routing_ids(channels.size()); | 61 std::vector<int> routing_ids(channels.size()); |
| 59 for (size_t i = 0; i < channels.size(); ++i) { | 62 for (size_t i = 0; i < channels.size(); ++i) { |
| 60 WebMessagePortChannelImpl* webchannel = | 63 WebMessagePortChannelImpl* webchannel = |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 client_->postMessageToWorkerObject(message, channels); | 124 client_->postMessageToWorkerObject(message, channels); |
| 122 } | 125 } |
| 123 | 126 |
| 124 void WebWorkerProxy::OnPostConsoleMessageToWorkerObject( | 127 void WebWorkerProxy::OnPostConsoleMessageToWorkerObject( |
| 125 const WorkerHostMsg_PostConsoleMessageToWorkerObject_Params& params) { | 128 const WorkerHostMsg_PostConsoleMessageToWorkerObject_Params& params) { |
| 126 client_->postConsoleMessageToWorkerObject(params.destination_identifier, | 129 client_->postConsoleMessageToWorkerObject(params.destination_identifier, |
| 127 params.source_identifier, params.message_type, params.message_level, | 130 params.source_identifier, params.message_type, params.message_level, |
| 128 params.message, params.line_number, params.source_url); | 131 params.message, params.line_number, params.source_url); |
| 129 } | 132 } |
| 130 | 133 |
| OLD | NEW |