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

Unified Diff: extensions/common/permissions/permissions_data.cc

Issue 321533003: Separate PermissionsData::CanExecuteScriptOnPage into two functions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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: extensions/common/permissions/permissions_data.cc
diff --git a/extensions/common/permissions/permissions_data.cc b/extensions/common/permissions/permissions_data.cc
index a6248260468da42a105096b639d9949b51d122fc..72717f7617d493ac2c9955155082def54ae0e951 100644
--- a/extensions/common/permissions/permissions_data.cc
+++ b/extensions/common/permissions/permissions_data.cc
@@ -161,69 +161,34 @@ PermissionsData::GetPermissionMessageDetailsStrings() const {
active_permissions(), manifest_type_);
}
-bool PermissionsData::CanExecuteScriptOnPage(const Extension* extension,
- const GURL& document_url,
- const GURL& top_frame_url,
- int tab_id,
- const UserScript* script,
- int process_id,
- std::string* error) const {
- if (g_policy_delegate &&
- !g_policy_delegate->CanExecuteScriptOnPage(extension,
- document_url,
- top_frame_url,
- tab_id,
- script,
- process_id,
- error)) {
- return false;
- }
-
- bool can_execute_everywhere = CanExecuteScriptEverywhere(extension);
- if (!can_execute_everywhere &&
- !ExtensionsClient::Get()->IsScriptableURL(document_url, error)) {
- return false;
- }
-
- if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kExtensionsOnChromeURLs)) {
- if (document_url.SchemeIs(content::kChromeUIScheme) &&
- !can_execute_everywhere) {
- if (error)
- *error = manifest_errors::kCannotAccessChromeUrl;
- return false;
- }
- }
-
- if (top_frame_url.SchemeIs(kExtensionScheme) &&
- top_frame_url.GetOrigin() !=
- Extension::GetBaseURLFromExtensionId(extension->id()).GetOrigin() &&
- !can_execute_everywhere) {
- if (error)
- *error = manifest_errors::kCannotAccessExtensionUrl;
- return false;
- }
-
- if (HasTabSpecificPermissionToExecuteScript(tab_id, top_frame_url))
- return true;
-
- bool can_access = false;
-
- if (script) {
- // If a script is specified, use its matches.
- can_access = script->MatchesURL(document_url);
- } else {
- // Otherwise, see if this extension has permission to execute script
- // programmatically on pages.
- can_access = active_permissions()->HasExplicitAccessToOrigin(document_url);
- }
-
- if (!can_access && error) {
- *error = ErrorUtils::FormatErrorMessage(manifest_errors::kCannotAccessPage,
- document_url.spec());
- }
+bool PermissionsData::CanAccessPage(const Extension* extension,
+ const GURL& document_url,
+ const GURL& top_frame_url,
+ int tab_id,
+ int process_id,
+ std::string* error) const {
+ return CanRunOnPage(extension,
+ document_url,
+ top_frame_url,
+ tab_id,
+ process_id,
+ active_permissions()->explicit_hosts(),
+ error);
+}
- return can_access;
+bool PermissionsData::CanRunContentScriptOnPage(const Extension* extension,
+ const GURL& document_url,
+ const GURL& top_frame_url,
+ int tab_id,
+ int process_id,
+ std::string* error) const {
+ return CanRunOnPage(extension,
+ document_url,
+ top_frame_url,
+ tab_id,
+ process_id,
+ active_permissions()->scriptable_hosts(),
+ error);
}
bool PermissionsData::CanCaptureVisiblePage(int tab_id,
@@ -305,4 +270,55 @@ bool PermissionsData::HasTabSpecificPermissionToExecuteScript(
return false;
}
+bool PermissionsData::CanRunOnPage(const Extension* extension,
+ const GURL& document_url,
+ const GURL& top_frame_url,
+ int tab_id,
+ int process_id,
+ const URLPatternSet& permitted_url_patterns,
+ std::string* error) const {
+ if (g_policy_delegate &&
+ !g_policy_delegate->CanExecuteScriptOnPage(
+ extension, document_url, top_frame_url, tab_id, process_id, error)) {
+ return false;
+ }
+
+ bool can_execute_everywhere = CanExecuteScriptEverywhere(extension);
+ if (!can_execute_everywhere &&
+ !ExtensionsClient::Get()->IsScriptableURL(document_url, error)) {
+ return false;
+ }
+
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kExtensionsOnChromeURLs)) {
+ if (document_url.SchemeIs(content::kChromeUIScheme) &&
+ !can_execute_everywhere) {
+ if (error)
+ *error = manifest_errors::kCannotAccessChromeUrl;
+ return false;
+ }
+ }
+
+ if (top_frame_url.SchemeIs(kExtensionScheme) &&
+ top_frame_url.GetOrigin() !=
+ Extension::GetBaseURLFromExtensionId(extension->id()).GetOrigin() &&
+ !can_execute_everywhere) {
+ if (error)
+ *error = manifest_errors::kCannotAccessExtensionUrl;
+ return false;
+ }
+
+ if (HasTabSpecificPermissionToExecuteScript(tab_id, top_frame_url))
+ return true;
+
+ bool can_access = permitted_url_patterns.MatchesURL(document_url);
+
+ if (!can_access && error) {
+ *error = ErrorUtils::FormatErrorMessage(manifest_errors::kCannotAccessPage,
+ document_url.spec());
+ }
+
+ return can_access;
+}
+
} // namespace extensions
« no previous file with comments | « extensions/common/permissions/permissions_data.h ('k') | extensions/common/permissions/permissions_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698