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/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: Fixed stupid virtual ommission 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 namespace {
18 // Allow tests to disable shortcut creation, to prevent developers' desktops
19 // becoming overrun with shortcuts.
20 bool disable_shortcut_creation_for_tests = false;
21 } // namespace
22
23 AppShortcutManager::AppShortcutManager(Profile* profile)
24 : profile_(profile),
25 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
26 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
27 content::Source<Profile>(profile_));
28 }
29
30 void AppShortcutManager::OnImageLoaded(SkBitmap *image,
31 const ExtensionResource &resource,
32 int index) {
33 // If the image failed to load (e.g. if the resource being loaded was empty)
34 // use the standard application icon.
35 if (!image || image->isNull())
36 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON);
37
38 shortcut_info_.favicon = *image;
39 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_);
40 }
41
42 void AppShortcutManager::Observe(int type,
43 const content::NotificationSource& source,
44 const content::NotificationDetails& details) {
45 DCHECK(type == chrome::NOTIFICATION_EXTENSION_INSTALLED);
46 const Extension* extension = content::Details<const Extension>(details).ptr();
47 if (!disable_shortcut_creation_for_tests && extension->is_platform_app())
48 InstallApplicationShortcuts(extension);
49 }
50
51 // static
52 void AppShortcutManager::SetShortcutCreationDisabledForTesting(bool disabled) {
53 disable_shortcut_creation_for_tests = disabled;
54 }
55
56 void AppShortcutManager::InstallApplicationShortcuts(
57 const Extension* extension) {
58 #if !defined(OS_MACOSX)
59 const int kAppIconSize = 32;
60
61 shortcut_info_.extension_id = extension->id();
62 shortcut_info_.url = GURL(extension->launch_web_url());
63 shortcut_info_.title = UTF8ToUTF16(extension->name());
64 shortcut_info_.description = UTF8ToUTF16(extension->description());
65 shortcut_info_.create_in_applications_menu = true;
66 shortcut_info_.create_in_quick_launch_bar = true;
67 shortcut_info_.create_on_desktop = true;
68
69 // The icon will be resized to |max_size|.
70 const gfx::Size max_size(kAppIconSize, kAppIconSize);
71
72 // Look for an icon. If there is no icon at the ideal size, we will resize
73 // whatever we can get. Making a large icon smaller is prefered to making a
74 // small icon larger, so look for a larger icon first:
75 ExtensionResource icon_resource = extension->GetIconResource(
76 kAppIconSize,
77 ExtensionIconSet::MATCH_BIGGER);
78
79 // If no icon exists that is the desired size or larger, get the
80 // largest icon available:
81 if (icon_resource.empty()) {
82 icon_resource = extension->GetIconResource(
83 kAppIconSize,
84 ExtensionIconSet::MATCH_SMALLER);
85 }
86
87 // icon_resource may still be empty at this point, in which case LoadImage
88 // which call the OnImageLoaded callback with a NULL image and exit
89 // immediately.
90 tracker_.LoadImage(extension,
91 icon_resource,
92 max_size,
93 ImageLoadingTracker::DONT_CACHE);
94 #endif
95 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/app_shortcut_manager.h ('k') | chrome/browser/extensions/extension_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698