| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_COMPONENT_LOADER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 | 22 |
| 23 // For registering, loading, and unloading component extensions. | 23 // For registering, loading, and unloading component extensions. |
| 24 class ComponentLoader : public content::NotificationObserver { | 24 class ComponentLoader : public content::NotificationObserver { |
| 25 public: | 25 public: |
| 26 ComponentLoader(ExtensionServiceInterface* extension_service, | 26 ComponentLoader(ExtensionServiceInterface* extension_service, |
| 27 PrefService* prefs, | 27 PrefService* prefs, |
| 28 PrefService* local_state); | 28 PrefService* local_state); |
| 29 virtual ~ComponentLoader(); | 29 virtual ~ComponentLoader(); |
| 30 | 30 |
| 31 size_t registered_extensions_count() const { |
| 32 return component_extensions_.size(); |
| 33 } |
| 34 |
| 31 // Loads any registered component extensions. | 35 // Loads any registered component extensions. |
| 32 void LoadAll(); | 36 void LoadAll(); |
| 33 | 37 |
| 34 // Registers and possibly loads a component extension. If ExtensionService | 38 // Registers and possibly loads a component extension. If ExtensionService |
| 35 // has been initialized, the extension is loaded; otherwise, the load is | 39 // has been initialized, the extension is loaded; otherwise, the load is |
| 36 // deferred until LoadAll is called. | 40 // deferred until LoadAll is called. |
| 37 const Extension* Add(std::string& manifest_contents, | 41 const Extension* Add(std::string& manifest_contents, |
| 38 const FilePath& root_directory); | 42 const FilePath& root_directory); |
| 39 | 43 |
| 40 // Convenience method for registering a component extension by resource id. | 44 // Convenience method for registering a component extension by resource id. |
| 41 const Extension* Add(int manifest_resource_id, | 45 const Extension* Add(int manifest_resource_id, |
| 42 const FilePath& root_directory); | 46 const FilePath& root_directory); |
| 43 | 47 |
| 48 // Loads a component extension from file system. Replaces previously added |
| 49 // extension with the same ID. |
| 50 const Extension* AddOrReplace(const FilePath& path); |
| 51 |
| 44 // Unloads a component extension and removes it from the list of component | 52 // Unloads a component extension and removes it from the list of component |
| 45 // extensions to be loaded. | 53 // extensions to be loaded. |
| 46 void Remove(const FilePath& root_directory); | 54 void Remove(const FilePath& root_directory); |
| 55 void Remove(const std::string& id); |
| 47 | 56 |
| 48 // Adds the default component extensions. | 57 // Adds the default component extensions. |
| 49 // | 58 // |
| 50 // Component extension manifests must contain a 'key' property with a unique | 59 // Component extension manifests must contain a 'key' property with a unique |
| 51 // public key, serialized in base64. You can create a suitable value with the | 60 // public key, serialized in base64. You can create a suitable value with the |
| 52 // following commands on a unixy system: | 61 // following commands on a unixy system: |
| 53 // | 62 // |
| 54 // ssh-keygen -t rsa -b 1024 -N '' -f /tmp/key.pem | 63 // ssh-keygen -t rsa -b 1024 -N '' -f /tmp/key.pem |
| 55 // openssl rsa -pubout -outform DER < /tmp/key.pem 2>/dev/null | base64 -w 0 | 64 // openssl rsa -pubout -outform DER < /tmp/key.pem 2>/dev/null | base64 -w 0 |
| 56 void AddDefaultComponentExtensions(); | 65 void AddDefaultComponentExtensions(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 const FilePath& root_directory); | 98 const FilePath& root_directory); |
| 90 | 99 |
| 91 // Loads a registered component extension. | 100 // Loads a registered component extension. |
| 92 const Extension* Load(const ComponentExtensionInfo& info); | 101 const Extension* Load(const ComponentExtensionInfo& info); |
| 93 | 102 |
| 94 void AddFileManagerExtension(); | 103 void AddFileManagerExtension(); |
| 95 | 104 |
| 96 // Add the enterprise webstore extension, or reload it if already loaded. | 105 // Add the enterprise webstore extension, or reload it if already loaded. |
| 97 void AddOrReloadEnterpriseWebStore(); | 106 void AddOrReloadEnterpriseWebStore(); |
| 98 | 107 |
| 108 // Returns true if an extension with the specified id has been added. |
| 109 bool Exists(const std::string& id) const; |
| 110 |
| 111 // Determine the extension id. |
| 112 static std::string GenerateId(const base::DictionaryValue* manifest); |
| 113 |
| 99 PrefService* prefs_; | 114 PrefService* prefs_; |
| 100 PrefService* local_state_; | 115 PrefService* local_state_; |
| 101 | 116 |
| 102 ExtensionServiceInterface* extension_service_; | 117 ExtensionServiceInterface* extension_service_; |
| 103 | 118 |
| 104 // List of registered component extensions (see Extension::Location). | 119 // List of registered component extensions (see Extension::Location). |
| 105 typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions; | 120 typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions; |
| 106 RegisteredComponentExtensions component_extensions_; | 121 RegisteredComponentExtensions component_extensions_; |
| 107 | 122 |
| 108 PrefChangeRegistrar pref_change_registrar_; | 123 PrefChangeRegistrar pref_change_registrar_; |
| 109 }; | 124 }; |
| 110 | 125 |
| 111 } // namespace extensions | 126 } // namespace extensions |
| 112 | 127 |
| 113 #endif // CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ | 128 #endif // CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ |
| OLD | NEW |