| 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/memory/ptr_util.h" |
| 8 #include "content/browser/devtools/devtools_session.h" | 9 #include "content/browser/devtools/devtools_session.h" |
| 9 #include "content/browser/devtools/protocol/inspector_handler.h" | 10 #include "content/browser/devtools/protocol/inspector_handler.h" |
| 10 #include "content/browser/devtools/protocol/network_handler.h" | 11 #include "content/browser/devtools/protocol/network_handler.h" |
| 11 #include "content/browser/devtools/protocol/protocol.h" | 12 #include "content/browser/devtools/protocol/protocol.h" |
| 12 #include "content/browser/devtools/protocol/schema_handler.h" | 13 #include "content/browser/devtools/protocol/schema_handler.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 BrowserContext* WorkerDevToolsAgentHost::GetBrowserContext() { | 19 BrowserContext* WorkerDevToolsAgentHost::GetBrowserContext() { |
| 19 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first); | 20 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first); |
| 20 return rph ? rph->GetBrowserContext() : nullptr; | 21 return rph ? rph->GetBrowserContext() : nullptr; |
| 21 } | 22 } |
| 22 | 23 |
| 23 void WorkerDevToolsAgentHost::Attach() { | 24 void WorkerDevToolsAgentHost::AttachSession(DevToolsSession* session) { |
| 24 if (state_ != WORKER_INSPECTED) { | 25 if (state_ != WORKER_INSPECTED) { |
| 25 state_ = WORKER_INSPECTED; | 26 state_ = WORKER_INSPECTED; |
| 26 AttachToWorker(); | 27 AttachToWorker(); |
| 27 } | 28 } |
| 28 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { | 29 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { |
| 29 host->Send(new DevToolsAgentMsg_Attach( | 30 host->Send(new DevToolsAgentMsg_Attach( |
| 30 worker_id_.second, GetId(), session()->session_id())); | 31 worker_id_.second, GetId(), session->session_id())); |
| 31 } | 32 } |
| 32 session()->dispatcher()->setFallThroughForNotFound(true); | 33 session->SetFallThroughForNotFound(true); |
| 33 inspector_handler_.reset(new protocol::InspectorHandler()); | 34 session->AddHandler(base::WrapUnique(new protocol::InspectorHandler())); |
| 34 inspector_handler_->Wire(session()->dispatcher()); | 35 session->AddHandler(base::WrapUnique(new protocol::NetworkHandler())); |
| 35 network_handler_.reset(new protocol::NetworkHandler()); | 36 session->AddHandler(base::WrapUnique(new protocol::SchemaHandler())); |
| 36 network_handler_->Wire(session()->dispatcher()); | |
| 37 schema_handler_.reset(new protocol::SchemaHandler()); | |
| 38 schema_handler_->Wire(session()->dispatcher()); | |
| 39 session()->dispatcher()->setFallThroughForNotFound(true); | |
| 40 OnAttachedStateChanged(true); | 37 OnAttachedStateChanged(true); |
| 41 } | 38 } |
| 42 | 39 |
| 43 void WorkerDevToolsAgentHost::Detach() { | 40 void WorkerDevToolsAgentHost::DetachSession(int session_id) { |
| 44 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 41 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
| 45 host->Send(new DevToolsAgentMsg_Detach(worker_id_.second)); | 42 host->Send(new DevToolsAgentMsg_Detach(worker_id_.second)); |
| 46 inspector_handler_->Disable(); | |
| 47 inspector_handler_.reset(); | |
| 48 network_handler_->Disable(); | |
| 49 network_handler_.reset(); | |
| 50 schema_handler_->Disable(); | |
| 51 schema_handler_.reset(); | |
| 52 OnAttachedStateChanged(false); | 43 OnAttachedStateChanged(false); |
| 53 if (state_ == WORKER_INSPECTED) { | 44 if (state_ == WORKER_INSPECTED) { |
| 54 state_ = WORKER_UNINSPECTED; | 45 state_ = WORKER_UNINSPECTED; |
| 55 DetachFromWorker(); | 46 DetachFromWorker(); |
| 56 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { | 47 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { |
| 57 state_ = WORKER_UNINSPECTED; | 48 state_ = WORKER_UNINSPECTED; |
| 58 } | 49 } |
| 59 } | 50 } |
| 60 | 51 |
| 61 bool WorkerDevToolsAgentHost::DispatchProtocolMessage( | 52 bool WorkerDevToolsAgentHost::DispatchProtocolMessage( |
| 53 DevToolsSession* session, |
| 62 const std::string& message) { | 54 const std::string& message) { |
| 63 if (state_ != WORKER_INSPECTED) | 55 if (state_ != WORKER_INSPECTED) |
| 64 return true; | 56 return true; |
| 65 | 57 |
| 66 int call_id = 0; | 58 int call_id = 0; |
| 67 std::string method; | 59 std::string method; |
| 68 if (session()->Dispatch(message, &call_id, &method) != | 60 if (session->Dispatch(message, true, &call_id, &method) != |
| 69 protocol::Response::kFallThrough) { | 61 protocol::Response::kFallThrough) { |
| 70 return true; | 62 return true; |
| 71 } | 63 } |
| 72 | 64 |
| 73 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { | 65 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { |
| 74 host->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( | 66 host->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( |
| 75 worker_id_.second, session()->session_id(), call_id, method, message)); | 67 worker_id_.second, session->session_id(), call_id, method, message)); |
| 76 } | 68 } |
| 77 return true; | 69 return true; |
| 78 } | 70 } |
| 79 | 71 |
| 80 bool WorkerDevToolsAgentHost::OnMessageReceived( | 72 bool WorkerDevToolsAgentHost::OnMessageReceived( |
| 81 const IPC::Message& msg) { | 73 const IPC::Message& msg) { |
| 82 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 74 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 83 bool handled = true; | 75 bool handled = true; |
| 84 IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentHost, msg) | 76 IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentHost, msg) |
| 85 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, | 77 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 116 DCHECK_EQ(WORKER_TERMINATED, state_); | 108 DCHECK_EQ(WORKER_TERMINATED, state_); |
| 117 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED; | 109 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED; |
| 118 worker_id_ = worker_id; | 110 worker_id_ = worker_id; |
| 119 WorkerCreated(); | 111 WorkerCreated(); |
| 120 } | 112 } |
| 121 | 113 |
| 122 void WorkerDevToolsAgentHost::WorkerDestroyed() { | 114 void WorkerDevToolsAgentHost::WorkerDestroyed() { |
| 123 DCHECK_NE(WORKER_TERMINATED, state_); | 115 DCHECK_NE(WORKER_TERMINATED, state_); |
| 124 if (state_ == WORKER_INSPECTED) { | 116 if (state_ == WORKER_INSPECTED) { |
| 125 DCHECK(IsAttached()); | 117 DCHECK(IsAttached()); |
| 126 inspector_handler_->TargetCrashed(); | 118 protocol::InspectorHandler::FromSession(session())->TargetCrashed(); |
| 127 DetachFromWorker(); | 119 DetachFromWorker(); |
| 128 } | 120 } |
| 129 state_ = WORKER_TERMINATED; | 121 state_ = WORKER_TERMINATED; |
| 130 Release(); // Balanced in WorkerCreated(). | 122 Release(); // Balanced in WorkerCreated(). |
| 131 } | 123 } |
| 132 | 124 |
| 133 bool WorkerDevToolsAgentHost::IsTerminated() { | 125 bool WorkerDevToolsAgentHost::IsTerminated() { |
| 134 return state_ == WORKER_TERMINATED; | 126 return state_ == WORKER_TERMINATED; |
| 135 } | 127 } |
| 136 | 128 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 166 | 158 |
| 167 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 159 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( |
| 168 const DevToolsMessageChunk& message) { | 160 const DevToolsMessageChunk& message) { |
| 169 if (!IsAttached()) | 161 if (!IsAttached()) |
| 170 return; | 162 return; |
| 171 | 163 |
| 172 chunk_processor_.ProcessChunkedMessageFromAgent(message); | 164 chunk_processor_.ProcessChunkedMessageFromAgent(message); |
| 173 } | 165 } |
| 174 | 166 |
| 175 } // namespace content | 167 } // namespace content |
| OLD | NEW |