OLD | NEW |
---|---|
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/logging.h" | |
8 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/web_applications/web_app.h" | 12 #include "chrome/browser/web_applications/web_app.h" |
11 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
12 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/extensions/extension_resource.h" | 15 #include "chrome/common/extensions/extension_resource.h" |
14 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
16 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
17 #include "skia/ext/image_operations.h" | 19 #include "skia/ext/image_operations.h" |
18 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
19 | 21 |
22 #if defined(OS_WIN) | |
23 #include "chrome/browser/extensions/app_host_installer_win.h" | |
24 #endif | |
25 | |
20 namespace extensions { | 26 namespace extensions { |
21 | 27 |
22 namespace { | 28 namespace { |
23 | 29 |
24 #if defined(OS_MACOSX) | 30 #if defined(OS_MACOSX) |
25 const int kDesiredSizes[] = {16, 32, 128, 256, 512}; | 31 const int kDesiredSizes[] = {16, 32, 128, 256, 512}; |
26 #else | 32 #else |
27 const int kDesiredSizes[] = {32}; | 33 const int kDesiredSizes[] = {32}; |
28 #endif | 34 #endif |
29 | 35 |
30 ShellIntegration::ShortcutInfo ShortcutInfoForExtensionAndProfile( | 36 ShellIntegration::ShortcutInfo ShortcutInfoForExtensionAndProfile( |
31 const Extension* extension, Profile* profile) { | 37 const Extension* extension, Profile* profile) { |
32 ShellIntegration::ShortcutInfo shortcut_info; | 38 ShellIntegration::ShortcutInfo shortcut_info; |
33 shortcut_info.extension_id = extension->id(); | 39 shortcut_info.extension_id = extension->id(); |
34 shortcut_info.url = GURL(extension->launch_web_url()); | 40 shortcut_info.url = GURL(extension->launch_web_url()); |
35 shortcut_info.title = UTF8ToUTF16(extension->name()); | 41 shortcut_info.title = UTF8ToUTF16(extension->name()); |
36 shortcut_info.description = UTF8ToUTF16(extension->description()); | 42 shortcut_info.description = UTF8ToUTF16(extension->description()); |
37 shortcut_info.extension_path = extension->path(); | 43 shortcut_info.extension_path = extension->path(); |
38 shortcut_info.create_in_applications_menu = true; | 44 shortcut_info.create_in_applications_menu = true; |
39 shortcut_info.create_in_quick_launch_bar = true; | 45 shortcut_info.create_in_quick_launch_bar = true; |
40 shortcut_info.create_on_desktop = true; | 46 shortcut_info.create_on_desktop = true; |
41 shortcut_info.profile_path = profile->GetPath(); | 47 shortcut_info.profile_path = profile->GetPath(); |
42 return shortcut_info; | 48 return shortcut_info; |
43 } | 49 } |
44 | 50 |
45 } // namespace | 51 } // namespace |
46 | 52 |
47 AppShortcutManager::AppShortcutManager(Profile* profile) | 53 AppShortcutManager::AppShortcutManager(Profile* profile) |
48 : profile_(profile), | 54 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
erikwright (departed)
2012/11/02 20:40:59
#include "base/compiler_specific.h"
huangs
2012/11/02 22:15:33
Done.
| |
55 profile_(profile), | |
49 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 56 tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
50 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | 57 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
51 content::Source<Profile>(profile_)); | 58 content::Source<Profile>(profile_)); |
52 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 59 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
53 content::Source<Profile>(profile_)); | 60 content::Source<Profile>(profile_)); |
54 } | 61 } |
55 | 62 |
56 void AppShortcutManager::OnImageLoaded(const gfx::Image& image, | 63 void AppShortcutManager::OnImageLoaded(const gfx::Image& image, |
57 const std::string& extension_id, | 64 const std::string& extension_id, |
58 int index) { | 65 int index) { |
(...skipping 15 matching lines...) Expand all Loading... | |
74 } | 81 } |
75 | 82 |
76 void AppShortcutManager::Observe(int type, | 83 void AppShortcutManager::Observe(int type, |
77 const content::NotificationSource& source, | 84 const content::NotificationSource& source, |
78 const content::NotificationDetails& details) { | 85 const content::NotificationDetails& details) { |
79 #if !defined(OS_MACOSX) | 86 #if !defined(OS_MACOSX) |
80 switch (type) { | 87 switch (type) { |
81 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { | 88 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { |
82 const Extension* extension = content::Details<const Extension>( | 89 const Extension* extension = content::Details<const Extension>( |
83 details).ptr(); | 90 details).ptr(); |
84 if (extension->is_platform_app()) | 91 if (extension->is_platform_app()) { |
92 #if defined(OS_WIN) | |
93 extensions::AppHostInstaller::EnsureAppHostInstalled( | |
94 base::Bind(&AppShortcutManager::OnAppHostInstallationComplete, | |
95 weak_factory_.GetWeakPtr(), extension)); | |
96 #else | |
85 UpdateApplicationShortcuts(extension); | 97 UpdateApplicationShortcuts(extension); |
98 #endif | |
99 } | |
86 break; | 100 break; |
87 } | 101 } |
88 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { | 102 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
89 const Extension* extension = content::Details<const Extension>( | 103 const Extension* extension = content::Details<const Extension>( |
90 details).ptr(); | 104 details).ptr(); |
91 DeleteApplicationShortcuts(extension); | 105 DeleteApplicationShortcuts(extension); |
92 break; | 106 break; |
93 } | 107 } |
94 default: | 108 default: |
95 NOTREACHED(); | 109 NOTREACHED(); |
96 } | 110 } |
97 #endif | 111 #endif |
98 } | 112 } |
99 | 113 |
114 #if defined(OS_WIN) | |
115 void AppShortcutManager::OnAppHostInstallationComplete( | |
116 const Extension* extension, bool app_host_install_success) { | |
117 if (!app_host_install_success) { | |
118 // Do not create shortcuts if App Host fails to install. | |
119 LOG(ERROR) << "Application Runtime installation failed."; | |
120 return; | |
121 } | |
122 UpdateApplicationShortcuts(extension); | |
123 } | |
124 #endif | |
125 | |
100 void AppShortcutManager::UpdateApplicationShortcuts( | 126 void AppShortcutManager::UpdateApplicationShortcuts( |
101 const Extension* extension) { | 127 const Extension* extension) { |
102 shortcut_info_ = ShortcutInfoForExtensionAndProfile(extension, profile_); | 128 shortcut_info_ = ShortcutInfoForExtensionAndProfile(extension, profile_); |
103 | 129 |
104 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; | 130 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; |
105 for (size_t i = 0; i < arraysize(kDesiredSizes); ++i) { | 131 for (size_t i = 0; i < arraysize(kDesiredSizes); ++i) { |
106 int size = kDesiredSizes[i]; | 132 int size = kDesiredSizes[i]; |
107 ExtensionResource resource = extension->GetIconResource( | 133 ExtensionResource resource = extension->GetIconResource( |
108 size, ExtensionIconSet::MATCH_EXACTLY); | 134 size, ExtensionIconSet::MATCH_EXACTLY); |
109 if (!resource.empty()) { | 135 if (!resource.empty()) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 } | 168 } |
143 | 169 |
144 void AppShortcutManager::DeleteApplicationShortcuts( | 170 void AppShortcutManager::DeleteApplicationShortcuts( |
145 const Extension* extension) { | 171 const Extension* extension) { |
146 ShellIntegration::ShortcutInfo delete_info = | 172 ShellIntegration::ShortcutInfo delete_info = |
147 ShortcutInfoForExtensionAndProfile(extension, profile_); | 173 ShortcutInfoForExtensionAndProfile(extension, profile_); |
148 web_app::DeleteAllShortcuts(delete_info); | 174 web_app::DeleteAllShortcuts(delete_info); |
149 } | 175 } |
150 | 176 |
151 } // namespace extensions | 177 } // namespace extensions |
OLD | NEW |