| 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/devtools_session.h" |
| 9 #include "content/browser/devtools/protocol/schema_handler.h" | 10 #include "content/browser/devtools/protocol/schema_handler.h" |
| 10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 | 15 |
| 15 BrowserContext* WorkerDevToolsAgentHost::GetBrowserContext() { | 16 BrowserContext* WorkerDevToolsAgentHost::GetBrowserContext() { |
| 16 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first); | 17 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first); |
| 17 return rph ? rph->GetBrowserContext() : nullptr; | 18 return rph ? rph->GetBrowserContext() : nullptr; |
| 18 } | 19 } |
| 19 | 20 |
| 20 void WorkerDevToolsAgentHost::Attach() { | 21 void WorkerDevToolsAgentHost::Attach() { |
| 21 if (state_ != WORKER_INSPECTED) { | 22 if (state_ != WORKER_INSPECTED) { |
| 22 state_ = WORKER_INSPECTED; | 23 state_ = WORKER_INSPECTED; |
| 23 AttachToWorker(); | 24 AttachToWorker(); |
| 24 } | 25 } |
| 25 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 26 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { |
| 26 host->Send( | 27 host->Send(new DevToolsAgentMsg_Attach( |
| 27 new DevToolsAgentMsg_Attach(worker_id_.second, GetId(), session_id())); | 28 worker_id_.second, GetId(), session()->session_id())); |
| 29 } |
| 28 OnAttachedStateChanged(true); | 30 OnAttachedStateChanged(true); |
| 29 } | 31 } |
| 30 | 32 |
| 31 void WorkerDevToolsAgentHost::Detach() { | 33 void WorkerDevToolsAgentHost::Detach() { |
| 32 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 34 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
| 33 host->Send(new DevToolsAgentMsg_Detach(worker_id_.second)); | 35 host->Send(new DevToolsAgentMsg_Detach(worker_id_.second)); |
| 34 OnAttachedStateChanged(false); | 36 OnAttachedStateChanged(false); |
| 35 if (state_ == WORKER_INSPECTED) { | 37 if (state_ == WORKER_INSPECTED) { |
| 36 state_ = WORKER_UNINSPECTED; | 38 state_ = WORKER_UNINSPECTED; |
| 37 DetachFromWorker(); | 39 DetachFromWorker(); |
| 38 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { | 40 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { |
| 39 state_ = WORKER_UNINSPECTED; | 41 state_ = WORKER_UNINSPECTED; |
| 40 } | 42 } |
| 41 } | 43 } |
| 42 | 44 |
| 43 bool WorkerDevToolsAgentHost::DispatchProtocolMessage( | 45 bool WorkerDevToolsAgentHost::DispatchProtocolMessage( |
| 44 const std::string& message) { | 46 const std::string& message) { |
| 45 if (state_ != WORKER_INSPECTED) | 47 if (state_ != WORKER_INSPECTED) |
| 46 return true; | 48 return true; |
| 47 | 49 |
| 48 int call_id; | 50 int call_id; |
| 49 std::string method; | 51 std::string method; |
| 50 if (protocol_handler_->HandleOptionalMessage(session_id(), message, &call_id, | 52 if (protocol_handler_->HandleOptionalMessage(session()->session_id(), message, |
| 51 &method)) | 53 &call_id, &method)) |
| 52 return true; | 54 return true; |
| 53 | 55 |
| 54 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { | 56 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { |
| 55 host->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( | 57 host->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( |
| 56 worker_id_.second, session_id(), call_id, method, message)); | 58 worker_id_.second, session()->session_id(), call_id, method, message)); |
| 57 } | 59 } |
| 58 return true; | 60 return true; |
| 59 } | 61 } |
| 60 | 62 |
| 61 bool WorkerDevToolsAgentHost::OnMessageReceived( | 63 bool WorkerDevToolsAgentHost::OnMessageReceived( |
| 62 const IPC::Message& msg) { | 64 const IPC::Message& msg) { |
| 63 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 65 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 64 bool handled = true; | 66 bool handled = true; |
| 65 IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentHost, msg) | 67 IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentHost, msg) |
| 66 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, | 68 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 79 return state_ == WORKER_PAUSED_FOR_DEBUG_ON_START; | 81 return state_ == WORKER_PAUSED_FOR_DEBUG_ON_START; |
| 80 } | 82 } |
| 81 | 83 |
| 82 void WorkerDevToolsAgentHost::WorkerReadyForInspection() { | 84 void WorkerDevToolsAgentHost::WorkerReadyForInspection() { |
| 83 if (state_ == WORKER_PAUSED_FOR_REATTACH) { | 85 if (state_ == WORKER_PAUSED_FOR_REATTACH) { |
| 84 DCHECK(IsAttached()); | 86 DCHECK(IsAttached()); |
| 85 state_ = WORKER_INSPECTED; | 87 state_ = WORKER_INSPECTED; |
| 86 AttachToWorker(); | 88 AttachToWorker(); |
| 87 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { | 89 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { |
| 88 host->Send(new DevToolsAgentMsg_Reattach( | 90 host->Send(new DevToolsAgentMsg_Reattach( |
| 89 worker_id_.second, GetId(), session_id(), | 91 worker_id_.second, GetId(), session()->session_id(), |
| 90 chunk_processor_.state_cookie())); | 92 chunk_processor_.state_cookie())); |
| 91 } | 93 } |
| 92 OnAttachedStateChanged(true); | 94 OnAttachedStateChanged(true); |
| 93 } | 95 } |
| 94 } | 96 } |
| 95 | 97 |
| 96 void WorkerDevToolsAgentHost::WorkerRestarted(WorkerId worker_id) { | 98 void WorkerDevToolsAgentHost::WorkerRestarted(WorkerId worker_id) { |
| 97 DCHECK_EQ(WORKER_TERMINATED, state_); | 99 DCHECK_EQ(WORKER_TERMINATED, state_); |
| 98 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED; | 100 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED; |
| 99 worker_id_ = worker_id; | 101 worker_id_ = worker_id; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 155 |
| 154 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 156 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( |
| 155 const DevToolsMessageChunk& message) { | 157 const DevToolsMessageChunk& message) { |
| 156 if (!IsAttached()) | 158 if (!IsAttached()) |
| 157 return; | 159 return; |
| 158 | 160 |
| 159 chunk_processor_.ProcessChunkedMessageFromAgent(message); | 161 chunk_processor_.ProcessChunkedMessageFromAgent(message); |
| 160 } | 162 } |
| 161 | 163 |
| 162 } // namespace content | 164 } // namespace content |
| OLD | NEW |