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 #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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/prefs/pref_change_registrar.h" | 11 #include "base/prefs/pref_change_registrar.h" |
12 #include "base/prefs/pref_notifier.h" | |
13 #include "base/prefs/pref_service.h" | |
14 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
18 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
20 #include "chrome/common/extensions/extension_file_util.h" | 18 #include "chrome/common/extensions/extension_file_util.h" |
21 #include "chrome/common/extensions/extension_manifest_constants.h" | 19 #include "chrome/common/extensions/extension_manifest_constants.h" |
22 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
23 #include "components/user_prefs/pref_registry_syncable.h" | |
24 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
25 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
26 #include "extensions/common/id_util.h" | 23 #include "extensions/common/id_util.h" |
27 #include "grit/browser_resources.h" | 24 #include "grit/browser_resources.h" |
28 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
29 | 26 |
30 #if defined(USE_AURA) | 27 #if defined(USE_AURA) |
31 #include "grit/keyboard_resources.h" | 28 #include "grit/keyboard_resources.h" |
32 #endif | 29 #endif |
33 | 30 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 root_directory = root_directory.Append(directory); | 76 root_directory = root_directory.Append(directory); |
80 } | 77 } |
81 extension_id = GenerateId(manifest, root_directory); | 78 extension_id = GenerateId(manifest, root_directory); |
82 } | 79 } |
83 | 80 |
84 ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service, | 81 ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service, |
85 PrefService* profile_prefs, | 82 PrefService* profile_prefs, |
86 PrefService* local_state) | 83 PrefService* local_state) |
87 : profile_prefs_(profile_prefs), | 84 : profile_prefs_(profile_prefs), |
88 local_state_(local_state), | 85 local_state_(local_state), |
89 extension_service_(extension_service) { | 86 extension_service_(extension_service) {} |
90 pref_change_registrar_.Init(profile_prefs); | |
91 | |
92 // This pref is set by policy. We have to watch it for change because on | |
93 // ChromeOS, policy isn't loaded until after the browser process is started. | |
94 pref_change_registrar_.Add( | |
95 prefs::kEnterpriseWebStoreURL, | |
96 base::Bind(&ComponentLoader::AddOrReloadEnterpriseWebStore, | |
97 base::Unretained(this))); | |
98 } | |
99 | 87 |
100 ComponentLoader::~ComponentLoader() { | 88 ComponentLoader::~ComponentLoader() { |
101 ClearAllRegistered(); | 89 ClearAllRegistered(); |
102 } | 90 } |
103 | 91 |
104 void ComponentLoader::LoadAll() { | 92 void ComponentLoader::LoadAll() { |
105 for (RegisteredComponentExtensions::iterator it = | 93 for (RegisteredComponentExtensions::iterator it = |
106 component_extensions_.begin(); | 94 component_extensions_.begin(); |
107 it != component_extensions_.end(); ++it) { | 95 it != component_extensions_.end(); ++it) { |
108 Load(*it); | 96 Load(*it); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 command_line->GetSwitchValuePath(switches::kImageLoaderExtensionPath)); | 265 command_line->GetSwitchValuePath(switches::kImageLoaderExtensionPath)); |
278 Add(IDR_IMAGE_LOADER_MANIFEST, image_loader_extension_path); | 266 Add(IDR_IMAGE_LOADER_MANIFEST, image_loader_extension_path); |
279 return; | 267 return; |
280 } | 268 } |
281 #endif // NDEBUG | 269 #endif // NDEBUG |
282 Add(IDR_IMAGE_LOADER_MANIFEST, | 270 Add(IDR_IMAGE_LOADER_MANIFEST, |
283 base::FilePath(FILE_PATH_LITERAL("image_loader"))); | 271 base::FilePath(FILE_PATH_LITERAL("image_loader"))); |
284 #endif // defined(IMAGE_LOADER_EXTENSION) | 272 #endif // defined(IMAGE_LOADER_EXTENSION) |
285 } | 273 } |
286 | 274 |
287 void ComponentLoader::AddOrReloadEnterpriseWebStore() { | |
288 base::FilePath path(FILE_PATH_LITERAL("enterprise_web_store")); | |
289 | |
290 // Remove the extension if it was already loaded. | |
291 Remove(path); | |
292 | |
293 std::string enterprise_webstore_url = | |
294 profile_prefs_->GetString(prefs::kEnterpriseWebStoreURL); | |
295 | |
296 // Load the extension only if the URL preference is set. | |
297 if (!enterprise_webstore_url.empty()) { | |
298 std::string manifest_contents = | |
299 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
300 IDR_ENTERPRISE_WEBSTORE_MANIFEST).as_string(); | |
301 | |
302 // The manifest is missing some values that are provided by policy. | |
303 DictionaryValue* manifest = ParseManifest(manifest_contents); | |
304 if (manifest) { | |
305 std::string name = | |
306 profile_prefs_->GetString(prefs::kEnterpriseWebStoreName); | |
307 manifest->SetString("app.launch.web_url", enterprise_webstore_url); | |
308 manifest->SetString("name", name); | |
309 Add(manifest, path); | |
310 } | |
311 } | |
312 } | |
313 | |
314 void ComponentLoader::AddChromeApp() { | 275 void ComponentLoader::AddChromeApp() { |
315 #if defined(ENABLE_APP_LIST) | 276 #if defined(ENABLE_APP_LIST) |
316 std::string manifest_contents = | 277 std::string manifest_contents = |
317 ResourceBundle::GetSharedInstance().GetRawDataResource( | 278 ResourceBundle::GetSharedInstance().GetRawDataResource( |
318 IDR_CHROME_APP_MANIFEST).as_string(); | 279 IDR_CHROME_APP_MANIFEST).as_string(); |
319 | 280 |
320 // The Value is kept for the lifetime of the ComponentLoader. This is | 281 // The Value is kept for the lifetime of the ComponentLoader. This is |
321 // required in case LoadAll() is called again. | 282 // required in case LoadAll() is called again. |
322 DictionaryValue* manifest = ParseManifest(manifest_contents); | 283 DictionaryValue* manifest = ParseManifest(manifest_contents); |
323 | 284 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 DCHECK(!skip_session_components); | 331 DCHECK(!skip_session_components); |
371 Add(IDR_BOOKMARKS_MANIFEST, | 332 Add(IDR_BOOKMARKS_MANIFEST, |
372 base::FilePath(FILE_PATH_LITERAL("bookmark_manager"))); | 333 base::FilePath(FILE_PATH_LITERAL("bookmark_manager"))); |
373 // Cloud Print component app. Not required on Chrome OS. | 334 // Cloud Print component app. Not required on Chrome OS. |
374 Add(IDR_CLOUDPRINT_MANIFEST, | 335 Add(IDR_CLOUDPRINT_MANIFEST, |
375 base::FilePath(FILE_PATH_LITERAL("cloud_print"))); | 336 base::FilePath(FILE_PATH_LITERAL("cloud_print"))); |
376 #endif | 337 #endif |
377 | 338 |
378 if (!skip_session_components) { | 339 if (!skip_session_components) { |
379 Add(IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store"))); | 340 Add(IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store"))); |
380 | |
381 // If a URL for the enterprise webstore has been specified, load the | |
382 // component extension. This extension might also be loaded later, because | |
383 // it is specified by policy, and on ChromeOS policies are loaded after | |
384 // the browser process has started. | |
385 AddOrReloadEnterpriseWebStore(); | |
386 | |
387 AddChromeApp(); | 341 AddChromeApp(); |
388 } | 342 } |
389 | 343 |
390 AddKeyboardApp(); | 344 AddKeyboardApp(); |
391 | 345 |
392 AddDefaultComponentExtensionsWithBackgroundPages(skip_session_components); | 346 AddDefaultComponentExtensionsWithBackgroundPages(skip_session_components); |
393 } | 347 } |
394 | 348 |
395 void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages( | 349 void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages( |
396 bool skip_session_components) { | 350 bool skip_session_components) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 434 |
481 void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) { | 435 void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) { |
482 delete component->manifest; | 436 delete component->manifest; |
483 if (extension_service_->is_ready()) { | 437 if (extension_service_->is_ready()) { |
484 extension_service_-> | 438 extension_service_-> |
485 UnloadExtension(component->extension_id, | 439 UnloadExtension(component->extension_id, |
486 extension_misc::UNLOAD_REASON_DISABLE); | 440 extension_misc::UNLOAD_REASON_DISABLE); |
487 } | 441 } |
488 } | 442 } |
489 | 443 |
490 // static | |
491 void ComponentLoader::RegisterUserPrefs( | |
492 user_prefs::PrefRegistrySyncable* registry) { | |
493 registry->RegisterStringPref( | |
494 prefs::kEnterpriseWebStoreURL, | |
495 std::string() /* default_value */, | |
496 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
497 registry->RegisterStringPref( | |
498 prefs::kEnterpriseWebStoreName, | |
499 std::string() /* default_value */, | |
500 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
501 } | |
502 | |
503 } // namespace extensions | 444 } // namespace extensions |
OLD | NEW |