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.
5 #include "apps/shortcut_manager.h"
8 #include "base/compiler_specific.h"
9 #include "chrome/browser/shell_integration.h"
10 #include "chrome/browser/ui/web_applications/web_app_ui.h"
11 #include "chrome/browser/web_applications/web_app.h"
12 #include "chrome/common/chrome_notification_types.h"
13 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_source.h"
16 using extensions::Extension
;
20 // Creates a shortcut for an application in the applications menu.
21 void CreateShortcutsInApplicationsMenu(
22 const ShellIntegration::ShortcutInfo
& shortcut_info
) {
23 ShellIntegration::ShortcutLocations creation_locations
;
24 creation_locations
.in_applications_menu
= true;
25 // Create the shortcut in the Chrome Apps subdir.
26 creation_locations
.applications_menu_subdir
=
27 web_app::GetAppShortcutsSubdirName();
28 web_app::CreateShortcuts(shortcut_info
, creation_locations
);
35 ShortcutManager::ShortcutManager(Profile
* profile
)
38 registrar_
.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED
,
39 content::Source
<Profile
>(profile_
));
40 registrar_
.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED
,
41 content::Source
<Profile
>(profile_
));
44 ShortcutManager::~ShortcutManager() {}
46 void ShortcutManager::Observe(int type
,
47 const content::NotificationSource
& source
,
48 const content::NotificationDetails
& details
) {
50 case chrome::NOTIFICATION_EXTENSION_INSTALLED
: {
51 #if !defined(OS_MACOSX)
52 const extensions::InstalledExtensionInfo
* installed_info
=
53 content::Details
<const extensions::InstalledExtensionInfo
>(details
)
55 const Extension
* extension
= installed_info
->extension
;
56 if (extension
->is_platform_app() &&
57 extension
->location() != extensions::Manifest::COMPONENT
) {
58 // If the app is being updated, update any existing shortcuts but do not
59 // create new ones. If it is being installed, automatically create a
60 // shortcut in the applications menu (e.g., Start Menu).
61 base::Callback
<void(const ShellIntegration::ShortcutInfo
&)>
63 if (installed_info
->is_update
) {
64 create_or_update
= base::Bind(&web_app::UpdateAllShortcuts
);
66 create_or_update
= base::Bind(&CreateShortcutsInApplicationsMenu
);
69 web_app::UpdateShortcutInfoAndIconForApp(*extension
, profile_
,
72 #endif // !defined(OS_MACOSX)
75 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED
: {
76 const Extension
* extension
= content::Details
<const Extension
>(
78 DeleteApplicationShortcuts(extension
);
86 void ShortcutManager::DeleteApplicationShortcuts(
87 const Extension
* extension
) {
88 ShellIntegration::ShortcutInfo delete_info
=
89 web_app::ShortcutInfoForExtensionAndProfile(extension
, profile_
);
90 web_app::DeleteAllShortcuts(delete_info
);