| 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/devtools/embedded_worker_devtools_agent_host.h" | 5 #include "content/browser/devtools/embedded_worker_devtools_agent_host.h" |
| 6 | 6 |
| 7 #include "content/browser/devtools/devtools_manager_impl.h" | 7 #include "content/browser/devtools/devtools_manager_impl.h" |
| 8 #include "content/browser/devtools/devtools_protocol.h" | 8 #include "content/browser/devtools/devtools_protocol.h" |
| 9 #include "content/browser/devtools/devtools_protocol_constants.h" | 9 #include "content/browser/devtools/devtools_protocol_constants.h" |
| 10 #include "content/browser/service_worker/service_worker_context_core.h" |
| 11 #include "content/browser/service_worker/service_worker_version.h" |
| 12 #include "content/browser/shared_worker/shared_worker_service_impl.h" |
| 10 #include "content/common/devtools_messages.h" | 13 #include "content/common/devtools_messages.h" |
| 11 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 13 | 16 |
| 14 namespace content { | 17 namespace content { |
| 15 | 18 |
| 19 namespace { |
| 20 |
| 21 void TerminateSharedWorkerOnIO( |
| 22 EmbeddedWorkerDevToolsAgentHost::WorkerId worker_id) { |
| 23 SharedWorkerServiceImpl::GetInstance()->TerminateWorker( |
| 24 worker_id.first, worker_id.second); |
| 25 } |
| 26 |
| 27 void StatusNoOp(ServiceWorkerStatusCode status) { |
| 28 } |
| 29 |
| 30 void TerminateServiceWorkerOnIO( |
| 31 base::WeakPtr<ServiceWorkerContextCore> context_weak, |
| 32 int64 version_id) { |
| 33 if (ServiceWorkerContextCore* context = context_weak.get()) { |
| 34 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id)) |
| 35 version->StopWorker(base::Bind(&StatusNoOp)); |
| 36 } |
| 37 } |
| 38 |
| 39 } |
| 40 |
| 16 EmbeddedWorkerDevToolsAgentHost::EmbeddedWorkerDevToolsAgentHost( | 41 EmbeddedWorkerDevToolsAgentHost::EmbeddedWorkerDevToolsAgentHost( |
| 17 WorkerId worker_id, | 42 WorkerId worker_id, |
| 18 const SharedWorkerInstance& shared_worker) | 43 const SharedWorkerInstance& shared_worker) |
| 19 : shared_worker_(new SharedWorkerInstance(shared_worker)), | 44 : shared_worker_(new SharedWorkerInstance(shared_worker)), |
| 20 state_(WORKER_UNINSPECTED), | 45 state_(WORKER_UNINSPECTED), |
| 21 worker_id_(worker_id) { | 46 worker_id_(worker_id) { |
| 22 WorkerCreated(); | 47 WorkerCreated(); |
| 23 } | 48 } |
| 24 | 49 |
| 25 EmbeddedWorkerDevToolsAgentHost::EmbeddedWorkerDevToolsAgentHost( | 50 EmbeddedWorkerDevToolsAgentHost::EmbeddedWorkerDevToolsAgentHost( |
| 26 WorkerId worker_id, | 51 WorkerId worker_id, |
| 27 const ServiceWorkerIdentifier& service_worker, | 52 const ServiceWorkerIdentifier& service_worker, |
| 28 bool debug_service_worker_on_start) | 53 bool debug_service_worker_on_start) |
| 29 : service_worker_(new ServiceWorkerIdentifier(service_worker)), | 54 : service_worker_(new ServiceWorkerIdentifier(service_worker)), |
| 30 state_(WORKER_UNINSPECTED), | 55 state_(WORKER_UNINSPECTED), |
| 31 worker_id_(worker_id) { | 56 worker_id_(worker_id) { |
| 32 if (debug_service_worker_on_start) | 57 if (debug_service_worker_on_start) |
| 33 state_ = WORKER_PAUSED_FOR_DEBUG_ON_START; | 58 state_ = WORKER_PAUSED_FOR_DEBUG_ON_START; |
| 34 WorkerCreated(); | 59 WorkerCreated(); |
| 35 } | 60 } |
| 36 | 61 |
| 37 bool EmbeddedWorkerDevToolsAgentHost::IsWorker() const { | 62 bool EmbeddedWorkerDevToolsAgentHost::IsWorker() const { |
| 38 return true; | 63 return true; |
| 39 } | 64 } |
| 40 | 65 |
| 66 GURL EmbeddedWorkerDevToolsAgentHost::GetURL() { |
| 67 if (shared_worker_) |
| 68 return shared_worker_->url(); |
| 69 if (service_worker_) |
| 70 return service_worker_->url(); |
| 71 return GURL(); |
| 72 } |
| 73 |
| 74 bool EmbeddedWorkerDevToolsAgentHost::Close() { |
| 75 if (shared_worker_) { |
| 76 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 77 base::Bind(&TerminateSharedWorkerOnIO, worker_id_)); |
| 78 return true; |
| 79 } |
| 80 if (service_worker_) { |
| 81 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 82 base::Bind(&TerminateServiceWorkerOnIO, |
| 83 service_worker_->context_weak(), |
| 84 service_worker_->version_id())); |
| 85 return true; |
| 86 } |
| 87 return false; |
| 88 } |
| 89 |
| 41 void EmbeddedWorkerDevToolsAgentHost::SendMessageToAgent( | 90 void EmbeddedWorkerDevToolsAgentHost::SendMessageToAgent( |
| 42 IPC::Message* message_raw) { | 91 IPC::Message* message_raw) { |
| 43 scoped_ptr<IPC::Message> message(message_raw); | 92 scoped_ptr<IPC::Message> message(message_raw); |
| 44 if (state_ != WORKER_INSPECTED) | 93 if (state_ != WORKER_INSPECTED) |
| 45 return; | 94 return; |
| 46 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { | 95 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { |
| 47 message->set_routing_id(worker_id_.second); | 96 message->set_routing_id(worker_id_.second); |
| 48 host->Send(message.release()); | 97 host->Send(message.release()); |
| 49 } | 98 } |
| 50 } | 99 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( | 199 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( |
| 151 this, message); | 200 this, message); |
| 152 } | 201 } |
| 153 | 202 |
| 154 void EmbeddedWorkerDevToolsAgentHost::OnSaveAgentRuntimeState( | 203 void EmbeddedWorkerDevToolsAgentHost::OnSaveAgentRuntimeState( |
| 155 const std::string& state) { | 204 const std::string& state) { |
| 156 saved_agent_state_ = state; | 205 saved_agent_state_ = state; |
| 157 } | 206 } |
| 158 | 207 |
| 159 } // namespace content | 208 } // namespace content |
| OLD | NEW |