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 23 matching lines...) Expand all Loading... | |
34 // Registers and possibly loads a component extension. If ExtensionService | 34 // Registers and possibly loads a component extension. If ExtensionService |
35 // has been initialized, the extension is loaded; otherwise, the load is | 35 // has been initialized, the extension is loaded; otherwise, the load is |
36 // deferred until LoadAll is called. | 36 // deferred until LoadAll is called. |
37 const Extension* Add(std::string& manifest_contents, | 37 const Extension* Add(std::string& manifest_contents, |
38 const FilePath& root_directory); | 38 const FilePath& root_directory); |
39 | 39 |
40 // Convenience method for registering a component extension by resource id. | 40 // Convenience method for registering a component extension by resource id. |
41 const Extension* Add(int manifest_resource_id, | 41 const Extension* Add(int manifest_resource_id, |
42 const FilePath& root_directory); | 42 const FilePath& root_directory); |
43 | 43 |
44 // Loads a component extension from file system. Replaces previously added | |
45 // extension with the same ID. | |
46 const Extension* AddOrReplace(const FilePath& path); | |
47 | |
44 // Unloads a component extension and removes it from the list of component | 48 // Unloads a component extension and removes it from the list of component |
45 // extensions to be loaded. | 49 // extensions to be loaded. |
46 void Remove(const FilePath& root_directory); | 50 void Remove(const FilePath& root_directory); |
51 void Remove(const std::string& id); | |
47 | 52 |
48 // Adds the default component extensions. | 53 // Adds the default component extensions. |
49 // | 54 // |
50 // Component extension manifests must contain a 'key' property with a unique | 55 // 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 | 56 // public key, serialized in base64. You can create a suitable value with the |
52 // following commands on a unixy system: | 57 // following commands on a unixy system: |
53 // | 58 // |
54 // ssh-keygen -t rsa -b 1024 -N '' -f /tmp/key.pem | 59 // 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 | 60 // openssl rsa -pubout -outform DER < /tmp/key.pem 2>/dev/null | base64 -w 0 |
56 void AddDefaultComponentExtensions(); | 61 void AddDefaultComponentExtensions(); |
57 | 62 |
58 // content::NotificationObserver implementation | 63 // content::NotificationObserver implementation |
59 virtual void Observe(int type, | 64 virtual void Observe(int type, |
60 const content::NotificationSource& source, | 65 const content::NotificationSource& source, |
61 const content::NotificationDetails& details) OVERRIDE; | 66 const content::NotificationDetails& details) OVERRIDE; |
62 | 67 |
63 static void RegisterUserPrefs(PrefService* prefs); | 68 static void RegisterUserPrefs(PrefService* prefs); |
64 | 69 |
65 // Parse the given JSON manifest. Returns NULL if it cannot be parsed, or if | 70 // Parse the given JSON manifest. Returns NULL if it cannot be parsed, or if |
66 // if the result is not a DictionaryValue. | 71 // if the result is not a DictionaryValue. |
67 DictionaryValue* ParseManifest(const std::string& manifest_contents) const; | 72 DictionaryValue* ParseManifest(const std::string& manifest_contents) const; |
68 | 73 |
69 // Clear the list of registered extensions. | 74 // Clear the list of registered extensions. |
70 void ClearAllRegistered(); | 75 void ClearAllRegistered(); |
71 | 76 |
77 size_t GetRegisteredExtensionsCount() const { | |
Aaron Boodman
2011/12/06 19:43:35
Sorry I didn't notice this earlier: This should be
SeRya
2011/12/06 22:19:37
Done.
| |
78 return component_extensions_.size(); | |
79 } | |
80 | |
72 private: | 81 private: |
73 // Information about a registered component extension. | 82 // Information about a registered component extension. |
74 struct ComponentExtensionInfo { | 83 struct ComponentExtensionInfo { |
75 ComponentExtensionInfo(const DictionaryValue* manifest, | 84 ComponentExtensionInfo(const DictionaryValue* manifest, |
76 const FilePath& root_directory) | 85 const FilePath& root_directory) |
77 : manifest(manifest), | 86 : manifest(manifest), |
78 root_directory(root_directory) { | 87 root_directory(root_directory) { |
79 } | 88 } |
80 | 89 |
81 // The parsed contents of the extensions's manifest file. | 90 // The parsed contents of the extensions's manifest file. |
82 const DictionaryValue* manifest; | 91 const DictionaryValue* manifest; |
83 | 92 |
84 // Directory where the extension is stored. | 93 // Directory where the extension is stored. |
85 FilePath root_directory; | 94 FilePath root_directory; |
86 }; | 95 }; |
87 | 96 |
88 const Extension* Add(const DictionaryValue* parsed_manifest, | 97 const Extension* Add(const DictionaryValue* parsed_manifest, |
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 |