OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/worker/websharedworker_stub.h" | 5 #include "content/worker/websharedworker_stub.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "content/child/child_process.h" | 8 #include "content/child/child_process.h" |
9 #include "content/child/child_thread.h" | 9 #include "content/child/child_thread.h" |
10 #include "content/child/fileapi/file_system_dispatcher.h" | 10 #include "content/child/fileapi/file_system_dispatcher.h" |
11 #include "content/child/webmessageportchannel_impl.h" | 11 #include "content/child/webmessageportchannel_impl.h" |
12 #include "content/common/worker_messages.h" | 12 #include "content/common/worker_messages.h" |
13 #include "content/worker/shared_worker_devtools_agent.h" | 13 #include "content/worker/shared_worker_devtools_agent.h" |
14 #include "content/worker/worker_thread.h" | 14 #include "content/worker/worker_thread.h" |
15 #include "third_party/WebKit/public/web/WebSharedWorker.h" | 15 #include "third_party/WebKit/public/web/WebSharedWorker.h" |
16 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
17 #include "third_party/WebKit/public/platform/WebURL.h" | 17 #include "third_party/WebKit/public/platform/WebURL.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 WebSharedWorkerStub::WebSharedWorkerStub( | 21 WebSharedWorkerStub::WebSharedWorkerStub( |
| 22 const GURL& url, |
22 const base::string16& name, | 23 const base::string16& name, |
| 24 const base::string16& content_security_policy, |
| 25 blink::WebContentSecurityPolicyType security_policy_type, |
23 int route_id, | 26 int route_id, |
24 const WorkerAppCacheInitInfo& appcache_init_info) | 27 const WorkerAppCacheInitInfo& appcache_init_info) |
25 : route_id_(route_id), | 28 : route_id_(route_id), |
26 appcache_init_info_(appcache_init_info), | 29 appcache_init_info_(appcache_init_info), |
27 client_(route_id, this), | 30 client_(route_id, this), |
28 name_(name), | 31 name_(name), |
29 started_(false) { | 32 started_(false), |
| 33 worker_script_loaded_(false) { |
30 | 34 |
31 WorkerThread* worker_thread = WorkerThread::current(); | 35 WorkerThread* worker_thread = WorkerThread::current(); |
32 DCHECK(worker_thread); | 36 DCHECK(worker_thread); |
33 worker_thread->AddWorkerStub(this); | 37 worker_thread->AddWorkerStub(this); |
34 // Start processing incoming IPCs for this worker. | 38 // Start processing incoming IPCs for this worker. |
35 worker_thread->AddRoute(route_id_, this); | 39 worker_thread->AddRoute(route_id_, this); |
36 | 40 |
37 // TODO(atwilson): Add support for NaCl when they support MessagePorts. | 41 // TODO(atwilson): Add support for NaCl when they support MessagePorts. |
38 impl_ = blink::WebSharedWorker::create(client()); | 42 impl_ = blink::WebSharedWorker::create(client()); |
39 worker_devtools_agent_.reset(new SharedWorkerDevToolsAgent(route_id, impl_)); | 43 worker_devtools_agent_.reset(new SharedWorkerDevToolsAgent(route_id, impl_)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 blink::WebContentSecurityPolicyType policy_type) { | 91 blink::WebContentSecurityPolicyType policy_type) { |
88 // Ignore multiple attempts to start this worker (can happen if two pages | 92 // Ignore multiple attempts to start this worker (can happen if two pages |
89 // try to start it simultaneously). | 93 // try to start it simultaneously). |
90 if (started_) | 94 if (started_) |
91 return; | 95 return; |
92 | 96 |
93 impl_->startWorkerContext(url, name_, user_agent, source_code, | 97 impl_->startWorkerContext(url, name_, user_agent, source_code, |
94 content_security_policy, policy_type, 0); | 98 content_security_policy, policy_type, 0); |
95 started_ = true; | 99 started_ = true; |
96 url_ = url; | 100 url_ = url; |
97 | |
98 // Process any pending connections. | |
99 for (PendingConnectInfoList::const_iterator iter = pending_connects_.begin(); | |
100 iter != pending_connects_.end(); | |
101 ++iter) { | |
102 OnConnect(iter->first, iter->second); | |
103 } | |
104 pending_connects_.clear(); | |
105 } | 101 } |
106 | 102 |
107 void WebSharedWorkerStub::OnConnect(int sent_message_port_id, int routing_id) { | 103 void WebSharedWorkerStub::OnConnect(int sent_message_port_id, int routing_id) { |
108 if (started_) { | 104 blink::WebMessagePortChannel* channel = |
109 blink::WebMessagePortChannel* channel = | 105 new WebMessagePortChannelImpl(routing_id, |
110 new WebMessagePortChannelImpl(routing_id, | 106 sent_message_port_id, |
111 sent_message_port_id, | 107 base::MessageLoopProxy::current().get()); |
112 base::MessageLoopProxy::current().get()); | 108 if (started_ && worker_script_loaded_) { |
113 impl_->connect(channel); | 109 impl_->connect(channel); |
114 } else { | 110 } else { |
115 // If two documents try to load a SharedWorker at the same time, the | 111 // If two documents try to load a SharedWorker at the same time, the |
116 // WorkerMsg_Connect for one of the documents can come in before the | 112 // WorkerMsg_Connect for one of the documents can come in before the |
117 // worker is started. Just queue up the connect and deliver it once the | 113 // worker is started. Just queue up the connect and deliver it once the |
118 // worker starts. | 114 // worker starts. |
119 PendingConnectInfo pending_connect(sent_message_port_id, routing_id); | 115 pending_channels_.push_back(channel); |
120 pending_connects_.push_back(pending_connect); | |
121 } | 116 } |
122 } | 117 } |
123 | 118 |
124 void WebSharedWorkerStub::OnTerminateWorkerContext() { | 119 void WebSharedWorkerStub::OnTerminateWorkerContext() { |
125 impl_->terminateWorkerContext(); | 120 impl_->terminateWorkerContext(); |
126 | 121 |
127 // Call the client to make sure context exits. | 122 // Call the client to make sure context exits. |
128 EnsureWorkerContextTerminates(); | 123 EnsureWorkerContextTerminates(); |
129 started_ = false; | 124 started_ = false; |
130 } | 125 } |
131 | 126 |
| 127 void WebSharedWorkerStub::workerScriptLoaded() { |
| 128 worker_script_loaded_ = true; |
| 129 // Process any pending connections. |
| 130 for (PendingChannelList::const_iterator iter = pending_channels_.begin(); |
| 131 iter != pending_channels_.end(); |
| 132 ++iter) { |
| 133 impl_->connect(*iter); |
| 134 } |
| 135 pending_channels_.clear(); |
| 136 } |
| 137 |
| 138 void WebSharedWorkerStub::workerScriptLoadFailed() { |
| 139 // FIXME(horo): Implement this. |
| 140 } |
| 141 |
132 } // namespace content | 142 } // namespace content |
OLD | NEW |