Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/shared_worker/shared_worker_host.h" | 5 #include "content/browser/shared_worker/shared_worker_host.h" |
| 6 | 6 |
| 7 #include "content/browser/devtools/shared_worker_devtools_manager.h" | |
| 7 #include "content/browser/frame_host/render_frame_host_delegate.h" | 8 #include "content/browser/frame_host/render_frame_host_delegate.h" |
| 8 #include "content/browser/frame_host/render_frame_host_impl.h" | 9 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 9 #include "content/browser/message_port_service.h" | 10 #include "content/browser/message_port_service.h" |
| 10 #include "content/browser/shared_worker/shared_worker_instance.h" | 11 #include "content/browser/shared_worker/shared_worker_instance.h" |
| 11 #include "content/browser/shared_worker/shared_worker_message_filter.h" | 12 #include "content/browser/shared_worker/shared_worker_message_filter.h" |
| 13 #include "content/browser/shared_worker/shared_worker_service_impl.h" | |
| 12 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
| 13 #include "content/common/worker_messages.h" | 15 #include "content/common/worker_messages.h" |
| 14 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/content_browser_client.h" | 17 #include "content/public/browser/content_browser_client.h" |
| 18 #include "content/public/browser/render_process_host.h" | |
| 16 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
| 17 | 20 |
| 18 namespace content { | 21 namespace content { |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| 21 // Notifies RenderViewHost that one or more worker objects crashed. | 24 // Notifies RenderViewHost that one or more worker objects crashed. |
| 22 void WorkerCrashCallback(int render_process_unique_id, int render_frame_id) { | 25 void WorkerCrashCallback(int render_process_unique_id, int render_frame_id) { |
| 23 RenderFrameHostImpl* host = | 26 RenderFrameHostImpl* host = |
| 24 RenderFrameHostImpl::FromID(render_process_unique_id, render_frame_id); | 27 RenderFrameHostImpl::FromID(render_process_unique_id, render_frame_id); |
| 25 if (host) | 28 if (host) |
| 26 host->delegate()->WorkerCrashed(host); | 29 host->delegate()->WorkerCrashed(host); |
| 27 } | 30 } |
| 28 | 31 |
| 32 void WorkerCreatedOnUI(int worker_process_id, | |
| 33 int worker_route_id, | |
| 34 const GURL& url, | |
| 35 const base::string16& name) { | |
| 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 37 SharedWorkerDevToolsManager::GetInstance()->WorkerCreated( | |
| 38 worker_process_id, worker_route_id, url, name); | |
| 39 } | |
| 40 | |
| 41 void WorkerScriptLoadedOnUI(int worker_process_id, int worker_route_id) { | |
| 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 43 SharedWorkerDevToolsManager::GetInstance()->WorkerContextStarted( | |
| 44 worker_process_id, worker_route_id); | |
| 45 } | |
| 46 | |
| 47 void WorkerDestroyedOnUI(int worker_process_id, int worker_route_id) { | |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 49 SharedWorkerDevToolsManager::GetInstance()->WorkerDestroyed( | |
| 50 worker_process_id, worker_route_id); | |
| 51 } | |
| 52 | |
| 29 } // namespace | 53 } // namespace |
| 30 | 54 |
| 31 SharedWorkerHost::SharedWorkerHost(SharedWorkerInstance* instance) | 55 SharedWorkerHost::SharedWorkerHost(SharedWorkerInstance* instance) |
| 32 : instance_(instance), | 56 : instance_(instance), |
| 33 container_render_filter_(NULL), | 57 container_render_filter_(NULL), |
| 34 worker_route_id_(MSG_ROUTING_NONE) { | 58 worker_route_id_(MSG_ROUTING_NONE) { |
| 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 36 } | 60 } |
| 37 | 61 |
| 38 SharedWorkerHost::~SharedWorkerHost() { | 62 SharedWorkerHost::~SharedWorkerHost() { |
| 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 40 // If we crashed, tell the RenderViewHosts. | 64 // If we crashed, tell the RenderViewHosts. |
| 41 if (instance_ && !instance_->load_failed()) { | 65 if (instance_ && !instance_->load_failed()) { |
| 42 const WorkerDocumentSet::DocumentInfoSet& parents = | 66 const WorkerDocumentSet::DocumentInfoSet& parents = |
| 43 instance_->worker_document_set()->documents(); | 67 instance_->worker_document_set()->documents(); |
| 44 for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter = | 68 for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter = |
| 45 parents.begin(); | 69 parents.begin(); |
| 46 parent_iter != parents.end(); | 70 parent_iter != parents.end(); |
| 47 ++parent_iter) { | 71 ++parent_iter) { |
| 48 BrowserThread::PostTask(BrowserThread::UI, | 72 BrowserThread::PostTask(BrowserThread::UI, |
| 49 FROM_HERE, | 73 FROM_HERE, |
| 50 base::Bind(&WorkerCrashCallback, | 74 base::Bind(&WorkerCrashCallback, |
| 51 parent_iter->render_process_id(), | 75 parent_iter->render_process_id(), |
| 52 parent_iter->render_frame_id())); | 76 parent_iter->render_frame_id())); |
| 53 } | 77 } |
| 54 } | 78 } |
| 79 BrowserThread::PostTask( | |
| 80 BrowserThread::UI, | |
| 81 FROM_HERE, | |
| 82 base::Bind( | |
| 83 &WorkerDestroyedOnUI, worker_process_id_, worker_route_id_)); | |
| 84 SharedWorkerServiceImpl::GetInstance()->NotifyWorkerDestroyed( | |
| 85 worker_process_id_, worker_route_id_); | |
| 55 } | 86 } |
| 56 | 87 |
| 57 bool SharedWorkerHost::Send(IPC::Message* message) { | 88 bool SharedWorkerHost::Send(IPC::Message* message) { |
| 58 if (!container_render_filter_) { | 89 if (!container_render_filter_) { |
| 59 delete message; | 90 delete message; |
| 60 return false; | 91 return false; |
| 61 } | 92 } |
| 62 return container_render_filter_->Send(message); | 93 return container_render_filter_->Send(message); |
| 63 } | 94 } |
| 64 | 95 |
| 65 void SharedWorkerHost::Init(SharedWorkerMessageFilter* filter) { | 96 void SharedWorkerHost::Init(SharedWorkerMessageFilter* filter) { |
| 66 CHECK(instance_); | 97 CHECK(instance_); |
| 67 DCHECK(worker_route_id_ == MSG_ROUTING_NONE); | 98 DCHECK(worker_route_id_ == MSG_ROUTING_NONE); |
| 68 container_render_filter_ = filter; | 99 container_render_filter_ = filter; |
| 100 worker_process_id_ = filter->render_process_id(); | |
| 69 worker_route_id_ = filter->GetNextRoutingID(); | 101 worker_route_id_ = filter->GetNextRoutingID(); |
| 70 | 102 |
| 103 BrowserThread::PostTask(BrowserThread::UI, | |
| 104 FROM_HERE, | |
| 105 base::Bind(WorkerCreatedOnUI, | |
|
kinuko
2014/03/24 12:24:02
& is missing?
horo
2014/03/25 06:28:17
Done.
| |
| 106 worker_process_id_, | |
| 107 worker_route_id_, | |
| 108 instance_->url(), | |
| 109 instance_->name())); | |
| 110 | |
| 71 WorkerProcessMsg_CreateWorker_Params params; | 111 WorkerProcessMsg_CreateWorker_Params params; |
| 72 params.url = instance_->url(); | 112 params.url = instance_->url(); |
| 73 params.name = instance_->name(); | 113 params.name = instance_->name(); |
| 74 params.content_security_policy = instance_->content_security_policy(); | 114 params.content_security_policy = instance_->content_security_policy(); |
| 75 params.security_policy_type = instance_->security_policy_type(); | 115 params.security_policy_type = instance_->security_policy_type(); |
| 76 params.route_id = worker_route_id_; | 116 params.route_id = worker_route_id_; |
| 77 Send(new WorkerProcessMsg_CreateWorker(params)); | 117 Send(new WorkerProcessMsg_CreateWorker(params)); |
| 78 | 118 |
| 79 for (SharedWorkerInstance::FilterList::const_iterator i = | 119 for (SharedWorkerInstance::FilterList::const_iterator i = |
| 80 instance_->filters().begin(); | 120 instance_->filters().begin(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 void SharedWorkerHost::WorkerContextClosed() { | 163 void SharedWorkerHost::WorkerContextClosed() { |
| 124 if (!instance_) | 164 if (!instance_) |
| 125 return; | 165 return; |
| 126 // Set the closed flag - this will stop any further messages from | 166 // Set the closed flag - this will stop any further messages from |
| 127 // being sent to the worker (messages can still be sent from the worker, | 167 // being sent to the worker (messages can still be sent from the worker, |
| 128 // for exception reporting, etc). | 168 // for exception reporting, etc). |
| 129 instance_->set_closed(true); | 169 instance_->set_closed(true); |
| 130 } | 170 } |
| 131 | 171 |
| 132 void SharedWorkerHost::WorkerContextDestroyed() { | 172 void SharedWorkerHost::WorkerContextDestroyed() { |
| 133 if (!instance_) | |
| 134 return; | |
| 135 instance_.reset(); | 173 instance_.reset(); |
| 136 } | 174 } |
| 137 | 175 |
| 138 void SharedWorkerHost::WorkerScriptLoaded() { | 176 void SharedWorkerHost::WorkerScriptLoaded() { |
| 139 // TODO(horo): implement this. | 177 BrowserThread::PostTask( |
| 178 BrowserThread::UI, | |
| 179 FROM_HERE, | |
| 180 base::Bind( | |
| 181 &WorkerScriptLoadedOnUI, worker_process_id_, worker_route_id_)); | |
| 140 } | 182 } |
| 141 | 183 |
| 142 void SharedWorkerHost::WorkerScriptLoadFailed() { | 184 void SharedWorkerHost::WorkerScriptLoadFailed() { |
| 143 if (!instance_) | 185 if (!instance_) |
| 144 return; | 186 return; |
| 145 instance_->set_load_failed(true); | 187 instance_->set_load_failed(true); |
| 146 for (SharedWorkerInstance::FilterList::const_iterator i = | 188 for (SharedWorkerInstance::FilterList::const_iterator i = |
| 147 instance_->filters().begin(); | 189 instance_->filters().begin(); |
| 148 i != instance_->filters().end(); ++i) { | 190 i != instance_->filters().end(); ++i) { |
| 149 i->filter()->Send(new ViewMsg_WorkerScriptLoadFailed(i->route_id())); | 191 i->filter()->Send(new ViewMsg_WorkerScriptLoadFailed(i->route_id())); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 documents.begin(); | 290 documents.begin(); |
| 249 doc != documents.end(); | 291 doc != documents.end(); |
| 250 ++doc) { | 292 ++doc) { |
| 251 result.push_back( | 293 result.push_back( |
| 252 std::make_pair(doc->render_process_id(), doc->render_frame_id())); | 294 std::make_pair(doc->render_process_id(), doc->render_frame_id())); |
| 253 } | 295 } |
| 254 return result; | 296 return result; |
| 255 } | 297 } |
| 256 | 298 |
| 257 } // namespace content | 299 } // namespace content |
| OLD | NEW |