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> |
11 | 11 |
12 #include "base/command_line.h" | |
12 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
13 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 20 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
20 #include "chrome/browser/api/infobars/infobar_service.h" | 21 #include "chrome/browser/api/infobars/infobar_service.h" |
21 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" | 22 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" |
22 #include "chrome/browser/extensions/event_router.h" | 23 #include "chrome/browser/extensions/event_router.h" |
24 #include "chrome/browser/extensions/extension_service.h" | |
23 #include "chrome/browser/extensions/extension_system.h" | 25 #include "chrome/browser/extensions/extension_system.h" |
24 #include "chrome/browser/extensions/extension_tab_util.h" | 26 #include "chrome/browser/extensions/extension_tab_util.h" |
25 #include "chrome/browser/infobars/infobar.h" | 27 #include "chrome/browser/infobars/infobar.h" |
26 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 29 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
28 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
31 #include "chrome/common/chrome_switches.h" | |
29 #include "chrome/common/extensions/api/debugger.h" | 32 #include "chrome/common/extensions/api/debugger.h" |
30 #include "chrome/common/extensions/extension.h" | 33 #include "chrome/common/extensions/extension.h" |
31 #include "content/public/browser/devtools_agent_host.h" | 34 #include "content/public/browser/devtools_agent_host.h" |
32 #include "content/public/browser/devtools_client_host.h" | 35 #include "content/public/browser/devtools_client_host.h" |
33 #include "content/public/browser/devtools_manager.h" | 36 #include "content/public/browser/devtools_manager.h" |
34 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
35 #include "content/public/browser/notification_source.h" | 38 #include "content/public/browser/notification_source.h" |
39 #include "content/public/browser/render_process_host.h" | |
36 #include "content/public/browser/render_view_host.h" | 40 #include "content/public/browser/render_view_host.h" |
41 #include "content/public/browser/render_widget_host.h" | |
37 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
38 #include "content/public/common/content_client.h" | 43 #include "content/public/common/content_client.h" |
39 #include "content/public/common/url_constants.h" | 44 #include "content/public/common/url_constants.h" |
40 #include "extensions/common/error_utils.h" | 45 #include "extensions/common/error_utils.h" |
41 #include "grit/generated_resources.h" | 46 #include "grit/generated_resources.h" |
42 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
43 #include "webkit/glue/webkit_glue.h" | 48 #include "webkit/glue/webkit_glue.h" |
44 | 49 |
45 using content::DevToolsAgentHost; | 50 using content::DevToolsAgentHost; |
46 using content::DevToolsClientHost; | 51 using content::DevToolsClientHost; |
47 using content::DevToolsManager; | 52 using content::DevToolsManager; |
53 using content::RenderProcessHost; | |
54 using content::RenderViewHost; | |
55 using content::RenderWidgetHost; | |
48 using content::WebContents; | 56 using content::WebContents; |
49 using extensions::api::debugger::Debuggee; | 57 using extensions::api::debugger::Debuggee; |
50 using extensions::ErrorUtils; | 58 using extensions::ErrorUtils; |
51 | 59 |
52 namespace keys = debugger_api_constants; | 60 namespace keys = debugger_api_constants; |
53 namespace Attach = extensions::api::debugger::Attach; | 61 namespace Attach = extensions::api::debugger::Attach; |
54 namespace Detach = extensions::api::debugger::Detach; | 62 namespace Detach = extensions::api::debugger::Detach; |
55 namespace OnDetach = extensions::api::debugger::OnDetach; | 63 namespace OnDetach = extensions::api::debugger::OnDetach; |
56 namespace OnEvent = extensions::api::debugger::OnEvent; | 64 namespace OnEvent = extensions::api::debugger::OnEvent; |
57 namespace SendCommand = extensions::api::debugger::SendCommand; | 65 namespace SendCommand = extensions::api::debugger::SendCommand; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 ExtensionDevToolsClientHost* client_host_; | 99 ExtensionDevToolsClientHost* client_host_; |
92 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate); | 100 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate); |
93 }; | 101 }; |
94 | 102 |
95 class ExtensionDevToolsClientHost : public DevToolsClientHost, | 103 class ExtensionDevToolsClientHost : public DevToolsClientHost, |
96 public content::NotificationObserver { | 104 public content::NotificationObserver { |
97 public: | 105 public: |
98 ExtensionDevToolsClientHost(WebContents* web_contents, | 106 ExtensionDevToolsClientHost(WebContents* web_contents, |
99 const std::string& extension_id, | 107 const std::string& extension_id, |
100 const std::string& extension_name, | 108 const std::string& extension_name, |
101 int tab_id); | 109 int debuggee_tab_id, |
110 const std::string& debuggee_extension_id); | |
102 | 111 |
103 virtual ~ExtensionDevToolsClientHost(); | 112 virtual ~ExtensionDevToolsClientHost(); |
104 | 113 |
105 bool MatchesContentsAndExtensionId(WebContents* web_contents, | 114 bool MatchesContentsAndExtensionId(WebContents* web_contents, |
106 const std::string& extension_id); | 115 const std::string& extension_id); |
107 void Close(); | 116 void Close(); |
108 void SendMessageToBackend(DebuggerSendCommandFunction* function, | 117 void SendMessageToBackend(DebuggerSendCommandFunction* function, |
109 const std::string& method, | 118 const std::string& method, |
110 SendCommand::Params::CommandParams* command_params); | 119 SendCommand::Params::CommandParams* command_params); |
111 | 120 |
112 // Marks connection as to-be-terminated by the user. | 121 // Marks connection as to-be-terminated by the user. |
113 void MarkAsDismissed(); | 122 void MarkAsDismissed(); |
114 | 123 |
115 // DevToolsClientHost interface | 124 // DevToolsClientHost interface |
116 virtual void InspectedContentsClosing() OVERRIDE; | 125 virtual void InspectedContentsClosing() OVERRIDE; |
117 virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE; | 126 virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE; |
118 virtual void ReplacedWithAnotherClient() OVERRIDE; | 127 virtual void ReplacedWithAnotherClient() OVERRIDE; |
119 | 128 |
120 private: | 129 private: |
121 void SendDetachedEvent(); | 130 void SendDetachedEvent(); |
122 | 131 |
123 // content::NotificationObserver implementation. | 132 // content::NotificationObserver implementation. |
124 virtual void Observe(int type, | 133 virtual void Observe(int type, |
125 const content::NotificationSource& source, | 134 const content::NotificationSource& source, |
126 const content::NotificationDetails& details) OVERRIDE; | 135 const content::NotificationDetails& details) OVERRIDE; |
127 | 136 |
128 WebContents* web_contents_; | 137 WebContents* web_contents_; |
129 std::string extension_id_; | 138 std::string extension_id_; |
130 int tab_id_; | 139 Debuggee debuggee_; |
131 content::NotificationRegistrar registrar_; | 140 content::NotificationRegistrar registrar_; |
132 int last_request_id_; | 141 int last_request_id_; |
133 typedef std::map<int, scoped_refptr<DebuggerSendCommandFunction> > | 142 typedef std::map<int, scoped_refptr<DebuggerSendCommandFunction> > |
134 PendingRequests; | 143 PendingRequests; |
135 PendingRequests pending_requests_; | 144 PendingRequests pending_requests_; |
136 ExtensionDevToolsInfoBarDelegate* infobar_delegate_; | 145 ExtensionDevToolsInfoBarDelegate* infobar_delegate_; |
137 OnDetach::Reason detach_reason_; | 146 OnDetach::Reason detach_reason_; |
138 | 147 |
139 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost); | 148 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost); |
140 }; | 149 }; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 private: | 184 private: |
176 std::set<DevToolsClientHost*> client_hosts_; | 185 std::set<DevToolsClientHost*> client_hosts_; |
177 }; | 186 }; |
178 | 187 |
179 } // namespace | 188 } // namespace |
180 | 189 |
181 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( | 190 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( |
182 WebContents* web_contents, | 191 WebContents* web_contents, |
183 const std::string& extension_id, | 192 const std::string& extension_id, |
184 const std::string& extension_name, | 193 const std::string& extension_name, |
185 int tab_id) | 194 int debuggee_tab_id, |
195 const std::string& debuggee_extension_id) | |
186 : web_contents_(web_contents), | 196 : web_contents_(web_contents), |
187 extension_id_(extension_id), | 197 extension_id_(extension_id), |
188 tab_id_(tab_id), | |
189 last_request_id_(0), | 198 last_request_id_(0), |
190 infobar_delegate_(NULL), | 199 infobar_delegate_(NULL), |
191 detach_reason_(OnDetach::REASON_TARGET_CLOSED) { | 200 detach_reason_(OnDetach::REASON_TARGET_CLOSED) { |
201 if (debuggee_tab_id) | |
202 debuggee_.tab_id.reset(new int(debuggee_tab_id)); | |
203 else | |
204 debuggee_.extension_id.reset(new std::string(debuggee_extension_id)); | |
205 | |
192 AttachedClientHosts::GetInstance()->Add(this); | 206 AttachedClientHosts::GetInstance()->Add(this); |
193 | 207 |
194 // Detach from debugger when extension unloads. | 208 // Detach from debugger when extension unloads. |
195 Profile* profile = | 209 Profile* profile = |
196 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 210 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
197 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 211 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
198 content::Source<Profile>(profile)); | 212 content::Source<Profile>(profile)); |
199 | 213 |
200 // Attach to debugger and tell it we are ready. | 214 // Attach to debugger and tell it we are ready. |
201 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor( | 215 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor( |
202 web_contents_->GetRenderViewHost())); | 216 web_contents_->GetRenderViewHost())); |
203 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); | 217 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); |
204 | 218 |
205 InfoBarService* infobar_service = | 219 if (!CommandLine::ForCurrentProcess()-> |
206 InfoBarService::FromWebContents(web_contents_); | 220 HasSwitch(switches::kExtensionDebuggingSilent)) { |
207 infobar_delegate_ = ExtensionDevToolsInfoBarDelegate::Create(infobar_service, | 221 InfoBarService* infobar_service = |
208 extension_name, | 222 InfoBarService::FromWebContents(web_contents_); |
209 this); | 223 infobar_delegate_ = ExtensionDevToolsInfoBarDelegate::Create( |
210 if (infobar_delegate_) { | 224 infobar_service, extension_name, this); |
211 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 225 if (infobar_delegate_) { |
212 content::Source<InfoBarService>(infobar_service)); | 226 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
227 content::Source<InfoBarService>(infobar_service)); | |
228 } | |
213 } | 229 } |
214 } | 230 } |
215 | 231 |
216 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { | 232 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { |
217 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to | 233 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to |
218 // Close() us. | 234 // Close() us. |
219 registrar_.RemoveAll(); | 235 registrar_.RemoveAll(); |
220 | 236 |
221 if (infobar_delegate_) { | 237 if (infobar_delegate_) { |
222 infobar_delegate_->DiscardClientHost(); | 238 infobar_delegate_->DiscardClientHost(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 | 286 |
271 void ExtensionDevToolsClientHost::MarkAsDismissed() { | 287 void ExtensionDevToolsClientHost::MarkAsDismissed() { |
272 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER; | 288 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER; |
273 } | 289 } |
274 | 290 |
275 void ExtensionDevToolsClientHost::SendDetachedEvent() { | 291 void ExtensionDevToolsClientHost::SendDetachedEvent() { |
276 Profile* profile = | 292 Profile* profile = |
277 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 293 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
278 if (profile != NULL && | 294 if (profile != NULL && |
279 extensions::ExtensionSystem::Get(profile)->event_router()) { | 295 extensions::ExtensionSystem::Get(profile)->event_router()) { |
280 Debuggee debuggee; | 296 scoped_ptr<base::ListValue> args(OnDetach::Create(debuggee_, |
281 debuggee.tab_id = tab_id_; | |
282 scoped_ptr<base::ListValue> args(OnDetach::Create(debuggee, | |
283 detach_reason_)); | 297 detach_reason_)); |
284 scoped_ptr<extensions::Event> event(new extensions::Event( | 298 scoped_ptr<extensions::Event> event(new extensions::Event( |
285 keys::kOnDetach, args.Pass())); | 299 keys::kOnDetach, args.Pass())); |
286 event->restrict_to_profile = profile; | 300 event->restrict_to_profile = profile; |
287 extensions::ExtensionSystem::Get(profile)->event_router()-> | 301 extensions::ExtensionSystem::Get(profile)->event_router()-> |
288 DispatchEventToExtension(extension_id_, event.Pass()); | 302 DispatchEventToExtension(extension_id_, event.Pass()); |
289 } | 303 } |
290 } | 304 } |
291 | 305 |
292 void ExtensionDevToolsClientHost::Observe( | 306 void ExtensionDevToolsClientHost::Observe( |
(...skipping 29 matching lines...) Expand all Loading... | |
322 if (!result->IsType(Value::TYPE_DICTIONARY)) | 336 if (!result->IsType(Value::TYPE_DICTIONARY)) |
323 return; | 337 return; |
324 DictionaryValue* dictionary = static_cast<DictionaryValue*>(result.get()); | 338 DictionaryValue* dictionary = static_cast<DictionaryValue*>(result.get()); |
325 | 339 |
326 int id; | 340 int id; |
327 if (!dictionary->GetInteger("id", &id)) { | 341 if (!dictionary->GetInteger("id", &id)) { |
328 std::string method_name; | 342 std::string method_name; |
329 if (!dictionary->GetString("method", &method_name)) | 343 if (!dictionary->GetString("method", &method_name)) |
330 return; | 344 return; |
331 | 345 |
332 Debuggee debuggee; | |
333 debuggee.tab_id = tab_id_; | |
334 | |
335 OnEvent::Params params; | 346 OnEvent::Params params; |
336 DictionaryValue* params_value; | 347 DictionaryValue* params_value; |
337 if (dictionary->GetDictionary("params", ¶ms_value)) | 348 if (dictionary->GetDictionary("params", ¶ms_value)) |
338 params.additional_properties.Swap(params_value); | 349 params.additional_properties.Swap(params_value); |
339 | 350 |
340 scoped_ptr<ListValue> args(OnEvent::Create(debuggee, method_name, params)); | 351 scoped_ptr<ListValue> args(OnEvent::Create(debuggee_, method_name, params)); |
341 scoped_ptr<extensions::Event> event(new extensions::Event( | 352 scoped_ptr<extensions::Event> event(new extensions::Event( |
342 keys::kOnEvent, args.Pass())); | 353 keys::kOnEvent, args.Pass())); |
343 event->restrict_to_profile = profile; | 354 event->restrict_to_profile = profile; |
344 extensions::ExtensionSystem::Get(profile)->event_router()-> | 355 extensions::ExtensionSystem::Get(profile)->event_router()-> |
345 DispatchEventToExtension(extension_id_, event.Pass()); | 356 DispatchEventToExtension(extension_id_, event.Pass()); |
346 } else { | 357 } else { |
347 DebuggerSendCommandFunction* function = pending_requests_[id]; | 358 DebuggerSendCommandFunction* function = pending_requests_[id]; |
348 if (!function) | 359 if (!function) |
349 return; | 360 return; |
350 | 361 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 } | 415 } |
405 | 416 |
406 bool ExtensionDevToolsInfoBarDelegate::Cancel() { | 417 bool ExtensionDevToolsInfoBarDelegate::Cancel() { |
407 if (client_host_) | 418 if (client_host_) |
408 client_host_->MarkAsDismissed(); | 419 client_host_->MarkAsDismissed(); |
409 return true; | 420 return true; |
410 } | 421 } |
411 | 422 |
412 DebuggerFunction::DebuggerFunction() | 423 DebuggerFunction::DebuggerFunction() |
413 : contents_(0), | 424 : contents_(0), |
414 tab_id_(0), | 425 debuggee_tab_id_(0), |
pfeldman
2013/02/20 14:58:39
debuggee_
Vladislav Kaznacheev
2013/02/20 15:24:50
Done.
| |
415 client_host_(0) { | 426 client_host_(0) { |
416 } | 427 } |
417 | 428 |
429 void DebuggerFunction::FormatErrorMessage(const std::string& format) { | |
430 error_ = ErrorUtils::FormatErrorMessage( | |
431 format, | |
432 debuggee_tab_id_ ? | |
433 keys::kTabTargetType : | |
434 keys::kExtensionTargetType, | |
435 debuggee_tab_id_ ? | |
436 base::IntToString(debuggee_tab_id_) : | |
437 debuggee_extension_id_); | |
438 } | |
439 | |
440 static WebContents* FindWebContentsForExtension( | |
441 const extensions::Extension* extension) { | |
442 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | |
443 !it.IsAtEnd(); it.Advance()) { | |
444 RenderProcessHost* render_process_host = it.GetCurrentValue(); | |
445 DCHECK(render_process_host); | |
446 | |
447 // Ignore processes that don't have a connection, such as crashed tabs. | |
448 if (!render_process_host->HasConnection()) | |
449 continue; | |
450 | |
451 RenderProcessHost::RenderWidgetHostsIterator rwit( | |
452 render_process_host->GetRenderWidgetHostsIterator()); | |
453 for (; !rwit.IsAtEnd(); rwit.Advance()) { | |
454 const RenderWidgetHost* widget = rwit.GetCurrentValue(); | |
455 DCHECK(widget); | |
456 if (!widget || !widget->IsRenderView()) | |
457 continue; | |
458 | |
459 RenderViewHost* rvh = | |
460 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); | |
461 | |
462 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | |
463 if (web_contents) { | |
464 GURL url = web_contents->GetURL(); | |
465 if (url.host() == extension->id()) { | |
466 return web_contents; | |
467 } | |
468 } | |
469 } | |
470 } | |
471 return NULL; | |
472 } | |
473 | |
418 bool DebuggerFunction::InitWebContents() { | 474 bool DebuggerFunction::InitWebContents() { |
419 // Find the WebContents that contains this tab id. | 475 // Find the WebContents that contains this tab id. |
420 contents_ = NULL; | 476 contents_ = NULL; |
421 WebContents* web_contents = NULL; | 477 if (debuggee_tab_id_) { |
422 bool result = ExtensionTabUtil::GetTabById( | 478 WebContents* web_contents = NULL; |
423 tab_id_, profile(), include_incognito(), NULL, NULL, &web_contents, NULL); | 479 bool result = ExtensionTabUtil::GetTabById(debuggee_tab_id_, profile(), |
424 if (!result || !web_contents) { | 480 include_incognito(), NULL, NULL, &web_contents, NULL); |
425 error_ = ErrorUtils::FormatErrorMessage( | 481 if (!result || !web_contents) { |
426 keys::kNoTabError, | 482 FormatErrorMessage(keys::kNoTargetError); |
427 base::IntToString(tab_id_)); | 483 return false; |
428 return false; | 484 } |
485 contents_ = web_contents; | |
486 | |
487 if (content::HasWebUIScheme(contents_->GetURL())) { | |
488 error_ = ErrorUtils::FormatErrorMessage( | |
489 keys::kAttachToWebUIError, | |
490 contents_->GetURL().scheme()); | |
491 return false; | |
492 } | |
493 | |
494 return true; | |
429 } | 495 } |
430 contents_ = web_contents; | |
431 | 496 |
432 if (content::HasWebUIScheme(contents_->GetURL())) { | 497 if (debuggee_extension_id_.size()) { |
433 error_ = ErrorUtils::FormatErrorMessage( | 498 if (!CommandLine::ForCurrentProcess()-> |
434 keys::kAttachToWebUIError, | 499 HasSwitch(switches::kExtensionDebuggingSilent)) { |
435 contents_->GetURL().scheme()); | 500 error_ = ErrorUtils::FormatErrorMessage( |
501 keys::kSilentDebuggingRequired, | |
502 switches::kExtensionDebuggingSilent); | |
503 return false; | |
504 } | |
505 | |
506 const extensions::Extension* extension = profile()->GetExtensionService()-> | |
507 extensions()->GetByID(debuggee_extension_id_); | |
508 if (extension) { | |
509 contents_ = FindWebContentsForExtension(extension); | |
510 if (contents_) | |
511 return true; | |
512 } | |
513 | |
514 FormatErrorMessage(keys::kNoTargetError); | |
436 return false; | 515 return false; |
437 } | 516 } |
438 | 517 |
439 return true; | 518 error_ = keys::kInvalidTargetError; |
519 return false; | |
440 } | 520 } |
441 | 521 |
442 bool DebuggerFunction::InitClientHost() { | 522 bool DebuggerFunction::InitClientHost() { |
443 if (!InitWebContents()) | 523 if (!InitWebContents()) |
444 return false; | 524 return false; |
445 | 525 |
446 // Don't fetch rvh from the contents since it'll be wrong upon navigation. | 526 // Don't fetch rvh from the contents since it'll be wrong upon navigation. |
447 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_); | 527 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_); |
448 | 528 |
449 if (!client_host_ || | 529 if (!client_host_ || |
450 !client_host_->MatchesContentsAndExtensionId(contents_, | 530 !client_host_->MatchesContentsAndExtensionId(contents_, |
451 GetExtension()->id())) { | 531 GetExtension()->id())) { |
452 error_ = ErrorUtils::FormatErrorMessage( | 532 FormatErrorMessage(keys::kNotAttachedError); |
453 keys::kNotAttachedError, | |
454 base::IntToString(tab_id_)); | |
455 return false; | 533 return false; |
456 } | 534 } |
457 return true; | 535 return true; |
458 } | 536 } |
459 | 537 |
460 DebuggerAttachFunction::DebuggerAttachFunction() {} | 538 DebuggerAttachFunction::DebuggerAttachFunction() {} |
461 | 539 |
462 DebuggerAttachFunction::~DebuggerAttachFunction() {} | 540 DebuggerAttachFunction::~DebuggerAttachFunction() {} |
463 | 541 |
464 bool DebuggerAttachFunction::RunImpl() { | 542 bool DebuggerAttachFunction::RunImpl() { |
465 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_)); | 543 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_)); |
466 EXTENSION_FUNCTION_VALIDATE(params.get()); | 544 EXTENSION_FUNCTION_VALIDATE(params.get()); |
467 | 545 |
468 tab_id_ = params->target.tab_id; | 546 if (params->target.tab_id) |
547 debuggee_tab_id_ = *params->target.tab_id; | |
548 if (params->target.extension_id) | |
549 debuggee_extension_id_ = *params->target.extension_id; | |
469 if (!InitWebContents()) | 550 if (!InitWebContents()) |
470 return false; | 551 return false; |
471 | 552 |
472 if (!webkit_glue::IsInspectorProtocolVersionSupported( | 553 if (!webkit_glue::IsInspectorProtocolVersionSupported( |
473 params->required_version)) { | 554 params->required_version)) { |
474 error_ = ErrorUtils::FormatErrorMessage( | 555 error_ = ErrorUtils::FormatErrorMessage( |
475 keys::kProtocolVersionNotSupportedError, | 556 keys::kProtocolVersionNotSupportedError, |
476 params->required_version); | 557 params->required_version); |
477 return false; | 558 return false; |
478 } | 559 } |
479 | 560 |
480 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor( | 561 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor( |
481 contents_->GetRenderViewHost())); | 562 contents_->GetRenderViewHost())); |
482 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> | 563 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> |
483 GetDevToolsClientHostFor(agent); | 564 GetDevToolsClientHostFor(agent); |
484 | 565 |
485 if (client_host != NULL) { | 566 if (client_host != NULL) { |
486 error_ = ErrorUtils::FormatErrorMessage( | 567 FormatErrorMessage(keys::kAlreadyAttachedError); |
487 keys::kAlreadyAttachedError, | |
488 base::IntToString(tab_id_)); | |
489 return false; | 568 return false; |
490 } | 569 } |
491 | 570 |
492 new ExtensionDevToolsClientHost(contents_, | 571 new ExtensionDevToolsClientHost(contents_, |
493 GetExtension()->id(), | 572 GetExtension()->id(), |
494 GetExtension()->name(), | 573 GetExtension()->name(), |
495 tab_id_); | 574 debuggee_tab_id_, |
pfeldman
2013/02/20 14:58:39
Pass debuggee_ here and clone it in the constructo
Vladislav Kaznacheev
2013/02/20 15:24:50
Done.
| |
575 debuggee_extension_id_); | |
496 SendResponse(true); | 576 SendResponse(true); |
497 return true; | 577 return true; |
498 } | 578 } |
499 | 579 |
500 DebuggerDetachFunction::DebuggerDetachFunction() {} | 580 DebuggerDetachFunction::DebuggerDetachFunction() {} |
501 | 581 |
502 DebuggerDetachFunction::~DebuggerDetachFunction() {} | 582 DebuggerDetachFunction::~DebuggerDetachFunction() {} |
503 | 583 |
504 bool DebuggerDetachFunction::RunImpl() { | 584 bool DebuggerDetachFunction::RunImpl() { |
505 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_)); | 585 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_)); |
506 EXTENSION_FUNCTION_VALIDATE(params.get()); | 586 EXTENSION_FUNCTION_VALIDATE(params.get()); |
507 | 587 |
508 tab_id_ = params->target.tab_id; | 588 if (params->target.tab_id) |
589 debuggee_tab_id_ = *params->target.tab_id; | |
590 if (params->target.extension_id) | |
591 debuggee_extension_id_ = *params->target.extension_id; | |
509 if (!InitClientHost()) | 592 if (!InitClientHost()) |
510 return false; | 593 return false; |
511 | 594 |
512 client_host_->Close(); | 595 client_host_->Close(); |
513 SendResponse(true); | 596 SendResponse(true); |
514 return true; | 597 return true; |
515 } | 598 } |
516 | 599 |
517 DebuggerSendCommandFunction::DebuggerSendCommandFunction() {} | 600 DebuggerSendCommandFunction::DebuggerSendCommandFunction() {} |
518 | 601 |
519 DebuggerSendCommandFunction::~DebuggerSendCommandFunction() {} | 602 DebuggerSendCommandFunction::~DebuggerSendCommandFunction() {} |
520 | 603 |
521 bool DebuggerSendCommandFunction::RunImpl() { | 604 bool DebuggerSendCommandFunction::RunImpl() { |
522 scoped_ptr<SendCommand::Params> params(SendCommand::Params::Create(*args_)); | 605 scoped_ptr<SendCommand::Params> params(SendCommand::Params::Create(*args_)); |
523 EXTENSION_FUNCTION_VALIDATE(params.get()); | 606 EXTENSION_FUNCTION_VALIDATE(params.get()); |
524 | 607 |
525 tab_id_ = params->target.tab_id; | 608 if (params->target.tab_id) |
609 debuggee_tab_id_ = *params->target.tab_id; | |
610 if (params->target.extension_id) | |
611 debuggee_extension_id_ = *params->target.extension_id; | |
526 if (!InitClientHost()) | 612 if (!InitClientHost()) |
527 return false; | 613 return false; |
528 | 614 |
529 client_host_->SendMessageToBackend(this, params->method, | 615 client_host_->SendMessageToBackend(this, params->method, |
530 params->command_params.get()); | 616 params->command_params.get()); |
531 return true; | 617 return true; |
532 } | 618 } |
533 | 619 |
534 void DebuggerSendCommandFunction::SendResponseBody( | 620 void DebuggerSendCommandFunction::SendResponseBody( |
535 DictionaryValue* response) { | 621 DictionaryValue* response) { |
536 Value* error_body; | 622 Value* error_body; |
537 if (response->Get("error", &error_body)) { | 623 if (response->Get("error", &error_body)) { |
538 base::JSONWriter::Write(error_body, &error_); | 624 base::JSONWriter::Write(error_body, &error_); |
539 SendResponse(false); | 625 SendResponse(false); |
540 return; | 626 return; |
541 } | 627 } |
542 | 628 |
543 DictionaryValue* result_body; | 629 DictionaryValue* result_body; |
544 SendCommand::Results::Result result; | 630 SendCommand::Results::Result result; |
545 if (response->GetDictionary("result", &result_body)) | 631 if (response->GetDictionary("result", &result_body)) |
546 result.additional_properties.Swap(result_body); | 632 result.additional_properties.Swap(result_body); |
547 | 633 |
548 results_ = SendCommand::Results::Create(result); | 634 results_ = SendCommand::Results::Create(result); |
549 SendResponse(true); | 635 SendResponse(true); |
550 } | 636 } |
OLD | NEW |