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 29 matching lines...) Expand all Loading... | |
40 #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" | 41 #include "content/public/browser/render_widget_host.h" |
42 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
43 #include "content/public/common/content_client.h" | 43 #include "content/public/common/content_client.h" |
44 #include "content/public/common/url_utils.h" | 44 #include "content/public/common/url_utils.h" |
45 #include "extensions/browser/event_router.h" | 45 #include "extensions/browser/event_router.h" |
46 #include "extensions/browser/extension_host.h" | 46 #include "extensions/browser/extension_host.h" |
47 #include "extensions/browser/extension_registry.h" | 47 #include "extensions/browser/extension_registry.h" |
48 #include "extensions/browser/extension_registry_observer.h" | 48 #include "extensions/browser/extension_registry_observer.h" |
49 #include "extensions/browser/extension_system.h" | 49 #include "extensions/browser/extension_system.h" |
50 #include "extensions/common/constants.h" | |
50 #include "extensions/common/error_utils.h" | 51 #include "extensions/common/error_utils.h" |
51 #include "extensions/common/extension.h" | 52 #include "extensions/common/extension.h" |
53 #include "extensions/common/permissions/permissions_data.h" | |
54 #include "extensions/common/switches.h" | |
52 #include "grit/generated_resources.h" | 55 #include "grit/generated_resources.h" |
53 #include "ui/base/l10n/l10n_util.h" | 56 #include "ui/base/l10n/l10n_util.h" |
54 | 57 |
55 using content::DevToolsAgentHost; | 58 using content::DevToolsAgentHost; |
56 using content::DevToolsClientHost; | 59 using content::DevToolsClientHost; |
57 using content::DevToolsHttpHandler; | 60 using content::DevToolsHttpHandler; |
58 using content::DevToolsManager; | 61 using content::DevToolsManager; |
59 using content::RenderProcessHost; | 62 using content::RenderProcessHost; |
60 using content::RenderViewHost; | 63 using content::RenderViewHost; |
61 using content::RenderWidgetHost; | 64 using content::RenderWidgetHost; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 for (ClientHosts::iterator it = client_hosts_.begin(); | 296 for (ClientHosts::iterator it = client_hosts_.begin(); |
294 it != client_hosts_.end(); ++it) { | 297 it != client_hosts_.end(); ++it) { |
295 ExtensionDevToolsClientHost* client_host = *it; | 298 ExtensionDevToolsClientHost* client_host = *it; |
296 if (manager->GetDevToolsAgentHostFor(client_host) == agent_host && | 299 if (manager->GetDevToolsAgentHostFor(client_host) == agent_host && |
297 client_host->extension_id() == extension_id) | 300 client_host->extension_id() == extension_id) |
298 return client_host; | 301 return client_host; |
299 } | 302 } |
300 return NULL; | 303 return NULL; |
301 } | 304 } |
302 | 305 |
306 // Returns true if the given |extension| is allowed to run the debugger on | |
307 // other extensions' pages. | |
308 bool CanRunOnOtherExtensionPages(const Extension* extension) { | |
meacer
2014/06/24 18:15:54
nit: CanDebugExtensionPages sounds slightly more d
not at google - send to devlin
2014/06/24 18:35:08
+1
though I'm still worried that a blacklist is j
Devlin
2014/06/24 18:45:40
Done.
Devlin
2014/06/24 18:49:08
I'm not entirely sure I follow - won't it _still_
not at google - send to devlin
2014/06/24 19:07:51
IsRestricted would be checked from CanAccessPage,
Devlin
2014/06/24 19:54:55
Done...
| |
309 return extension->permissions_data()->CanExecuteScriptEverywhere( | |
meacer
2014/06/24 18:15:54
Static method, you can use PermissionsData::CanExe
Devlin
2014/06/24 18:45:40
Whoops! Done.
| |
310 extension) || | |
311 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
312 switches::kExtensionsOnChromeURLs); | |
meacer
2014/06/24 18:15:54
Is kExtensionsOnChromeURLs the right switch? Looks
not at google - send to devlin
2014/06/24 18:35:08
kSilentDebuggerExtensionAPI is subtly different, a
Devlin
2014/06/24 18:45:40
I'm not sure - the chrome urls switch was taken fr
| |
313 } | |
314 | |
303 } // namespace | 315 } // namespace |
304 | 316 |
305 | 317 |
306 // ExtensionDevToolsClientHost ------------------------------------------------ | 318 // ExtensionDevToolsClientHost ------------------------------------------------ |
307 | 319 |
308 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( | 320 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( |
309 Profile* profile, | 321 Profile* profile, |
310 DevToolsAgentHost* agent_host, | 322 DevToolsAgentHost* agent_host, |
311 const std::string& extension_id, | 323 const std::string& extension_id, |
312 const std::string& extension_name, | 324 const std::string& extension_name, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 format, keys::kTabTargetType, base::IntToString(*debuggee_.tab_id)); | 508 format, keys::kTabTargetType, base::IntToString(*debuggee_.tab_id)); |
497 else if (debuggee_.extension_id) | 509 else if (debuggee_.extension_id) |
498 error_ = ErrorUtils::FormatErrorMessage( | 510 error_ = ErrorUtils::FormatErrorMessage( |
499 format, keys::kBackgroundPageTargetType, *debuggee_.extension_id); | 511 format, keys::kBackgroundPageTargetType, *debuggee_.extension_id); |
500 else | 512 else |
501 error_ = ErrorUtils::FormatErrorMessage( | 513 error_ = ErrorUtils::FormatErrorMessage( |
502 format, keys::kOpaqueTargetType, *debuggee_.target_id); | 514 format, keys::kOpaqueTargetType, *debuggee_.target_id); |
503 } | 515 } |
504 | 516 |
505 bool DebuggerFunction::InitAgentHost() { | 517 bool DebuggerFunction::InitAgentHost() { |
518 const Extension* extension = GetExtension(); | |
506 if (debuggee_.tab_id) { | 519 if (debuggee_.tab_id) { |
507 WebContents* web_contents = NULL; | 520 WebContents* web_contents = NULL; |
508 bool result = ExtensionTabUtil::GetTabById(*debuggee_.tab_id, | 521 bool result = ExtensionTabUtil::GetTabById(*debuggee_.tab_id, |
509 GetProfile(), | 522 GetProfile(), |
510 include_incognito(), | 523 include_incognito(), |
511 NULL, | 524 NULL, |
512 NULL, | 525 NULL, |
513 &web_contents, | 526 &web_contents, |
514 NULL); | 527 NULL); |
515 if (result && web_contents) { | 528 if (result && web_contents) { |
516 if (content::HasWebUIScheme(web_contents->GetURL())) { | 529 GURL url = web_contents->GetVisibleURL(); |
meacer
2014/06/24 18:54:27
Better to use GetLastCommittedURL instead.
Devlin
2014/06/24 19:54:55
Agreed. And tried that first. Unfortunately, thi
| |
530 if (content::HasWebUIScheme(url)) { | |
517 error_ = ErrorUtils::FormatErrorMessage( | 531 error_ = ErrorUtils::FormatErrorMessage( |
518 keys::kAttachToWebUIError, | 532 keys::kAttachToWebUIError, |
519 web_contents->GetURL().scheme()); | 533 web_contents->GetURL().scheme()); |
520 return false; | 534 return false; |
521 } | 535 } |
536 if (url.SchemeIs(kExtensionScheme) && url.host() != extension->id() && | |
537 !CanRunOnOtherExtensionPages(extension)) { | |
538 error_ = keys::kAttachToOtherExtensionError; | |
539 return false; | |
540 } | |
522 agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents); | 541 agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents); |
523 } | 542 } |
524 } else if (debuggee_.extension_id) { | 543 } else if (debuggee_.extension_id) { |
544 if (*debuggee_.extension_id != extension->id() && | |
545 !CanRunOnOtherExtensionPages(extension)) { | |
546 error_ = keys::kAttachToOtherExtensionError; | |
547 return false; | |
548 } | |
525 ExtensionHost* extension_host = | 549 ExtensionHost* extension_host = |
526 ExtensionSystem::Get(GetProfile()) | 550 ExtensionSystem::Get(GetProfile()) |
527 ->process_manager() | 551 ->process_manager() |
528 ->GetBackgroundHostForExtension(*debuggee_.extension_id); | 552 ->GetBackgroundHostForExtension(*debuggee_.extension_id); |
529 if (extension_host) { | 553 if (extension_host) { |
530 agent_host_ = DevToolsAgentHost::GetOrCreateFor( | 554 agent_host_ = DevToolsAgentHost::GetOrCreateFor( |
531 extension_host->render_view_host()); | 555 extension_host->render_view_host()); |
532 } | 556 } |
533 } else if (debuggee_.target_id) { | 557 } else if (debuggee_.target_id) { |
534 agent_host_ = DevToolsAgentHost::GetForId(*debuggee_.target_id); | 558 agent_host_ = DevToolsAgentHost::GetForId(*debuggee_.target_id); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 keys::kProtocolVersionNotSupportedError, | 605 keys::kProtocolVersionNotSupportedError, |
582 params->required_version); | 606 params->required_version); |
583 return false; | 607 return false; |
584 } | 608 } |
585 | 609 |
586 if (agent_host_->IsAttached()) { | 610 if (agent_host_->IsAttached()) { |
587 FormatErrorMessage(keys::kAlreadyAttachedError); | 611 FormatErrorMessage(keys::kAlreadyAttachedError); |
588 return false; | 612 return false; |
589 } | 613 } |
590 | 614 |
615 const Extension* extension = GetExtension(); | |
591 infobars::InfoBar* infobar = NULL; | 616 infobars::InfoBar* infobar = NULL; |
592 if (!CommandLine::ForCurrentProcess()-> | 617 if (!CommandLine::ForCurrentProcess()-> |
593 HasSwitch(switches::kSilentDebuggerExtensionAPI)) { | 618 HasSwitch(::switches::kSilentDebuggerExtensionAPI)) { |
meacer
2014/06/24 18:54:27
Is this flag going to be redundant with this chang
Devlin
2014/06/24 19:54:55
Hmm... good question.
The thing is, we don't even
| |
594 // Do not attach to the target if for any reason the infobar cannot be shown | 619 // Do not attach to the target if for any reason the infobar cannot be shown |
595 // for this WebContents instance. | 620 // for this WebContents instance. |
596 infobar = ExtensionDevToolsInfoBarDelegate::Create( | 621 infobar = ExtensionDevToolsInfoBarDelegate::Create( |
597 agent_host_->GetRenderViewHost(), GetExtension()->name()); | 622 agent_host_->GetRenderViewHost(), extension->name()); |
598 if (!infobar) { | 623 if (!infobar) { |
599 error_ = ErrorUtils::FormatErrorMessage( | 624 error_ = ErrorUtils::FormatErrorMessage( |
600 keys::kSilentDebuggingRequired, | 625 keys::kSilentDebuggingRequired, |
601 switches::kSilentDebuggerExtensionAPI); | 626 ::switches::kSilentDebuggerExtensionAPI); |
602 return false; | 627 return false; |
603 } | 628 } |
604 } | 629 } |
605 | 630 |
606 new ExtensionDevToolsClientHost(GetProfile(), | 631 new ExtensionDevToolsClientHost(GetProfile(), |
607 agent_host_.get(), | 632 agent_host_.get(), |
608 GetExtension()->id(), | 633 extension->id(), |
609 GetExtension()->name(), | 634 extension->name(), |
610 debuggee_, | 635 debuggee_, |
611 infobar); | 636 infobar); |
612 SendResponse(true); | 637 SendResponse(true); |
613 return true; | 638 return true; |
614 } | 639 } |
615 | 640 |
616 | 641 |
617 // DebuggerDetachFunction ----------------------------------------------------- | 642 // DebuggerDetachFunction ----------------------------------------------------- |
618 | 643 |
619 DebuggerDetachFunction::DebuggerDetachFunction() { | 644 DebuggerDetachFunction::DebuggerDetachFunction() { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
737 const std::vector<DevToolsTargetImpl*>& target_list) { | 762 const std::vector<DevToolsTargetImpl*>& target_list) { |
738 scoped_ptr<base::ListValue> result(new base::ListValue()); | 763 scoped_ptr<base::ListValue> result(new base::ListValue()); |
739 for (size_t i = 0; i < target_list.size(); ++i) | 764 for (size_t i = 0; i < target_list.size(); ++i) |
740 result->Append(SerializeTarget(*target_list[i])); | 765 result->Append(SerializeTarget(*target_list[i])); |
741 STLDeleteContainerPointers(target_list.begin(), target_list.end()); | 766 STLDeleteContainerPointers(target_list.begin(), target_list.end()); |
742 SetResult(result.release()); | 767 SetResult(result.release()); |
743 SendResponse(true); | 768 SendResponse(true); |
744 } | 769 } |
745 | 770 |
746 } // namespace extensions | 771 } // namespace extensions |
OLD | NEW |