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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/web_applications/web_app.h" | 21 #include "chrome/browser/web_applications/web_app.h" |
22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
24 #include "components/pref_registry/pref_registry_syncable.h" | 24 #include "components/pref_registry/pref_registry_syncable.h" |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
27 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
28 #include "extensions/browser/extension_system.h" | 28 #include "extensions/browser/extension_system.h" |
29 #include "extensions/common/extension_set.h" | 29 #include "extensions/common/extension_set.h" |
30 | 30 |
31 #if defined(OS_MACOSX) | |
32 #include "apps/app_shim/app_shim_mac.h" | |
33 #endif | |
34 | |
35 using extensions::Extension; | 31 using extensions::Extension; |
36 | 32 |
37 namespace { | 33 namespace { |
38 | 34 |
39 // Creates a shortcut for an application in the applications menu, if there is | 35 // Creates a shortcut for an application in the applications menu, if there is |
40 // not already one present. | 36 // not already one present. |
41 void CreateShortcutsInApplicationsMenu(Profile* profile, | 37 void CreateShortcutsInApplicationsMenu(Profile* profile, |
42 const Extension* app) { | 38 const Extension* app) { |
43 web_app::ShortcutLocations creation_locations; | 39 web_app::ShortcutLocations creation_locations; |
44 // Create the shortcut in the Chrome Apps subdir. | 40 // Create the shortcut in the Chrome Apps subdir. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 99 |
104 void AppShortcutManager::Observe(int type, | 100 void AppShortcutManager::Observe(int type, |
105 const content::NotificationSource& source, | 101 const content::NotificationSource& source, |
106 const content::NotificationDetails& details) { | 102 const content::NotificationDetails& details) { |
107 switch (type) { | 103 switch (type) { |
108 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 104 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
109 OnceOffCreateShortcuts(); | 105 OnceOffCreateShortcuts(); |
110 break; | 106 break; |
111 } | 107 } |
112 case chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED: { | 108 case chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED: { |
113 #if defined(OS_MACOSX) | |
114 if (!apps::IsAppShimsEnabled()) | |
115 break; | |
116 #endif // defined(OS_MACOSX) | |
117 | |
118 const extensions::InstalledExtensionInfo* installed_info = | 109 const extensions::InstalledExtensionInfo* installed_info = |
119 content::Details<const extensions::InstalledExtensionInfo>(details) | 110 content::Details<const extensions::InstalledExtensionInfo>(details) |
120 .ptr(); | 111 .ptr(); |
121 const Extension* extension = installed_info->extension; | 112 const Extension* extension = installed_info->extension; |
122 // If the app is being updated, update any existing shortcuts but do not | 113 // If the app is being updated, update any existing shortcuts but do not |
123 // create new ones. If it is being installed, automatically create a | 114 // create new ones. If it is being installed, automatically create a |
124 // shortcut in the applications menu (e.g., Start Menu). | 115 // shortcut in the applications menu (e.g., Start Menu). |
125 if (installed_info->is_update) { | 116 if (installed_info->is_update) { |
126 web_app::UpdateAllShortcuts( | 117 web_app::UpdateAllShortcuts( |
127 base::UTF8ToUTF16(installed_info->old_name), profile_, extension); | 118 base::UTF8ToUTF16(installed_info->old_name), profile_, extension); |
(...skipping 17 matching lines...) Expand all Loading... |
145 const base::FilePath& profile_path) { | 136 const base::FilePath& profile_path) { |
146 if (profile_path != profile_->GetPath()) | 137 if (profile_path != profile_->GetPath()) |
147 return; | 138 return; |
148 content::BrowserThread::PostTask( | 139 content::BrowserThread::PostTask( |
149 content::BrowserThread::FILE, FROM_HERE, | 140 content::BrowserThread::FILE, FROM_HERE, |
150 base::Bind(&web_app::internals::DeleteAllShortcutsForProfile, | 141 base::Bind(&web_app::internals::DeleteAllShortcutsForProfile, |
151 profile_path)); | 142 profile_path)); |
152 } | 143 } |
153 | 144 |
154 void AppShortcutManager::OnceOffCreateShortcuts() { | 145 void AppShortcutManager::OnceOffCreateShortcuts() { |
155 bool was_enabled = prefs_->GetBoolean(prefs::kAppShortcutsHaveBeenCreated); | 146 if (prefs_->GetBoolean(prefs::kAppShortcutsHaveBeenCreated)) |
| 147 return; |
156 | 148 |
157 // Creation of shortcuts on Mac currently can be disabled with | 149 prefs_->SetBoolean(prefs::kAppShortcutsHaveBeenCreated, true); |
158 // --disable-app-shims, so check the flag, and set the pref accordingly. | |
159 #if defined(OS_MACOSX) | |
160 bool is_now_enabled = apps::IsAppShimsEnabled(); | |
161 #else | |
162 bool is_now_enabled = true; | |
163 #endif // defined(OS_MACOSX) | |
164 | |
165 if (was_enabled != is_now_enabled) | |
166 prefs_->SetBoolean(prefs::kAppShortcutsHaveBeenCreated, is_now_enabled); | |
167 | |
168 if (was_enabled || !is_now_enabled) | |
169 return; | |
170 | 150 |
171 // Check if extension system/service are available. They might not be in | 151 // Check if extension system/service are available. They might not be in |
172 // tests. | 152 // tests. |
173 extensions::ExtensionSystem* extension_system; | 153 extensions::ExtensionSystem* extension_system; |
174 ExtensionServiceInterface* extension_service; | 154 ExtensionServiceInterface* extension_service; |
175 if (!(extension_system = extensions::ExtensionSystem::Get(profile_)) || | 155 if (!(extension_system = extensions::ExtensionSystem::Get(profile_)) || |
176 !(extension_service = extension_system->extension_service())) | 156 !(extension_service = extension_system->extension_service())) |
177 return; | 157 return; |
178 | 158 |
179 // Create an applications menu shortcut for each app in this profile. | 159 // Create an applications menu shortcut for each app in this profile. |
180 const extensions::ExtensionSet* apps = extension_service->extensions(); | 160 const extensions::ExtensionSet* apps = extension_service->extensions(); |
181 for (extensions::ExtensionSet::const_iterator it = apps->begin(); | 161 for (extensions::ExtensionSet::const_iterator it = apps->begin(); |
182 it != apps->end(); ++it) { | 162 it != apps->end(); ++it) { |
183 if (ShouldCreateShortcutFor(profile_, it->get())) | 163 if (ShouldCreateShortcutFor(profile_, it->get())) |
184 CreateShortcutsInApplicationsMenu(profile_, it->get()); | 164 CreateShortcutsInApplicationsMenu(profile_, it->get()); |
185 } | 165 } |
186 } | 166 } |
OLD | NEW |