Chromium Code Reviews| 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/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 #include "chrome/browser/search_engines/template_url_service.h" | 67 #include "chrome/browser/search_engines/template_url_service.h" |
| 68 #include "chrome/browser/search_engines/template_url_service_factory.h" | 68 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 69 #include "chrome/browser/sync/api/sync_change.h" | 69 #include "chrome/browser/sync/api/sync_change.h" |
| 70 #include "chrome/browser/themes/theme_service.h" | 70 #include "chrome/browser/themes/theme_service.h" |
| 71 #include "chrome/browser/themes/theme_service_factory.h" | 71 #include "chrome/browser/themes/theme_service_factory.h" |
| 72 #include "chrome/browser/ui/browser.h" | 72 #include "chrome/browser/ui/browser.h" |
| 73 #include "chrome/browser/ui/browser_list.h" | 73 #include "chrome/browser/ui/browser_list.h" |
| 74 #include "chrome/browser/ui/global_error_service.h" | 74 #include "chrome/browser/ui/global_error_service.h" |
| 75 #include "chrome/browser/ui/global_error_service_factory.h" | 75 #include "chrome/browser/ui/global_error_service_factory.h" |
| 76 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 76 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 77 #include "chrome/browser/ui/webui/extension_icon_source.h" | |
| 77 #include "chrome/browser/ui/webui/favicon_source.h" | 78 #include "chrome/browser/ui/webui/favicon_source.h" |
| 78 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 79 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
| 80 #include "chrome/browser/web_applications/web_app.h" | |
| 79 #include "chrome/common/child_process_logging.h" | 81 #include "chrome/common/child_process_logging.h" |
| 80 #include "chrome/common/chrome_notification_types.h" | 82 #include "chrome/common/chrome_notification_types.h" |
| 81 #include "chrome/common/chrome_paths.h" | 83 #include "chrome/common/chrome_paths.h" |
| 82 #include "chrome/common/chrome_switches.h" | 84 #include "chrome/common/chrome_switches.h" |
| 83 #include "chrome/common/extensions/extension.h" | 85 #include "chrome/common/extensions/extension.h" |
| 84 #include "chrome/common/extensions/extension_constants.h" | 86 #include "chrome/common/extensions/extension_constants.h" |
| 85 #include "chrome/common/extensions/extension_error_utils.h" | 87 #include "chrome/common/extensions/extension_error_utils.h" |
| 86 #include "chrome/common/extensions/extension_file_util.h" | 88 #include "chrome/common/extensions/extension_file_util.h" |
| 87 #include "chrome/common/extensions/extension_messages.h" | 89 #include "chrome/common/extensions/extension_messages.h" |
| 88 #include "chrome/common/extensions/extension_resource.h" | 90 #include "chrome/common/extensions/extension_resource.h" |
| 89 #include "chrome/common/pref_names.h" | 91 #include "chrome/common/pref_names.h" |
| 90 #include "chrome/common/url_constants.h" | 92 #include "chrome/common/url_constants.h" |
| 91 #include "content/browser/plugin_process_host.h" | 93 #include "content/browser/plugin_process_host.h" |
| 92 #include "content/browser/plugin_service.h" | 94 #include "content/browser/plugin_service.h" |
| 93 #include "content/browser/user_metrics.h" | 95 #include "content/browser/user_metrics.h" |
| 94 #include "content/public/browser/browser_thread.h" | 96 #include "content/public/browser/browser_thread.h" |
| 95 #include "content/public/browser/devtools_agent_host_registry.h" | 97 #include "content/public/browser/devtools_agent_host_registry.h" |
| 96 #include "content/public/browser/devtools_manager.h" | 98 #include "content/public/browser/devtools_manager.h" |
| 97 #include "content/public/browser/notification_service.h" | 99 #include "content/public/browser/notification_service.h" |
| 98 #include "content/public/browser/notification_types.h" | 100 #include "content/public/browser/notification_types.h" |
| 99 #include "content/public/browser/render_process_host.h" | 101 #include "content/public/browser/render_process_host.h" |
| 100 #include "content/public/common/pepper_plugin_info.h" | 102 #include "content/public/common/pepper_plugin_info.h" |
| 101 #include "googleurl/src/gurl.h" | 103 #include "googleurl/src/gurl.h" |
| 104 #include "grit/theme_resources.h" | |
| 102 #include "net/base/registry_controlled_domain.h" | 105 #include "net/base/registry_controlled_domain.h" |
| 103 #include "webkit/database/database_tracker.h" | 106 #include "webkit/database/database_tracker.h" |
| 104 #include "webkit/database/database_util.h" | 107 #include "webkit/database/database_util.h" |
| 105 | 108 |
| 106 #if defined(OS_CHROMEOS) | 109 #if defined(OS_CHROMEOS) |
| 107 #include "chrome/browser/chromeos/cros/cros_library.h" | 110 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 108 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" | 111 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
| 109 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" | 112 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
| 110 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" | 113 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" |
| 111 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 114 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 extensions_enabled_(extensions_enabled), | 385 extensions_enabled_(extensions_enabled), |
| 383 show_extensions_prompts_(true), | 386 show_extensions_prompts_(true), |
| 384 ready_(false), | 387 ready_(false), |
| 385 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 388 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 386 menu_manager_(profile), | 389 menu_manager_(profile), |
| 387 app_notification_manager_(new AppNotificationManager(profile)), | 390 app_notification_manager_(new AppNotificationManager(profile)), |
| 388 permissions_manager_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 391 permissions_manager_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 389 apps_promo_(profile->GetPrefs()), | 392 apps_promo_(profile->GetPrefs()), |
| 390 event_routers_initialized_(false), | 393 event_routers_initialized_(false), |
| 391 extension_warnings_(profile), | 394 extension_warnings_(profile), |
| 392 socket_controller_(new extensions::SocketController()) { | 395 socket_controller_(new extensions::SocketController()), |
| 396 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
| 393 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 397 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 394 | 398 |
| 395 // Figure out if extension installation should be enabled. | 399 // Figure out if extension installation should be enabled. |
| 396 if (command_line->HasSwitch(switches::kDisableExtensions)) { | 400 if (command_line->HasSwitch(switches::kDisableExtensions)) { |
| 397 extensions_enabled_ = false; | 401 extensions_enabled_ = false; |
| 398 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { | 402 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { |
| 399 extensions_enabled_ = false; | 403 extensions_enabled_ = false; |
| 400 } | 404 } |
| 401 | 405 |
| 402 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 406 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
| (...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2104 // the webRequest API), set the preference. Otherwise clear it, in case the | 2108 // the webRequest API), set the preference. Otherwise clear it, in case the |
| 2105 // extension stopped using a relevant API. | 2109 // extension stopped using a relevant API. |
| 2106 extension_prefs_->SetDelaysNetworkRequests( | 2110 extension_prefs_->SetDelaysNetworkRequests( |
| 2107 extension->id(), extension->ImplicitlyDelaysNetworkStartup()); | 2111 extension->id(), extension->ImplicitlyDelaysNetworkStartup()); |
| 2108 | 2112 |
| 2109 content::NotificationService::current()->Notify( | 2113 content::NotificationService::current()->Notify( |
| 2110 chrome::NOTIFICATION_EXTENSION_INSTALLED, | 2114 chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| 2111 content::Source<Profile>(profile_), | 2115 content::Source<Profile>(profile_), |
| 2112 content::Details<const Extension>(extension)); | 2116 content::Details<const Extension>(extension)); |
| 2113 | 2117 |
| 2118 // Temporary feature to always install shortcuts for platform apps to | |
| 2119 // facilitate early testing. | |
| 2120 // TODO(benwells): Remove before launching platform apps. | |
| 2121 if (extension->is_platform_app()) { | |
| 2122 StartInstallApplicationShortcut(extension); | |
|
Aaron Boodman
2012/02/01 01:31:42
indent
| |
| 2123 } | |
| 2124 | |
| 2114 // Transfer ownership of |extension| to AddExtension. | 2125 // Transfer ownership of |extension| to AddExtension. |
| 2115 AddExtension(scoped_extension); | 2126 AddExtension(scoped_extension); |
| 2116 } | 2127 } |
| 2117 | 2128 |
| 2118 const Extension* ExtensionService::GetExtensionByIdInternal( | 2129 const Extension* ExtensionService::GetExtensionByIdInternal( |
| 2119 const std::string& id, bool include_enabled, bool include_disabled, | 2130 const std::string& id, bool include_enabled, bool include_disabled, |
| 2120 bool include_terminated) const { | 2131 bool include_terminated) const { |
| 2121 std::string lowercase_id = StringToLowerASCII(id); | 2132 std::string lowercase_id = StringToLowerASCII(id); |
| 2122 if (include_enabled) { | 2133 if (include_enabled) { |
| 2123 const Extension* extension = extensions_.GetByID(lowercase_id); | 2134 const Extension* extension = extensions_.GetByID(lowercase_id); |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2516 | 2527 |
| 2517 ExtensionService::NaClModuleInfoList::iterator | 2528 ExtensionService::NaClModuleInfoList::iterator |
| 2518 ExtensionService::FindNaClModule(const GURL& url) { | 2529 ExtensionService::FindNaClModule(const GURL& url) { |
| 2519 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2530 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2520 iter != nacl_module_list_.end(); ++iter) { | 2531 iter != nacl_module_list_.end(); ++iter) { |
| 2521 if (iter->url == url) | 2532 if (iter->url == url) |
| 2522 return iter; | 2533 return iter; |
| 2523 } | 2534 } |
| 2524 return nacl_module_list_.end(); | 2535 return nacl_module_list_.end(); |
| 2525 } | 2536 } |
| 2537 | |
| 2538 void ExtensionService::StartInstallApplicationShortcut( | |
|
Aaron Boodman
2012/02/01 01:31:42
Please don't put random stuff like this in Extensi
| |
| 2539 const Extension* extension) { | |
| 2540 #if !defined(OS_MACOSX) | |
| 2541 const int kAppIconSize = 32; | |
| 2542 | |
| 2543 shortcut_info_.extension_id = extension->id(); | |
| 2544 shortcut_info_.url = GURL(extension->launch_web_url()); | |
| 2545 shortcut_info_.title = UTF8ToUTF16(extension->name()); | |
| 2546 shortcut_info_.description = UTF8ToUTF16(extension->description()); | |
| 2547 shortcut_info_.create_in_applications_menu = true; | |
| 2548 shortcut_info_.create_in_quick_launch_bar = true; | |
| 2549 shortcut_info_.create_on_desktop = true; | |
| 2550 | |
| 2551 // The icon will be resized to |max_size|. | |
| 2552 const gfx::Size max_size(kAppIconSize, kAppIconSize); | |
| 2553 | |
| 2554 // Look for an icon. If there is no icon at the ideal size, we will resize | |
| 2555 // whatever we can get. Making a large icon smaller is prefered to making a | |
| 2556 // small icon larger, so look for a larger icon first: | |
| 2557 ExtensionResource icon_resource = extension->GetIconResource( | |
| 2558 kAppIconSize, | |
| 2559 ExtensionIconSet::MATCH_BIGGER); | |
| 2560 | |
| 2561 // If no icon exists that is the desired size or larger, get the | |
| 2562 // largest icon available: | |
| 2563 if (icon_resource.empty()) { | |
| 2564 icon_resource = extension->GetIconResource( | |
| 2565 kAppIconSize, | |
| 2566 ExtensionIconSet::MATCH_SMALLER); | |
| 2567 } | |
| 2568 | |
| 2569 // icon_resource may still be empty at this point, in which case LoadImage | |
| 2570 // which call the OnImageLoaded callback with a NULL image and exit | |
| 2571 // immediately. | |
| 2572 tracker_.LoadImage(extension, | |
| 2573 icon_resource, | |
| 2574 max_size, | |
| 2575 ImageLoadingTracker::DONT_CACHE); | |
| 2576 #endif | |
| 2577 } | |
| 2578 | |
| 2579 void ExtensionService::OnImageLoaded(SkBitmap *image, | |
| 2580 const ExtensionResource &resource, | |
| 2581 int index) { | |
| 2582 // If the image failed to load (e.g. if the resource being loaded was empty) | |
| 2583 // use the standard application icon. | |
| 2584 if (!image || image->isNull()) | |
| 2585 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); | |
| 2586 | |
| 2587 shortcut_info_.favicon = *image; | |
| 2588 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_); | |
| 2589 } | |
| OLD | NEW |