NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / component_loader.h
blobda3f98a168ede42be5c8651e9199782000dcf607
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_
6 #define CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_
8 #include <string>
9 #include <vector>
11 #include "base/files/file_path.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/values.h"
15 class ExtensionServiceInterface;
16 class PrefService;
18 namespace content {
19 class BrowserContext;
22 namespace extensions {
24 // For registering, loading, and unloading component extensions.
25 class ComponentLoader {
26 public:
27 ComponentLoader(ExtensionServiceInterface* extension_service,
28 PrefService* prefs,
29 PrefService* local_state,
30 content::BrowserContext* browser_context);
31 virtual ~ComponentLoader();
33 size_t registered_extensions_count() const {
34 return component_extensions_.size();
37 // Creates and loads all registered component extensions.
38 void LoadAll();
40 // Registers and possibly loads a component extension. If ExtensionService
41 // has been initialized, the extension is loaded; otherwise, the load is
42 // deferred until LoadAll is called. The ID of the added extension is
43 // returned.
45 // Component extension manifests must contain a "key" property with a unique
46 // public key, serialized in base64. You can create a suitable value with the
47 // following commands on a unixy system:
49 // ssh-keygen -t rsa -b 1024 -N '' -f /tmp/key.pem
50 // openssl rsa -pubout -outform DER < /tmp/key.pem 2>/dev/null | base64 -w 0
51 std::string Add(const std::string& manifest_contents,
52 const base::FilePath& root_directory);
54 // Convenience method for registering a component extension by resource id.
55 std::string Add(int manifest_resource_id,
56 const base::FilePath& root_directory);
58 // Loads a component extension from file system. Replaces previously added
59 // extension with the same ID.
60 std::string AddOrReplace(const base::FilePath& path);
62 // Returns the extension ID of a component extension specified by resource
63 // id of its manifest file.
64 std::string GetExtensionID(int manifest_resource_id,
65 const base::FilePath& root_directory);
67 // Returns true if an extension with the specified id has been added.
68 bool Exists(const std::string& id) const;
70 // Unloads a component extension and removes it from the list of component
71 // extensions to be loaded.
72 void Remove(const base::FilePath& root_directory);
73 void Remove(const std::string& id);
75 // Call this during test setup to load component extensions that have
76 // background pages for testing, which could otherwise interfere with tests.
77 static void EnableBackgroundExtensionsForTesting();
79 // Adds the default component extensions. If |skip_session_components|
80 // the loader will skip loading component extensions that weren't supposed to
81 // be loaded unless we are in signed user session (ChromeOS). For all other
82 // platforms this |skip_session_components| is expected to be unset.
83 void AddDefaultComponentExtensions(bool skip_session_components);
85 // Similar to above but adds the default component extensions for kiosk mode.
86 void AddDefaultComponentExtensionsForKioskMode(bool skip_session_components);
88 // Parse the given JSON manifest. Returns NULL if it cannot be parsed, or if
89 // if the result is not a DictionaryValue.
90 base::DictionaryValue* ParseManifest(
91 const std::string& manifest_contents) const;
93 // Clear the list of registered extensions.
94 void ClearAllRegistered();
96 // Reloads a registered component extension.
97 void Reload(const std::string& extension_id);
99 #if defined(OS_CHROMEOS)
100 std::string AddChromeVoxExtension();
101 std::string AddChromeOsSpeechSynthesisExtension();
102 #endif
104 private:
105 // Information about a registered component extension.
106 struct ComponentExtensionInfo {
107 ComponentExtensionInfo(const base::DictionaryValue* manifest,
108 const base::FilePath& root_directory);
110 // The parsed contents of the extensions's manifest file.
111 const base::DictionaryValue* manifest;
113 // Directory where the extension is stored.
114 base::FilePath root_directory;
116 // The component extension's ID.
117 std::string extension_id;
120 std::string Add(const base::DictionaryValue* parsed_manifest,
121 const base::FilePath& root_directory);
123 // Loads a registered component extension.
124 void Load(const ComponentExtensionInfo& info);
126 void AddDefaultComponentExtensionsWithBackgroundPages(
127 bool skip_session_components);
128 void AddFileManagerExtension();
129 void AddHangoutServicesExtension();
130 void AddHotwordHelperExtension();
131 void AddImageLoaderExtension();
132 void AddBookmarksExtensions();
133 void AddNetworkSpeechSynthesisExtension();
135 void AddWithName(int manifest_resource_id,
136 const base::FilePath& root_directory,
137 const std::string& name);
138 void AddChromeApp();
139 void AddKeyboardApp();
140 void AddWebStoreApp();
142 // Unloads |component| from the memory.
143 void UnloadComponent(ComponentExtensionInfo* component);
145 // Enable HTML5 FileSystem for given component extension in Guest mode.
146 void EnableFileSystemInGuestMode(const std::string& id);
148 PrefService* profile_prefs_;
149 PrefService* local_state_;
150 content::BrowserContext* browser_context_;
152 ExtensionServiceInterface* extension_service_;
154 // List of registered component extensions (see Manifest::Location).
155 typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions;
156 RegisteredComponentExtensions component_extensions_;
158 FRIEND_TEST_ALL_PREFIXES(TtsApiTest, NetworkSpeechEngine);
159 FRIEND_TEST_ALL_PREFIXES(TtsApiTest, NoNetworkSpeechEngineWhenOffline);
161 DISALLOW_COPY_AND_ASSIGN(ComponentLoader);
164 } // namespace extensions
166 #endif // CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_