| 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_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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 size_t registered_extensions_count() const { | 32 size_t registered_extensions_count() const { |
| 33 return component_extensions_.size(); | 33 return component_extensions_.size(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Loads any registered component extensions. | 36 // Loads any registered component extensions. |
| 37 void LoadAll(); | 37 void LoadAll(); |
| 38 | 38 |
| 39 // Registers and possibly loads a component extension. If ExtensionService | 39 // Registers and possibly loads a component extension. If ExtensionService |
| 40 // has been initialized, the extension is loaded; otherwise, the load is | 40 // has been initialized, the extension is loaded; otherwise, the load is |
| 41 // deferred until LoadAll is called. | 41 // deferred until LoadAll is called. The ID of the added extension is |
| 42 const Extension* Add(const std::string& manifest_contents, | 42 // returned. |
| 43 const FilePath& root_directory); | 43 // |
| 44 // Component extension manifests must contain a "key" property with a unique |
| 45 // public key, serialized in base64. You can create a suitable value with the |
| 46 // following commands on a unixy system: |
| 47 // |
| 48 // ssh-keygen -t rsa -b 1024 -N '' -f /tmp/key.pem |
| 49 // openssl rsa -pubout -outform DER < /tmp/key.pem 2>/dev/null | base64 -w 0 |
| 50 std::string Add(const std::string& manifest_contents, |
| 51 const FilePath& root_directory); |
| 44 | 52 |
| 45 // Convenience method for registering a component extension by resource id. | 53 // Convenience method for registering a component extension by resource id. |
| 46 const Extension* Add(int manifest_resource_id, | 54 std::string Add(int manifest_resource_id, |
| 47 const FilePath& root_directory); | 55 const FilePath& root_directory); |
| 48 | 56 |
| 49 // Loads a component extension from file system. Replaces previously added | 57 // Loads a component extension from file system. Replaces previously added |
| 50 // extension with the same ID. | 58 // extension with the same ID. |
| 51 const Extension* AddOrReplace(const FilePath& path); | 59 std::string AddOrReplace(const FilePath& path); |
| 52 | 60 |
| 53 // Returns true if an extension with the specified id has been added. | 61 // Returns true if an extension with the specified id has been added. |
| 54 bool Exists(const std::string& id) const; | 62 bool Exists(const std::string& id) const; |
| 55 | 63 |
| 56 // Unloads a component extension and removes it from the list of component | 64 // Unloads a component extension and removes it from the list of component |
| 57 // extensions to be loaded. | 65 // extensions to be loaded. |
| 58 void Remove(const FilePath& root_directory); | 66 void Remove(const FilePath& root_directory); |
| 59 void Remove(const std::string& id); | 67 void Remove(const std::string& id); |
| 60 | 68 |
| 61 // Adds the default component extensions. | 69 // Adds the default component extensions. |
| 62 // | |
| 63 // Component extension manifests must contain a 'key' property with a unique | |
| 64 // public key, serialized in base64. You can create a suitable value with the | |
| 65 // following commands on a unixy system: | |
| 66 // | |
| 67 // ssh-keygen -t rsa -b 1024 -N '' -f /tmp/key.pem | |
| 68 // openssl rsa -pubout -outform DER < /tmp/key.pem 2>/dev/null | base64 -w 0 | |
| 69 void AddDefaultComponentExtensions(); | 70 void AddDefaultComponentExtensions(); |
| 70 | 71 |
| 71 // content::NotificationObserver implementation | 72 // content::NotificationObserver implementation |
| 72 virtual void Observe(int type, | 73 virtual void Observe(int type, |
| 73 const content::NotificationSource& source, | 74 const content::NotificationSource& source, |
| 74 const content::NotificationDetails& details) OVERRIDE; | 75 const content::NotificationDetails& details) OVERRIDE; |
| 75 | 76 |
| 76 static void RegisterUserPrefs(PrefService* prefs); | 77 static void RegisterUserPrefs(PrefService* prefs); |
| 77 | 78 |
| 78 // Parse the given JSON manifest. Returns NULL if it cannot be parsed, or if | 79 // Parse the given JSON manifest. Returns NULL if it cannot be parsed, or if |
| 79 // if the result is not a DictionaryValue. | 80 // if the result is not a DictionaryValue. |
| 80 DictionaryValue* ParseManifest(const std::string& manifest_contents) const; | 81 DictionaryValue* ParseManifest(const std::string& manifest_contents) const; |
| 81 | 82 |
| 82 // Clear the list of registered extensions. | 83 // Clear the list of registered extensions. |
| 83 void ClearAllRegistered(); | 84 void ClearAllRegistered(); |
| 84 | 85 |
| 85 // Reloads a registered component extension. | 86 // Reloads a registered component extension. |
| 86 void Reload(const std::string& extension_id); | 87 void Reload(const std::string& extension_id); |
| 87 | 88 |
| 89 // Adds the "Script Bubble" component extension, which puts an icon in the |
| 90 // omnibox indiciating the number of extensions running script in a tab. |
| 91 void AddScriptBubble(); |
| 92 |
| 93 // Returns the extension previously added by AddScriptBubble(), if any. |
| 94 const Extension* GetScriptBubble() const; |
| 95 |
| 88 private: | 96 private: |
| 89 // Information about a registered component extension. | 97 // Information about a registered component extension. |
| 90 struct ComponentExtensionInfo { | 98 struct ComponentExtensionInfo { |
| 91 ComponentExtensionInfo(const DictionaryValue* manifest, | 99 ComponentExtensionInfo(const DictionaryValue* manifest, |
| 92 const FilePath& root_directory) | 100 const FilePath& root_directory); |
| 93 : manifest(manifest), | |
| 94 root_directory(root_directory) { | |
| 95 } | |
| 96 | 101 |
| 97 // The parsed contents of the extensions's manifest file. | 102 // The parsed contents of the extensions's manifest file. |
| 98 const DictionaryValue* manifest; | 103 const DictionaryValue* manifest; |
| 99 | 104 |
| 100 // Directory where the extension is stored. | 105 // Directory where the extension is stored. |
| 101 FilePath root_directory; | 106 FilePath root_directory; |
| 107 |
| 108 // The component extension's ID. |
| 109 std::string extension_id; |
| 102 }; | 110 }; |
| 103 | 111 |
| 104 const Extension* Add(const DictionaryValue* parsed_manifest, | 112 std::string Add(const DictionaryValue* parsed_manifest, |
| 105 const FilePath& root_directory); | 113 const FilePath& root_directory); |
| 106 | 114 |
| 107 // Loads a registered component extension. | 115 // Loads a registered component extension. |
| 108 const Extension* Load(const ComponentExtensionInfo& info); | 116 const Extension* Load(const ComponentExtensionInfo& info); |
| 109 | 117 |
| 110 void AddFileManagerExtension(); | 118 void AddFileManagerExtension(); |
| 111 | 119 |
| 112 #if defined(OS_CHROMEOS) | 120 #if defined(OS_CHROMEOS) |
| 113 void AddGaiaAuthExtension(); | 121 void AddGaiaAuthExtension(); |
| 114 #endif | 122 #endif |
| 115 | 123 |
| 116 // Add the enterprise webstore extension, or reload it if already loaded. | 124 // Add the enterprise webstore extension, or reload it if already loaded. |
| 117 void AddOrReloadEnterpriseWebStore(); | 125 void AddOrReloadEnterpriseWebStore(); |
| 118 | 126 |
| 119 void AddChromeApp(); | 127 void AddChromeApp(); |
| 120 | 128 |
| 121 // Determine the extension id. | |
| 122 static std::string GenerateId(const base::DictionaryValue* manifest); | |
| 123 | |
| 124 PrefService* prefs_; | 129 PrefService* prefs_; |
| 125 PrefService* local_state_; | 130 PrefService* local_state_; |
| 126 | 131 |
| 127 ExtensionServiceInterface* extension_service_; | 132 ExtensionServiceInterface* extension_service_; |
| 128 | 133 |
| 129 // List of registered component extensions (see Extension::Location). | 134 // List of registered component extensions (see Extension::Location). |
| 130 typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions; | 135 typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions; |
| 131 RegisteredComponentExtensions component_extensions_; | 136 RegisteredComponentExtensions component_extensions_; |
| 132 | 137 |
| 133 PrefChangeRegistrar pref_change_registrar_; | 138 PrefChangeRegistrar pref_change_registrar_; |
| 134 | 139 |
| 140 std::string script_bubble_id_; |
| 141 |
| 135 DISALLOW_COPY_AND_ASSIGN(ComponentLoader); | 142 DISALLOW_COPY_AND_ASSIGN(ComponentLoader); |
| 136 }; | 143 }; |
| 137 | 144 |
| 138 } // namespace extensions | 145 } // namespace extensions |
| 139 | 146 |
| 140 #endif // CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ | 147 #endif // CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ |
| OLD | NEW |