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_notifier.h" | 11 #include "base/prefs/pref_notifier.h" |
12 #include "base/prefs/public/pref_change_registrar.h" | 12 #include "base/prefs/public/pref_change_registrar.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
21 #include "chrome/common/extensions/extension_file_util.h" | 21 #include "chrome/common/extensions/extension_file_util.h" |
22 #include "chrome/common/extensions/extension_manifest_constants.h" | 22 #include "chrome/common/extensions/extension_manifest_constants.h" |
23 #include "chrome/common/extensions/feature_switch.h" | |
24 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
25 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
26 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
27 #include "grit/browser_resources.h" | 26 #include "grit/browser_resources.h" |
28 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
29 | 28 |
30 #if defined(OFFICIAL_BUILD) | 29 #if defined(OFFICIAL_BUILD) |
31 #include "chrome/browser/defaults.h" | 30 #include "chrome/browser/defaults.h" |
32 #endif | 31 #endif |
33 | 32 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 pref_change_registrar_.Add( | 81 pref_change_registrar_.Add( |
83 prefs::kEnterpriseWebStoreURL, | 82 prefs::kEnterpriseWebStoreURL, |
84 base::Bind(&ComponentLoader::AddOrReloadEnterpriseWebStore, | 83 base::Bind(&ComponentLoader::AddOrReloadEnterpriseWebStore, |
85 base::Unretained(this))); | 84 base::Unretained(this))); |
86 } | 85 } |
87 | 86 |
88 ComponentLoader::~ComponentLoader() { | 87 ComponentLoader::~ComponentLoader() { |
89 ClearAllRegistered(); | 88 ClearAllRegistered(); |
90 } | 89 } |
91 | 90 |
92 const Extension* ComponentLoader::GetScriptBubble() const { | |
93 if (script_bubble_id_.empty()) | |
94 return NULL; | |
95 | |
96 return extension_service_->extensions()->GetByID(script_bubble_id_); | |
97 } | |
98 | |
99 void ComponentLoader::LoadAll() { | 91 void ComponentLoader::LoadAll() { |
100 for (RegisteredComponentExtensions::iterator it = | 92 for (RegisteredComponentExtensions::iterator it = |
101 component_extensions_.begin(); | 93 component_extensions_.begin(); |
102 it != component_extensions_.end(); ++it) { | 94 it != component_extensions_.end(); ++it) { |
103 Load(*it); | 95 Load(*it); |
104 } | 96 } |
105 } | 97 } |
106 | 98 |
107 DictionaryValue* ComponentLoader::ParseManifest( | 99 DictionaryValue* ComponentLoader::ParseManifest( |
108 const std::string& manifest_contents) const { | 100 const std::string& manifest_contents) const { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 298 |
307 // Update manifest to use a proper name. | 299 // Update manifest to use a proper name. |
308 manifest->SetString(extension_manifest_keys::kName, | 300 manifest->SetString(extension_manifest_keys::kName, |
309 l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME)); | 301 l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME)); |
310 | 302 |
311 if (manifest) | 303 if (manifest) |
312 Add(manifest, FilePath(FILE_PATH_LITERAL("chrome_app"))); | 304 Add(manifest, FilePath(FILE_PATH_LITERAL("chrome_app"))); |
313 #endif | 305 #endif |
314 } | 306 } |
315 | 307 |
316 void ComponentLoader::AddScriptBubble() { | |
317 if (FeatureSwitch::script_bubble()->IsEnabled()) { | |
318 script_bubble_id_ = | |
319 Add(IDR_SCRIPT_BUBBLE_MANIFEST, | |
320 FilePath(FILE_PATH_LITERAL("script_bubble"))); | |
321 } | |
322 } | |
323 | |
324 // static | 308 // static |
325 void ComponentLoader::EnableBackgroundExtensionsForTesting() { | 309 void ComponentLoader::EnableBackgroundExtensionsForTesting() { |
326 enable_background_extensions_during_testing = true; | 310 enable_background_extensions_during_testing = true; |
327 } | 311 } |
328 | 312 |
329 void ComponentLoader::AddDefaultComponentExtensions() { | 313 void ComponentLoader::AddDefaultComponentExtensions() { |
330 // Do not add component extensions that have background pages here -- add them | 314 // Do not add component extensions that have background pages here -- add them |
331 // to AddDefaultComponentExtensionsWithBackgroundPages. | 315 // to AddDefaultComponentExtensionsWithBackgroundPages. |
332 | 316 |
333 #if defined(OS_CHROMEOS) | 317 #if defined(OS_CHROMEOS) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 // If a URL for the enterprise webstore has been specified, load the | 359 // If a URL for the enterprise webstore has been specified, load the |
376 // component extension. This extension might also be loaded later, because | 360 // component extension. This extension might also be loaded later, because |
377 // it is specified by policy, and on ChromeOS policies are loaded after | 361 // it is specified by policy, and on ChromeOS policies are loaded after |
378 // the browser process has started. | 362 // the browser process has started. |
379 AddOrReloadEnterpriseWebStore(); | 363 AddOrReloadEnterpriseWebStore(); |
380 | 364 |
381 #if defined(USE_ASH) | 365 #if defined(USE_ASH) |
382 AddChromeApp(); | 366 AddChromeApp(); |
383 #endif | 367 #endif |
384 | 368 |
385 AddScriptBubble(); | |
386 AddDefaultComponentExtensionsWithBackgroundPages(); | 369 AddDefaultComponentExtensionsWithBackgroundPages(); |
387 } | 370 } |
388 | 371 |
389 void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages() { | 372 void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages() { |
390 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 373 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
391 | 374 |
392 // Component extensions with background pages are not enabled during tests | 375 // Component extensions with background pages are not enabled during tests |
393 // because they generate a lot of background behavior that can interfere. | 376 // because they generate a lot of background behavior that can interfere. |
394 if (!enable_background_extensions_during_testing && | 377 if (!enable_background_extensions_during_testing && |
395 command_line->HasSwitch(switches::kTestType)) { | 378 command_line->HasSwitch(switches::kTestType)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) { | 413 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) { |
431 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, | 414 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, |
432 std::string() /* default_value */, | 415 std::string() /* default_value */, |
433 PrefService::UNSYNCABLE_PREF); | 416 PrefService::UNSYNCABLE_PREF); |
434 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, | 417 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, |
435 std::string() /* default_value */, | 418 std::string() /* default_value */, |
436 PrefService::UNSYNCABLE_PREF); | 419 PrefService::UNSYNCABLE_PREF); |
437 } | 420 } |
438 | 421 |
439 } // namespace extensions | 422 } // namespace extensions |
OLD | NEW |