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 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 5 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "content/public/browser/navigation_details.h" | 8 #include "content/public/browser/navigation_details.h" |
9 #include "content/public/browser/navigation_entry.h" | 9 #include "content/public/browser/navigation_entry.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
11 #include "extensions/browser/extension_registry.h" | 11 #include "extensions/browser/extension_registry.h" |
12 #include "extensions/common/extension_messages.h" | 12 #include "extensions/common/extension_messages.h" |
13 #include "extensions/common/permissions/permission_set.h" | 13 #include "extensions/common/permissions/permission_set.h" |
14 #include "extensions/common/permissions/permissions_data.h" | 14 #include "extensions/common/permissions/permissions_data.h" |
15 #include "extensions/common/user_script.h" | 15 #include "extensions/common/user_script.h" |
| 16 #include "url/gurl.h" |
16 | 17 |
17 using content::RenderProcessHost; | 18 using content::RenderProcessHost; |
18 using content::WebContentsObserver; | 19 using content::WebContentsObserver; |
19 | 20 |
20 namespace extensions { | 21 namespace extensions { |
21 | 22 |
22 ActiveTabPermissionGranter::ActiveTabPermissionGranter( | 23 ActiveTabPermissionGranter::ActiveTabPermissionGranter( |
23 content::WebContents* web_contents, | 24 content::WebContents* web_contents, |
24 int tab_id, | 25 int tab_id, |
25 Profile* profile) | 26 Profile* profile) |
26 : WebContentsObserver(web_contents), | 27 : WebContentsObserver(web_contents), |
27 tab_id_(tab_id), | 28 tab_id_(tab_id), |
28 extension_registry_observer_(this) { | 29 extension_registry_observer_(this) { |
29 extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); | 30 extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); |
30 } | 31 } |
31 | 32 |
32 ActiveTabPermissionGranter::~ActiveTabPermissionGranter() {} | 33 ActiveTabPermissionGranter::~ActiveTabPermissionGranter() {} |
33 | 34 |
34 void ActiveTabPermissionGranter::GrantIfRequested(const Extension* extension) { | 35 void ActiveTabPermissionGranter::GrantIfRequested(const Extension* extension) { |
35 // Active tab grant request implies there was a user gesture. | 36 // Active tab grant request implies there was a user gesture. |
36 web_contents()->UserGestureDone(); | 37 web_contents()->UserGestureDone(); |
37 | 38 |
38 if (granted_extensions_.Contains(extension->id())) | 39 if (granted_extensions_.Contains(extension->id())) |
39 return; | 40 return; |
40 | 41 |
41 APIPermissionSet new_apis; | 42 APIPermissionSet new_apis; |
42 URLPatternSet new_hosts; | 43 URLPatternSet new_hosts; |
43 | 44 |
44 if (extension->HasAPIPermission(APIPermission::kActiveTab)) { | 45 // If the extension requires action for script execution, we grant it |
| 46 // active tab-style permissions, even if it doesn't have the activeTab |
| 47 // permission in the manifest. |
| 48 // We don't take tab id into account, because we want to know if the extension |
| 49 // should require active tab in general (not for the current tab). |
| 50 bool requires_action_for_script_execution = |
| 51 PermissionsData::RequiresActionForScriptExecution( |
| 52 extension, |
| 53 -1, // No tab id. |
| 54 GURL::EmptyGURL()); |
| 55 |
| 56 if (extension->HasAPIPermission(APIPermission::kActiveTab) || |
| 57 requires_action_for_script_execution) { |
45 URLPattern pattern(UserScript::ValidUserScriptSchemes()); | 58 URLPattern pattern(UserScript::ValidUserScriptSchemes()); |
46 // Pattern parsing could fail if this is an unsupported URL e.g. chrome://. | 59 // Pattern parsing could fail if this is an unsupported URL e.g. chrome://. |
47 if (pattern.Parse(web_contents()->GetURL().spec()) == | 60 if (pattern.Parse(web_contents()->GetURL().spec()) == |
48 URLPattern::PARSE_SUCCESS) { | 61 URLPattern::PARSE_SUCCESS) { |
49 new_hosts.AddPattern(pattern); | 62 new_hosts.AddPattern(pattern); |
50 } | 63 } |
51 new_apis.insert(APIPermission::kTab); | 64 new_apis.insert(APIPermission::kTab); |
52 } | 65 } |
53 | 66 |
54 if (extension->HasAPIPermission(APIPermission::kTabCapture)) | 67 if (extension->HasAPIPermission(APIPermission::kTabCapture)) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 it != granted_extensions_.end(); ++it) { | 119 it != granted_extensions_.end(); ++it) { |
107 PermissionsData::ClearTabSpecificPermissions(it->get(), tab_id_); | 120 PermissionsData::ClearTabSpecificPermissions(it->get(), tab_id_); |
108 extension_ids.push_back((*it)->id()); | 121 extension_ids.push_back((*it)->id()); |
109 } | 122 } |
110 | 123 |
111 Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids)); | 124 Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids)); |
112 granted_extensions_.Clear(); | 125 granted_extensions_.Clear(); |
113 } | 126 } |
114 | 127 |
115 } // namespace extensions | 128 } // namespace extensions |
OLD | NEW |