Chromium Code Reviews| 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(URLPatternSet permissions) { | |
|
not at google - send to devlin
2014/08/12 19:49:27
const URLPatternSet& permissions
gpdavis
2014/08/12 21:19:55
Done.
| |
| 40 URLPatternSet single_origin_permissions; | |
| 41 for (URLPatternSet::const_iterator iter = permissions.begin(); | |
| 42 iter != permissions.end(); | |
| 43 ++iter) { | |
| 44 if (iter->MatchesSingleOrigin()) | |
| 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, ExtensionPrefs* extension_prefs) { |
| 43 // If the extension has used the optional permissions API, it will have a | 54 // 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, | 55 // custom set of active permissions defined in the extension prefs. Here, |
| 45 // we update the extension's active permissions based on the prefs. | 56 // we update the extension's active permissions based on the prefs. |
| 46 scoped_refptr<const PermissionSet> active_permissions = | 57 scoped_refptr<const PermissionSet> active_permissions = |
| 47 extension_prefs->GetActivePermissions(extension->id()); | 58 extension_prefs->GetActivePermissions(extension->id()); |
| 48 if (!active_permissions) | 59 if (!active_permissions) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 60 PermissionsParser::GetOptionalPermissions(extension)); | 71 PermissionsParser::GetOptionalPermissions(extension)); |
| 61 | 72 |
| 62 // Make sure the active permissions contain no more than optional + default. | 73 // Make sure the active permissions contain no more than optional + default. |
| 63 scoped_refptr<PermissionSet> adjusted_active = | 74 scoped_refptr<PermissionSet> adjusted_active = |
| 64 PermissionSet::CreateIntersection(total_permissions, active_permissions); | 75 PermissionSet::CreateIntersection(total_permissions, active_permissions); |
| 65 | 76 |
| 66 // Make sure the active permissions contain the default permissions. | 77 // Make sure the active permissions contain the default permissions. |
| 67 adjusted_active = | 78 adjusted_active = |
| 68 PermissionSet::CreateUnion(required_permissions, adjusted_active); | 79 PermissionSet::CreateUnion(required_permissions, adjusted_active); |
| 69 | 80 |
| 81 // Re-add any active permissions that only match a single origin in order | |
| 82 // to persist "always run" script injection hosts. These permissions get | |
| 83 // filtered out because single origin permissions are not recognized as a | |
| 84 // subset of all-host permissions. | |
| 85 adjusted_active = PermissionSet::CreateUnion( | |
| 86 adjusted_active, | |
| 87 new PermissionSet( | |
| 88 APIPermissionSet(), | |
| 89 ManifestPermissionSet(), | |
| 90 FilterSingleOriginPermissions(active_permissions->explicit_hosts()), | |
| 91 FilterSingleOriginPermissions( | |
| 92 active_permissions->scriptable_hosts()))); | |
| 93 | |
| 70 return adjusted_active; | 94 return adjusted_active; |
| 71 } | 95 } |
| 72 | 96 |
| 73 // Divvy up the |url patterns| between those we grant and those we do not. If | 97 // Divvy up the |url patterns| between those we grant and those we do not. If |
| 74 // |withhold_permissions| is false (because the requisite feature is not | 98 // |withhold_permissions| is false (because the requisite feature is not |
| 75 // enabled), no permissions are withheld. | 99 // enabled), no permissions are withheld. |
| 76 void SegregateUrlPermissions(const URLPatternSet& url_patterns, | 100 void SegregateUrlPermissions(const URLPatternSet& url_patterns, |
| 77 bool withhold_permissions, | 101 bool withhold_permissions, |
| 78 URLPatternSet* granted, | 102 URLPatternSet* granted, |
| 79 URLPatternSet* withheld) { | 103 URLPatternSet* withheld) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 URLPatternSet granted_scriptable_hosts; | 195 URLPatternSet granted_scriptable_hosts; |
| 172 URLPatternSet withheld_scriptable_hosts; | 196 URLPatternSet withheld_scriptable_hosts; |
| 173 SegregateUrlPermissions(bounded_active->scriptable_hosts(), | 197 SegregateUrlPermissions(bounded_active->scriptable_hosts(), |
| 174 should_withhold_permissions, | 198 should_withhold_permissions, |
| 175 &granted_scriptable_hosts, | 199 &granted_scriptable_hosts, |
| 176 &withheld_scriptable_hosts); | 200 &withheld_scriptable_hosts); |
| 177 | 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); |
|
not at google - send to devlin
2014/08/12 19:49:27
I actually think this would be a better place to a
gpdavis
2014/08/12 21:19:55
Done.
| |
| 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); |
| 188 SetPermissions(extension, bounded_active, withheld); | 212 SetPermissions(extension, bounded_active, withheld); |
| 189 } | 213 } |
| 190 | 214 |
| 191 void PermissionsUpdater::WithholdImpliedAllHosts(const Extension* extension) { | 215 void PermissionsUpdater::WithholdImpliedAllHosts(const Extension* extension) { |
| (...skipping 129 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 |