OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/apps/shortcut_manager.h" | 5 #include "chrome/browser/apps/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/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/extension_ui_util.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_info_cache.h" | 18 #include "chrome/browser/profiles/profile_info_cache.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/shell_integration.h" | 20 #include "chrome/browser/shell_integration.h" |
20 #include "chrome/browser/web_applications/web_app.h" | 21 #include "chrome/browser/web_applications/web_app.h" |
21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "components/user_prefs/pref_registry_syncable.h" | 24 #include "components/user_prefs/pref_registry_syncable.h" |
24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
(...skipping 14 matching lines...) Expand all Loading... |
40 void CreateShortcutsInApplicationsMenu(Profile* profile, | 41 void CreateShortcutsInApplicationsMenu(Profile* profile, |
41 const Extension* app) { | 42 const Extension* app) { |
42 web_app::ShortcutLocations creation_locations; | 43 web_app::ShortcutLocations creation_locations; |
43 // Create the shortcut in the Chrome Apps subdir. | 44 // Create the shortcut in the Chrome Apps subdir. |
44 creation_locations.applications_menu_location = | 45 creation_locations.applications_menu_location = |
45 web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; | 46 web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; |
46 web_app::CreateShortcuts( | 47 web_app::CreateShortcuts( |
47 web_app::SHORTCUT_CREATION_AUTOMATED, creation_locations, profile, app); | 48 web_app::SHORTCUT_CREATION_AUTOMATED, creation_locations, profile, app); |
48 } | 49 } |
49 | 50 |
50 bool ShouldCreateShortcutFor(const Extension* extension) { | 51 bool ShouldCreateShortcutFor(Profile* profile, const Extension* extension) { |
51 return extension->is_platform_app() && | 52 return extension->is_platform_app() && |
52 extension->location() != extensions::Manifest::COMPONENT && | 53 extension->location() != extensions::Manifest::COMPONENT && |
53 extension->ShouldDisplayInAppLauncher(); | 54 extensions::ui_util::ShouldDisplayInAppLauncher(extension, profile); |
54 } | 55 } |
55 | 56 |
56 } // namespace | 57 } // namespace |
57 | 58 |
58 // static | 59 // static |
59 void AppShortcutManager::RegisterProfilePrefs( | 60 void AppShortcutManager::RegisterProfilePrefs( |
60 user_prefs::PrefRegistrySyncable* registry) { | 61 user_prefs::PrefRegistrySyncable* registry) { |
61 // Indicates whether app shortcuts have been created. | 62 // Indicates whether app shortcuts have been created. |
62 registry->RegisterBooleanPref( | 63 registry->RegisterBooleanPref( |
63 prefs::kAppShortcutsHaveBeenCreated, false, | 64 prefs::kAppShortcutsHaveBeenCreated, false, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 const extensions::InstalledExtensionInfo* installed_info = | 117 const extensions::InstalledExtensionInfo* installed_info = |
117 content::Details<const extensions::InstalledExtensionInfo>(details) | 118 content::Details<const extensions::InstalledExtensionInfo>(details) |
118 .ptr(); | 119 .ptr(); |
119 const Extension* extension = installed_info->extension; | 120 const Extension* extension = installed_info->extension; |
120 // If the app is being updated, update any existing shortcuts but do not | 121 // If the app is being updated, update any existing shortcuts but do not |
121 // create new ones. If it is being installed, automatically create a | 122 // create new ones. If it is being installed, automatically create a |
122 // shortcut in the applications menu (e.g., Start Menu). | 123 // shortcut in the applications menu (e.g., Start Menu). |
123 if (installed_info->is_update) { | 124 if (installed_info->is_update) { |
124 web_app::UpdateAllShortcuts( | 125 web_app::UpdateAllShortcuts( |
125 base::UTF8ToUTF16(installed_info->old_name), profile_, extension); | 126 base::UTF8ToUTF16(installed_info->old_name), profile_, extension); |
126 } else if (ShouldCreateShortcutFor(extension)) { | 127 } else if (ShouldCreateShortcutFor(profile_, extension)) { |
127 CreateShortcutsInApplicationsMenu(profile_, extension); | 128 CreateShortcutsInApplicationsMenu(profile_, extension); |
128 } | 129 } |
129 break; | 130 break; |
130 } | 131 } |
131 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { | 132 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
132 const Extension* extension = content::Details<const Extension>( | 133 const Extension* extension = content::Details<const Extension>( |
133 details).ptr(); | 134 details).ptr(); |
134 web_app::DeleteAllShortcuts(profile_, extension); | 135 web_app::DeleteAllShortcuts(profile_, extension); |
135 break; | 136 break; |
136 } | 137 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 extensions::ExtensionSystem* extension_system; | 172 extensions::ExtensionSystem* extension_system; |
172 ExtensionServiceInterface* extension_service; | 173 ExtensionServiceInterface* extension_service; |
173 if (!(extension_system = extensions::ExtensionSystem::Get(profile_)) || | 174 if (!(extension_system = extensions::ExtensionSystem::Get(profile_)) || |
174 !(extension_service = extension_system->extension_service())) | 175 !(extension_service = extension_system->extension_service())) |
175 return; | 176 return; |
176 | 177 |
177 // Create an applications menu shortcut for each app in this profile. | 178 // Create an applications menu shortcut for each app in this profile. |
178 const extensions::ExtensionSet* apps = extension_service->extensions(); | 179 const extensions::ExtensionSet* apps = extension_service->extensions(); |
179 for (extensions::ExtensionSet::const_iterator it = apps->begin(); | 180 for (extensions::ExtensionSet::const_iterator it = apps->begin(); |
180 it != apps->end(); ++it) { | 181 it != apps->end(); ++it) { |
181 if (ShouldCreateShortcutFor(it->get())) | 182 if (ShouldCreateShortcutFor(profile_, it->get())) |
182 CreateShortcutsInApplicationsMenu(profile_, it->get()); | 183 CreateShortcutsInApplicationsMenu(profile_, it->get()); |
183 } | 184 } |
184 } | 185 } |
OLD | NEW |