| 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/worker_devtools_agent_host.h" | 5 #include "content/browser/devtools/worker_devtools_agent_host.h" |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "content/browser/devtools/devtools_protocol_handler.h" | 8 #include "content/browser/devtools/devtools_protocol_handler.h" |
| 9 #include "content/browser/devtools/protocol/schema_handler.h" | 9 #include "content/browser/devtools/protocol/schema_handler.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 BrowserContext* WorkerDevToolsAgentHost::GetBrowserContext() { | 15 BrowserContext* WorkerDevToolsAgentHost::GetBrowserContext() { |
| 16 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first); | 16 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first); |
| 17 return rph ? rph->GetBrowserContext() : nullptr; | 17 return rph ? rph->GetBrowserContext() : nullptr; |
| 18 } | 18 } |
| 19 | 19 |
| 20 void WorkerDevToolsAgentHost::Attach() { | 20 void WorkerDevToolsAgentHost::Attach() { |
| 21 if (state_ != WORKER_INSPECTED) { | 21 if (state_ != WORKER_INSPECTED) { |
| 22 state_ = WORKER_INSPECTED; | 22 state_ = WORKER_INSPECTED; |
| 23 AttachToWorker(); | 23 AttachToWorker(); |
| 24 } | 24 } |
| 25 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 25 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
| 26 host->Send( | 26 host->Send( |
| 27 new DevToolsAgentMsg_Attach(worker_id_.second, GetId(), session_id())); | 27 new DevToolsAgentMsg_Attach(worker_id_.second, GetId(), session_id())); |
| 28 OnAttachedStateChanged(true); | 28 OnAttachedStateChanged(true); |
| 29 DevToolsAgentHostImpl::NotifyCallbacks(this, true); | |
| 30 } | 29 } |
| 31 | 30 |
| 32 void WorkerDevToolsAgentHost::Detach() { | 31 void WorkerDevToolsAgentHost::Detach() { |
| 33 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 32 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
| 34 host->Send(new DevToolsAgentMsg_Detach(worker_id_.second)); | 33 host->Send(new DevToolsAgentMsg_Detach(worker_id_.second)); |
| 35 OnAttachedStateChanged(false); | 34 OnAttachedStateChanged(false); |
| 36 if (state_ == WORKER_INSPECTED) { | 35 if (state_ == WORKER_INSPECTED) { |
| 37 state_ = WORKER_UNINSPECTED; | 36 state_ = WORKER_UNINSPECTED; |
| 38 DetachFromWorker(); | 37 DetachFromWorker(); |
| 39 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { | 38 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { |
| 40 state_ = WORKER_UNINSPECTED; | 39 state_ = WORKER_UNINSPECTED; |
| 41 } | 40 } |
| 42 DevToolsAgentHostImpl::NotifyCallbacks(this, false); | |
| 43 } | 41 } |
| 44 | 42 |
| 45 bool WorkerDevToolsAgentHost::DispatchProtocolMessage( | 43 bool WorkerDevToolsAgentHost::DispatchProtocolMessage( |
| 46 const std::string& message) { | 44 const std::string& message) { |
| 47 if (state_ != WORKER_INSPECTED) | 45 if (state_ != WORKER_INSPECTED) |
| 48 return true; | 46 return true; |
| 49 | 47 |
| 50 int call_id; | 48 int call_id; |
| 51 std::string method; | 49 std::string method; |
| 52 if (protocol_handler_->HandleOptionalMessage(session_id(), message, &call_id, | 50 if (protocol_handler_->HandleOptionalMessage(session_id(), message, &call_id, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 153 |
| 156 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 154 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( |
| 157 const DevToolsMessageChunk& message) { | 155 const DevToolsMessageChunk& message) { |
| 158 if (!IsAttached()) | 156 if (!IsAttached()) |
| 159 return; | 157 return; |
| 160 | 158 |
| 161 chunk_processor_.ProcessChunkedMessageFromAgent(message); | 159 chunk_processor_.ProcessChunkedMessageFromAgent(message); |
| 162 } | 160 } |
| 163 | 161 |
| 164 } // namespace content | 162 } // namespace content |
| OLD | NEW |