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/permissions_updater.h" | 5 #include "chrome/browser/extensions/permissions_updater.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 | 29 |
30 using content::RenderProcessHost; | 30 using content::RenderProcessHost; |
31 using extensions::permissions_api_helpers::PackPermissionSet; | 31 using extensions::permissions_api_helpers::PackPermissionSet; |
32 | 32 |
33 namespace extensions { | 33 namespace extensions { |
34 | 34 |
35 namespace permissions = api::permissions; | 35 namespace permissions = api::permissions; |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 URLPatternSet FilterSingleOriginPermissions(const URLPatternSet& permissions) { | |
Devlin
2014/08/13 16:55:04
Comment on the function
gpdavis
2014/08/13 22:18:36
Done.
| |
40 URLPatternSet single_origin_permissions; | |
41 for (URLPatternSet::const_iterator iter = permissions.begin(); | |
42 iter != permissions.end(); | |
43 ++iter) { | |
44 if (iter->MatchesSingleOrigin()) | |
not at google - send to devlin
2014/08/13 17:17:47
I just realised (after chatting to mek@) that this
gpdavis
2014/08/13 22:18:37
Alright, this makes sense to me. Can you think of
| |
45 single_origin_permissions.AddPattern(*iter); | |
46 } | |
47 return single_origin_permissions; | |
48 } | |
49 | |
39 // Returns a PermissionSet that has the active permissions of the extension, | 50 // Returns a PermissionSet that has the active permissions of the extension, |
40 // bounded to its current manifest. | 51 // bounded to its current manifest. |
41 scoped_refptr<const PermissionSet> GetBoundedActivePermissions( | 52 scoped_refptr<const PermissionSet> GetBoundedActivePermissions( |
42 const Extension* extension, ExtensionPrefs* extension_prefs) { | 53 const Extension* extension, |
54 const PermissionSet* active_permissions) { | |
43 // If the extension has used the optional permissions API, it will have a | 55 // If the extension has used the optional permissions API, it will have a |
44 // custom set of active permissions defined in the extension prefs. Here, | 56 // custom set of active permissions defined in the extension prefs. Here, |
45 // we update the extension's active permissions based on the prefs. | 57 // we update the extension's active permissions based on the prefs. |
46 scoped_refptr<const PermissionSet> active_permissions = | |
47 extension_prefs->GetActivePermissions(extension->id()); | |
Devlin
2014/08/13 16:55:04
any particular reason for the change?
gpdavis
2014/08/13 22:18:36
Kalman suggested we pass active permissions in ins
| |
48 if (!active_permissions) | 58 if (!active_permissions) |
49 return extension->permissions_data()->active_permissions(); | 59 return extension->permissions_data()->active_permissions(); |
50 | 60 |
51 scoped_refptr<const PermissionSet> required_permissions = | 61 scoped_refptr<const PermissionSet> required_permissions = |
52 PermissionsParser::GetRequiredPermissions(extension); | 62 PermissionsParser::GetRequiredPermissions(extension); |
53 | 63 |
54 // We restrict the active permissions to be within the bounds defined in the | 64 // We restrict the active permissions to be within the bounds defined in the |
55 // extension's manifest. | 65 // extension's manifest. |
56 // a) active permissions must be a subset of optional + default permissions | 66 // a) active permissions must be a subset of optional + default permissions |
57 // b) active permissions must contains all default permissions | 67 // b) active permissions must contains all default permissions |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 if (!Manifest::IsUnpackedLocation(extension->location()) && | 147 if (!Manifest::IsUnpackedLocation(extension->location()) && |
138 extension->location() != Manifest::INTERNAL) | 148 extension->location() != Manifest::INTERNAL) |
139 return; | 149 return; |
140 | 150 |
141 ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions( | 151 ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions( |
142 extension->id(), | 152 extension->id(), |
143 extension->permissions_data()->active_permissions().get()); | 153 extension->permissions_data()->active_permissions().get()); |
144 } | 154 } |
145 | 155 |
146 void PermissionsUpdater::InitializePermissions(const Extension* extension) { | 156 void PermissionsUpdater::InitializePermissions(const Extension* extension) { |
157 scoped_refptr<const PermissionSet> active_permissions = | |
158 ExtensionPrefs::Get(browser_context_) | |
159 ->GetActivePermissions(extension->id()); | |
147 scoped_refptr<const PermissionSet> bounded_active = | 160 scoped_refptr<const PermissionSet> bounded_active = |
148 GetBoundedActivePermissions(extension, | 161 GetBoundedActivePermissions(extension, active_permissions.get()); |
149 ExtensionPrefs::Get(browser_context_)); | |
150 | 162 |
151 // We withhold permissions iff the switch to do so is enabled, the extension | 163 // We withhold permissions iff the switch to do so is enabled, the extension |
152 // shows up in chrome:extensions (so the user can grant withheld permissions), | 164 // shows up in chrome:extensions (so the user can grant withheld permissions), |
153 // the extension is not part of chrome or corporate policy, and also not on | 165 // the extension is not part of chrome or corporate policy, and also not on |
154 // the scripting whitelist. Additionally, we don't withhold if the extension | 166 // the scripting whitelist. Additionally, we don't withhold if the extension |
155 // has the preference to allow scripting on all urls. | 167 // has the preference to allow scripting on all urls. |
156 bool should_withhold_permissions = | 168 bool should_withhold_permissions = |
157 FeatureSwitch::scripts_require_action()->IsEnabled() && | 169 FeatureSwitch::scripts_require_action()->IsEnabled() && |
158 extension->ShouldDisplayInExtensionSettings() && | 170 extension->ShouldDisplayInExtensionSettings() && |
159 !Manifest::IsPolicyLocation(extension->location()) && | 171 !Manifest::IsPolicyLocation(extension->location()) && |
160 !Manifest::IsComponentLocation(extension->location()) && | 172 !Manifest::IsComponentLocation(extension->location()) && |
161 !PermissionsData::CanExecuteScriptEverywhere(extension) && | 173 !PermissionsData::CanExecuteScriptEverywhere(extension) && |
162 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); | 174 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); |
163 | 175 |
164 URLPatternSet granted_explicit_hosts; | 176 URLPatternSet granted_explicit_hosts; |
165 URLPatternSet withheld_explicit_hosts; | 177 URLPatternSet withheld_explicit_hosts; |
166 SegregateUrlPermissions(bounded_active->explicit_hosts(), | 178 SegregateUrlPermissions(bounded_active->explicit_hosts(), |
167 should_withhold_permissions, | 179 should_withhold_permissions, |
168 &granted_explicit_hosts, | 180 &granted_explicit_hosts, |
169 &withheld_explicit_hosts); | 181 &withheld_explicit_hosts); |
170 | 182 |
171 URLPatternSet granted_scriptable_hosts; | 183 URLPatternSet granted_scriptable_hosts; |
172 URLPatternSet withheld_scriptable_hosts; | 184 URLPatternSet withheld_scriptable_hosts; |
173 SegregateUrlPermissions(bounded_active->scriptable_hosts(), | 185 SegregateUrlPermissions(bounded_active->scriptable_hosts(), |
174 should_withhold_permissions, | 186 should_withhold_permissions, |
175 &granted_scriptable_hosts, | 187 &granted_scriptable_hosts, |
176 &withheld_scriptable_hosts); | 188 &withheld_scriptable_hosts); |
177 | 189 |
190 // After withholding permissions, add back any origins to the active set that | |
191 // may have been lost during the set operations that would have dropped them. | |
192 // For example, the union of <all_urls> and <anything> is <all_urls>, so we | |
Devlin
2014/08/13 16:55:04
anything is bad. Use example.com or something.
gpdavis
2014/08/13 22:18:36
Done.
| |
193 // may lose the <anything>. However, that <anything> is important once | |
194 // <all_urls> is stripped during withholding. | |
195 if (active_permissions) { | |
196 granted_explicit_hosts.AddPatterns( | |
Devlin
2014/08/13 16:55:04
You need to check here that the extension still wa
gpdavis
2014/08/13 22:18:36
Is this what kalman was suggesting in the above co
| |
197 FilterSingleOriginPermissions(active_permissions->explicit_hosts())); | |
198 granted_scriptable_hosts.AddPatterns( | |
199 FilterSingleOriginPermissions(active_permissions->scriptable_hosts())); | |
200 } | |
201 | |
178 bounded_active = new PermissionSet(bounded_active->apis(), | 202 bounded_active = new PermissionSet(bounded_active->apis(), |
179 bounded_active->manifest_permissions(), | 203 bounded_active->manifest_permissions(), |
180 granted_explicit_hosts, | 204 granted_explicit_hosts, |
181 granted_scriptable_hosts); | 205 granted_scriptable_hosts); |
182 | 206 |
183 scoped_refptr<const PermissionSet> withheld = | 207 scoped_refptr<const PermissionSet> withheld = |
184 new PermissionSet(APIPermissionSet(), | 208 new PermissionSet(APIPermissionSet(), |
185 ManifestPermissionSet(), | 209 ManifestPermissionSet(), |
186 withheld_explicit_hosts, | 210 withheld_explicit_hosts, |
187 withheld_scriptable_hosts); | 211 withheld_scriptable_hosts); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 Profile::FromBrowserContext(host->GetBrowserContext()))) { | 345 Profile::FromBrowserContext(host->GetBrowserContext()))) { |
322 host->Send(new ExtensionMsg_UpdatePermissions(params)); | 346 host->Send(new ExtensionMsg_UpdatePermissions(params)); |
323 } | 347 } |
324 } | 348 } |
325 | 349 |
326 // Trigger the onAdded and onRemoved events in the extension. | 350 // Trigger the onAdded and onRemoved events in the extension. |
327 DispatchEvent(extension->id(), event_name, changed); | 351 DispatchEvent(extension->id(), event_name, changed); |
328 } | 352 } |
329 | 353 |
330 } // namespace extensions | 354 } // namespace extensions |
OLD | NEW |