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