diff options
author | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-12 11:06:37 +0000 |
---|---|---|
committer | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-12 11:06:37 +0000 |
commit | 9de83285d699b57e2fb2f01262e69425be72079e (patch) | |
tree | 0aceb688897b5347ede266d7446acab1c7b8df65 /chrome/browser/extensions | |
parent | 9888511ceb4882a6ccac4507708892f1d031b9cf (diff) | |
download | chromium_src-9de83285d699b57e2fb2f01262e69425be72079e.zip chromium_src-9de83285d699b57e2fb2f01262e69425be72079e.tar.gz chromium_src-9de83285d699b57e2fb2f01262e69425be72079e.tar.bz2 |
Installing a platform application will add all application shortucts.
Applications shortcuts will be added to the Start / Applications menu,
the taskbar and the desktop. This is a temporary change to help the
shortcut features of platform applications and make installed platform
applications more visible.
BUG=None
TEST=Manually tested on Windows
Review URL: http://codereview.chromium.org/8862007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extension_service.cc | 66 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service.h | 19 |
2 files changed, 83 insertions, 2 deletions
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index 402e0e4..03336f9 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -74,8 +74,10 @@ #include "chrome/browser/ui/global_error_service.h" #include "chrome/browser/ui/global_error_service_factory.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h" +#include "chrome/browser/ui/webui/extension_icon_source.h" #include "chrome/browser/ui/webui/favicon_source.h" #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" +#include "chrome/browser/web_applications/web_app.h" #include "chrome/common/child_process_logging.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_paths.h" @@ -99,6 +101,7 @@ #include "content/public/browser/render_process_host.h" #include "content/public/common/pepper_plugin_info.h" #include "googleurl/src/gurl.h" +#include "grit/theme_resources.h" #include "net/base/registry_controlled_domain.h" #include "webkit/database/database_tracker.h" #include "webkit/database/database_util.h" @@ -389,7 +392,8 @@ ExtensionService::ExtensionService(Profile* profile, apps_promo_(profile->GetPrefs()), event_routers_initialized_(false), extension_warnings_(profile), - socket_controller_(new extensions::SocketController()) { + socket_controller_(new extensions::SocketController()), + tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Figure out if extension installation should be enabled. @@ -2111,6 +2115,13 @@ void ExtensionService::OnExtensionInstalled( content::Source<Profile>(profile_), content::Details<const Extension>(extension)); + // Temporary feature to always install shortcuts for platform apps to + // facilitate early testing. + // TODO(benwells): Remove before launching platform apps. + if (extension->is_platform_app()) { + StartInstallApplicationShortcut(extension); + } + // Transfer ownership of |extension| to AddExtension. AddExtension(scoped_extension); } @@ -2523,3 +2534,56 @@ ExtensionService::NaClModuleInfoList::iterator } return nacl_module_list_.end(); } + +void ExtensionService::StartInstallApplicationShortcut( + const Extension* extension) { +#if !defined(OS_MACOSX) + const int kAppIconSize = 32; + + shortcut_info_.extension_id = extension->id(); + shortcut_info_.url = GURL(extension->launch_web_url()); + shortcut_info_.title = UTF8ToUTF16(extension->name()); + shortcut_info_.description = UTF8ToUTF16(extension->description()); + shortcut_info_.create_in_applications_menu = true; + shortcut_info_.create_in_quick_launch_bar = true; + shortcut_info_.create_on_desktop = true; + + // The icon will be resized to |max_size|. + const gfx::Size max_size(kAppIconSize, kAppIconSize); + + // Look for an icon. If there is no icon at the ideal size, we will resize + // whatever we can get. Making a large icon smaller is prefered to making a + // small icon larger, so look for a larger icon first: + ExtensionResource icon_resource = extension->GetIconResource( + kAppIconSize, + ExtensionIconSet::MATCH_BIGGER); + + // If no icon exists that is the desired size or larger, get the + // largest icon available: + if (icon_resource.empty()) { + icon_resource = extension->GetIconResource( + kAppIconSize, + ExtensionIconSet::MATCH_SMALLER); + } + + // icon_resource may still be empty at this point, in which case LoadImage + // which call the OnImageLoaded callback with a NULL image and exit + // immediately. + tracker_.LoadImage(extension, + icon_resource, + max_size, + ImageLoadingTracker::DONT_CACHE); +#endif +} + +void ExtensionService::OnImageLoaded(SkBitmap *image, + const ExtensionResource &resource, + int index) { + // If the image failed to load (e.g. if the resource being loaded was empty) + // use the standard application icon. + if (!image || image->isNull()) + image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); + + shortcut_info_.favicon = *image; + web_app::CreateShortcut(profile_->GetPath(), shortcut_info_); +} diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h index 1b288df..f5bda4f 100644 --- a/chrome/browser/extensions/extension_service.h +++ b/chrome/browser/extensions/extension_service.h @@ -37,6 +37,7 @@ #include "chrome/browser/extensions/process_map.h" #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" #include "chrome/browser/prefs/pref_change_registrar.h" +#include "chrome/browser/shell_integration.h" #include "chrome/browser/sync/api/sync_change.h" #include "chrome/browser/sync/api/syncable_service.h" #include "chrome/common/extensions/extension.h" @@ -131,7 +132,8 @@ class ExtensionService : public ExtensionServiceInterface, public ExternalExtensionProviderInterface::VisitorInterface, public base::SupportsWeakPtr<ExtensionService>, - public content::NotificationObserver { + public content::NotificationObserver, + public ImageLoadingTracker::Observer { public: using base::SupportsWeakPtr<ExtensionService>::AsWeakPtr; @@ -574,6 +576,13 @@ class ExtensionService return socket_controller_; } + // Implement ImageLoadingTracker::Observer. |tracker_| is used to + // load the application's icon, which is done when we start creating an + // application's shortcuts. This method receives the icon, and completes + // the process of installing the shortcuts. + virtual void OnImageLoaded(SkBitmap* image, + const ExtensionResource& resource, + int index) OVERRIDE; private: // Bundle of type (app or extension)-specific sync stuff. struct SyncBundle { @@ -688,6 +697,10 @@ class ExtensionService // a NaCl module to see those changes reflected in the PluginList. void UpdatePluginListWithNaClModules(); + // Start the process of installing an application shortcut. + // The process is finished when OnImageLoaded is called. + void StartInstallApplicationShortcut(const Extension* extension); + NaClModuleInfoList::iterator FindNaClModule(const GURL& url); // The profile this ExtensionService is part of. @@ -830,6 +843,10 @@ class ExtensionService extensions::ProcessMap process_map_; + // Fields used when installing application shortcuts. + ShellIntegration::ShortcutInfo shortcut_info_; + ImageLoadingTracker tracker_; + FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, InstallAppsWithUnlimtedStorage); FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |