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

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

Issue 10837034: Remove packaged app Windows shortcuts when app is uninstalled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Android compile Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
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/app_shortcut_manager.h" 5 #include "chrome/browser/extensions/app_shortcut_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/web_applications/web_app.h" 10 #include "chrome/browser/web_applications/web_app.h"
(...skipping 11 matching lines...) Expand all
22 namespace { 22 namespace {
23 // Allow tests to disable shortcut creation, to prevent developers' desktops 23 // Allow tests to disable shortcut creation, to prevent developers' desktops
24 // becoming overrun with shortcuts. 24 // becoming overrun with shortcuts.
25 bool disable_shortcut_creation_for_tests = false; 25 bool disable_shortcut_creation_for_tests = false;
26 26
27 #if defined(OS_MACOSX) 27 #if defined(OS_MACOSX)
28 const int kDesiredSizes[] = {16, 32, 128, 256, 512}; 28 const int kDesiredSizes[] = {16, 32, 128, 256, 512};
29 #else 29 #else
30 const int kDesiredSizes[] = {32}; 30 const int kDesiredSizes[] = {32};
31 #endif 31 #endif
32
33 ShellIntegration::ShortcutInfo ShortcutInfoForExtensionAndProfile(
34 const Extension* extension, Profile* profile) {
35 ShellIntegration::ShortcutInfo shortcut_info;
36 shortcut_info.extension_id = extension->id();
37 shortcut_info.url = GURL(extension->launch_web_url());
38 shortcut_info.title = UTF8ToUTF16(extension->name());
39 shortcut_info.description = UTF8ToUTF16(extension->description());
40 shortcut_info.extension_path = extension->path();
41 shortcut_info.is_platform_app = extension->is_platform_app();
42 shortcut_info.create_in_applications_menu = true;
43 shortcut_info.create_in_quick_launch_bar = true;
44 shortcut_info.create_on_desktop = true;
45 shortcut_info.profile_path = profile->GetPath();
46 return shortcut_info;
47 }
48
32 } // namespace 49 } // namespace
33 50
34 AppShortcutManager::AppShortcutManager(Profile* profile) 51 AppShortcutManager::AppShortcutManager(Profile* profile)
35 : profile_(profile), 52 : profile_(profile),
36 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 53 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 54 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
38 content::Source<Profile>(profile_)); 55 content::Source<Profile>(profile_));
39 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 56 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
40 content::Source<Profile>(profile_)); 57 content::Source<Profile>(profile_));
41 } 58 }
42 59
43 void AppShortcutManager::OnImageLoaded(const gfx::Image& image, 60 void AppShortcutManager::OnImageLoaded(const gfx::Image& image,
44 const std::string& extension_id, 61 const std::string& extension_id,
45 int index) { 62 int index) {
46 // If the image failed to load (e.g. if the resource being loaded was empty) 63 // If the image failed to load (e.g. if the resource being loaded was empty)
47 // use the standard application icon. 64 // use the standard application icon.
48 if (image.IsEmpty()) { 65 if (image.IsEmpty()) {
49 gfx::Image default_icon = 66 gfx::Image default_icon =
50 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON); 67 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON);
51 int size = kDesiredSizes[arraysize(kDesiredSizes) - 1]; 68 int size = kDesiredSizes[arraysize(kDesiredSizes) - 1];
52 SkBitmap bmp = skia::ImageOperations::Resize( 69 SkBitmap bmp = skia::ImageOperations::Resize(
53 *default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, 70 *default_icon.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST,
54 size, size); 71 size, size);
55 shortcut_info_.favicon = gfx::Image(bmp); 72 shortcut_info_.favicon = gfx::Image(bmp);
56 } else { 73 } else {
57 shortcut_info_.favicon = image; 74 shortcut_info_.favicon = image;
58 } 75 }
59 76
60 web_app::CreateShortcut(profile_->GetPath(), shortcut_info_); 77 web_app::CreateShortcuts(shortcut_info_);
61 } 78 }
62 79
63 void AppShortcutManager::Observe(int type, 80 void AppShortcutManager::Observe(int type,
64 const content::NotificationSource& source, 81 const content::NotificationSource& source,
65 const content::NotificationDetails& details) { 82 const content::NotificationDetails& details) {
66 #if !defined(OS_MACOSX) 83 #if !defined(OS_MACOSX)
67 switch (type) { 84 switch (type) {
68 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { 85 case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
69 const Extension* extension = content::Details<const Extension>( 86 const Extension* extension = content::Details<const Extension>(
70 details).ptr(); 87 details).ptr();
71 if (!disable_shortcut_creation_for_tests && 88 if (!disable_shortcut_creation_for_tests &&
72 extension->is_platform_app() && 89 extension->is_platform_app() &&
73 extension->location() != Extension::LOAD) { 90 extension->location() != Extension::LOAD) {
74 InstallApplicationShortcuts(extension); 91 InstallApplicationShortcuts(extension);
75 } 92 }
76 break; 93 break;
77 } 94 }
78 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { 95 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
79 std::string extension_id = 96 const Extension* extension = content::Details<const Extension>(
80 content::Details<const Extension>(details).ptr()->id(); 97 details).ptr();
81 if (!disable_shortcut_creation_for_tests) 98 if (!disable_shortcut_creation_for_tests)
82 web_app::DeleteAllShortcuts(profile_->GetPath(), extension_id); 99 DeleteApplicationShortcuts(extension);
83 break; 100 break;
84 } 101 }
85 default: 102 default:
86 NOTREACHED(); 103 NOTREACHED();
87 } 104 }
88 #endif 105 #endif
89 } 106 }
90 107
91 // static 108 // static
92 void AppShortcutManager::SetShortcutCreationDisabledForTesting(bool disabled) { 109 void AppShortcutManager::SetShortcutCreationDisabledForTesting(bool disabled) {
93 disable_shortcut_creation_for_tests = disabled; 110 disable_shortcut_creation_for_tests = disabled;
94 } 111 }
95 112
96 void AppShortcutManager::InstallApplicationShortcuts( 113 void AppShortcutManager::InstallApplicationShortcuts(
97 const Extension* extension) { 114 const Extension* extension) {
98 shortcut_info_.extension_id = extension->id(); 115 shortcut_info_ = ShortcutInfoForExtensionAndProfile(extension, profile_);
99 shortcut_info_.url = GURL(extension->launch_web_url());
100 shortcut_info_.title = UTF8ToUTF16(extension->name());
101 shortcut_info_.description = UTF8ToUTF16(extension->description());
102 shortcut_info_.extension_path = extension->path();
103 shortcut_info_.is_platform_app = extension->is_platform_app();
104 shortcut_info_.create_in_applications_menu = true;
105 shortcut_info_.create_in_quick_launch_bar = true;
106 shortcut_info_.create_on_desktop = true;
107 shortcut_info_.profile_path = profile_->GetPath();
108
109 std::vector<ImageLoadingTracker::ImageInfo> info_list; 116 std::vector<ImageLoadingTracker::ImageInfo> info_list;
110 for (size_t i = 0; i < arraysize(kDesiredSizes); ++i) { 117 for (size_t i = 0; i < arraysize(kDesiredSizes); ++i) {
111 int size = kDesiredSizes[i]; 118 int size = kDesiredSizes[i];
112 ExtensionResource resource = extension->GetIconResource( 119 ExtensionResource resource = extension->GetIconResource(
113 size, ExtensionIconSet::MATCH_EXACTLY); 120 size, ExtensionIconSet::MATCH_EXACTLY);
114 if (!resource.empty()) { 121 if (!resource.empty()) {
115 info_list.push_back( 122 info_list.push_back(
116 ImageLoadingTracker::ImageInfo(resource, gfx::Size(size, size))); 123 ImageLoadingTracker::ImageInfo(resource, gfx::Size(size, size)));
117 } 124 }
118 } 125 }
(...skipping 13 matching lines...) Expand all
132 } 139 }
133 info_list.push_back( 140 info_list.push_back(
134 ImageLoadingTracker::ImageInfo(resource, gfx::Size(size, size))); 141 ImageLoadingTracker::ImageInfo(resource, gfx::Size(size, size)));
135 } 142 }
136 143
137 // |icon_resources| may still be empty at this point, in which case LoadImage 144 // |icon_resources| may still be empty at this point, in which case LoadImage
138 // will call the OnImageLoaded callback with an empty image and exit 145 // will call the OnImageLoaded callback with an empty image and exit
139 // immediately. 146 // immediately.
140 tracker_.LoadImages(extension, info_list, ImageLoadingTracker::DONT_CACHE); 147 tracker_.LoadImages(extension, info_list, ImageLoadingTracker::DONT_CACHE);
141 } 148 }
149
150 void AppShortcutManager::DeleteApplicationShortcuts(
151 const Extension* extension) {
152 ShellIntegration::ShortcutInfo delete_info =
153 ShortcutInfoForExtensionAndProfile(extension, profile_);
154 web_app::DeleteAllShortcuts(delete_info);
155 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/app_shortcut_manager.h ('k') | chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698