| 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 content { | 14 namespace content { |
| 15 class BrowserContext; | 15 class BrowserContext; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 | 19 |
| 20 class Extension; | 20 class Extension; |
| 21 class PermissionSet; | 21 class PermissionSet; |
| 22 class URLPatternSet; | |
| 23 | 22 |
| 24 // Updates an Extension's active and granted permissions in persistent storage | 23 // Updates an Extension's active and granted permissions in persistent storage |
| 25 // and notifies interested parties of the changes. | 24 // and notifies interested parties of the changes. |
| 26 class PermissionsUpdater { | 25 class PermissionsUpdater { |
| 27 public: | 26 public: |
| 28 // Platform specific delegate. | 27 // Platform specific delegate. |
| 29 class Delegate { | 28 class Delegate { |
| 30 public: | 29 public: |
| 31 virtual ~Delegate() {} | 30 virtual ~Delegate() {} |
| 32 // Platform specific initialization of |extension|'s permissions (does any | 31 // Platform specific initialization of |extension|'s permissions (does any |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 void RemovePermissions(const Extension* extension, | 74 void RemovePermissions(const Extension* extension, |
| 76 const PermissionSet& permissions, | 75 const PermissionSet& permissions, |
| 77 RemoveType remove_type); | 76 RemoveType remove_type); |
| 78 | 77 |
| 79 // Removes the |permissions| from |extension| and makes no effort to determine | 78 // Removes the |permissions| from |extension| and makes no effort to determine |
| 80 // if doing so is safe in the slightlest. This method shouldn't be used, | 79 // if doing so is safe in the slightlest. This method shouldn't be used, |
| 81 // except for removing permissions totally blacklisted by management. | 80 // except for removing permissions totally blacklisted by management. |
| 82 void RemovePermissionsUnsafe(const Extension* extension, | 81 void RemovePermissionsUnsafe(const Extension* extension, |
| 83 const PermissionSet& permissions); | 82 const PermissionSet& permissions); |
| 84 | 83 |
| 85 // Sets list of hosts |extension| may not interact with (overrides default). | |
| 86 void SetPolicyHostRestrictions(const Extension* extension, | |
| 87 const URLPatternSet& runtime_blocked_hosts, | |
| 88 const URLPatternSet& runtime_allowed_hosts); | |
| 89 | |
| 90 // Sets extension to use the default list of policy host restrictions. | |
| 91 void SetUsesDefaultHostRestrictions(const Extension* extension); | |
| 92 | |
| 93 // Sets list of hosts extensions may not interact with. Extension specific | |
| 94 // exceptions to this default policy are defined with | |
| 95 // SetPolicyHostRestrictions. | |
| 96 void SetDefaultPolicyHostRestrictions( | |
| 97 const URLPatternSet& default_runtime_blocked_hosts, | |
| 98 const URLPatternSet& default_runtime_allowed_hosts); | |
| 99 | |
| 100 // Returns the set of revokable permissions. | 84 // Returns the set of revokable permissions. |
| 101 std::unique_ptr<const PermissionSet> GetRevokablePermissions( | 85 std::unique_ptr<const PermissionSet> GetRevokablePermissions( |
| 102 const Extension* extension) const; | 86 const Extension* extension) const; |
| 103 | 87 |
| 104 // Adds all permissions in the |extension|'s active permissions to its | 88 // Adds all permissions in the |extension|'s active permissions to its |
| 105 // granted permission set. | 89 // granted permission set. |
| 106 void GrantActivePermissions(const Extension* extension); | 90 void GrantActivePermissions(const Extension* extension); |
| 107 | 91 |
| 108 // Initializes the |extension|'s active permission set to include only | 92 // Initializes the |extension|'s active permission set to include only |
| 109 // permissions currently requested by the extension and all the permissions | 93 // permissions currently requested by the extension and all the permissions |
| 110 // required by the extension. | 94 // required by the extension. |
| 111 void InitializePermissions(const Extension* extension); | 95 void InitializePermissions(const Extension* extension); |
| 112 | 96 |
| 113 private: | 97 private: |
| 114 enum EventType { | 98 enum EventType { |
| 115 ADDED, | 99 ADDED, |
| 116 REMOVED, | 100 REMOVED, |
| 117 POLICY, | |
| 118 }; | 101 }; |
| 119 | 102 |
| 120 // Sets the |extension|'s active permissions to |active| and records the | 103 // Sets the |extension|'s active permissions to |active| and records the |
| 121 // change in the prefs. If |withheld| is non-null, also sets the extension's | 104 // change in the prefs. If |withheld| is non-null, also sets the extension's |
| 122 // withheld permissions to |withheld|. Otherwise, |withheld| permissions are | 105 // withheld permissions to |withheld|. Otherwise, |withheld| permissions are |
| 123 // not changed. | 106 // not changed. |
| 124 void SetPermissions(const Extension* extension, | 107 void SetPermissions(const Extension* extension, |
| 125 std::unique_ptr<const PermissionSet> active, | 108 std::unique_ptr<const PermissionSet> active, |
| 126 std::unique_ptr<const PermissionSet> withheld); | 109 std::unique_ptr<const PermissionSet> withheld); |
| 127 | 110 |
| 128 // Dispatches specified event to the extension. | 111 // Dispatches specified event to the extension. |
| 129 void DispatchEvent(const std::string& extension_id, | 112 void DispatchEvent(const std::string& extension_id, |
| 130 events::HistogramValue histogram_value, | 113 events::HistogramValue histogram_value, |
| 131 const char* event_name, | 114 const char* event_name, |
| 132 const PermissionSet& changed_permissions); | 115 const PermissionSet& changed_permissions); |
| 133 | 116 |
| 134 // Issues the relevant events, messages and notifications when the | 117 // Issues the relevant events, messages and notifications when the |
| 135 // |extension|'s permissions have |changed| (|changed| is the delta). | 118 // |extension|'s permissions have |changed| (|changed| is the delta). |
| 136 // Specifically, this sends the EXTENSION_PERMISSIONS_UPDATED notification, | 119 // Specifically, this sends the EXTENSION_PERMISSIONS_UPDATED notification, |
| 137 // the ExtensionMsg_UpdatePermissions IPC message, and fires the | 120 // the ExtensionMsg_UpdatePermissions IPC message, and fires the |
| 138 // onAdded/onRemoved events in the extension. | 121 // onAdded/onRemoved events in the extension. |
| 139 void NotifyPermissionsUpdated(EventType event_type, | 122 void NotifyPermissionsUpdated(EventType event_type, |
| 140 const Extension* extension, | 123 const Extension* extension, |
| 141 const PermissionSet& changed); | 124 const PermissionSet& changed); |
| 142 | 125 |
| 143 // Issues the relevant events, messages and notifications when the | |
| 144 // default scope management policy have changed. | |
| 145 // Specifically, this sends the ExtensionMsg_UpdateDefaultHostRestrictions | |
| 146 // IPC message. | |
| 147 void NotifyDefaultPolicyHostRestrictionsUpdated( | |
| 148 const URLPatternSet& default_runtime_blocked_hosts, | |
| 149 const URLPatternSet& default_runtime_allowed_hosts); | |
| 150 | |
| 151 // The associated BrowserContext. | 126 // The associated BrowserContext. |
| 152 content::BrowserContext* browser_context_; | 127 content::BrowserContext* browser_context_; |
| 153 | 128 |
| 154 // Initialization flag that determines whether prefs is consulted about the | 129 // Initialization flag that determines whether prefs is consulted about the |
| 155 // extension. Transient extensions should not have entries in prefs. | 130 // extension. Transient extensions should not have entries in prefs. |
| 156 InitFlag init_flag_; | 131 InitFlag init_flag_; |
| 157 | 132 |
| 158 DISALLOW_COPY_AND_ASSIGN(PermissionsUpdater); | 133 DISALLOW_COPY_AND_ASSIGN(PermissionsUpdater); |
| 159 }; | 134 }; |
| 160 | 135 |
| 161 } // namespace extensions | 136 } // namespace extensions |
| 162 | 137 |
| 163 #endif // CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ | 138 #endif // CHROME_BROWSER_EXTENSIONS_PERMISSIONS_UPDATER_H__ |
| OLD | NEW |