OLD | NEW |
| (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/bind.h" | |
8 #include "base/command_line.h" | |
9 #include "base/compiler_specific.h" | |
10 #include "base/logging.h" | |
11 #include "base/utf_string_conversions.h" | |
12 #include "chrome/browser/extensions/image_loader.h" | |
13 #include "chrome/browser/profiles/profile.h" | |
14 #include "chrome/browser/shell_integration.h" | |
15 #include "chrome/browser/ui/web_applications/web_app_ui.h" | |
16 #include "chrome/browser/web_applications/web_app.h" | |
17 #include "chrome/common/chrome_notification_types.h" | |
18 #include "chrome/common/chrome_switches.h" | |
19 #include "chrome/common/extensions/extension_resource.h" | |
20 #include "content/public/browser/notification_details.h" | |
21 #include "content/public/browser/notification_source.h" | |
22 #include "grit/theme_resources.h" | |
23 #include "skia/ext/image_operations.h" | |
24 #include "ui/base/resource/resource_bundle.h" | |
25 | |
26 namespace extensions { | |
27 | |
28 AppShortcutManager::AppShortcutManager(Profile* profile) | |
29 : profile_(profile), | |
30 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | |
31 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | |
32 content::Source<Profile>(profile_)); | |
33 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | |
34 content::Source<Profile>(profile_)); | |
35 } | |
36 | |
37 AppShortcutManager::~AppShortcutManager() {} | |
38 | |
39 void AppShortcutManager::Observe(int type, | |
40 const content::NotificationSource& source, | |
41 const content::NotificationDetails& details) { | |
42 switch (type) { | |
43 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { | |
44 #if !defined(OS_MACOSX) | |
45 const Extension* extension = content::Details<const Extension>( | |
46 details).ptr(); | |
47 if (extension->is_platform_app() && | |
48 extension->location() != Manifest::COMPONENT) { | |
49 web_app::UpdateShortcutInfoAndIconForApp(*extension, profile_, | |
50 base::Bind(&web_app::UpdateAllShortcuts)); | |
51 } | |
52 #endif // !defined(OS_MACOSX) | |
53 break; | |
54 } | |
55 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { | |
56 const Extension* extension = content::Details<const Extension>( | |
57 details).ptr(); | |
58 DeleteApplicationShortcuts(extension); | |
59 break; | |
60 } | |
61 default: | |
62 NOTREACHED(); | |
63 } | |
64 } | |
65 | |
66 void AppShortcutManager::DeleteApplicationShortcuts( | |
67 const Extension* extension) { | |
68 ShellIntegration::ShortcutInfo delete_info = | |
69 web_app::ShortcutInfoForExtensionAndProfile(extension, profile_); | |
70 web_app::DeleteAllShortcuts(delete_info); | |
71 } | |
72 | |
73 } // namespace extensions | |
OLD | NEW |