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/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/extensions/image_loader.h" | 12 #include "chrome/browser/extensions/image_loader.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 14 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
15 #include "chrome/browser/web_applications/web_app.h" | 15 #include "chrome/browser/web_applications/web_app.h" |
16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/extensions/extension_resource.h" | 18 #include "chrome/common/extensions/extension_resource.h" |
19 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
20 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
21 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
22 #include "skia/ext/image_operations.h" | 22 #include "skia/ext/image_operations.h" |
23 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
24 | 24 |
25 #if defined(OS_WIN) | |
26 #include "chrome/browser/extensions/app_host_installer_win.h" | |
27 #include "chrome/installer/util/browser_distribution.h" | |
28 #endif | |
29 | |
30 namespace extensions { | 25 namespace extensions { |
31 | 26 |
32 AppShortcutManager::AppShortcutManager(Profile* profile) | 27 AppShortcutManager::AppShortcutManager(Profile* profile) |
33 : profile_(profile), | 28 : profile_(profile), |
34 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 29 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
35 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | 30 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
36 content::Source<Profile>(profile_)); | 31 content::Source<Profile>(profile_)); |
37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 32 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
38 content::Source<Profile>(profile_)); | 33 content::Source<Profile>(profile_)); |
39 } | 34 } |
40 | 35 |
41 AppShortcutManager::~AppShortcutManager() {} | 36 AppShortcutManager::~AppShortcutManager() {} |
42 | 37 |
43 void AppShortcutManager::Observe(int type, | 38 void AppShortcutManager::Observe(int type, |
44 const content::NotificationSource& source, | 39 const content::NotificationSource& source, |
45 const content::NotificationDetails& details) { | 40 const content::NotificationDetails& details) { |
46 switch (type) { | 41 switch (type) { |
47 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { | 42 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { |
48 #if !defined(OS_MACOSX) | 43 #if !defined(OS_MACOSX) |
49 const Extension* extension = content::Details<const Extension>( | 44 const Extension* extension = content::Details<const Extension>( |
50 details).ptr(); | 45 details).ptr(); |
51 if (extension->is_platform_app() && | 46 if (extension->is_platform_app() && |
52 extension->location() != Manifest::COMPONENT) { | 47 extension->location() != Manifest::COMPONENT) { |
53 #if defined(OS_WIN) | 48 web_app::UpdateShortcutInfoAndIconForApp(*extension, profile_, |
54 if (BrowserDistribution::GetDistribution()->AppHostIsSupported() && | 49 base::Bind(&web_app::UpdateAllShortcuts)); |
55 extensions::AppHostInstaller::GetInstallWithLauncher()) { | |
56 scoped_refptr<Extension> extension_ref(const_cast<Extension*>( | |
57 extension)); | |
58 extensions::AppHostInstaller::EnsureAppHostInstalled( | |
59 base::Bind(&AppShortcutManager::OnAppHostInstallationComplete, | |
60 weak_factory_.GetWeakPtr(), extension_ref)); | |
61 } else { | |
62 UpdateApplicationShortcuts(extension); | |
63 } | |
64 #else | |
65 UpdateApplicationShortcuts(extension); | |
66 #endif // defined(OS_WIN) | |
67 } | 50 } |
68 #endif // !defined(OS_MACOSX) | 51 #endif // !defined(OS_MACOSX) |
69 break; | 52 break; |
70 } | 53 } |
71 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { | 54 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
72 const Extension* extension = content::Details<const Extension>( | 55 const Extension* extension = content::Details<const Extension>( |
73 details).ptr(); | 56 details).ptr(); |
74 DeleteApplicationShortcuts(extension); | 57 DeleteApplicationShortcuts(extension); |
75 break; | 58 break; |
76 } | 59 } |
77 default: | 60 default: |
78 NOTREACHED(); | 61 NOTREACHED(); |
79 } | 62 } |
80 } | 63 } |
81 | 64 |
82 #if defined(OS_WIN) | |
83 void AppShortcutManager::OnAppHostInstallationComplete( | |
84 scoped_refptr<Extension> extension, bool app_host_install_success) { | |
85 if (!app_host_install_success) { | |
86 // Do not create shortcuts if App Host fails to install. | |
87 LOG(ERROR) << "Application Runtime installation failed."; | |
88 return; | |
89 } | |
90 UpdateApplicationShortcuts(extension); | |
91 } | |
92 #endif | |
93 | |
94 void AppShortcutManager::UpdateApplicationShortcuts( | |
95 const Extension* extension) { | |
96 web_app::UpdateShortcutInfoAndIconForApp(*extension, profile_, | |
97 base::Bind(&web_app::UpdateAllShortcuts)); | |
98 } | |
99 | |
100 void AppShortcutManager::DeleteApplicationShortcuts( | 65 void AppShortcutManager::DeleteApplicationShortcuts( |
101 const Extension* extension) { | 66 const Extension* extension) { |
102 ShellIntegration::ShortcutInfo delete_info = | 67 ShellIntegration::ShortcutInfo delete_info = |
103 web_app::ShortcutInfoForExtensionAndProfile(extension, profile_); | 68 web_app::ShortcutInfoForExtensionAndProfile(extension, profile_); |
104 web_app::DeleteAllShortcuts(delete_info); | 69 web_app::DeleteAllShortcuts(delete_info); |
105 } | 70 } |
106 | 71 |
107 } // namespace extensions | 72 } // namespace extensions |
OLD | NEW |