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

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: should make chromeos go green Created 8 years, 1 month 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_extenstions_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_extenstions_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 #if defined(OS_CHROMEOS) 342 #if defined(OS_CHROMEOS)
332 Add(IDR_WALLPAPERMANAGER_MANIFEST,
333 FilePath(FILE_PATH_LITERAL("chromeos/wallpaper_manager")));
334 #endif
335
336 #if defined(FILE_MANAGER_EXTENSION)
337 AddFileManagerExtension();
338 #endif
339
340 #if defined(OS_CHROMEOS)
341 const CommandLine* command_line = CommandLine::ForCurrentProcess();
342 if (command_line->HasSwitch(switches::kEnableBackgroundLoader)) {
343 Add(IDR_BACKLOADER_MANIFEST,
344 FilePath(FILE_PATH_LITERAL("backloader")));
345 }
346
347 Add(IDR_MOBILE_MANIFEST, 343 Add(IDR_MOBILE_MANIFEST,
348 FilePath(FILE_PATH_LITERAL("/usr/share/chromeos-assets/mobile"))); 344 FilePath(FILE_PATH_LITERAL("/usr/share/chromeos-assets/mobile")));
349 345
350 Add(IDR_CROSH_BUILTIN_MANIFEST, FilePath(FILE_PATH_LITERAL( 346 Add(IDR_CROSH_BUILTIN_MANIFEST, FilePath(FILE_PATH_LITERAL(
351 "/usr/share/chromeos-assets/crosh_builtin"))); 347 "/usr/share/chromeos-assets/crosh_builtin")));
352 348
353 AddGaiaAuthExtension(); 349 AddGaiaAuthExtension();
354 350
355 // TODO(gauravsh): Only include echo extension on official builds. 351 // TODO(gauravsh): Only include echo extension on official builds.
356 FilePath echo_extension_path(FILE_PATH_LITERAL( 352 FilePath echo_extension_path(FILE_PATH_LITERAL(
357 "/usr/share/chromeos-assets/echo")); 353 "/usr/share/chromeos-assets/echo"));
358 if (command_line->HasSwitch(switches::kEchoExtensionPath)) { 354 if (command_line->HasSwitch(switches::kEchoExtensionPath)) {
359 echo_extension_path = 355 echo_extension_path =
360 command_line->GetSwitchValuePath(switches::kEchoExtensionPath); 356 command_line->GetSwitchValuePath(switches::kEchoExtensionPath);
361 } 357 }
362 Add(IDR_ECHO_MANIFEST, echo_extension_path); 358 Add(IDR_ECHO_MANIFEST, echo_extension_path);
363 359
364 #if defined(OFFICIAL_BUILD) 360 #if defined(OFFICIAL_BUILD)
365 if (browser_defaults::enable_help_app) { 361 if (browser_defaults::enable_help_app) {
366 Add(IDR_HELP_MANIFEST, 362 Add(IDR_HELP_MANIFEST,
367 FilePath(FILE_PATH_LITERAL("/usr/share/chromeos-assets/helpapp"))); 363 FilePath(FILE_PATH_LITERAL("/usr/share/chromeos-assets/helpapp")));
368 } 364 }
369 #endif 365 #endif
370 #endif // !defined(OS_CHROMEOS) 366 #endif // !defined(OS_CHROMEOS)
371 367
372 Add(IDR_WEBSTORE_MANIFEST, FilePath(FILE_PATH_LITERAL("web_store"))); 368 Add(IDR_WEBSTORE_MANIFEST, FilePath(FILE_PATH_LITERAL("web_store")));
373 369
374 #if defined(ENABLE_SETTINGS_APP)
375 Add(IDR_SETTINGS_APP_MANIFEST, FilePath(FILE_PATH_LITERAL("settings_app")));
376 #endif
377
378 #if !defined(OS_CHROMEOS) 370 #if !defined(OS_CHROMEOS)
379 // Cloud Print component app. Not required on Chrome OS. 371 // Cloud Print component app. Not required on Chrome OS.
380 Add(IDR_CLOUDPRINT_MANIFEST, FilePath(FILE_PATH_LITERAL("cloud_print"))); 372 Add(IDR_CLOUDPRINT_MANIFEST, FilePath(FILE_PATH_LITERAL("cloud_print")));
381 #endif 373 #endif
382 374
383 #if defined(OS_CHROMEOS)
384 // Register access extensions only if accessibility is enabled.
385 if (local_state_->GetBoolean(prefs::kSpokenFeedbackEnabled)) {
386 FilePath path = FilePath(extension_misc::kAccessExtensionPath)
387 .AppendASCII(extension_misc::kChromeVoxDirectoryName);
388 Add(IDR_CHROMEVOX_MANIFEST, path);
389 }
390 #endif
391
392 // 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
393 // component extension. This extension might also be loaded later, because 376 // component extension. This extension might also be loaded later, because
394 // 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
395 // the browser process has started. 378 // the browser process has started.
396 AddOrReloadEnterpriseWebStore(); 379 AddOrReloadEnterpriseWebStore();
397 380
398 #if defined(USE_ASH) 381 #if defined(USE_ASH)
399 AddChromeApp(); 382 AddChromeApp();
400 #endif 383 #endif
401 384
402 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_extenstions_during_testing &&
Yoyo Zhou 2012/11/27 23:54:18 typo: extensions
tapted 2012/11/28 06:21:14 Drat. Done.
395 command_line->HasSwitch(switches::kTestType)) {
396 return;
397 }
398
399 AddFileManagerExtension();
400
401 #if defined(OS_CHROMEOS)
402 Add(IDR_WALLPAPERMANAGER_MANIFEST,
403 FilePath(FILE_PATH_LITERAL("chromeos/wallpaper_manager")));
404
405 if (command_line->HasSwitch(switches::kEnableBackgroundLoader)) {
406 Add(IDR_BACKLOADER_MANIFEST,
407 FilePath(FILE_PATH_LITERAL("backloader")));
408 }
409
410 // Register access extensions only if accessibility is enabled.
411 if (local_state_->GetBoolean(prefs::kSpokenFeedbackEnabled)) {
412 FilePath path = FilePath(extension_misc::kAccessExtensionPath)
413 .AppendASCII(extension_misc::kChromeVoxDirectoryName);
414 Add(IDR_CHROMEVOX_MANIFEST, path);
415 }
416 #endif
417
418 #if defined(ENABLE_SETTINGS_APP)
419 Add(IDR_SETTINGS_APP_MANIFEST, FilePath(FILE_PATH_LITERAL("settings_app")));
420 #endif
403 } 421 }
404 422
405 // static 423 // static
406 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) { 424 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) {
407 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, 425 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL,
408 std::string() /* default_value */, 426 std::string() /* default_value */,
409 PrefService::UNSYNCABLE_PREF); 427 PrefService::UNSYNCABLE_PREF);
410 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, 428 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName,
411 std::string() /* default_value */, 429 std::string() /* default_value */,
412 PrefService::UNSYNCABLE_PREF); 430 PrefService::UNSYNCABLE_PREF);
413 } 431 }
414 432
415 } // namespace extensions 433 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698