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