OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Implements the Chrome Extensions Debugger API. | 5 // Implements the Chrome Extensions Debugger API. |
6 | 6 |
7 #include "chrome/browser/extensions/api/debugger/debugger_api.h" | 7 #include "chrome/browser/extensions/api/debugger/debugger_api.h" |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 ~ExtensionDevToolsClientHost(); | 95 ~ExtensionDevToolsClientHost(); |
96 | 96 |
97 bool MatchesContentsAndExtensionId(WebContents* web_contents, | 97 bool MatchesContentsAndExtensionId(WebContents* web_contents, |
98 const std::string& extension_id); | 98 const std::string& extension_id); |
99 void Close(); | 99 void Close(); |
100 void SendMessageToBackend(SendCommandDebuggerFunction* function, | 100 void SendMessageToBackend(SendCommandDebuggerFunction* function, |
101 const std::string& method, | 101 const std::string& method, |
102 SendCommand::Params::CommandParams* command_params); | 102 SendCommand::Params::CommandParams* command_params); |
103 | 103 |
104 // Mark methods below determine the connection termination reason. | 104 // Marks connection as to-be-terminated by the user. |
105 void MarkAsReplaced(); | |
106 void MarkAsDismissed(); | 105 void MarkAsDismissed(); |
107 | 106 |
108 // DevToolsClientHost interface | 107 // DevToolsClientHost interface |
109 virtual void InspectedContentsClosing() OVERRIDE; | 108 virtual void InspectedContentsClosing() OVERRIDE; |
110 virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE; | 109 virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE; |
111 virtual void ContentsReplaced(WebContents* web_contents) OVERRIDE; | 110 virtual void ContentsReplaced(WebContents* web_contents) OVERRIDE; |
| 111 virtual void ReplacedWithAnotherClient() OVERRIDE; |
112 virtual void FrameNavigating(const std::string& url) OVERRIDE {} | 112 virtual void FrameNavigating(const std::string& url) OVERRIDE {} |
113 | 113 |
114 private: | 114 private: |
115 void SendDetachedEvent(); | 115 void SendDetachedEvent(); |
116 | 116 |
117 // content::NotificationObserver implementation. | 117 // content::NotificationObserver implementation. |
118 virtual void Observe(int type, | 118 virtual void Observe(int type, |
119 const content::NotificationSource& source, | 119 const content::NotificationSource& source, |
120 const content::NotificationDetails& details); | 120 const content::NotificationDetails& details); |
121 | 121 |
(...skipping 23 matching lines...) Expand all Loading... |
145 } | 145 } |
146 | 146 |
147 void Add(ExtensionDevToolsClientHost* client_host) { | 147 void Add(ExtensionDevToolsClientHost* client_host) { |
148 client_hosts_.insert(client_host); | 148 client_hosts_.insert(client_host); |
149 } | 149 } |
150 | 150 |
151 void Remove(ExtensionDevToolsClientHost* client_host) { | 151 void Remove(ExtensionDevToolsClientHost* client_host) { |
152 client_hosts_.erase(client_host); | 152 client_hosts_.erase(client_host); |
153 } | 153 } |
154 | 154 |
155 ExtensionDevToolsClientHost* AsExtensionDevToolsClientHost( | |
156 DevToolsClientHost* client_host) { | |
157 for (std::set<DevToolsClientHost*>::iterator it = client_hosts_.begin(); | |
158 it != client_hosts_.end(); ++it) { | |
159 if (client_host == *it) | |
160 return static_cast<ExtensionDevToolsClientHost*>(*it); | |
161 } | |
162 return NULL; | |
163 } | |
164 | |
165 ExtensionDevToolsClientHost* Lookup(WebContents* contents) { | 155 ExtensionDevToolsClientHost* Lookup(WebContents* contents) { |
166 for (std::set<DevToolsClientHost*>::iterator it = client_hosts_.begin(); | 156 for (std::set<DevToolsClientHost*>::iterator it = client_hosts_.begin(); |
167 it != client_hosts_.end(); ++it) { | 157 it != client_hosts_.end(); ++it) { |
168 DevToolsAgentHost* agent_host = | 158 DevToolsAgentHost* agent_host = |
169 DevToolsManager::GetInstance()->GetDevToolsAgentHostFor(*it); | 159 DevToolsManager::GetInstance()->GetDevToolsAgentHostFor(*it); |
170 if (!agent_host) | 160 if (!agent_host) |
171 continue; | 161 continue; |
172 content::RenderViewHost* rvh = | 162 content::RenderViewHost* rvh = |
173 DevToolsAgentHostRegistry::GetRenderViewHost(agent_host); | 163 DevToolsAgentHostRegistry::GetRenderViewHost(agent_host); |
174 if (rvh && WebContents::FromRenderViewHost(rvh) == contents) | 164 if (rvh && WebContents::FromRenderViewHost(rvh) == contents) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // DevToolsClientHost interface | 234 // DevToolsClientHost interface |
245 void ExtensionDevToolsClientHost::InspectedContentsClosing() { | 235 void ExtensionDevToolsClientHost::InspectedContentsClosing() { |
246 SendDetachedEvent(); | 236 SendDetachedEvent(); |
247 delete this; | 237 delete this; |
248 } | 238 } |
249 | 239 |
250 void ExtensionDevToolsClientHost::ContentsReplaced(WebContents* web_contents) { | 240 void ExtensionDevToolsClientHost::ContentsReplaced(WebContents* web_contents) { |
251 web_contents_ = web_contents; | 241 web_contents_ = web_contents; |
252 } | 242 } |
253 | 243 |
| 244 void ExtensionDevToolsClientHost::ReplacedWithAnotherClient() { |
| 245 detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS; |
| 246 } |
| 247 |
254 void ExtensionDevToolsClientHost::Close() { | 248 void ExtensionDevToolsClientHost::Close() { |
255 DevToolsManager::GetInstance()->ClientHostClosing(this); | 249 DevToolsManager::GetInstance()->ClientHostClosing(this); |
256 delete this; | 250 delete this; |
257 } | 251 } |
258 | 252 |
259 void ExtensionDevToolsClientHost::SendMessageToBackend( | 253 void ExtensionDevToolsClientHost::SendMessageToBackend( |
260 SendCommandDebuggerFunction* function, | 254 SendCommandDebuggerFunction* function, |
261 const std::string& method, | 255 const std::string& method, |
262 SendCommand::Params::CommandParams* command_params) { | 256 SendCommand::Params::CommandParams* command_params) { |
263 DictionaryValue protocol_request; | 257 DictionaryValue protocol_request; |
264 int request_id = ++last_request_id_; | 258 int request_id = ++last_request_id_; |
265 pending_requests_[request_id] = function; | 259 pending_requests_[request_id] = function; |
266 protocol_request.SetInteger("id", request_id); | 260 protocol_request.SetInteger("id", request_id); |
267 protocol_request.SetString("method", method); | 261 protocol_request.SetString("method", method); |
268 if (command_params) { | 262 if (command_params) { |
269 protocol_request.Set("params", | 263 protocol_request.Set("params", |
270 command_params->additional_properties.DeepCopy()); | 264 command_params->additional_properties.DeepCopy()); |
271 } | 265 } |
272 | 266 |
273 std::string json_args; | 267 std::string json_args; |
274 base::JSONWriter::Write(&protocol_request, &json_args); | 268 base::JSONWriter::Write(&protocol_request, &json_args); |
275 DevToolsManager::GetInstance()->DispatchOnInspectorBackend(this, json_args); | 269 DevToolsManager::GetInstance()->DispatchOnInspectorBackend(this, json_args); |
276 } | 270 } |
277 | 271 |
278 void ExtensionDevToolsClientHost::MarkAsReplaced() { | |
279 detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS; | |
280 } | |
281 | |
282 void ExtensionDevToolsClientHost::MarkAsDismissed() { | 272 void ExtensionDevToolsClientHost::MarkAsDismissed() { |
283 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER; | 273 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER; |
284 } | 274 } |
285 | 275 |
286 void ExtensionDevToolsClientHost::SendDetachedEvent() { | 276 void ExtensionDevToolsClientHost::SendDetachedEvent() { |
287 Profile* profile = | 277 Profile* profile = |
288 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 278 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
289 if (profile != NULL && | 279 if (profile != NULL && |
290 extensions::ExtensionSystem::Get(profile)->event_router()) { | 280 extensions::ExtensionSystem::Get(profile)->event_router()) { |
291 Debuggee debuggee; | 281 Debuggee debuggee; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 } | 528 } |
539 | 529 |
540 DictionaryValue* result_body; | 530 DictionaryValue* result_body; |
541 SendCommand::Results::Result result; | 531 SendCommand::Results::Result result; |
542 if (response->GetDictionary("result", &result_body)) | 532 if (response->GetDictionary("result", &result_body)) |
543 result.additional_properties.Swap(result_body); | 533 result.additional_properties.Swap(result_body); |
544 | 534 |
545 results_ = SendCommand::Results::Create(result); | 535 results_ = SendCommand::Results::Create(result); |
546 SendResponse(true); | 536 SendResponse(true); |
547 } | 537 } |
548 | |
549 // static | |
550 void DebuggerApi::MarkDevToolsClientHostAsReplaced( | |
551 DevToolsClientHost* client_host) { | |
552 ExtensionDevToolsClientHost* host = AttachedClientHosts::GetInstance()-> | |
553 AsExtensionDevToolsClientHost(client_host); | |
554 if (host) | |
555 host->MarkAsReplaced(); | |
556 } | |
OLD | NEW |