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 #include "chrome/browser/extensions/component_loader.h" | 5 #include "chrome/browser/extensions/component_loader.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/json/json_value_serializer.h" | 9 #include "base/json/json_value_serializer.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 } | 57 } |
58 | 58 |
59 void ComponentLoader::LoadAll() { | 59 void ComponentLoader::LoadAll() { |
60 for (RegisteredComponentExtensions::iterator it = | 60 for (RegisteredComponentExtensions::iterator it = |
61 component_extensions_.begin(); | 61 component_extensions_.begin(); |
62 it != component_extensions_.end(); ++it) { | 62 it != component_extensions_.end(); ++it) { |
63 Load(*it); | 63 Load(*it); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 const Extension* ComponentLoader::Add( | 67 const Extension* ComponentLoader::Add(const std::string& manifest, |
68 const std::string& manifest, const FilePath& root_directory) { | 68 const FilePath& root_directory, DictionaryValue* manifest_overrides) { |
69 ComponentExtensionInfo info(manifest, root_directory); | 69 ComponentExtensionInfo info(manifest, root_directory, manifest_overrides); |
70 Register(info); | 70 Register(info); |
71 if (extension_service_->is_ready()) | 71 if (extension_service_->is_ready()) |
72 return Load(info); | 72 return Load(info); |
73 return NULL; | 73 return NULL; |
74 } | 74 } |
75 | 75 |
76 const Extension* ComponentLoader::Load(const ComponentExtensionInfo& info) { | 76 const Extension* ComponentLoader::Load(const ComponentExtensionInfo& info) { |
77 JSONStringValueSerializer serializer(info.manifest); | 77 JSONStringValueSerializer serializer(info.manifest); |
78 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); | 78 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); |
79 if (!manifest.get()) { | 79 if (!manifest.get()) { |
80 LOG(ERROR) << "Failed to parse manifest for extension"; | 80 LOG(ERROR) << "Failed to parse manifest for extension"; |
81 return NULL; | 81 return NULL; |
82 } | 82 } |
83 | 83 |
84 DCHECK(manifest->IsType(Value::TYPE_DICTIONARY)); | |
85 | |
86 if (info.manifest_overrides != NULL) { | |
87 ((DictionaryValue*)manifest.get())->MergeDictionary( | |
88 info.manifest_overrides); | |
89 } | |
90 | |
84 int flags = Extension::REQUIRE_KEY; | 91 int flags = Extension::REQUIRE_KEY; |
85 if (Extension::ShouldDoStrictErrorChecking(Extension::COMPONENT)) | 92 if (Extension::ShouldDoStrictErrorChecking(Extension::COMPONENT)) |
86 flags |= Extension::STRICT_ERROR_CHECKS; | 93 flags |= Extension::STRICT_ERROR_CHECKS; |
87 std::string error; | 94 std::string error; |
88 scoped_refptr<const Extension> extension(Extension::Create( | 95 scoped_refptr<const Extension> extension(Extension::Create( |
89 info.root_directory, | 96 info.root_directory, |
90 Extension::COMPONENT, | 97 Extension::COMPONENT, |
91 *static_cast<DictionaryValue*>(manifest.get()), | 98 *static_cast<DictionaryValue*>(manifest.get()), |
92 flags, | 99 flags, |
93 &error)); | 100 &error)); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 FILE_PATH_LITERAL("web_store"), | 190 FILE_PATH_LITERAL("web_store"), |
184 IDR_WEBSTORE_MANIFEST)); | 191 IDR_WEBSTORE_MANIFEST)); |
185 | 192 |
186 #if !defined(OS_CHROMEOS) | 193 #if !defined(OS_CHROMEOS) |
187 // Cloud Print component app. Not required on Chrome OS. | 194 // Cloud Print component app. Not required on Chrome OS. |
188 component_extensions.push_back(std::make_pair( | 195 component_extensions.push_back(std::make_pair( |
189 FILE_PATH_LITERAL("cloud_print"), | 196 FILE_PATH_LITERAL("cloud_print"), |
190 IDR_CLOUDPRINT_MANIFEST)); | 197 IDR_CLOUDPRINT_MANIFEST)); |
191 #endif // !defined(OS_CHROMEOS) | 198 #endif // !defined(OS_CHROMEOS) |
192 | 199 |
200 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); | |
201 | |
193 for (ComponentExtensionList::iterator iter = component_extensions.begin(); | 202 for (ComponentExtensionList::iterator iter = component_extensions.begin(); |
194 iter != component_extensions.end(); ++iter) { | 203 iter != component_extensions.end(); ++iter) { |
195 FilePath path(iter->first); | 204 FilePath path(iter->first); |
196 if (!path.IsAbsolute()) { | 205 if (!path.IsAbsolute()) { |
197 if (PathService::Get(chrome::DIR_RESOURCES, &path)) { | 206 if (PathService::Get(chrome::DIR_RESOURCES, &path)) { |
198 path = path.Append(iter->first); | 207 path = path.Append(iter->first); |
199 } else { | 208 } else { |
200 NOTREACHED(); | 209 NOTREACHED(); |
201 } | 210 } |
202 } | 211 } |
203 | 212 |
204 std::string manifest = | 213 std::string manifest = resource_bundle.GetRawDataResource( |
205 ResourceBundle::GetSharedInstance().GetRawDataResource( | 214 iter->second).as_string(); |
206 iter->second).as_string(); | |
207 Add(manifest, path); | 215 Add(manifest, path); |
208 } | 216 } |
209 | 217 |
210 #if defined(OS_CHROMEOS) | 218 #if defined(OS_CHROMEOS) |
211 // Register access extensions only if accessibility is enabled. | 219 // Register access extensions only if accessibility is enabled. |
212 if (g_browser_process->local_state()-> | 220 if (g_browser_process->local_state()-> |
213 GetBoolean(prefs::kAccessibilityEnabled)) { | 221 GetBoolean(prefs::kAccessibilityEnabled)) { |
214 FilePath path = FilePath(extension_misc::kAccessExtensionPath) | 222 FilePath path = FilePath(extension_misc::kAccessExtensionPath) |
215 .AppendASCII(extension_misc::kChromeVoxDirectoryName); | 223 .AppendASCII(extension_misc::kChromeVoxDirectoryName); |
216 std::string manifest = | 224 std::string manifest = resource_bundle.GetRawDataResource( |
217 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
218 IDR_CHROMEVOX_MANIFEST).as_string(); | 225 IDR_CHROMEVOX_MANIFEST).as_string(); |
219 Add(manifest, path); | 226 Add(manifest, path); |
220 } | 227 } |
221 #endif | 228 #endif |
229 | |
230 if (/* policy specifies an enterprise web store */ 1) { | |
231 DictionaryValue* manifest_overrides = new DictionaryValue(); // FIXME: Leak. | |
232 | |
233 // FIXME: Fetch the URL from the appropriate policy | |
234 manifest_overrides->SetString("app.launch.web_url", "http://www.corp.google. com"); | |
235 | |
236 FilePath path; | |
237 if (!PathService::Get(chrome::DIR_RESOURCES, &path)) | |
238 NOTREACHED(); | |
239 path.Append(FILE_PATH_LITERAL("enterprise_web_store")); | |
240 std::string manifest = resource_bundle.GetRawDataResource( | |
241 IDR_ENTERPRISE_WEBSTORE_MANIFEST).as_string(); | |
242 Add(manifest, path, manifest_overrides); | |
Aaron Boodman
2011/11/06 23:05:40
Instead of introducing this overrides thing, just
| |
243 } | |
222 } | 244 } |
223 | |
224 } // namespace extensions | 245 } // namespace extensions |
OLD | NEW |