| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_EXTENSION_MANAGEMENT_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ |
| 7 | 7 |
| 8 #include <string> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/containers/scoped_ptr_hash_map.h" | 11 #include "base/containers/scoped_ptr_hash_map.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 17 #include "base/prefs/pref_change_registrar.h" | 18 #include "base/prefs/pref_change_registrar.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // Get the list of ManagementPolicy::Provider controlled by extension | 82 // Get the list of ManagementPolicy::Provider controlled by extension |
| 82 // management policy settings. | 83 // management policy settings. |
| 83 std::vector<ManagementPolicy::Provider*> GetProviders() const; | 84 std::vector<ManagementPolicy::Provider*> GetProviders() const; |
| 84 | 85 |
| 85 // Checks if extensions are blacklisted by default, by policy. When true, | 86 // Checks if extensions are blacklisted by default, by policy. When true, |
| 86 // this means that even extensions without an ID should be blacklisted (e.g. | 87 // this means that even extensions without an ID should be blacklisted (e.g. |
| 87 // from the command line, or when loaded as an unpacked extension). | 88 // from the command line, or when loaded as an unpacked extension). |
| 88 bool BlacklistedByDefault() const; | 89 bool BlacklistedByDefault() const; |
| 89 | 90 |
| 90 // Returns installation mode for an extension. | 91 // Returns installation mode for an extension. |
| 91 InstallationMode GetInstallationMode(const ExtensionId& id) const; | 92 InstallationMode GetInstallationMode(const Extension* extension) const; |
| 92 | 93 |
| 93 // Returns the force install list, in format specified by | 94 // Returns the force install list, in format specified by |
| 94 // ExternalPolicyLoader::AddExtension(). | 95 // ExternalPolicyLoader::AddExtension(). |
| 95 scoped_ptr<base::DictionaryValue> GetForceInstallList() const; | 96 scoped_ptr<base::DictionaryValue> GetForceInstallList() const; |
| 96 | 97 |
| 97 // Like GetForceInstallList(), but returns recommended install list instead. | 98 // Like GetForceInstallList(), but returns recommended install list instead. |
| 98 scoped_ptr<base::DictionaryValue> GetRecommendedInstallList() const; | 99 scoped_ptr<base::DictionaryValue> GetRecommendedInstallList() const; |
| 99 | 100 |
| 100 // Returns if an extension with id |id| is explicitly allowed by enterprise | 101 // Returns if an extension with id |id| is explicitly allowed by enterprise |
| 101 // policy or not. | 102 // policy or not. |
| 102 bool IsInstallationExplicitlyAllowed(const ExtensionId& id) const; | 103 bool IsInstallationExplicitlyAllowed(const ExtensionId& id) const; |
| 103 | 104 |
| 104 // Returns true if an extension download should be allowed to proceed. | 105 // Returns true if an extension download should be allowed to proceed. |
| 105 bool IsOffstoreInstallAllowed(const GURL& url, | 106 bool IsOffstoreInstallAllowed(const GURL& url, |
| 106 const GURL& referrer_url) const; | 107 const GURL& referrer_url) const; |
| 107 | 108 |
| 108 // Returns true if an extension with manifest type |manifest_type| is | 109 // Returns true if an extension with manifest type |manifest_type| is |
| 109 // allowed to be installed. | 110 // allowed to be installed. |
| 110 bool IsAllowedManifestType(Manifest::Type manifest_type) const; | 111 bool IsAllowedManifestType(Manifest::Type manifest_type) const; |
| 111 | 112 |
| 112 // Returns the list of blocked API permissions for the extension |id|. | 113 // Returns the list of blocked API permissions for |extension|. |
| 113 const APIPermissionSet& GetBlockedAPIPermissions(const ExtensionId& id) const; | 114 APIPermissionSet GetBlockedAPIPermissions(const Extension* extension) const; |
| 114 | 115 |
| 115 // Returns blocked permission set for extension |id|. | 116 // Returns blocked permission set for |extension|. |
| 116 scoped_refptr<const PermissionSet> GetBlockedPermissions( | 117 scoped_refptr<const PermissionSet> GetBlockedPermissions( |
| 117 const ExtensionId& id) const; | 118 const Extension* extension) const; |
| 118 | 119 |
| 119 // Returns true if every permission in |perms| is allowed for extension |id|. | 120 // Returns true if every permission in |perms| is allowed for |extension|. |
| 120 bool IsPermissionSetAllowed(const ExtensionId& id, | 121 bool IsPermissionSetAllowed(const Extension* extension, |
| 121 scoped_refptr<const PermissionSet> perms) const; | 122 scoped_refptr<const PermissionSet> perms) const; |
| 122 | 123 |
| 123 private: | 124 private: |
| 124 typedef base::ScopedPtrHashMap<ExtensionId, internal::IndividualSettings> | 125 typedef base::ScopedPtrHashMap<ExtensionId, internal::IndividualSettings> |
| 125 SettingsIdMap; | 126 SettingsIdMap; |
| 127 typedef base::ScopedPtrHashMap<std::string, internal::IndividualSettings> |
| 128 SettingsUpdateUrlMap; |
| 126 friend class ExtensionManagementServiceTest; | 129 friend class ExtensionManagementServiceTest; |
| 127 | 130 |
| 128 // Load all extension management preferences from |pref_service|, and | 131 // Load all extension management preferences from |pref_service|, and |
| 129 // refresh the settings. | 132 // refresh the settings. |
| 130 void Refresh(); | 133 void Refresh(); |
| 131 | 134 |
| 132 // Load preference with name |pref_name| and expected type |expected_type|. | 135 // Load preference with name |pref_name| and expected type |expected_type|. |
| 133 // If |force_managed| is true, only loading from the managed preference store | 136 // If |force_managed| is true, only loading from the managed preference store |
| 134 // is allowed. Returns NULL if the preference is not present, not allowed to | 137 // is allowed. Returns NULL if the preference is not present, not allowed to |
| 135 // be loaded from or has the wrong type. | 138 // be loaded from or has the wrong type. |
| 136 const base::Value* LoadPreference(const char* pref_name, | 139 const base::Value* LoadPreference(const char* pref_name, |
| 137 bool force_managed, | 140 bool force_managed, |
| 138 base::Value::Type expected_type); | 141 base::Value::Type expected_type); |
| 139 | 142 |
| 140 void OnExtensionPrefChanged(); | 143 void OnExtensionPrefChanged(); |
| 141 void NotifyExtensionManagementPrefChanged(); | 144 void NotifyExtensionManagementPrefChanged(); |
| 142 | 145 |
| 143 // Helper function to read |settings_by_id_| with |id| as key. Returns a | |
| 144 // constant reference to default settings if |id| does not exist. | |
| 145 const internal::IndividualSettings* ReadById(const ExtensionId& id) const; | |
| 146 | |
| 147 // Returns a constant reference to |global_settings_|. | |
| 148 const internal::GlobalSettings* ReadGlobalSettings() const; | |
| 149 | |
| 150 // Helper function to access |settings_by_id_| with |id| as key. | 146 // Helper function to access |settings_by_id_| with |id| as key. |
| 151 // Adds a new IndividualSettings entry to |settings_by_id_| if none exists for | 147 // Adds a new IndividualSettings entry to |settings_by_id_| if none exists for |
| 152 // |id| yet. | 148 // |id| yet. |
| 153 internal::IndividualSettings* AccessById(const ExtensionId& id); | 149 internal::IndividualSettings* AccessById(const ExtensionId& id); |
| 154 | 150 |
| 151 // Similar to AccessById(), but access |settings_by_update_url_| instead. |
| 152 internal::IndividualSettings* AccessByUpdateUrl( |
| 153 const std::string& update_url); |
| 154 |
| 155 // A map containing all IndividualSettings applied to an individual extension | 155 // A map containing all IndividualSettings applied to an individual extension |
| 156 // identified by extension ID. The extension ID is used as index key of the | 156 // identified by extension ID. The extension ID is used as index key of the |
| 157 // map. | 157 // map. |
| 158 // TODO(binjin): Add |settings_by_update_url_|, and implement mechanism for | |
| 159 // it. | |
| 160 SettingsIdMap settings_by_id_; | 158 SettingsIdMap settings_by_id_; |
| 161 | 159 |
| 160 // Similar to |settings_by_id_|, but contains the settings for a group of |
| 161 // extensions with same update URL. The update url itself is used as index |
| 162 // key for the map. |
| 163 SettingsUpdateUrlMap settings_by_update_url_; |
| 164 |
| 162 // The default IndividualSettings. | 165 // The default IndividualSettings. |
| 163 // For extension settings applied to an individual extension (identified by | 166 // For extension settings applied to an individual extension (identified by |
| 164 // extension ID) or a group of extension (with specified extension update | 167 // extension ID) or a group of extension (with specified extension update |
| 165 // URL), all unspecified part will take value from |default_settings_|. | 168 // URL), all unspecified part will take value from |default_settings_|. |
| 166 // For all other extensions, all settings from |default_settings_| will be | 169 // For all other extensions, all settings from |default_settings_| will be |
| 167 // enforced. | 170 // enforced. |
| 168 scoped_ptr<internal::IndividualSettings> default_settings_; | 171 scoped_ptr<internal::IndividualSettings> default_settings_; |
| 169 | 172 |
| 170 // Extension settings applicable to all extensions. | 173 // Extension settings applicable to all extensions. |
| 171 scoped_ptr<internal::GlobalSettings> global_settings_; | 174 scoped_ptr<internal::GlobalSettings> global_settings_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 198 content::BrowserContext* context) const override; | 201 content::BrowserContext* context) const override; |
| 199 void RegisterProfilePrefs( | 202 void RegisterProfilePrefs( |
| 200 user_prefs::PrefRegistrySyncable* registry) override; | 203 user_prefs::PrefRegistrySyncable* registry) override; |
| 201 | 204 |
| 202 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementFactory); | 205 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementFactory); |
| 203 }; | 206 }; |
| 204 | 207 |
| 205 } // namespace extensions | 208 } // namespace extensions |
| 206 | 209 |
| 207 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ | 210 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ |
| OLD | NEW |