| 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" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 started_(false) { | 29 started_(false) { |
| 30 | 30 |
| 31 WorkerThread* worker_thread = WorkerThread::current(); | 31 WorkerThread* worker_thread = WorkerThread::current(); |
| 32 DCHECK(worker_thread); | 32 DCHECK(worker_thread); |
| 33 worker_thread->AddWorkerStub(this); | 33 worker_thread->AddWorkerStub(this); |
| 34 // Start processing incoming IPCs for this worker. | 34 // Start processing incoming IPCs for this worker. |
| 35 worker_thread->AddRoute(route_id_, this); | 35 worker_thread->AddRoute(route_id_, this); |
| 36 ChildProcess::current()->AddRefProcess(); | 36 ChildProcess::current()->AddRefProcess(); |
| 37 | 37 |
| 38 // TODO(atwilson): Add support for NaCl when they support MessagePorts. | 38 // TODO(atwilson): Add support for NaCl when they support MessagePorts. |
| 39 impl_ = WebKit::WebSharedWorker::create(client()); | 39 impl_ = blink::WebSharedWorker::create(client()); |
| 40 worker_devtools_agent_.reset(new SharedWorkerDevToolsAgent(route_id, impl_)); | 40 worker_devtools_agent_.reset(new SharedWorkerDevToolsAgent(route_id, impl_)); |
| 41 client()->set_devtools_agent(worker_devtools_agent_.get()); | 41 client()->set_devtools_agent(worker_devtools_agent_.get()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 WebSharedWorkerStub::~WebSharedWorkerStub() { | 44 WebSharedWorkerStub::~WebSharedWorkerStub() { |
| 45 impl_->clientDestroyed(); | 45 impl_->clientDestroyed(); |
| 46 WorkerThread* worker_thread = WorkerThread::current(); | 46 WorkerThread* worker_thread = WorkerThread::current(); |
| 47 DCHECK(worker_thread); | 47 DCHECK(worker_thread); |
| 48 worker_thread->RemoveWorkerStub(this); | 48 worker_thread->RemoveWorkerStub(this); |
| 49 worker_thread->RemoveRoute(route_id_); | 49 worker_thread->RemoveRoute(route_id_); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 78 OnTerminateWorkerContext(); | 78 OnTerminateWorkerContext(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 const GURL& WebSharedWorkerStub::url() { | 81 const GURL& WebSharedWorkerStub::url() { |
| 82 return url_; | 82 return url_; |
| 83 } | 83 } |
| 84 | 84 |
| 85 void WebSharedWorkerStub::OnStartWorkerContext( | 85 void WebSharedWorkerStub::OnStartWorkerContext( |
| 86 const GURL& url, const string16& user_agent, const string16& source_code, | 86 const GURL& url, const string16& user_agent, const string16& source_code, |
| 87 const string16& content_security_policy, | 87 const string16& content_security_policy, |
| 88 WebKit::WebContentSecurityPolicyType policy_type) { | 88 blink::WebContentSecurityPolicyType policy_type) { |
| 89 // Ignore multiple attempts to start this worker (can happen if two pages | 89 // Ignore multiple attempts to start this worker (can happen if two pages |
| 90 // try to start it simultaneously). | 90 // try to start it simultaneously). |
| 91 if (started_) | 91 if (started_) |
| 92 return; | 92 return; |
| 93 | 93 |
| 94 impl_->startWorkerContext(url, name_, user_agent, source_code, | 94 impl_->startWorkerContext(url, name_, user_agent, source_code, |
| 95 content_security_policy, policy_type, 0); | 95 content_security_policy, policy_type, 0); |
| 96 started_ = true; | 96 started_ = true; |
| 97 url_ = url; | 97 url_ = url; |
| 98 | 98 |
| 99 // Process any pending connections. | 99 // Process any pending connections. |
| 100 for (PendingConnectInfoList::const_iterator iter = pending_connects_.begin(); | 100 for (PendingConnectInfoList::const_iterator iter = pending_connects_.begin(); |
| 101 iter != pending_connects_.end(); | 101 iter != pending_connects_.end(); |
| 102 ++iter) { | 102 ++iter) { |
| 103 OnConnect(iter->first, iter->second); | 103 OnConnect(iter->first, iter->second); |
| 104 } | 104 } |
| 105 pending_connects_.clear(); | 105 pending_connects_.clear(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void WebSharedWorkerStub::OnConnect(int sent_message_port_id, int routing_id) { | 108 void WebSharedWorkerStub::OnConnect(int sent_message_port_id, int routing_id) { |
| 109 if (started_) { | 109 if (started_) { |
| 110 WebKit::WebMessagePortChannel* channel = | 110 blink::WebMessagePortChannel* channel = |
| 111 new WebMessagePortChannelImpl(routing_id, | 111 new WebMessagePortChannelImpl(routing_id, |
| 112 sent_message_port_id, | 112 sent_message_port_id, |
| 113 base::MessageLoopProxy::current().get()); | 113 base::MessageLoopProxy::current().get()); |
| 114 impl_->connect(channel, NULL); | 114 impl_->connect(channel, NULL); |
| 115 } else { | 115 } else { |
| 116 // If two documents try to load a SharedWorker at the same time, the | 116 // If two documents try to load a SharedWorker at the same time, the |
| 117 // WorkerMsg_Connect for one of the documents can come in before the | 117 // WorkerMsg_Connect for one of the documents can come in before the |
| 118 // worker is started. Just queue up the connect and deliver it once the | 118 // worker is started. Just queue up the connect and deliver it once the |
| 119 // worker starts. | 119 // worker starts. |
| 120 PendingConnectInfo pending_connect(sent_message_port_id, routing_id); | 120 PendingConnectInfo pending_connect(sent_message_port_id, routing_id); |
| 121 pending_connects_.push_back(pending_connect); | 121 pending_connects_.push_back(pending_connect); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 void WebSharedWorkerStub::OnTerminateWorkerContext() { | 125 void WebSharedWorkerStub::OnTerminateWorkerContext() { |
| 126 impl_->terminateWorkerContext(); | 126 impl_->terminateWorkerContext(); |
| 127 | 127 |
| 128 // Call the client to make sure context exits. | 128 // Call the client to make sure context exits. |
| 129 EnsureWorkerContextTerminates(); | 129 EnsureWorkerContextTerminates(); |
| 130 started_ = false; | 130 started_ = false; |
| 131 } | 131 } |
| 132 | 132 |
| 133 } // namespace content | 133 } // namespace content |
| OLD | NEW |