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