Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: chrome/browser/extensions/component_loader.cc

Issue 11275069: Perform install tasks for newly installed or upgraded component apps/extensions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase and move v2 component app added in r169911 (and r170087) into background section in componen… Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 26 matching lines...) Expand all
37 37
38 #if defined(USE_ASH) 38 #if defined(USE_ASH)
39 #include "grit/chromium_strings.h" 39 #include "grit/chromium_strings.h"
40 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
41 #endif 41 #endif
42 42
43 namespace extensions { 43 namespace extensions {
44 44
45 namespace { 45 namespace {
46 46
47 static bool enable_background_extensions_during_testing = false;
48
47 std::string GenerateId(const DictionaryValue* manifest, const FilePath& path) { 49 std::string GenerateId(const DictionaryValue* manifest, const FilePath& path) {
48 std::string raw_key; 50 std::string raw_key;
49 std::string id_input; 51 std::string id_input;
50 std::string id; 52 std::string id;
51 CHECK(manifest->GetString(extension_manifest_keys::kPublicKey, &raw_key)); 53 CHECK(manifest->GetString(extension_manifest_keys::kPublicKey, &raw_key));
52 CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input)); 54 CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input));
53 CHECK(Extension::GenerateId(id_input, &id)); 55 CHECK(Extension::GenerateId(id_input, &id));
54 return id; 56 return id;
55 } 57 }
56 58
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 info.root_directory, 192 info.root_directory,
191 Extension::COMPONENT, 193 Extension::COMPONENT,
192 *info.manifest, 194 *info.manifest,
193 flags, 195 flags,
194 &error)); 196 &error));
195 if (!extension.get()) { 197 if (!extension.get()) {
196 LOG(ERROR) << error; 198 LOG(ERROR) << error;
197 return NULL; 199 return NULL;
198 } 200 }
199 CHECK_EQ(info.extension_id, extension->id()) << extension->name(); 201 CHECK_EQ(info.extension_id, extension->id()) << extension->name();
200 extension_service_->AddExtension(extension); 202 extension_service_->AddComponentExtension(extension);
201 return extension; 203 return extension;
202 } 204 }
203 205
204 void ComponentLoader::Remove(const FilePath& root_directory) { 206 void ComponentLoader::Remove(const FilePath& root_directory) {
205 // Find the ComponentExtensionInfo for the extension. 207 // Find the ComponentExtensionInfo for the extension.
206 RegisteredComponentExtensions::iterator it = component_extensions_.begin(); 208 RegisteredComponentExtensions::iterator it = component_extensions_.begin();
207 for (; it != component_extensions_.end(); ++it) { 209 for (; it != component_extensions_.end(); ++it) {
208 if (it->root_directory == root_directory) { 210 if (it->root_directory == root_directory) {
209 Remove(GenerateId(it->manifest, root_directory)); 211 Remove(GenerateId(it->manifest, root_directory));
210 break; 212 break;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 314 }
313 315
314 void ComponentLoader::AddScriptBubble() { 316 void ComponentLoader::AddScriptBubble() {
315 if (FeatureSwitch::script_bubble()->IsEnabled()) { 317 if (FeatureSwitch::script_bubble()->IsEnabled()) {
316 script_bubble_id_ = 318 script_bubble_id_ =
317 Add(IDR_SCRIPT_BUBBLE_MANIFEST, 319 Add(IDR_SCRIPT_BUBBLE_MANIFEST,
318 FilePath(FILE_PATH_LITERAL("script_bubble"))); 320 FilePath(FILE_PATH_LITERAL("script_bubble")));
319 } 321 }
320 } 322 }
321 323
324 // static
325 void ComponentLoader::EnableBackgroundExtensionsForTesting() {
326 enable_background_extensions_during_testing = true;
327 }
328
322 void ComponentLoader::AddDefaultComponentExtensions() { 329 void ComponentLoader::AddDefaultComponentExtensions() {
330 // Do not add component extensions that have background pages here -- add them
331 // to AddDefaultComponentExtensionsWithBackgroundPages.
332
323 #if defined(OS_CHROMEOS) 333 #if defined(OS_CHROMEOS)
324 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) 334 const CommandLine* command_line = CommandLine::ForCurrentProcess();
335 if (!command_line->HasSwitch(switches::kGuestSession))
325 Add(IDR_BOOKMARKS_MANIFEST, 336 Add(IDR_BOOKMARKS_MANIFEST,
326 FilePath(FILE_PATH_LITERAL("bookmark_manager"))); 337 FilePath(FILE_PATH_LITERAL("bookmark_manager")));
327 #else 338 #else
328 Add(IDR_BOOKMARKS_MANIFEST, FilePath(FILE_PATH_LITERAL("bookmark_manager"))); 339 Add(IDR_BOOKMARKS_MANIFEST, FilePath(FILE_PATH_LITERAL("bookmark_manager")));
329 #endif 340 #endif
330 341
331 // Apps Debugger
332 if (CommandLine::ForCurrentProcess()->HasSwitch(
333 switches::kAppsDebugger)) {
334 Add(IDR_APPS_DEBUGGER_MANIFEST,
335 FilePath(FILE_PATH_LITERAL("apps_debugger")));
336 }
337
338 #if defined(OS_CHROMEOS) 342 #if defined(OS_CHROMEOS)
339 Add(IDR_WALLPAPERMANAGER_MANIFEST,
340 FilePath(FILE_PATH_LITERAL("chromeos/wallpaper_manager")));
341 #endif
342
343 #if defined(FILE_MANAGER_EXTENSION)
344 AddFileManagerExtension();
345 #endif
346
347 #if defined(OS_CHROMEOS)
348 const CommandLine* command_line = CommandLine::ForCurrentProcess();
349 if (command_line->HasSwitch(switches::kEnableBackgroundLoader)) {
350 Add(IDR_BACKLOADER_MANIFEST,
351 FilePath(FILE_PATH_LITERAL("backloader")));
352 }
353
354 Add(IDR_MOBILE_MANIFEST, 343 Add(IDR_MOBILE_MANIFEST,
355 FilePath(FILE_PATH_LITERAL("/usr/share/chromeos-assets/mobile"))); 344 FilePath(FILE_PATH_LITERAL("/usr/share/chromeos-assets/mobile")));
356 345
357 Add(IDR_CROSH_BUILTIN_MANIFEST, FilePath(FILE_PATH_LITERAL( 346 Add(IDR_CROSH_BUILTIN_MANIFEST, FilePath(FILE_PATH_LITERAL(
358 "/usr/share/chromeos-assets/crosh_builtin"))); 347 "/usr/share/chromeos-assets/crosh_builtin")));
359 348
360 AddGaiaAuthExtension(); 349 AddGaiaAuthExtension();
361 350
362 // TODO(gauravsh): Only include echo extension on official builds. 351 // TODO(gauravsh): Only include echo extension on official builds.
363 FilePath echo_extension_path(FILE_PATH_LITERAL( 352 FilePath echo_extension_path(FILE_PATH_LITERAL(
364 "/usr/share/chromeos-assets/echo")); 353 "/usr/share/chromeos-assets/echo"));
365 if (command_line->HasSwitch(switches::kEchoExtensionPath)) { 354 if (command_line->HasSwitch(switches::kEchoExtensionPath)) {
366 echo_extension_path = 355 echo_extension_path =
367 command_line->GetSwitchValuePath(switches::kEchoExtensionPath); 356 command_line->GetSwitchValuePath(switches::kEchoExtensionPath);
368 } 357 }
369 Add(IDR_ECHO_MANIFEST, echo_extension_path); 358 Add(IDR_ECHO_MANIFEST, echo_extension_path);
370 359
371 #if defined(OFFICIAL_BUILD) 360 #if defined(OFFICIAL_BUILD)
372 if (browser_defaults::enable_help_app) { 361 if (browser_defaults::enable_help_app) {
373 Add(IDR_HELP_MANIFEST, 362 Add(IDR_HELP_MANIFEST,
374 FilePath(FILE_PATH_LITERAL("/usr/share/chromeos-assets/helpapp"))); 363 FilePath(FILE_PATH_LITERAL("/usr/share/chromeos-assets/helpapp")));
375 } 364 }
376 #endif 365 #endif
377 #endif // !defined(OS_CHROMEOS) 366 #endif // !defined(OS_CHROMEOS)
378 367
379 Add(IDR_WEBSTORE_MANIFEST, FilePath(FILE_PATH_LITERAL("web_store"))); 368 Add(IDR_WEBSTORE_MANIFEST, FilePath(FILE_PATH_LITERAL("web_store")));
380 369
381 #if defined(ENABLE_SETTINGS_APP)
382 Add(IDR_SETTINGS_APP_MANIFEST, FilePath(FILE_PATH_LITERAL("settings_app")));
383 #endif
384
385 #if !defined(OS_CHROMEOS) 370 #if !defined(OS_CHROMEOS)
386 // Cloud Print component app. Not required on Chrome OS. 371 // Cloud Print component app. Not required on Chrome OS.
387 Add(IDR_CLOUDPRINT_MANIFEST, FilePath(FILE_PATH_LITERAL("cloud_print"))); 372 Add(IDR_CLOUDPRINT_MANIFEST, FilePath(FILE_PATH_LITERAL("cloud_print")));
388 #endif 373 #endif
389 374
390 #if defined(OS_CHROMEOS)
391 // Load ChromeVox extension now if spoken feedback is enabled.
392 if (local_state_->GetBoolean(prefs::kSpokenFeedbackEnabled)) {
393 FilePath path = FilePath(extension_misc::kChromeVoxExtensionPath);
394 Add(IDR_CHROMEVOX_MANIFEST, path);
395 }
396 #endif
397
398 // If a URL for the enterprise webstore has been specified, load the 375 // If a URL for the enterprise webstore has been specified, load the
399 // component extension. This extension might also be loaded later, because 376 // component extension. This extension might also be loaded later, because
400 // it is specified by policy, and on ChromeOS policies are loaded after 377 // it is specified by policy, and on ChromeOS policies are loaded after
401 // the browser process has started. 378 // the browser process has started.
402 AddOrReloadEnterpriseWebStore(); 379 AddOrReloadEnterpriseWebStore();
403 380
404 #if defined(USE_ASH) 381 #if defined(USE_ASH)
405 AddChromeApp(); 382 AddChromeApp();
406 #endif 383 #endif
407 384
408 AddScriptBubble(); 385 AddScriptBubble();
386 AddDefaultComponentExtensionsWithBackgroundPages();
387 }
388
389 void ComponentLoader::AddDefaultComponentExtensionsWithBackgroundPages() {
390 const CommandLine* command_line = CommandLine::ForCurrentProcess();
391
392 // Component extensions with background pages are not enabled during tests
393 // because they generate a lot of background behavior that can interfere.
394 if (!enable_background_extensions_during_testing &&
395 command_line->HasSwitch(switches::kTestType)) {
396 return;
397 }
398
399 // Apps Debugger
400 if (CommandLine::ForCurrentProcess()->HasSwitch(
401 switches::kAppsDebugger)) {
402 Add(IDR_APPS_DEBUGGER_MANIFEST,
403 FilePath(FILE_PATH_LITERAL("apps_debugger")));
404 }
405
406 AddFileManagerExtension();
407
408 #if defined(OS_CHROMEOS)
409 Add(IDR_WALLPAPERMANAGER_MANIFEST,
410 FilePath(FILE_PATH_LITERAL("chromeos/wallpaper_manager")));
411
412 if (command_line->HasSwitch(switches::kEnableBackgroundLoader)) {
413 Add(IDR_BACKLOADER_MANIFEST,
414 FilePath(FILE_PATH_LITERAL("backloader")));
415 }
416
417 // Load ChromeVox extension now if spoken feedback is enabled.
418 if (local_state_->GetBoolean(prefs::kSpokenFeedbackEnabled)) {
419 FilePath path = FilePath(extension_misc::kChromeVoxExtensionPath);
420 Add(IDR_CHROMEVOX_MANIFEST, path);
421 }
422 #endif
423
424 #if defined(ENABLE_SETTINGS_APP)
425 Add(IDR_SETTINGS_APP_MANIFEST, FilePath(FILE_PATH_LITERAL("settings_app")));
426 #endif
409 } 427 }
410 428
411 // static 429 // static
412 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) { 430 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) {
413 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, 431 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL,
414 std::string() /* default_value */, 432 std::string() /* default_value */,
415 PrefService::UNSYNCABLE_PREF); 433 PrefService::UNSYNCABLE_PREF);
416 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, 434 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName,
417 std::string() /* default_value */, 435 std::string() /* default_value */,
418 PrefService::UNSYNCABLE_PREF); 436 PrefService::UNSYNCABLE_PREF);
419 } 437 }
420 438
421 } // namespace extensions 439 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/component_loader.h ('k') | chrome/browser/extensions/component_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698