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