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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 PermissionsParser::GetOptionalPermissions(extension)); | 60 PermissionsParser::GetOptionalPermissions(extension)); |
61 | 61 |
62 // Make sure the active permissions contain no more than optional + default. | 62 // Make sure the active permissions contain no more than optional + default. |
63 scoped_refptr<PermissionSet> adjusted_active = | 63 scoped_refptr<PermissionSet> adjusted_active = |
64 PermissionSet::CreateIntersection(total_permissions, active_permissions); | 64 PermissionSet::CreateIntersection(total_permissions, active_permissions); |
65 | 65 |
66 // Make sure the active permissions contain the default permissions. | 66 // Make sure the active permissions contain the default permissions. |
67 adjusted_active = | 67 adjusted_active = |
68 PermissionSet::CreateUnion(required_permissions, adjusted_active); | 68 PermissionSet::CreateUnion(required_permissions, adjusted_active); |
69 | 69 |
| 70 // Re-add any active permissions that only match a single origin in order |
| 71 // to persist "always run" script injection hosts. |
| 72 URLPatternSet single_origin_explicit; |
| 73 URLPatternSet single_origin_scriptable; |
| 74 for (URLPatternSet::const_iterator iter = |
| 75 active_permissions->explicit_hosts().begin(); |
| 76 iter != active_permissions->explicit_hosts().end(); |
| 77 ++iter) { |
| 78 if (iter->MatchesSingleOrigin()) |
| 79 single_origin_explicit.AddPattern(*iter); |
| 80 } |
| 81 for (URLPatternSet::const_iterator iter = |
| 82 active_permissions->scriptable_hosts().begin(); |
| 83 iter != active_permissions->scriptable_hosts().end(); |
| 84 ++iter) { |
| 85 if (iter->MatchesSingleOrigin()) |
| 86 single_origin_scriptable.AddPattern(*iter); |
| 87 } |
| 88 |
| 89 adjusted_active = PermissionSet::CreateUnion( |
| 90 adjusted_active, |
| 91 new PermissionSet(APIPermissionSet(), |
| 92 ManifestPermissionSet(), |
| 93 single_origin_explicit, |
| 94 single_origin_scriptable)); |
| 95 |
70 return adjusted_active; | 96 return adjusted_active; |
71 } | 97 } |
72 | 98 |
73 // Divvy up the |url patterns| between those we grant and those we do not. If | 99 // 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 | 100 // |withhold_permissions| is false (because the requisite feature is not |
75 // enabled), no permissions are withheld. | 101 // enabled), no permissions are withheld. |
76 void SegregateUrlPermissions(const URLPatternSet& url_patterns, | 102 void SegregateUrlPermissions(const URLPatternSet& url_patterns, |
77 bool withhold_permissions, | 103 bool withhold_permissions, |
78 URLPatternSet* granted, | 104 URLPatternSet* granted, |
79 URLPatternSet* withheld) { | 105 URLPatternSet* withheld) { |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 Profile::FromBrowserContext(host->GetBrowserContext()))) { | 347 Profile::FromBrowserContext(host->GetBrowserContext()))) { |
322 host->Send(new ExtensionMsg_UpdatePermissions(params)); | 348 host->Send(new ExtensionMsg_UpdatePermissions(params)); |
323 } | 349 } |
324 } | 350 } |
325 | 351 |
326 // Trigger the onAdded and onRemoved events in the extension. | 352 // Trigger the onAdded and onRemoved events in the extension. |
327 DispatchEvent(extension->id(), event_name, changed); | 353 DispatchEvent(extension->id(), event_name, changed); |
328 } | 354 } |
329 | 355 |
330 } // namespace extensions | 356 } // namespace extensions |
OLD | NEW |