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 #ifndef CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "extensions/browser/extension_event_histogram_value.h" | 12 #include "extensions/browser/extension_event_histogram_value.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 class DictionaryValue; | 15 class DictionaryValue; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 class BrowserContext; | 19 class BrowserContext; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace extensions { | 22 namespace extensions { |
| 23 | 23 |
| 24 class Extension; | 24 class Extension; |
| 25 class ExtensionPrefs; | 25 class ExtensionPrefs; |
| 26 class PermissionSet; | 26 class PermissionSet; |
| 27 class URLPatternSet; | |
| 27 | 28 |
| 28 // Updates an Extension's active and granted permissions in persistent storage | 29 // Updates an Extension's active and granted permissions in persistent storage |
| 29 // and notifies interested parties of the changes. | 30 // and notifies interested parties of the changes. |
| 30 class PermissionsUpdater { | 31 class PermissionsUpdater { |
| 31 public: | 32 public: |
| 32 enum InitFlag { | 33 enum InitFlag { |
| 33 INIT_FLAG_NONE = 0, | 34 INIT_FLAG_NONE = 0, |
| 34 INIT_FLAG_TRANSIENT = 1 << 0, | 35 INIT_FLAG_TRANSIENT = 1 << 0, |
| 35 }; | 36 }; |
| 36 | 37 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 62 void RemovePermissions(const Extension* extension, | 63 void RemovePermissions(const Extension* extension, |
| 63 const PermissionSet& permissions, | 64 const PermissionSet& permissions, |
| 64 RemoveType remove_type); | 65 RemoveType remove_type); |
| 65 | 66 |
| 66 // Removes the |permissions| from |extension| and makes no effort to determine | 67 // Removes the |permissions| from |extension| and makes no effort to determine |
| 67 // if doing so is safe in the slightlest. This method shouldn't be used, | 68 // if doing so is safe in the slightlest. This method shouldn't be used, |
| 68 // except for removing permissions totally blacklisted by management. | 69 // except for removing permissions totally blacklisted by management. |
| 69 void RemovePermissionsUnsafe(const Extension* extension, | 70 void RemovePermissionsUnsafe(const Extension* extension, |
| 70 const PermissionSet& permissions); | 71 const PermissionSet& permissions); |
| 71 | 72 |
| 73 // Sets list of hosts |extension| may not interact with (overrides default). | |
| 74 // This is the individual scope of ExtensionSettings. | |
| 75 void SetPolicyHostRestrictions(const Extension* extension, | |
| 76 const URLPatternSet& runtime_blocked_hosts, | |
| 77 const URLPatternSet& runtime_allowed_hosts, | |
| 78 bool is_default); | |
| 79 | |
| 80 // Sets list of hosts extensions may not interact with. Extension specific | |
| 81 // exceptions to this default policy are defined with | |
| 82 // SetPolicyHostRestrictions. This is the Deault scope "*" of | |
|
Devlin
2017/02/14 23:17:10
I don't follow the last sentence here....
nrpeter
2017/03/22 23:47:39
Removed as it wasn't strictly necessary.
| |
| 83 // ExtensionSettings. | |
| 84 void SetDefaultPolicyHostRestrictions( | |
| 85 const URLPatternSet& default_runtime_blocked_hosts, | |
| 86 const URLPatternSet& default_runtime_allowed_hosts); | |
| 87 | |
| 72 // Returns the set of revokable permissions. | 88 // Returns the set of revokable permissions. |
| 73 std::unique_ptr<const PermissionSet> GetRevokablePermissions( | 89 std::unique_ptr<const PermissionSet> GetRevokablePermissions( |
| 74 const Extension* extension) const; | 90 const Extension* extension) const; |
| 75 | 91 |
| 76 // Adds all permissions in the |extension|'s active permissions to its | 92 // Adds all permissions in the |extension|'s active permissions to its |
| 77 // granted permission set. | 93 // granted permission set. |
| 78 void GrantActivePermissions(const Extension* extension); | 94 void GrantActivePermissions(const Extension* extension); |
| 79 | 95 |
| 80 // Initializes the |extension|'s active permission set to include only | 96 // Initializes the |extension|'s active permission set to include only |
| 81 // permissions currently requested by the extension and all the permissions | 97 // permissions currently requested by the extension and all the permissions |
| 82 // required by the extension. | 98 // required by the extension. |
| 83 void InitializePermissions(const Extension* extension); | 99 void InitializePermissions(const Extension* extension); |
| 84 | 100 |
| 85 private: | 101 private: |
| 86 enum EventType { | 102 enum EventType { |
| 87 ADDED, | 103 ADDED, |
| 88 REMOVED, | 104 REMOVED, |
| 105 POLICY, | |
| 89 }; | 106 }; |
| 90 | 107 |
| 91 // Sets the |extension|'s active permissions to |active| and records the | 108 // Sets the |extension|'s active permissions to |active| and records the |
| 92 // change in the prefs. If |withheld| is non-null, also sets the extension's | 109 // change in the prefs. If |withheld| is non-null, also sets the extension's |
| 93 // withheld permissions to |withheld|. Otherwise, |withheld| permissions are | 110 // withheld permissions to |withheld|. Otherwise, |withheld| permissions are |
| 94 // not changed. | 111 // not changed. |
| 95 void SetPermissions(const Extension* extension, | 112 void SetPermissions(const Extension* extension, |
| 96 std::unique_ptr<const PermissionSet> active, | 113 std::unique_ptr<const PermissionSet> active, |
| 97 std::unique_ptr<const PermissionSet> withheld); | 114 std::unique_ptr<const PermissionSet> withheld); |
| 98 | 115 |
| 99 // Dispatches specified event to the extension. | 116 // Dispatches specified event to the extension. |
| 100 void DispatchEvent(const std::string& extension_id, | 117 void DispatchEvent(const std::string& extension_id, |
| 101 events::HistogramValue histogram_value, | 118 events::HistogramValue histogram_value, |
| 102 const char* event_name, | 119 const char* event_name, |
| 103 const PermissionSet& changed_permissions); | 120 const PermissionSet& changed_permissions); |
| 104 | 121 |
| 105 // Issues the relevant events, messages and notifications when the | 122 // Issues the relevant events, messages and notifications when the |
| 106 // |extension|'s permissions have |changed| (|changed| is the delta). | 123 // |extension|'s permissions have |changed| (|changed| is the delta). |
| 107 // Specifically, this sends the EXTENSION_PERMISSIONS_UPDATED notification, | 124 // Specifically, this sends the EXTENSION_PERMISSIONS_UPDATED notification, |
| 108 // the ExtensionMsg_UpdatePermissions IPC message, and fires the | 125 // the ExtensionMsg_UpdatePermissions IPC message, and fires the |
| 109 // onAdded/onRemoved events in the extension. | 126 // onAdded/onRemoved events in the extension. |
| 110 void NotifyPermissionsUpdated(EventType event_type, | 127 void NotifyPermissionsUpdated(EventType event_type, |
| 111 const Extension* extension, | 128 const Extension* extension, |
| 112 const PermissionSet& changed); | 129 const PermissionSet& changed); |
| 113 | 130 |
| 131 // Issues the relevant events, messages and notifications when the | |
| 132 // default scope management policy have changed. | |
| 133 // Specifically, this sends the ExtensionMsg_UpdateDefaultHostRestrictions | |
| 134 // IPC message. | |
| 135 void NotifyDefaultPolicyHostRestrictionsUpdated( | |
| 136 const URLPatternSet& default_runtime_blocked_hosts, | |
| 137 const URLPatternSet& default_runtime_allowed_hosts); | |
| 138 | |
| 114 // The associated BrowserContext. | 139 // The associated BrowserContext. |
| 115 content::BrowserContext* browser_context_; | 140 content::BrowserContext* browser_context_; |
| 116 | 141 |
| 117 // Initialization flag that determines whether prefs is consulted about the | 142 // Initialization flag that determines whether prefs is consulted about the |
| 118 // extension. Transient extensions should not have entries in prefs. | 143 // extension. Transient extensions should not have entries in prefs. |
| 119 InitFlag init_flag_; | 144 InitFlag init_flag_; |
| 120 | 145 |
| 121 DISALLOW_COPY_AND_ASSIGN(PermissionsUpdater); | 146 DISALLOW_COPY_AND_ASSIGN(PermissionsUpdater); |
| 122 }; | 147 }; |
| 123 | 148 |
| 124 } // namespace extensions | 149 } // namespace extensions |
| 125 | 150 |
| 126 #endif // CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ | 151 #endif // CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ |
| OLD | NEW |