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 // TODO(rdevlin.cronin) This should definitely be GetLastCommittedURL(). |
517 error_ = ErrorUtils::FormatErrorMessage( | 522 GURL url = web_contents->GetVisibleURL(); |
518 keys::kAttachToWebUIError, | 523 if (PermissionsData::IsRestrictedUrl(url, url, extension, &error_)) |
519 web_contents->GetURL().scheme()); | |
520 return false; | 524 return false; |
521 } | |
522 agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents); | 525 agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents); |
523 } | 526 } |
524 } else if (debuggee_.extension_id) { | 527 } else if (debuggee_.extension_id) { |
525 ExtensionHost* extension_host = | 528 ExtensionHost* extension_host = |
526 ExtensionSystem::Get(GetProfile()) | 529 ExtensionSystem::Get(GetProfile()) |
527 ->process_manager() | 530 ->process_manager() |
528 ->GetBackgroundHostForExtension(*debuggee_.extension_id); | 531 ->GetBackgroundHostForExtension(*debuggee_.extension_id); |
529 if (extension_host) { | 532 if (extension_host) { |
| 533 if (PermissionsData::IsRestrictedUrl(extension_host->GetURL(), |
| 534 extension_host->GetURL(), |
| 535 extension, |
| 536 &error_)) { |
| 537 return false; |
| 538 } |
530 agent_host_ = DevToolsAgentHost::GetOrCreateFor( | 539 agent_host_ = DevToolsAgentHost::GetOrCreateFor( |
531 extension_host->render_view_host()); | 540 extension_host->render_view_host()); |
532 } | 541 } |
533 } else if (debuggee_.target_id) { | 542 } else if (debuggee_.target_id) { |
534 agent_host_ = DevToolsAgentHost::GetForId(*debuggee_.target_id); | 543 agent_host_ = DevToolsAgentHost::GetForId(*debuggee_.target_id); |
535 } else { | 544 } else { |
536 error_ = keys::kInvalidTargetError; | 545 error_ = keys::kInvalidTargetError; |
537 return false; | 546 return false; |
538 } | 547 } |
539 | 548 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 keys::kProtocolVersionNotSupportedError, | 590 keys::kProtocolVersionNotSupportedError, |
582 params->required_version); | 591 params->required_version); |
583 return false; | 592 return false; |
584 } | 593 } |
585 | 594 |
586 if (agent_host_->IsAttached()) { | 595 if (agent_host_->IsAttached()) { |
587 FormatErrorMessage(keys::kAlreadyAttachedError); | 596 FormatErrorMessage(keys::kAlreadyAttachedError); |
588 return false; | 597 return false; |
589 } | 598 } |
590 | 599 |
| 600 const Extension* extension = GetExtension(); |
591 infobars::InfoBar* infobar = NULL; | 601 infobars::InfoBar* infobar = NULL; |
592 if (!CommandLine::ForCurrentProcess()-> | 602 if (!CommandLine::ForCurrentProcess()-> |
593 HasSwitch(switches::kSilentDebuggerExtensionAPI)) { | 603 HasSwitch(::switches::kSilentDebuggerExtensionAPI)) { |
594 // Do not attach to the target if for any reason the infobar cannot be shown | 604 // Do not attach to the target if for any reason the infobar cannot be shown |
595 // for this WebContents instance. | 605 // for this WebContents instance. |
596 infobar = ExtensionDevToolsInfoBarDelegate::Create( | 606 infobar = ExtensionDevToolsInfoBarDelegate::Create( |
597 agent_host_->GetRenderViewHost(), GetExtension()->name()); | 607 agent_host_->GetRenderViewHost(), extension->name()); |
598 if (!infobar) { | 608 if (!infobar) { |
599 error_ = ErrorUtils::FormatErrorMessage( | 609 error_ = ErrorUtils::FormatErrorMessage( |
600 keys::kSilentDebuggingRequired, | 610 keys::kSilentDebuggingRequired, |
601 switches::kSilentDebuggerExtensionAPI); | 611 ::switches::kSilentDebuggerExtensionAPI); |
602 return false; | 612 return false; |
603 } | 613 } |
604 } | 614 } |
605 | 615 |
606 new ExtensionDevToolsClientHost(GetProfile(), | 616 new ExtensionDevToolsClientHost(GetProfile(), |
607 agent_host_.get(), | 617 agent_host_.get(), |
608 GetExtension()->id(), | 618 extension->id(), |
609 GetExtension()->name(), | 619 extension->name(), |
610 debuggee_, | 620 debuggee_, |
611 infobar); | 621 infobar); |
612 SendResponse(true); | 622 SendResponse(true); |
613 return true; | 623 return true; |
614 } | 624 } |
615 | 625 |
616 | 626 |
617 // DebuggerDetachFunction ----------------------------------------------------- | 627 // DebuggerDetachFunction ----------------------------------------------------- |
618 | 628 |
619 DebuggerDetachFunction::DebuggerDetachFunction() { | 629 DebuggerDetachFunction::DebuggerDetachFunction() { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 const std::vector<DevToolsTargetImpl*>& target_list) { | 747 const std::vector<DevToolsTargetImpl*>& target_list) { |
738 scoped_ptr<base::ListValue> result(new base::ListValue()); | 748 scoped_ptr<base::ListValue> result(new base::ListValue()); |
739 for (size_t i = 0; i < target_list.size(); ++i) | 749 for (size_t i = 0; i < target_list.size(); ++i) |
740 result->Append(SerializeTarget(*target_list[i])); | 750 result->Append(SerializeTarget(*target_list[i])); |
741 STLDeleteContainerPointers(target_list.begin(), target_list.end()); | 751 STLDeleteContainerPointers(target_list.begin(), target_list.end()); |
742 SetResult(result.release()); | 752 SetResult(result.release()); |
743 SendResponse(true); | 753 SendResponse(true); |
744 } | 754 } |
745 | 755 |
746 } // namespace extensions | 756 } // namespace extensions |
OLD | NEW |