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

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

Issue 9310079: Moved app shortcut code out of ExtensionService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed unneeded includes Created 8 years, 10 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/app_shortcut_manager.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/web_applications/web_app.h"
11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/extensions/extension_resource.h"
13 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_source.h"
15 #include "grit/theme_resources.h"
16
17 AppShortcutManager::AppShortcutManager(Profile* profile)
18 : profile_(profile),
19 disable_shortcut_creation_(false),
20 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
21 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
22 content::Source<Profile>(profile_));
23 }
24
25 void AppShortcutManager::OnImageLoaded(SkBitmap *image,
26 const ExtensionResource &resource,
27 int index) {
28 // If the image failed to load (e.g. if the resource being loaded was empty)
29 // use the standard application icon.
30 if (!image || image->isNull())
31 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON);
32
33 shortcut_info_.favicon = *image;
34 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_);
35 }
36
37 void AppShortcutManager::Observe(int type,
38 const content::NotificationSource& source,
39 const content::NotificationDetails& details) {
40 DCHECK(type == chrome::NOTIFICATION_EXTENSION_INSTALLED);
Mihai Parparita -not on Chrome 2012/02/06 22:35:53 We may want this for when an extension is updated
benwells 2012/02/07 06:57:01 That makes sense. We'd only want to create the sho
41 const Extension* extension = content::Details<const Extension>(details).ptr();
42 if (!disable_shortcut_creation_ && extension->is_platform_app())
43 InstallApplicationShortcuts(extension);
44 }
45
46 void AppShortcutManager::InstallApplicationShortcuts(
47 const Extension* extension) {
48 #if !defined(OS_MACOSX)
49 const int kAppIconSize = 32;
50
51 shortcut_info_.extension_id = extension->id();
52 shortcut_info_.url = GURL(extension->launch_web_url());
53 shortcut_info_.title = UTF8ToUTF16(extension->name());
54 shortcut_info_.description = UTF8ToUTF16(extension->description());
55 shortcut_info_.create_in_applications_menu = true;
56 shortcut_info_.create_in_quick_launch_bar = true;
57 shortcut_info_.create_on_desktop = true;
58
59 // The icon will be resized to |max_size|.
60 const gfx::Size max_size(kAppIconSize, kAppIconSize);
61
62 // Look for an icon. If there is no icon at the ideal size, we will resize
63 // whatever we can get. Making a large icon smaller is prefered to making a
64 // small icon larger, so look for a larger icon first:
65 ExtensionResource icon_resource = extension->GetIconResource(
66 kAppIconSize,
67 ExtensionIconSet::MATCH_BIGGER);
68
69 // If no icon exists that is the desired size or larger, get the
70 // largest icon available:
71 if (icon_resource.empty()) {
72 icon_resource = extension->GetIconResource(
73 kAppIconSize,
74 ExtensionIconSet::MATCH_SMALLER);
75 }
76
77 // icon_resource may still be empty at this point, in which case LoadImage
78 // which call the OnImageLoaded callback with a NULL image and exit
79 // immediately.
80 tracker_.LoadImage(extension,
81 icon_resource,
82 max_size,
83 ImageLoadingTracker::DONT_CACHE);
84 #endif
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698