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 DevToolsManagerImpl::GetInstance()->Inspect(rph->GetBrowserContext(), this); | 86 Inspect(rph->GetBrowserContext()); |
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 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( | 110 SendMessageToClient(notification); |
111 this, notification); | |
112 DetachFromWorker(); | 111 DetachFromWorker(); |
113 } | 112 } |
114 state_ = WORKER_TERMINATED; | 113 state_ = WORKER_TERMINATED; |
115 Release(); // Balanced in WorkerCreated() | 114 Release(); // Balanced in WorkerCreated() |
116 } | 115 } |
117 | 116 |
118 bool EmbeddedWorkerDevToolsAgentHost::Matches( | 117 bool EmbeddedWorkerDevToolsAgentHost::Matches( |
119 const SharedWorkerInstance& other) { | 118 const SharedWorkerInstance& other) { |
120 return shared_worker_ && shared_worker_->Matches(other); | 119 return shared_worker_ && shared_worker_->Matches(other); |
121 } | 120 } |
(...skipping 18 matching lines...) Expand all Loading... |
140 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 139 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
141 host->RemoveRoute(worker_id_.second); | 140 host->RemoveRoute(worker_id_.second); |
142 } | 141 } |
143 | 142 |
144 void EmbeddedWorkerDevToolsAgentHost::WorkerCreated() { | 143 void EmbeddedWorkerDevToolsAgentHost::WorkerCreated() { |
145 AddRef(); // Balanced in WorkerDestroyed() | 144 AddRef(); // Balanced in WorkerDestroyed() |
146 } | 145 } |
147 | 146 |
148 void EmbeddedWorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 147 void EmbeddedWorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( |
149 const std::string& message) { | 148 const std::string& message) { |
150 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( | 149 SendMessageToClient(message); |
151 this, message); | |
152 } | 150 } |
153 | 151 |
154 void EmbeddedWorkerDevToolsAgentHost::OnSaveAgentRuntimeState( | 152 void EmbeddedWorkerDevToolsAgentHost::OnSaveAgentRuntimeState( |
155 const std::string& state) { | 153 const std::string& state) { |
156 saved_agent_state_ = state; | 154 saved_agent_state_ = state; |
157 } | 155 } |
158 | 156 |
159 } // namespace content | 157 } // namespace content |
OLD | NEW |