| 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/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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 #include "chrome/browser/search_engines/template_url_service.h" | 69 #include "chrome/browser/search_engines/template_url_service.h" |
| 70 #include "chrome/browser/search_engines/template_url_service_factory.h" | 70 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 71 #include "chrome/browser/sync/api/sync_change.h" | 71 #include "chrome/browser/sync/api/sync_change.h" |
| 72 #include "chrome/browser/themes/theme_service.h" | 72 #include "chrome/browser/themes/theme_service.h" |
| 73 #include "chrome/browser/themes/theme_service_factory.h" | 73 #include "chrome/browser/themes/theme_service_factory.h" |
| 74 #include "chrome/browser/ui/browser.h" | 74 #include "chrome/browser/ui/browser.h" |
| 75 #include "chrome/browser/ui/browser_list.h" | 75 #include "chrome/browser/ui/browser_list.h" |
| 76 #include "chrome/browser/ui/global_error_service.h" | 76 #include "chrome/browser/ui/global_error_service.h" |
| 77 #include "chrome/browser/ui/global_error_service_factory.h" | 77 #include "chrome/browser/ui/global_error_service_factory.h" |
| 78 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 78 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 79 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | |
| 80 #include "chrome/browser/ui/webui/favicon_source.h" | 79 #include "chrome/browser/ui/webui/favicon_source.h" |
| 81 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 80 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
| 82 #include "chrome/browser/web_applications/web_app.h" | |
| 83 #include "chrome/common/child_process_logging.h" | 81 #include "chrome/common/child_process_logging.h" |
| 84 #include "chrome/common/chrome_notification_types.h" | 82 #include "chrome/common/chrome_notification_types.h" |
| 85 #include "chrome/common/chrome_paths.h" | 83 #include "chrome/common/chrome_paths.h" |
| 86 #include "chrome/common/chrome_switches.h" | 84 #include "chrome/common/chrome_switches.h" |
| 87 #include "chrome/common/extensions/extension.h" | 85 #include "chrome/common/extensions/extension.h" |
| 88 #include "chrome/common/extensions/extension_constants.h" | 86 #include "chrome/common/extensions/extension_constants.h" |
| 89 #include "chrome/common/extensions/extension_error_utils.h" | 87 #include "chrome/common/extensions/extension_error_utils.h" |
| 90 #include "chrome/common/extensions/extension_file_util.h" | 88 #include "chrome/common/extensions/extension_file_util.h" |
| 91 #include "chrome/common/extensions/extension_messages.h" | 89 #include "chrome/common/extensions/extension_messages.h" |
| 92 #include "chrome/common/extensions/extension_resource.h" | 90 #include "chrome/common/extensions/extension_resource.h" |
| 93 #include "chrome/common/pref_names.h" | 91 #include "chrome/common/pref_names.h" |
| 94 #include "chrome/common/url_constants.h" | 92 #include "chrome/common/url_constants.h" |
| 95 #include "content/public/browser/browser_thread.h" | 93 #include "content/public/browser/browser_thread.h" |
| 96 #include "content/public/browser/devtools_agent_host_registry.h" | 94 #include "content/public/browser/devtools_agent_host_registry.h" |
| 97 #include "content/public/browser/devtools_manager.h" | 95 #include "content/public/browser/devtools_manager.h" |
| 98 #include "content/public/browser/notification_service.h" | 96 #include "content/public/browser/notification_service.h" |
| 99 #include "content/public/browser/notification_types.h" | 97 #include "content/public/browser/notification_types.h" |
| 100 #include "content/public/browser/plugin_service.h" | 98 #include "content/public/browser/plugin_service.h" |
| 101 #include "content/public/browser/render_process_host.h" | 99 #include "content/public/browser/render_process_host.h" |
| 102 #include "content/public/common/pepper_plugin_info.h" | 100 #include "content/public/common/pepper_plugin_info.h" |
| 103 #include "googleurl/src/gurl.h" | 101 #include "googleurl/src/gurl.h" |
| 104 #include "grit/theme_resources.h" | |
| 105 #include "net/base/registry_controlled_domain.h" | 102 #include "net/base/registry_controlled_domain.h" |
| 106 #include "webkit/database/database_tracker.h" | 103 #include "webkit/database/database_tracker.h" |
| 107 #include "webkit/database/database_util.h" | 104 #include "webkit/database/database_util.h" |
| 108 | 105 |
| 109 #if defined(OS_CHROMEOS) | 106 #if defined(OS_CHROMEOS) |
| 110 #include "chrome/browser/chromeos/cros/cros_library.h" | 107 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 111 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" | 108 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
| 112 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" | 109 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
| 113 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" | 110 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" |
| 114 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 111 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 extensions_enabled_(extensions_enabled), | 380 extensions_enabled_(extensions_enabled), |
| 384 show_extensions_prompts_(true), | 381 show_extensions_prompts_(true), |
| 385 ready_(false), | 382 ready_(false), |
| 386 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 383 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 387 menu_manager_(profile), | 384 menu_manager_(profile), |
| 388 app_notification_manager_(new AppNotificationManager(profile)), | 385 app_notification_manager_(new AppNotificationManager(profile)), |
| 389 apps_promo_(profile->GetPrefs()), | 386 apps_promo_(profile->GetPrefs()), |
| 390 event_routers_initialized_(false), | 387 event_routers_initialized_(false), |
| 391 extension_warnings_(profile), | 388 extension_warnings_(profile), |
| 392 socket_controller_(NULL), | 389 socket_controller_(NULL), |
| 393 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 390 app_shortcut_manager_(profile) { |
| 394 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 391 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 395 | 392 |
| 396 // Figure out if extension installation should be enabled. | 393 // Figure out if extension installation should be enabled. |
| 397 if (command_line->HasSwitch(switches::kDisableExtensions)) { | 394 if (command_line->HasSwitch(switches::kDisableExtensions)) { |
| 398 extensions_enabled_ = false; | 395 extensions_enabled_ = false; |
| 399 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { | 396 } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { |
| 400 extensions_enabled_ = false; | 397 extensions_enabled_ = false; |
| 401 } | 398 } |
| 402 | 399 |
| 403 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 400 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
| (...skipping 1841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2245 // the webRequest API), set the preference. Otherwise clear it, in case the | 2242 // the webRequest API), set the preference. Otherwise clear it, in case the |
| 2246 // extension stopped using a relevant API. | 2243 // extension stopped using a relevant API. |
| 2247 extension_prefs_->SetDelaysNetworkRequests( | 2244 extension_prefs_->SetDelaysNetworkRequests( |
| 2248 extension->id(), extension->ImplicitlyDelaysNetworkStartup()); | 2245 extension->id(), extension->ImplicitlyDelaysNetworkStartup()); |
| 2249 | 2246 |
| 2250 content::NotificationService::current()->Notify( | 2247 content::NotificationService::current()->Notify( |
| 2251 chrome::NOTIFICATION_EXTENSION_INSTALLED, | 2248 chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| 2252 content::Source<Profile>(profile_), | 2249 content::Source<Profile>(profile_), |
| 2253 content::Details<const Extension>(extension)); | 2250 content::Details<const Extension>(extension)); |
| 2254 | 2251 |
| 2255 // Temporary feature to always install shortcuts for platform apps to | |
| 2256 // facilitate early testing. | |
| 2257 // TODO(benwells): Remove before launching platform apps. | |
| 2258 if (extension->is_platform_app()) { | |
| 2259 StartInstallApplicationShortcut(extension); | |
| 2260 } | |
| 2261 | |
| 2262 // Transfer ownership of |extension| to AddExtension. | 2252 // Transfer ownership of |extension| to AddExtension. |
| 2263 AddExtension(scoped_extension); | 2253 AddExtension(scoped_extension); |
| 2264 } | 2254 } |
| 2265 | 2255 |
| 2266 const Extension* ExtensionService::GetExtensionByIdInternal( | 2256 const Extension* ExtensionService::GetExtensionByIdInternal( |
| 2267 const std::string& id, bool include_enabled, bool include_disabled, | 2257 const std::string& id, bool include_enabled, bool include_disabled, |
| 2268 bool include_terminated) const { | 2258 bool include_terminated) const { |
| 2269 std::string lowercase_id = StringToLowerASCII(id); | 2259 std::string lowercase_id = StringToLowerASCII(id); |
| 2270 if (include_enabled) { | 2260 if (include_enabled) { |
| 2271 const Extension* extension = extensions_.GetByID(lowercase_id); | 2261 const Extension* extension = extensions_.GetByID(lowercase_id); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2626 ExtensionService::NaClModuleInfoList::iterator | 2616 ExtensionService::NaClModuleInfoList::iterator |
| 2627 ExtensionService::FindNaClModule(const GURL& url) { | 2617 ExtensionService::FindNaClModule(const GURL& url) { |
| 2628 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2618 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2629 iter != nacl_module_list_.end(); ++iter) { | 2619 iter != nacl_module_list_.end(); ++iter) { |
| 2630 if (iter->url == url) | 2620 if (iter->url == url) |
| 2631 return iter; | 2621 return iter; |
| 2632 } | 2622 } |
| 2633 return nacl_module_list_.end(); | 2623 return nacl_module_list_.end(); |
| 2634 } | 2624 } |
| 2635 | 2625 |
| 2636 void ExtensionService::StartInstallApplicationShortcut( | |
| 2637 const Extension* extension) { | |
| 2638 #if !defined(OS_MACOSX) | |
| 2639 const int kAppIconSize = 32; | |
| 2640 | |
| 2641 shortcut_info_.extension_id = extension->id(); | |
| 2642 shortcut_info_.url = GURL(extension->launch_web_url()); | |
| 2643 shortcut_info_.title = UTF8ToUTF16(extension->name()); | |
| 2644 shortcut_info_.description = UTF8ToUTF16(extension->description()); | |
| 2645 shortcut_info_.create_in_applications_menu = true; | |
| 2646 shortcut_info_.create_in_quick_launch_bar = true; | |
| 2647 shortcut_info_.create_on_desktop = true; | |
| 2648 | |
| 2649 // The icon will be resized to |max_size|. | |
| 2650 const gfx::Size max_size(kAppIconSize, kAppIconSize); | |
| 2651 | |
| 2652 // Look for an icon. If there is no icon at the ideal size, we will resize | |
| 2653 // whatever we can get. Making a large icon smaller is prefered to making a | |
| 2654 // small icon larger, so look for a larger icon first: | |
| 2655 ExtensionResource icon_resource = extension->GetIconResource( | |
| 2656 kAppIconSize, | |
| 2657 ExtensionIconSet::MATCH_BIGGER); | |
| 2658 | |
| 2659 // If no icon exists that is the desired size or larger, get the | |
| 2660 // largest icon available: | |
| 2661 if (icon_resource.empty()) { | |
| 2662 icon_resource = extension->GetIconResource( | |
| 2663 kAppIconSize, | |
| 2664 ExtensionIconSet::MATCH_SMALLER); | |
| 2665 } | |
| 2666 | |
| 2667 // icon_resource may still be empty at this point, in which case LoadImage | |
| 2668 // which call the OnImageLoaded callback with a NULL image and exit | |
| 2669 // immediately. | |
| 2670 tracker_.LoadImage(extension, | |
| 2671 icon_resource, | |
| 2672 max_size, | |
| 2673 ImageLoadingTracker::DONT_CACHE); | |
| 2674 #endif | |
| 2675 } | |
| 2676 | |
| 2677 void ExtensionService::OnImageLoaded(SkBitmap *image, | |
| 2678 const ExtensionResource &resource, | |
| 2679 int index) { | |
| 2680 // If the image failed to load (e.g. if the resource being loaded was empty) | |
| 2681 // use the standard application icon. | |
| 2682 if (!image || image->isNull()) | |
| 2683 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); | |
| 2684 | |
| 2685 shortcut_info_.favicon = *image; | |
| 2686 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_); | |
| 2687 } | |
| 2688 | |
| 2689 extensions::SocketController* ExtensionService::socket_controller() { | 2626 extensions::SocketController* ExtensionService::socket_controller() { |
| 2690 // TODO(miket): Find a better place for SocketController to live. It needs | 2627 // TODO(miket): Find a better place for SocketController to live. It needs |
| 2691 // to be scoped such that it can be created and destroyed on the IO thread. | 2628 // to be scoped such that it can be created and destroyed on the IO thread. |
| 2692 // | 2629 // |
| 2693 // To coexist with certain unit tests that don't have an IO thread message | 2630 // To coexist with certain unit tests that don't have an IO thread message |
| 2694 // loop available at ExtensionService shutdown, we lazy-initialize this | 2631 // loop available at ExtensionService shutdown, we lazy-initialize this |
| 2695 // object so that those cases neither create nor destroy a SocketController. | 2632 // object so that those cases neither create nor destroy a SocketController. |
| 2696 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2633 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2697 if (!socket_controller_) { | 2634 if (!socket_controller_) { |
| 2698 socket_controller_ = new extensions::SocketController(); | 2635 socket_controller_ = new extensions::SocketController(); |
| 2699 } | 2636 } |
| 2700 return socket_controller_; | 2637 return socket_controller_; |
| 2701 } | 2638 } |
| OLD | NEW |