Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Unified Diff: chrome/browser/extensions/api/debugger/debugger_api.cc

Issue 352523003: Have the Debugger extension api check that it has access to the tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/debugger/debugger_api.cc
diff --git a/chrome/browser/extensions/api/debugger/debugger_api.cc b/chrome/browser/extensions/api/debugger/debugger_api.cc
index ebbc10207223aa9f07f5fed2ca7ee92480921f65..6576c0a31050d95d21fc9d71aecc111444d84f64 100644
--- a/chrome/browser/extensions/api/debugger/debugger_api.cc
+++ b/chrome/browser/extensions/api/debugger/debugger_api.cc
@@ -47,8 +47,11 @@
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/extension_system.h"
+#include "extensions/common/constants.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h"
+#include "extensions/common/permissions/permissions_data.h"
+#include "extensions/common/switches.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
@@ -300,6 +303,15 @@ ExtensionDevToolsClientHost* AttachedClientHosts::Lookup(
return NULL;
}
+// Returns true if the given |extension| is allowed to run the debugger on
+// other extensions' pages.
+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...
+ 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.
+ extension) ||
+ base::CommandLine::ForCurrentProcess()->HasSwitch(
+ 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
+}
+
} // namespace
@@ -503,6 +515,7 @@ void DebuggerFunction::FormatErrorMessage(const std::string& format) {
}
bool DebuggerFunction::InitAgentHost() {
+ const Extension* extension = GetExtension();
if (debuggee_.tab_id) {
WebContents* web_contents = NULL;
bool result = ExtensionTabUtil::GetTabById(*debuggee_.tab_id,
@@ -513,15 +526,26 @@ bool DebuggerFunction::InitAgentHost() {
&web_contents,
NULL);
if (result && web_contents) {
- if (content::HasWebUIScheme(web_contents->GetURL())) {
+ 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
+ if (content::HasWebUIScheme(url)) {
error_ = ErrorUtils::FormatErrorMessage(
keys::kAttachToWebUIError,
web_contents->GetURL().scheme());
return false;
}
+ if (url.SchemeIs(kExtensionScheme) && url.host() != extension->id() &&
+ !CanRunOnOtherExtensionPages(extension)) {
+ error_ = keys::kAttachToOtherExtensionError;
+ return false;
+ }
agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents);
}
} else if (debuggee_.extension_id) {
+ if (*debuggee_.extension_id != extension->id() &&
+ !CanRunOnOtherExtensionPages(extension)) {
+ error_ = keys::kAttachToOtherExtensionError;
+ return false;
+ }
ExtensionHost* extension_host =
ExtensionSystem::Get(GetProfile())
->process_manager()
@@ -588,25 +612,26 @@ bool DebuggerAttachFunction::RunAsync() {
return false;
}
+ const Extension* extension = GetExtension();
infobars::InfoBar* infobar = NULL;
if (!CommandLine::ForCurrentProcess()->
- HasSwitch(switches::kSilentDebuggerExtensionAPI)) {
+ 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
// Do not attach to the target if for any reason the infobar cannot be shown
// for this WebContents instance.
infobar = ExtensionDevToolsInfoBarDelegate::Create(
- agent_host_->GetRenderViewHost(), GetExtension()->name());
+ agent_host_->GetRenderViewHost(), extension->name());
if (!infobar) {
error_ = ErrorUtils::FormatErrorMessage(
keys::kSilentDebuggingRequired,
- switches::kSilentDebuggerExtensionAPI);
+ ::switches::kSilentDebuggerExtensionAPI);
return false;
}
}
new ExtensionDevToolsClientHost(GetProfile(),
agent_host_.get(),
- GetExtension()->id(),
- GetExtension()->name(),
+ extension->id(),
+ extension->name(),
debuggee_,
infobar);
SendResponse(true);

Powered by Google App Engine
This is Rietveld 408576698