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_base.h" | 5 #include "chrome/renderer/webworker_base.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::WebMessagePortChannel; | 14 using WebKit::WebMessagePortChannel; |
15 using WebKit::WebMessagePortChannelArray; | 15 using WebKit::WebMessagePortChannelArray; |
16 using WebKit::WebString; | 16 using WebKit::WebString; |
17 using WebKit::WebURL; | 17 using WebKit::WebURL; |
18 using WebKit::WebWorkerClient; | 18 using WebKit::WebWorkerClient; |
19 | 19 |
20 WebWorkerBase::WebWorkerBase( | 20 WebWorkerBase::WebWorkerBase( |
21 ChildThread* child_thread, | 21 ChildThread* child_thread, |
| 22 unsigned long long document_id, |
22 int route_id, | 23 int route_id, |
23 int render_view_route_id) | 24 int render_view_route_id) |
24 : route_id_(route_id), | 25 : route_id_(route_id), |
25 render_view_route_id_(render_view_route_id), | 26 render_view_route_id_(render_view_route_id), |
26 child_thread_(child_thread) { | 27 child_thread_(child_thread), |
| 28 document_id_(document_id) { |
27 if (route_id_ != MSG_ROUTING_NONE) | 29 if (route_id_ != MSG_ROUTING_NONE) |
28 child_thread_->AddRoute(route_id_, this); | 30 child_thread_->AddRoute(route_id_, this); |
29 } | 31 } |
30 | 32 |
31 WebWorkerBase::~WebWorkerBase() { | 33 WebWorkerBase::~WebWorkerBase() { |
32 Disconnect(); | 34 Disconnect(); |
33 | 35 |
34 // Free up any unsent queued messages. | 36 // Free up any unsent queued messages. |
35 for (size_t i = 0; i < queued_messages_.size(); ++i) | 37 for (size_t i = 0; i < queued_messages_.size(); ++i) |
36 delete queued_messages_[i]; | 38 delete queued_messages_[i]; |
(...skipping 10 matching lines...) Expand all Loading... |
47 | 49 |
48 route_id_ = MSG_ROUTING_NONE; | 50 route_id_ = MSG_ROUTING_NONE; |
49 } | 51 } |
50 | 52 |
51 void WebWorkerBase::CreateWorkerContext(const GURL& script_url, | 53 void WebWorkerBase::CreateWorkerContext(const GURL& script_url, |
52 bool is_shared, | 54 bool is_shared, |
53 const string16& name, | 55 const string16& name, |
54 const string16& user_agent, | 56 const string16& user_agent, |
55 const string16& source_code) { | 57 const string16& source_code) { |
56 DCHECK(route_id_ == MSG_ROUTING_NONE); | 58 DCHECK(route_id_ == MSG_ROUTING_NONE); |
| 59 ViewHostMsg_CreateWorker_Params params; |
| 60 params.url = script_url; |
| 61 params.is_shared = is_shared; |
| 62 params.name = name; |
| 63 params.document_id = document_id_; |
| 64 params.render_view_route_id = render_view_route_id_; |
57 IPC::Message* create_message = new ViewHostMsg_CreateWorker( | 65 IPC::Message* create_message = new ViewHostMsg_CreateWorker( |
58 script_url, is_shared, name, render_view_route_id_, &route_id_); | 66 params, &route_id_); |
59 child_thread_->Send(create_message); | 67 child_thread_->Send(create_message); |
60 if (route_id_ == MSG_ROUTING_NONE) | 68 if (route_id_ == MSG_ROUTING_NONE) |
61 return; | 69 return; |
62 | 70 |
63 child_thread_->AddRoute(route_id_, this); | 71 child_thread_->AddRoute(route_id_, this); |
64 | 72 |
65 // We make sure that the start message is the first, since postMessage or | 73 // We make sure that the start message is the first, since postMessage or |
66 // connect might have already been called. | 74 // connect might have already been called. |
67 queued_messages_.insert(queued_messages_.begin(), | 75 queued_messages_.insert(queued_messages_.begin(), |
68 new WorkerMsg_StartWorkerContext( | 76 new WorkerMsg_StartWorkerContext( |
(...skipping 26 matching lines...) Expand all Loading... |
95 | 103 |
96 void WebWorkerBase::SendQueuedMessages() { | 104 void WebWorkerBase::SendQueuedMessages() { |
97 DCHECK(queued_messages_.size()); | 105 DCHECK(queued_messages_.size()); |
98 std::vector<IPC::Message*> queued_messages = queued_messages_; | 106 std::vector<IPC::Message*> queued_messages = queued_messages_; |
99 queued_messages_.clear(); | 107 queued_messages_.clear(); |
100 for (size_t i = 0; i < queued_messages.size(); ++i) { | 108 for (size_t i = 0; i < queued_messages.size(); ++i) { |
101 queued_messages[i]->set_routing_id(route_id_); | 109 queued_messages[i]->set_routing_id(route_id_); |
102 Send(queued_messages[i]); | 110 Send(queued_messages[i]); |
103 } | 111 } |
104 } | 112 } |
OLD | NEW |