Chromium Code Reviews| Index: chrome/browser/extensions/active_tab_permission_granter.cc |
| diff --git a/chrome/browser/extensions/active_tab_permission_granter.cc b/chrome/browser/extensions/active_tab_permission_granter.cc |
| index a62b18124f3604e59cdd18e6529aed2360c23efc..606d290ff8614616493101d69baf36722c1240d7 100644 |
| --- a/chrome/browser/extensions/active_tab_permission_granter.cc |
| +++ b/chrome/browser/extensions/active_tab_permission_granter.cc |
| @@ -37,40 +37,42 @@ ActiveTabPermissionGranter::ActiveTabPermissionGranter( |
| ActiveTabPermissionGranter::~ActiveTabPermissionGranter() {} |
| void ActiveTabPermissionGranter::GrantIfRequested(const Extension* extension) { |
| - if (!extension->HasAPIPermission(extensions::APIPermission::kActiveTab) && |
| - !extension->HasAPIPermission(extensions::APIPermission::kTabCapture)) { |
| + if (!extension->HasAPIPermission(APIPermission::kActiveTab) && |
| + !extension->HasAPIPermission(APIPermission::kTabCapture)) { |
| return; |
| } |
| - if (IsGranted(extension)) |
| + if (granted_extensions_.Contains(extension->id())) |
| return; |
| - URLPattern pattern(UserScript::ValidUserScriptSchemes()); |
| - if (pattern.Parse(web_contents()->GetURL().spec()) != |
| - URLPattern::PARSE_SUCCESS) { |
| - // Pattern parsing could fail if this is an unsupported URL e.g. chrome://. |
| - return; |
| - } |
| - |
| APIPermissionSet new_apis; |
| - new_apis.insert(APIPermission::kTab); |
| URLPatternSet new_hosts; |
| - new_hosts.AddPattern(pattern); |
| - scoped_refptr<const PermissionSet> new_permissions = |
| - new PermissionSet(new_apis, new_hosts, URLPatternSet()); |
| - |
| - PermissionsData::UpdateTabSpecificPermissions(extension, |
| - tab_id_, |
| - new_permissions); |
| - granted_extensions_.Insert(extension); |
| - Send(new ExtensionMsg_UpdateTabSpecificPermissions(GetPageID(), |
| - tab_id_, |
| - extension->id(), |
| - new_hosts)); |
| -} |
| -bool ActiveTabPermissionGranter::IsGranted(const Extension* extension) { |
| - return granted_extensions_.Contains(extension->id()); |
| + if (extension->HasAPIPermission(APIPermission::kActiveTab)) { |
| + URLPattern pattern(UserScript::ValidUserScriptSchemes()); |
| + // Pattern parsing could fail if this is an unsupported URL e.g. chrome://. |
| + if (pattern.Parse(web_contents()->GetURL().spec()) == |
| + URLPattern::PARSE_SUCCESS) { |
| + new_hosts.AddPattern(pattern); |
| + new_apis.insert(APIPermission::kTab); |
|
not at google - send to devlin
2013/09/13 22:09:45
for consistency with tabCapture I think add this p
justinlin
2013/09/13 22:47:15
OK, I'll do this separately. I'm not really sure w
not at google - send to devlin
2013/09/13 22:48:52
It would mean that extensions could read the title
|
| + granted_extensions_.Insert(extension); |
| + } |
| + } |
| + |
| + if (extension->HasAPIPermission(APIPermission::kTabCapture)) |
| + new_apis.insert(APIPermission::kTabCaptureForTab); |
| + |
| + if (!new_apis.empty()) { |
| + scoped_refptr<const PermissionSet> new_permissions = |
| + new PermissionSet(new_apis, new_hosts, URLPatternSet()); |
| + PermissionsData::UpdateTabSpecificPermissions(extension, |
| + tab_id_, |
| + new_permissions); |
| + Send(new ExtensionMsg_UpdateTabSpecificPermissions(GetPageID(), |
| + tab_id_, |
| + extension->id(), |
| + new_hosts)); |
| + } |
| } |
| void ActiveTabPermissionGranter::DidNavigateMainFrame( |
| @@ -119,4 +121,14 @@ int32 ActiveTabPermissionGranter::GetPageID() { |
| return web_contents()->GetController().GetVisibleEntry()->GetPageID(); |
| } |
| +// static |
| +bool ActiveTabPermissionGranter::IsGrantedForTab( |
| + const Extension* extension, |
| + const content::WebContents* web_contents) { |
| + return PermissionsData::HasAPIPermissionForTab( |
| + extension, |
| + SessionID::IdForTab(web_contents), |
| + APIPermission::kTab); |
|
not at google - send to devlin
2013/09/13 22:09:45
can you just write this check specifically whereve
justinlin
2013/09/13 22:47:15
Done.
|
| +} |
| + |
| } // namespace extensions |