Chromium Code Reviews| 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/manifest_constants.h" | |
| 54 #include "extensions/common/permissions/permissions_data.h" | |
| 55 #include "extensions/common/switches.h" | |
| 52 #include "grit/generated_resources.h" | 56 #include "grit/generated_resources.h" |
| 53 #include "ui/base/l10n/l10n_util.h" | 57 #include "ui/base/l10n/l10n_util.h" |
| 54 | 58 |
| 55 using content::DevToolsAgentHost; | 59 using content::DevToolsAgentHost; |
| 56 using content::DevToolsClientHost; | 60 using content::DevToolsClientHost; |
| 57 using content::DevToolsHttpHandler; | 61 using content::DevToolsHttpHandler; |
| 58 using content::DevToolsManager; | 62 using content::DevToolsManager; |
| 59 using content::RenderProcessHost; | 63 using content::RenderProcessHost; |
| 60 using content::RenderViewHost; | 64 using content::RenderViewHost; |
| 61 using content::RenderWidgetHost; | 65 using content::RenderWidgetHost; |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 format, keys::kTabTargetType, base::IntToString(*debuggee_.tab_id)); | 500 format, keys::kTabTargetType, base::IntToString(*debuggee_.tab_id)); |
| 497 else if (debuggee_.extension_id) | 501 else if (debuggee_.extension_id) |
| 498 error_ = ErrorUtils::FormatErrorMessage( | 502 error_ = ErrorUtils::FormatErrorMessage( |
| 499 format, keys::kBackgroundPageTargetType, *debuggee_.extension_id); | 503 format, keys::kBackgroundPageTargetType, *debuggee_.extension_id); |
| 500 else | 504 else |
| 501 error_ = ErrorUtils::FormatErrorMessage( | 505 error_ = ErrorUtils::FormatErrorMessage( |
| 502 format, keys::kOpaqueTargetType, *debuggee_.target_id); | 506 format, keys::kOpaqueTargetType, *debuggee_.target_id); |
| 503 } | 507 } |
| 504 | 508 |
| 505 bool DebuggerFunction::InitAgentHost() { | 509 bool DebuggerFunction::InitAgentHost() { |
| 510 const Extension* extension = GetExtension(); | |
| 506 if (debuggee_.tab_id) { | 511 if (debuggee_.tab_id) { |
| 507 WebContents* web_contents = NULL; | 512 WebContents* web_contents = NULL; |
| 508 bool result = ExtensionTabUtil::GetTabById(*debuggee_.tab_id, | 513 bool result = ExtensionTabUtil::GetTabById(*debuggee_.tab_id, |
| 509 GetProfile(), | 514 GetProfile(), |
| 510 include_incognito(), | 515 include_incognito(), |
| 511 NULL, | 516 NULL, |
| 512 NULL, | 517 NULL, |
| 513 &web_contents, | 518 &web_contents, |
| 514 NULL); | 519 NULL); |
| 515 if (result && web_contents) { | 520 if (result && web_contents) { |
| 516 if (content::HasWebUIScheme(web_contents->GetURL())) { | 521 GURL url = web_contents->GetVisibleURL(); |
|
not at google - send to devlin
2014/06/25 20:42:16
yeah this really should be GetLastCommittedURL. co
Devlin
2014/06/25 23:30:00
Done.
| |
| 517 error_ = ErrorUtils::FormatErrorMessage( | 522 if (PermissionsData::UrlIsRestricted(url, url, extension, &error_)) |
| 518 keys::kAttachToWebUIError, | |
| 519 web_contents->GetURL().scheme()); | |
| 520 return false; | 523 return false; |
| 521 } | |
| 522 agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents); | 524 agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents); |
| 523 } | 525 } |
| 524 } else if (debuggee_.extension_id) { | 526 } else if (debuggee_.extension_id) { |
| 525 ExtensionHost* extension_host = | 527 ExtensionHost* extension_host = |
| 526 ExtensionSystem::Get(GetProfile()) | 528 ExtensionSystem::Get(GetProfile()) |
| 527 ->process_manager() | 529 ->process_manager() |
| 528 ->GetBackgroundHostForExtension(*debuggee_.extension_id); | 530 ->GetBackgroundHostForExtension(*debuggee_.extension_id); |
| 529 if (extension_host) { | 531 if (extension_host) { |
| 532 if (PermissionsData::UrlIsRestricted(extension_host->GetURL(), | |
| 533 extension_host->GetURL(), | |
| 534 extension, | |
| 535 &error_)) { | |
| 536 return false; | |
| 537 } | |
| 530 agent_host_ = DevToolsAgentHost::GetOrCreateFor( | 538 agent_host_ = DevToolsAgentHost::GetOrCreateFor( |
| 531 extension_host->render_view_host()); | 539 extension_host->render_view_host()); |
| 532 } | 540 } |
| 533 } else if (debuggee_.target_id) { | 541 } else if (debuggee_.target_id) { |
| 534 agent_host_ = DevToolsAgentHost::GetForId(*debuggee_.target_id); | 542 agent_host_ = DevToolsAgentHost::GetForId(*debuggee_.target_id); |
| 535 } else { | 543 } else { |
| 536 error_ = keys::kInvalidTargetError; | 544 error_ = keys::kInvalidTargetError; |
| 537 return false; | 545 return false; |
| 538 } | 546 } |
| 539 | 547 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 keys::kProtocolVersionNotSupportedError, | 589 keys::kProtocolVersionNotSupportedError, |
| 582 params->required_version); | 590 params->required_version); |
| 583 return false; | 591 return false; |
| 584 } | 592 } |
| 585 | 593 |
| 586 if (agent_host_->IsAttached()) { | 594 if (agent_host_->IsAttached()) { |
| 587 FormatErrorMessage(keys::kAlreadyAttachedError); | 595 FormatErrorMessage(keys::kAlreadyAttachedError); |
| 588 return false; | 596 return false; |
| 589 } | 597 } |
| 590 | 598 |
| 599 const Extension* extension = GetExtension(); | |
| 591 infobars::InfoBar* infobar = NULL; | 600 infobars::InfoBar* infobar = NULL; |
| 592 if (!CommandLine::ForCurrentProcess()-> | 601 if (!CommandLine::ForCurrentProcess()-> |
| 593 HasSwitch(switches::kSilentDebuggerExtensionAPI)) { | 602 HasSwitch(::switches::kSilentDebuggerExtensionAPI)) { |
| 594 // Do not attach to the target if for any reason the infobar cannot be shown | 603 // Do not attach to the target if for any reason the infobar cannot be shown |
| 595 // for this WebContents instance. | 604 // for this WebContents instance. |
| 596 infobar = ExtensionDevToolsInfoBarDelegate::Create( | 605 infobar = ExtensionDevToolsInfoBarDelegate::Create( |
| 597 agent_host_->GetRenderViewHost(), GetExtension()->name()); | 606 agent_host_->GetRenderViewHost(), extension->name()); |
| 598 if (!infobar) { | 607 if (!infobar) { |
| 599 error_ = ErrorUtils::FormatErrorMessage( | 608 error_ = ErrorUtils::FormatErrorMessage( |
| 600 keys::kSilentDebuggingRequired, | 609 keys::kSilentDebuggingRequired, |
| 601 switches::kSilentDebuggerExtensionAPI); | 610 ::switches::kSilentDebuggerExtensionAPI); |
| 602 return false; | 611 return false; |
| 603 } | 612 } |
| 604 } | 613 } |
| 605 | 614 |
| 606 new ExtensionDevToolsClientHost(GetProfile(), | 615 new ExtensionDevToolsClientHost(GetProfile(), |
| 607 agent_host_.get(), | 616 agent_host_.get(), |
| 608 GetExtension()->id(), | 617 extension->id(), |
| 609 GetExtension()->name(), | 618 extension->name(), |
| 610 debuggee_, | 619 debuggee_, |
| 611 infobar); | 620 infobar); |
| 612 SendResponse(true); | 621 SendResponse(true); |
| 613 return true; | 622 return true; |
| 614 } | 623 } |
| 615 | 624 |
| 616 | 625 |
| 617 // DebuggerDetachFunction ----------------------------------------------------- | 626 // DebuggerDetachFunction ----------------------------------------------------- |
| 618 | 627 |
| 619 DebuggerDetachFunction::DebuggerDetachFunction() { | 628 DebuggerDetachFunction::DebuggerDetachFunction() { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 const std::vector<DevToolsTargetImpl*>& target_list) { | 746 const std::vector<DevToolsTargetImpl*>& target_list) { |
| 738 scoped_ptr<base::ListValue> result(new base::ListValue()); | 747 scoped_ptr<base::ListValue> result(new base::ListValue()); |
| 739 for (size_t i = 0; i < target_list.size(); ++i) | 748 for (size_t i = 0; i < target_list.size(); ++i) |
| 740 result->Append(SerializeTarget(*target_list[i])); | 749 result->Append(SerializeTarget(*target_list[i])); |
| 741 STLDeleteContainerPointers(target_list.begin(), target_list.end()); | 750 STLDeleteContainerPointers(target_list.begin(), target_list.end()); |
| 742 SetResult(result.release()); | 751 SetResult(result.release()); |
| 743 SendResponse(true); | 752 SendResponse(true); |
| 744 } | 753 } |
| 745 | 754 |
| 746 } // namespace extensions | 755 } // namespace extensions |
| OLD | NEW |