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

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

Issue 11054006: Make application shortcuts point to app_host.exe, install App Host during app installation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixing headers. Created 8 years, 1 month 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
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/bind.h"
7 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h"
10 #include "base/logging.h"
8 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/web_applications/web_app.h" 13 #include "chrome/browser/web_applications/web_app.h"
11 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/extensions/extension_resource.h" 16 #include "chrome/common/extensions/extension_resource.h"
14 #include "content/public/browser/notification_details.h" 17 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_source.h" 18 #include "content/public/browser/notification_source.h"
16 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
17 #include "skia/ext/image_operations.h" 20 #include "skia/ext/image_operations.h"
18 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
19 22
23 #if defined(OS_WIN)
24 #include "chrome/browser/extensions/app_host_installer_win.h"
25 #endif
26
20 namespace extensions { 27 namespace extensions {
21 28
22 namespace { 29 namespace {
23 30
24 #if defined(OS_MACOSX) 31 #if defined(OS_MACOSX)
25 const int kDesiredSizes[] = {16, 32, 128, 256, 512}; 32 const int kDesiredSizes[] = {16, 32, 128, 256, 512};
26 #else 33 #else
27 const int kDesiredSizes[] = {32}; 34 const int kDesiredSizes[] = {32};
28 #endif 35 #endif
29 36
30 ShellIntegration::ShortcutInfo ShortcutInfoForExtensionAndProfile( 37 ShellIntegration::ShortcutInfo ShortcutInfoForExtensionAndProfile(
31 const Extension* extension, Profile* profile) { 38 const Extension* extension, Profile* profile) {
32 ShellIntegration::ShortcutInfo shortcut_info; 39 ShellIntegration::ShortcutInfo shortcut_info;
33 shortcut_info.extension_id = extension->id(); 40 shortcut_info.extension_id = extension->id();
34 shortcut_info.url = GURL(extension->launch_web_url()); 41 shortcut_info.url = GURL(extension->launch_web_url());
35 shortcut_info.title = UTF8ToUTF16(extension->name()); 42 shortcut_info.title = UTF8ToUTF16(extension->name());
36 shortcut_info.description = UTF8ToUTF16(extension->description()); 43 shortcut_info.description = UTF8ToUTF16(extension->description());
37 shortcut_info.extension_path = extension->path(); 44 shortcut_info.extension_path = extension->path();
38 shortcut_info.create_in_applications_menu = true; 45 shortcut_info.create_in_applications_menu = true;
39 shortcut_info.create_in_quick_launch_bar = true; 46 shortcut_info.create_in_quick_launch_bar = true;
40 shortcut_info.create_on_desktop = true; 47 shortcut_info.create_on_desktop = true;
41 shortcut_info.profile_path = profile->GetPath(); 48 shortcut_info.profile_path = profile->GetPath();
42 return shortcut_info; 49 return shortcut_info;
43 } 50 }
44 51
45 } // namespace 52 } // namespace
46 53
47 AppShortcutManager::AppShortcutManager(Profile* profile) 54 AppShortcutManager::AppShortcutManager(Profile* profile)
48 : profile_(profile), 55 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
grt (UTC plus 2) 2012/11/05 16:58:30 move this after tracker_'s initialization to fix l
huangs 2012/11/07 20:06:00 Done. Thanks!!
56 profile_(profile),
49 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 57 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
50 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 58 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
51 content::Source<Profile>(profile_)); 59 content::Source<Profile>(profile_));
52 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 60 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
53 content::Source<Profile>(profile_)); 61 content::Source<Profile>(profile_));
54 } 62 }
55 63
56 void AppShortcutManager::OnImageLoaded(const gfx::Image& image, 64 void AppShortcutManager::OnImageLoaded(const gfx::Image& image,
57 const std::string& extension_id, 65 const std::string& extension_id,
58 int index) { 66 int index) {
(...skipping 15 matching lines...) Expand all
74 } 82 }
75 83
76 void AppShortcutManager::Observe(int type, 84 void AppShortcutManager::Observe(int type,
77 const content::NotificationSource& source, 85 const content::NotificationSource& source,
78 const content::NotificationDetails& details) { 86 const content::NotificationDetails& details) {
79 #if !defined(OS_MACOSX) 87 #if !defined(OS_MACOSX)
80 switch (type) { 88 switch (type) {
81 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { 89 case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
82 const Extension* extension = content::Details<const Extension>( 90 const Extension* extension = content::Details<const Extension>(
83 details).ptr(); 91 details).ptr();
84 if (extension->is_platform_app()) 92 if (extension->is_platform_app()) {
93 #if defined(OS_WIN)
94 extensions::AppHostInstaller::EnsureAppHostInstalled(
95 base::Bind(&AppShortcutManager::OnAppHostInstallationComplete,
96 weak_factory_.GetWeakPtr(), extension));
benwells 2012/11/05 07:44:33 What happens if the app shortcut manager is freed
benwells 2012/11/05 08:04:44 Sorry, my mistake, got mixed up with Unretained. C
97 #else
85 UpdateApplicationShortcuts(extension); 98 UpdateApplicationShortcuts(extension);
99 #endif
100 }
86 break; 101 break;
87 } 102 }
88 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { 103 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
89 const Extension* extension = content::Details<const Extension>( 104 const Extension* extension = content::Details<const Extension>(
90 details).ptr(); 105 details).ptr();
91 DeleteApplicationShortcuts(extension); 106 DeleteApplicationShortcuts(extension);
92 break; 107 break;
93 } 108 }
94 default: 109 default:
95 NOTREACHED(); 110 NOTREACHED();
96 } 111 }
97 #endif 112 #endif
98 } 113 }
99 114
115 #if defined(OS_WIN)
116 void AppShortcutManager::OnAppHostInstallationComplete(
117 const Extension* extension, bool app_host_install_success) {
118 if (!app_host_install_success) {
119 // Do not create shortcuts if App Host fails to install.
120 LOG(ERROR) << "Application Runtime installation failed.";
121 return;
122 }
123 UpdateApplicationShortcuts(extension);
124 }
125 #endif
126
100 void AppShortcutManager::UpdateApplicationShortcuts( 127 void AppShortcutManager::UpdateApplicationShortcuts(
101 const Extension* extension) { 128 const Extension* extension) {
102 shortcut_info_ = ShortcutInfoForExtensionAndProfile(extension, profile_); 129 shortcut_info_ = ShortcutInfoForExtensionAndProfile(extension, profile_);
103 130
104 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; 131 std::vector<ImageLoadingTracker::ImageRepresentation> info_list;
105 for (size_t i = 0; i < arraysize(kDesiredSizes); ++i) { 132 for (size_t i = 0; i < arraysize(kDesiredSizes); ++i) {
106 int size = kDesiredSizes[i]; 133 int size = kDesiredSizes[i];
107 ExtensionResource resource = extension->GetIconResource( 134 ExtensionResource resource = extension->GetIconResource(
108 size, ExtensionIconSet::MATCH_EXACTLY); 135 size, ExtensionIconSet::MATCH_EXACTLY);
109 if (!resource.empty()) { 136 if (!resource.empty()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 169 }
143 170
144 void AppShortcutManager::DeleteApplicationShortcuts( 171 void AppShortcutManager::DeleteApplicationShortcuts(
145 const Extension* extension) { 172 const Extension* extension) {
146 ShellIntegration::ShortcutInfo delete_info = 173 ShellIntegration::ShortcutInfo delete_info =
147 ShortcutInfoForExtensionAndProfile(extension, profile_); 174 ShortcutInfoForExtensionAndProfile(extension, profile_);
148 web_app::DeleteAllShortcuts(delete_info); 175 web_app::DeleteAllShortcuts(delete_info);
149 } 176 }
150 177
151 } // namespace extensions 178 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/app_shortcut_manager.h ('k') | chrome/browser/web_applications/web_app_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698