| Index: extensions/common/permissions/permissions_data.cc
|
| diff --git a/extensions/common/permissions/permissions_data.cc b/extensions/common/permissions/permissions_data.cc
|
| index 65359d9950954bd8496fa38b5d6b1dfff2da1c5f..0f20bc21585690f37f13b759fe1fe25c921bb797 100644
|
| --- a/extensions/common/permissions/permissions_data.cc
|
| +++ b/extensions/common/permissions/permissions_data.cc
|
| @@ -342,6 +342,21 @@ void PermissionsData::ClearTabSpecificPermissions(
|
| }
|
|
|
| // static
|
| +bool PermissionsData::HasTabSpecificScriptPermission(const Extension* extension,
|
| + int tab_id,
|
| + const GURL& url) {
|
| + if (tab_id >= 0) {
|
| + scoped_refptr<const PermissionSet> tab_permissions =
|
| + GetTabSpecificPermissions(extension, tab_id);
|
| + if (tab_permissions.get() &&
|
| + tab_permissions->explicit_hosts().MatchesSecurityOrigin(url)) {
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +// static
|
| bool PermissionsData::HasAPIPermission(const Extension* extension,
|
| APIPermission::ID permission) {
|
| base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_);
|
| @@ -414,6 +429,12 @@ bool PermissionsData::HasEffectiveAccessToAllHosts(const Extension* extension) {
|
| }
|
|
|
| // static
|
| +bool PermissionsData::ShouldWarnAllHosts(const Extension* extension) {
|
| + base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_);
|
| + return GetActivePermissions(extension)->ShouldWarnAllHosts();
|
| +}
|
| +
|
| +// static
|
| PermissionMessages PermissionsData::GetPermissionMessages(
|
| const Extension* extension) {
|
| base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_);
|
| @@ -490,15 +511,8 @@ bool PermissionsData::CanExecuteScriptOnPage(const Extension* extension,
|
| return false;
|
| }
|
|
|
| - // If a tab ID is specified, try the tab-specific permissions.
|
| - if (tab_id >= 0) {
|
| - scoped_refptr<const PermissionSet> tab_permissions =
|
| - GetTabSpecificPermissions(extension, tab_id);
|
| - if (tab_permissions.get() &&
|
| - tab_permissions->explicit_hosts().MatchesSecurityOrigin(document_url)) {
|
| - return true;
|
| - }
|
| - }
|
| + if (HasTabSpecificScriptPermission(extension, tab_id, top_frame_url))
|
| + return true;
|
|
|
| bool can_access = false;
|
|
|
| @@ -562,14 +576,26 @@ bool PermissionsData::CanCaptureVisiblePage(const Extension* extension,
|
|
|
| // static
|
| bool PermissionsData::RequiresActionForScriptExecution(
|
| - const Extension* extension) {
|
| + const Extension* extension,
|
| + int tab_id,
|
| + const GURL& url) {
|
| // For now, the user should be notified when an extension with all hosts
|
| - // permission tries to execute a script on a page. Exceptions for policy-
|
| - // enabled and component extensions.
|
| - return extension->ShouldDisplayInExtensionSettings() &&
|
| - !Manifest::IsPolicyLocation(extension->location()) &&
|
| - !Manifest::IsComponentLocation(extension->location()) &&
|
| - HasEffectiveAccessToAllHosts(extension);
|
| + // permission tries to execute a script on a page, with exceptions for policy-
|
| + // enabled and component extensions. If this doesn't meet those criteria,
|
| + // return immediately.
|
| + if (!extension->ShouldDisplayInExtensionSettings() ||
|
| + Manifest::IsPolicyLocation(extension->location()) ||
|
| + Manifest::IsComponentLocation(extension->location()) ||
|
| + !ShouldWarnAllHosts(extension)) {
|
| + return false;
|
| + }
|
| +
|
| + // If the extension has explicit permission to run on the given tab, then
|
| + // we don't need to alert the user.
|
| + if (HasTabSpecificScriptPermission(extension, tab_id, url))
|
| + return false;
|
| +
|
| + return true;
|
| }
|
|
|
| bool PermissionsData::ParsePermissions(Extension* extension,
|
|
|