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/extensions/active_script_controller.h" | 7 #include "chrome/browser/extensions/active_script_controller.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "content/public/browser/navigation_details.h" | 9 #include "content/public/browser/navigation_details.h" |
10 #include "content/public/browser/navigation_entry.h" | 10 #include "content/public/browser/navigation_entry.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 void ActiveTabPermissionGranter::GrantIfRequested(const Extension* extension) { | 36 void ActiveTabPermissionGranter::GrantIfRequested(const Extension* extension) { |
37 // Active tab grant request implies there was a user gesture. | 37 // Active tab grant request implies there was a user gesture. |
38 web_contents()->UserGestureDone(); | 38 web_contents()->UserGestureDone(); |
39 | 39 |
40 if (granted_extensions_.Contains(extension->id())) | 40 if (granted_extensions_.Contains(extension->id())) |
41 return; | 41 return; |
42 | 42 |
43 APIPermissionSet new_apis; | 43 APIPermissionSet new_apis; |
44 URLPatternSet new_hosts; | 44 URLPatternSet new_hosts; |
45 | 45 |
| 46 const PermissionsData* permissions_data = |
| 47 PermissionsData::ForExtension(extension); |
| 48 |
46 // If the extension requires action for script execution, we grant it | 49 // If the extension requires action for script execution, we grant it |
47 // active tab-style permissions, even if it doesn't have the activeTab | 50 // active tab-style permissions, even if it doesn't have the activeTab |
48 // permission in the manifest. | 51 // permission in the manifest. |
49 // We don't take tab id into account, because we want to know if the extension | 52 // We don't take tab id into account, because we want to know if the extension |
50 // should require active tab in general (not for the current tab). | 53 // should require active tab in general (not for the current tab). |
51 bool requires_action_for_script_execution = | 54 bool requires_action_for_script_execution = |
52 PermissionsData::RequiresActionForScriptExecution( | 55 permissions_data->RequiresActionForScriptExecution(extension, |
53 extension, | 56 -1, // No tab id. |
54 -1, // No tab id. | 57 GURL()); |
55 GURL::EmptyGURL()); | |
56 | 58 |
57 if (extension->HasAPIPermission(APIPermission::kActiveTab) || | 59 if (extension->HasAPIPermission(APIPermission::kActiveTab) || |
58 requires_action_for_script_execution) { | 60 requires_action_for_script_execution) { |
59 URLPattern pattern(UserScript::ValidUserScriptSchemes()); | 61 URLPattern pattern(UserScript::ValidUserScriptSchemes()); |
60 // Pattern parsing could fail if this is an unsupported URL e.g. chrome://. | 62 // Pattern parsing could fail if this is an unsupported URL e.g. chrome://. |
61 if (pattern.Parse(web_contents()->GetURL().spec()) == | 63 if (pattern.Parse(web_contents()->GetURL().spec()) == |
62 URLPattern::PARSE_SUCCESS) { | 64 URLPattern::PARSE_SUCCESS) { |
63 new_hosts.AddPattern(pattern); | 65 new_hosts.AddPattern(pattern); |
64 } | 66 } |
65 new_apis.insert(APIPermission::kTab); | 67 new_apis.insert(APIPermission::kTab); |
66 } | 68 } |
67 | 69 |
68 if (extension->HasAPIPermission(APIPermission::kTabCapture)) | 70 if (extension->HasAPIPermission(APIPermission::kTabCapture)) |
69 new_apis.insert(APIPermission::kTabCaptureForTab); | 71 new_apis.insert(APIPermission::kTabCaptureForTab); |
70 | 72 |
71 if (!new_apis.empty() || !new_hosts.is_empty()) { | 73 if (!new_apis.empty() || !new_hosts.is_empty()) { |
72 granted_extensions_.Insert(extension); | 74 granted_extensions_.Insert(extension); |
73 scoped_refptr<const PermissionSet> new_permissions = | 75 scoped_refptr<const PermissionSet> new_permissions = |
74 new PermissionSet(new_apis, ManifestPermissionSet(), | 76 new PermissionSet(new_apis, ManifestPermissionSet(), |
75 new_hosts, URLPatternSet()); | 77 new_hosts, URLPatternSet()); |
76 PermissionsData::UpdateTabSpecificPermissions(extension, | 78 permissions_data->UpdateTabSpecificPermissions(tab_id_, new_permissions); |
77 tab_id_, | |
78 new_permissions); | |
79 const content::NavigationEntry* navigation_entry = | 79 const content::NavigationEntry* navigation_entry = |
80 web_contents()->GetController().GetVisibleEntry(); | 80 web_contents()->GetController().GetVisibleEntry(); |
81 if (navigation_entry) { | 81 if (navigation_entry) { |
82 Send(new ExtensionMsg_UpdateTabSpecificPermissions( | 82 Send(new ExtensionMsg_UpdateTabSpecificPermissions( |
83 navigation_entry->GetPageID(), | 83 navigation_entry->GetPageID(), |
84 tab_id_, | 84 tab_id_, |
85 extension->id(), | 85 extension->id(), |
86 new_hosts)); | 86 new_hosts)); |
87 // If more things ever need to know about this, we should consider making | 87 // If more things ever need to know about this, we should consider making |
88 // an observer class. | 88 // an observer class. |
(...skipping 29 matching lines...) Expand all Loading... |
118 } | 118 } |
119 | 119 |
120 void ActiveTabPermissionGranter::ClearActiveExtensionsAndNotify() { | 120 void ActiveTabPermissionGranter::ClearActiveExtensionsAndNotify() { |
121 if (granted_extensions_.is_empty()) | 121 if (granted_extensions_.is_empty()) |
122 return; | 122 return; |
123 | 123 |
124 std::vector<std::string> extension_ids; | 124 std::vector<std::string> extension_ids; |
125 | 125 |
126 for (ExtensionSet::const_iterator it = granted_extensions_.begin(); | 126 for (ExtensionSet::const_iterator it = granted_extensions_.begin(); |
127 it != granted_extensions_.end(); ++it) { | 127 it != granted_extensions_.end(); ++it) { |
128 PermissionsData::ClearTabSpecificPermissions(it->get(), tab_id_); | 128 PermissionsData::ForExtension(it->get()) |
| 129 ->ClearTabSpecificPermissions(tab_id_); |
129 extension_ids.push_back((*it)->id()); | 130 extension_ids.push_back((*it)->id()); |
130 } | 131 } |
131 | 132 |
132 Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids)); | 133 Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids)); |
133 granted_extensions_.Clear(); | 134 granted_extensions_.Clear(); |
134 } | 135 } |
135 | 136 |
136 } // namespace extensions | 137 } // namespace extensions |
OLD | NEW |