| 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 "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "content/browser/devtools/devtools_protocol_handler.h" | 9 #include "content/browser/devtools/devtools_protocol_handler.h" |
| 10 #include "content/browser/devtools/devtools_session.h" | 10 #include "content/browser/devtools/devtools_session.h" |
| 11 #include "content/browser/devtools/protocol/inspector_handler.h" |
| 11 #include "content/browser/devtools/protocol/schema_handler.h" | 12 #include "content/browser/devtools/protocol/schema_handler.h" |
| 12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 BrowserContext* WorkerDevToolsAgentHost::GetBrowserContext() { | 18 BrowserContext* WorkerDevToolsAgentHost::GetBrowserContext() { |
| 18 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first); | 19 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first); |
| 19 return rph ? rph->GetBrowserContext() : nullptr; | 20 return rph ? rph->GetBrowserContext() : nullptr; |
| 20 } | 21 } |
| 21 | 22 |
| 22 void WorkerDevToolsAgentHost::Attach() { | 23 void WorkerDevToolsAgentHost::Attach() { |
| 23 if (state_ != WORKER_INSPECTED) { | 24 if (state_ != WORKER_INSPECTED) { |
| 24 state_ = WORKER_INSPECTED; | 25 state_ = WORKER_INSPECTED; |
| 25 AttachToWorker(); | 26 AttachToWorker(); |
| 26 } | 27 } |
| 28 |
| 29 inspector_handler_.reset(new protocol::InspectorHandler()); |
| 30 inspector_handler_->Wire(session()->dispatcher()); |
| 31 |
| 27 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { | 32 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { |
| 28 host->Send(new DevToolsAgentMsg_Attach( | 33 host->Send(new DevToolsAgentMsg_Attach( |
| 29 worker_id_.second, GetId(), session()->session_id())); | 34 worker_id_.second, GetId(), session()->session_id())); |
| 30 } | 35 } |
| 31 OnAttachedStateChanged(true); | 36 OnAttachedStateChanged(true); |
| 32 } | 37 } |
| 33 | 38 |
| 34 void WorkerDevToolsAgentHost::Detach() { | 39 void WorkerDevToolsAgentHost::Detach() { |
| 35 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 40 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
| 36 host->Send(new DevToolsAgentMsg_Detach(worker_id_.second)); | 41 host->Send(new DevToolsAgentMsg_Detach(worker_id_.second)); |
| 42 |
| 43 inspector_handler_->Disable(); |
| 44 inspector_handler_.reset(); |
| 45 |
| 37 OnAttachedStateChanged(false); | 46 OnAttachedStateChanged(false); |
| 38 if (state_ == WORKER_INSPECTED) { | 47 if (state_ == WORKER_INSPECTED) { |
| 39 state_ = WORKER_UNINSPECTED; | 48 state_ = WORKER_UNINSPECTED; |
| 40 DetachFromWorker(); | 49 DetachFromWorker(); |
| 41 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { | 50 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { |
| 42 state_ = WORKER_UNINSPECTED; | 51 state_ = WORKER_UNINSPECTED; |
| 43 } | 52 } |
| 44 } | 53 } |
| 45 | 54 |
| 46 bool WorkerDevToolsAgentHost::DispatchProtocolMessage( | 55 bool WorkerDevToolsAgentHost::DispatchProtocolMessage( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 DCHECK_EQ(WORKER_TERMINATED, state_); | 111 DCHECK_EQ(WORKER_TERMINATED, state_); |
| 103 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED; | 112 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED; |
| 104 worker_id_ = worker_id; | 113 worker_id_ = worker_id; |
| 105 WorkerCreated(); | 114 WorkerCreated(); |
| 106 } | 115 } |
| 107 | 116 |
| 108 void WorkerDevToolsAgentHost::WorkerDestroyed() { | 117 void WorkerDevToolsAgentHost::WorkerDestroyed() { |
| 109 DCHECK_NE(WORKER_TERMINATED, state_); | 118 DCHECK_NE(WORKER_TERMINATED, state_); |
| 110 if (state_ == WORKER_INSPECTED) { | 119 if (state_ == WORKER_INSPECTED) { |
| 111 DCHECK(IsAttached()); | 120 DCHECK(IsAttached()); |
| 112 // Client host is debugging this worker agent host. | 121 inspector_handler_->TargetCrashed(); |
| 113 devtools::inspector::Client inspector(this); | |
| 114 inspector.TargetCrashed( | |
| 115 devtools::inspector::TargetCrashedParams::Create()); | |
| 116 DetachFromWorker(); | 122 DetachFromWorker(); |
| 117 } | 123 } |
| 118 state_ = WORKER_TERMINATED; | 124 state_ = WORKER_TERMINATED; |
| 119 Release(); // Balanced in WorkerCreated(). | 125 Release(); // Balanced in WorkerCreated(). |
| 120 } | 126 } |
| 121 | 127 |
| 122 bool WorkerDevToolsAgentHost::IsTerminated() { | 128 bool WorkerDevToolsAgentHost::IsTerminated() { |
| 123 return state_ == WORKER_TERMINATED; | 129 return state_ == WORKER_TERMINATED; |
| 124 } | 130 } |
| 125 | 131 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 164 |
| 159 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 165 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( |
| 160 const DevToolsMessageChunk& message) { | 166 const DevToolsMessageChunk& message) { |
| 161 if (!IsAttached()) | 167 if (!IsAttached()) |
| 162 return; | 168 return; |
| 163 | 169 |
| 164 chunk_processor_.ProcessChunkedMessageFromAgent(message); | 170 chunk_processor_.ProcessChunkedMessageFromAgent(message); |
| 165 } | 171 } |
| 166 | 172 |
| 167 } // namespace content | 173 } // namespace content |
| OLD | NEW |