| 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/common/devtools_messages.h" | 10 #include "content/common/devtools_messages.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState, | 76 IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState, |
| 77 OnSaveAgentRuntimeState) | 77 OnSaveAgentRuntimeState) |
| 78 IPC_MESSAGE_UNHANDLED(handled = false) | 78 IPC_MESSAGE_UNHANDLED(handled = false) |
| 79 IPC_END_MESSAGE_MAP() | 79 IPC_END_MESSAGE_MAP() |
| 80 return handled; | 80 return handled; |
| 81 } | 81 } |
| 82 | 82 |
| 83 void EmbeddedWorkerDevToolsAgentHost::WorkerContextStarted() { | 83 void EmbeddedWorkerDevToolsAgentHost::WorkerContextStarted() { |
| 84 if (state_ == WORKER_PAUSED_FOR_DEBUG_ON_START) { | 84 if (state_ == WORKER_PAUSED_FOR_DEBUG_ON_START) { |
| 85 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first); | 85 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first); |
| 86 Inspect(rph->GetBrowserContext()); | 86 DevToolsManagerImpl::GetInstance()->Inspect(rph->GetBrowserContext(), this); |
| 87 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { | 87 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { |
| 88 DCHECK(IsAttached()); | 88 DCHECK(IsAttached()); |
| 89 state_ = WORKER_INSPECTED; | 89 state_ = WORKER_INSPECTED; |
| 90 AttachToWorker(); | 90 AttachToWorker(); |
| 91 Reattach(saved_agent_state_); | 91 Reattach(saved_agent_state_); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 void EmbeddedWorkerDevToolsAgentHost::WorkerRestarted(WorkerId worker_id) { | 95 void EmbeddedWorkerDevToolsAgentHost::WorkerRestarted(WorkerId worker_id) { |
| 96 DCHECK_EQ(WORKER_TERMINATED, state_); | 96 DCHECK_EQ(WORKER_TERMINATED, state_); |
| 97 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED; | 97 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED; |
| 98 worker_id_ = worker_id; | 98 worker_id_ = worker_id; |
| 99 WorkerCreated(); | 99 WorkerCreated(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void EmbeddedWorkerDevToolsAgentHost::WorkerDestroyed() { | 102 void EmbeddedWorkerDevToolsAgentHost::WorkerDestroyed() { |
| 103 DCHECK_NE(WORKER_TERMINATED, state_); | 103 DCHECK_NE(WORKER_TERMINATED, state_); |
| 104 if (state_ == WORKER_INSPECTED) { | 104 if (state_ == WORKER_INSPECTED) { |
| 105 DCHECK(IsAttached()); | 105 DCHECK(IsAttached()); |
| 106 // Client host is debugging this worker agent host. | 106 // Client host is debugging this worker agent host. |
| 107 std::string notification = | 107 std::string notification = |
| 108 DevToolsProtocol::CreateNotification( | 108 DevToolsProtocol::CreateNotification( |
| 109 devtools::Worker::disconnectedFromWorker::kName, NULL)->Serialize(); | 109 devtools::Worker::disconnectedFromWorker::kName, NULL)->Serialize(); |
| 110 SendMessageToClient(notification); | 110 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( |
| 111 this, notification); |
| 111 DetachFromWorker(); | 112 DetachFromWorker(); |
| 112 } | 113 } |
| 113 state_ = WORKER_TERMINATED; | 114 state_ = WORKER_TERMINATED; |
| 114 Release(); // Balanced in WorkerCreated() | 115 Release(); // Balanced in WorkerCreated() |
| 115 } | 116 } |
| 116 | 117 |
| 117 bool EmbeddedWorkerDevToolsAgentHost::Matches( | 118 bool EmbeddedWorkerDevToolsAgentHost::Matches( |
| 118 const SharedWorkerInstance& other) { | 119 const SharedWorkerInstance& other) { |
| 119 return shared_worker_ && shared_worker_->Matches(other); | 120 return shared_worker_ && shared_worker_->Matches(other); |
| 120 } | 121 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 139 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 140 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
| 140 host->RemoveRoute(worker_id_.second); | 141 host->RemoveRoute(worker_id_.second); |
| 141 } | 142 } |
| 142 | 143 |
| 143 void EmbeddedWorkerDevToolsAgentHost::WorkerCreated() { | 144 void EmbeddedWorkerDevToolsAgentHost::WorkerCreated() { |
| 144 AddRef(); // Balanced in WorkerDestroyed() | 145 AddRef(); // Balanced in WorkerDestroyed() |
| 145 } | 146 } |
| 146 | 147 |
| 147 void EmbeddedWorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 148 void EmbeddedWorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( |
| 148 const std::string& message) { | 149 const std::string& message) { |
| 149 SendMessageToClient(message); | 150 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( |
| 151 this, message); |
| 150 } | 152 } |
| 151 | 153 |
| 152 void EmbeddedWorkerDevToolsAgentHost::OnSaveAgentRuntimeState( | 154 void EmbeddedWorkerDevToolsAgentHost::OnSaveAgentRuntimeState( |
| 153 const std::string& state) { | 155 const std::string& state) { |
| 154 saved_agent_state_ = state; | 156 saved_agent_state_ = state; |
| 155 } | 157 } |
| 156 | 158 |
| 157 } // namespace content | 159 } // namespace content |
| OLD | NEW |