Chromium Code Reviews| 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 "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_vector.h" | |
| 11 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 12 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 13 #include "base/prefs/pref_change_registrar.h" | 15 #include "base/prefs/pref_change_registrar.h" |
| 14 #include "base/values.h" | 16 #include "base/values.h" |
| 15 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" | 17 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" |
| 16 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
| 17 #include "extensions/browser/management_policy.h" | 19 #include "extensions/browser/management_policy.h" |
| 18 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 19 #include "extensions/common/manifest.h" | 21 #include "extensions/common/manifest.h" |
| 20 | 22 |
| 21 class GURL; | 23 class GURL; |
| 22 class PrefService; | 24 class PrefService; |
| 23 | 25 |
| 24 namespace content { | 26 namespace content { |
| 25 class BrowserContext; | 27 class BrowserContext; |
| 26 } // namespace content | 28 } // namespace content |
| 27 | 29 |
| 28 namespace extensions { | 30 namespace extensions { |
| 29 | 31 |
| 30 namespace internal { | 32 namespace internal { |
| 31 | 33 |
| 32 struct IndividualSettings; | 34 struct IndividualSettings; |
| 33 struct GlobalSettings; | 35 struct GlobalSettings; |
| 34 | 36 |
| 35 } // namespace internal | 37 } // namespace internal |
| 36 | 38 |
| 39 class APIPermissionSet; | |
| 40 class PermissionSet; | |
| 41 | |
| 37 // Tracks the management policies that affect extensions and provides interfaces | 42 // Tracks the management policies that affect extensions and provides interfaces |
| 38 // for observing and obtaining the global settings for all extensions, as well | 43 // for observing and obtaining the global settings for all extensions, as well |
| 39 // as per-extension settings. | 44 // as per-extension settings. |
| 40 class ExtensionManagement : public KeyedService { | 45 class ExtensionManagement : public KeyedService { |
| 41 public: | 46 public: |
| 42 // Observer class for extension management settings changes. | 47 // Observer class for extension management settings changes. |
| 43 class Observer { | 48 class Observer { |
| 44 public: | 49 public: |
| 45 virtual ~Observer() {} | 50 virtual ~Observer() {} |
| 46 | 51 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 61 INSTALLATION_FORCED, | 66 INSTALLATION_FORCED, |
| 62 INSTALLATION_RECOMMENDED, | 67 INSTALLATION_RECOMMENDED, |
| 63 }; | 68 }; |
| 64 | 69 |
| 65 explicit ExtensionManagement(PrefService* pref_service); | 70 explicit ExtensionManagement(PrefService* pref_service); |
| 66 virtual ~ExtensionManagement(); | 71 virtual ~ExtensionManagement(); |
| 67 | 72 |
| 68 void AddObserver(Observer* observer); | 73 void AddObserver(Observer* observer); |
| 69 void RemoveObserver(Observer* observer); | 74 void RemoveObserver(Observer* observer); |
| 70 | 75 |
| 71 // Get the ManagementPolicy::Provider controlled by extension management | 76 // Get the list of ManagementPolicy::Provider controlled by extension |
| 72 // policy settings. | 77 // management policy settings. |
| 73 ManagementPolicy::Provider* GetProvider() const; | 78 std::vector<ManagementPolicy::Provider*> GetProviders() const; |
| 74 | 79 |
| 75 // Checks if extensions are blacklisted by default, by policy. When true, | 80 // Checks if extensions are blacklisted by default, by policy. When true, |
| 76 // this means that even extensions without an ID should be blacklisted (e.g. | 81 // this means that even extensions without an ID should be blacklisted (e.g. |
| 77 // from the command line, or when loaded as an unpacked extension). | 82 // from the command line, or when loaded as an unpacked extension). |
| 78 bool BlacklistedByDefault() const; | 83 bool BlacklistedByDefault() const; |
| 79 | 84 |
| 80 // Returns installation mode for an extension. | 85 // Returns installation mode for an extension. |
| 81 InstallationMode GetInstallationMode(const ExtensionId& id) const; | 86 InstallationMode GetInstallationMode(const ExtensionId& id) const; |
| 82 | 87 |
| 83 // Returns the force install list, in format specified by | 88 // Returns the force install list, in format specified by |
| 84 // ExternalPolicyLoader::AddExtension(). | 89 // ExternalPolicyLoader::AddExtension(). |
| 85 scoped_ptr<base::DictionaryValue> GetForceInstallList() const; | 90 scoped_ptr<base::DictionaryValue> GetForceInstallList() const; |
| 86 | 91 |
| 87 // Returns if an extension with id |id| is allowed to install or not. | 92 // Returns if an extension with id |id| is allowed to install or not. |
| 88 bool IsInstallationAllowed(const ExtensionId& id) const; | 93 bool IsInstallationAllowed(const ExtensionId& id) const; |
| 89 | 94 |
| 90 // Returns true if an extension download should be allowed to proceed. | 95 // Returns true if an extension download should be allowed to proceed. |
| 91 bool IsOffstoreInstallAllowed(const GURL& url, | 96 bool IsOffstoreInstallAllowed(const GURL& url, |
| 92 const GURL& referrer_url) const; | 97 const GURL& referrer_url) const; |
| 93 | 98 |
| 94 // Returns true if an extension with manifest type |manifest_type| is | 99 // Returns true if an extension with manifest type |manifest_type| is |
| 95 // allowed to be installed. | 100 // allowed to be installed. |
| 96 bool IsAllowedManifestType(Manifest::Type manifest_type) const; | 101 bool IsAllowedManifestType(Manifest::Type manifest_type) const; |
| 97 | 102 |
| 103 // Returns the list of blocked API permissions for the extension |id|. | |
| 104 const APIPermissionSet& GetBlockedAPIPermissions(const ExtensionId& id) const; | |
| 105 | |
| 106 // Returns blocked permission set for extension |id|. | |
| 107 scoped_refptr<const PermissionSet> GetBlockedPermissions( | |
| 108 const ExtensionId& id) const; | |
| 109 | |
| 110 // Returns true if every permssion in |perms| are allowed for extension |id|. | |
|
Joao da Silva
2014/10/15 14:39:25
permission
is allowed
binjin
2014/10/16 18:13:57
Done.
| |
| 111 bool IsPermissionSetAllowed(const ExtensionId& id, | |
| 112 scoped_refptr<const PermissionSet> perms) const; | |
| 113 | |
| 98 private: | 114 private: |
| 99 typedef base::ScopedPtrHashMap<ExtensionId, internal::IndividualSettings> | 115 typedef base::ScopedPtrHashMap<ExtensionId, internal::IndividualSettings> |
| 100 SettingsIdMap; | 116 SettingsIdMap; |
| 101 friend class ExtensionManagementServiceTest; | 117 friend class ExtensionManagementServiceTest; |
| 102 | 118 |
| 103 // Load all extension management preferences from |pref_service|, and | 119 // Load all extension management preferences from |pref_service|, and |
| 104 // refresh the settings. | 120 // refresh the settings. |
| 105 void Refresh(); | 121 void Refresh(); |
| 106 | 122 |
| 107 // Load preference with name |pref_name| and expected type |expected_type|. | 123 // Load preference with name |pref_name| and expected type |expected_type|. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 // enforced. | 158 // enforced. |
| 143 scoped_ptr<internal::IndividualSettings> default_settings_; | 159 scoped_ptr<internal::IndividualSettings> default_settings_; |
| 144 | 160 |
| 145 // Extension settings applicable to all extensions. | 161 // Extension settings applicable to all extensions. |
| 146 scoped_ptr<internal::GlobalSettings> global_settings_; | 162 scoped_ptr<internal::GlobalSettings> global_settings_; |
| 147 | 163 |
| 148 PrefService* pref_service_; | 164 PrefService* pref_service_; |
| 149 | 165 |
| 150 ObserverList<Observer, true> observer_list_; | 166 ObserverList<Observer, true> observer_list_; |
| 151 PrefChangeRegistrar pref_change_registrar_; | 167 PrefChangeRegistrar pref_change_registrar_; |
| 152 scoped_ptr<ManagementPolicy::Provider> provider_; | 168 ScopedVector<ManagementPolicy::Provider> providers_; |
| 153 | 169 |
| 154 DISALLOW_COPY_AND_ASSIGN(ExtensionManagement); | 170 DISALLOW_COPY_AND_ASSIGN(ExtensionManagement); |
| 155 }; | 171 }; |
| 156 | 172 |
| 157 class ExtensionManagementFactory : public BrowserContextKeyedServiceFactory { | 173 class ExtensionManagementFactory : public BrowserContextKeyedServiceFactory { |
| 158 public: | 174 public: |
| 159 static ExtensionManagement* GetForBrowserContext( | 175 static ExtensionManagement* GetForBrowserContext( |
| 160 content::BrowserContext* context); | 176 content::BrowserContext* context); |
| 161 static ExtensionManagementFactory* GetInstance(); | 177 static ExtensionManagementFactory* GetInstance(); |
| 162 | 178 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 173 content::BrowserContext* context) const override; | 189 content::BrowserContext* context) const override; |
| 174 virtual void RegisterProfilePrefs( | 190 virtual void RegisterProfilePrefs( |
| 175 user_prefs::PrefRegistrySyncable* registry) override; | 191 user_prefs::PrefRegistrySyncable* registry) override; |
| 176 | 192 |
| 177 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementFactory); | 193 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementFactory); |
| 178 }; | 194 }; |
| 179 | 195 |
| 180 } // namespace extensions | 196 } // namespace extensions |
| 181 | 197 |
| 182 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ | 198 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ |
| OLD | NEW |