[email protected] | b6b7222 | 2012-02-11 02:04:13 | [diff] [blame] | 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/web_applications/web_app.h" |
| 6 | |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
[email protected] | b6b7222 | 2012-02-11 02:04:13 | [diff] [blame] | 9 | #include "base/environment.h" |
[email protected] | 9226938 | 2012-03-03 09:00:08 | [diff] [blame] | 10 | #include "base/logging.h" |
avi | 664c07b | 2015-12-26 02:18:31 | [diff] [blame] | 11 | #include "build/build_config.h" |
[email protected] | 8806d3b | 2012-04-13 06:46:34 | [diff] [blame] | 12 | #include "chrome/browser/shell_integration_linux.h" |
[email protected] | b6b7222 | 2012-02-11 02:04:13 | [diff] [blame] | 13 | #include "content/public/browser/browser_thread.h" |
| 14 | |
| 15 | namespace web_app { |
[email protected] | e66ba95 | 2012-10-09 09:59:44 | [diff] [blame] | 16 | |
[email protected] | 090e1ee7 | 2014-06-03 13:08:40 | [diff] [blame] | 17 | void UpdateShortcutsForAllApps(Profile* profile, |
| 18 | const base::Closure& callback) { |
| 19 | callback.Run(); |
| 20 | } |
| 21 | |
[email protected] | b6b7222 | 2012-02-11 02:04:13 | [diff] [blame] | 22 | namespace internals { |
| 23 | |
[email protected] | c002e75 | 2012-08-10 12:50:11 | [diff] [blame] | 24 | bool CreatePlatformShortcuts( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 25 | const base::FilePath& web_app_path, |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 26 | std::unique_ptr<ShortcutInfo> shortcut_info, |
[email protected] | e6be3fe | 2014-04-11 13:17:51 | [diff] [blame] | 27 | const extensions::FileHandlersInfo& file_handlers_info, |
[email protected] | 9b1b5fe | 2014-05-15 08:23:17 | [diff] [blame] | 28 | const ShortcutLocations& creation_locations, |
[email protected] | a705c7ee7 | 2013-07-26 08:01:54 | [diff] [blame] | 29 | ShortcutCreationReason /*creation_reason*/) { |
[email protected] | 9aadaa4 | 2013-08-16 10:43:17 | [diff] [blame] | 30 | #if !defined(OS_CHROMEOS) |
anujk.sharma | 9fcea9a | 2015-04-22 06:57:49 | [diff] [blame] | 31 | DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
mgiuca | b21fe8ee | 2015-04-09 04:00:44 | [diff] [blame] | 32 | return shell_integration_linux::CreateDesktopShortcut(*shortcut_info, |
| 33 | creation_locations); |
[email protected] | 9aadaa4 | 2013-08-16 10:43:17 | [diff] [blame] | 34 | #else |
| 35 | return false; |
| 36 | #endif |
[email protected] | b6b7222 | 2012-02-11 02:04:13 | [diff] [blame] | 37 | } |
| 38 | |
[email protected] | 9b1b5fe | 2014-05-15 08:23:17 | [diff] [blame] | 39 | void DeletePlatformShortcuts(const base::FilePath& web_app_path, |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 40 | std::unique_ptr<ShortcutInfo> shortcut_info) { |
[email protected] | 9aadaa4 | 2013-08-16 10:43:17 | [diff] [blame] | 41 | #if !defined(OS_CHROMEOS) |
mgiuca | b21fe8ee | 2015-04-09 04:00:44 | [diff] [blame] | 42 | shell_integration_linux::DeleteDesktopShortcuts(shortcut_info->profile_path, |
| 43 | shortcut_info->extension_id); |
[email protected] | 9aadaa4 | 2013-08-16 10:43:17 | [diff] [blame] | 44 | #endif |
[email protected] | 0b7df36d | 2012-07-11 09:50:47 | [diff] [blame] | 45 | } |
| 46 | |
[email protected] | e66ba95 | 2012-10-09 09:59:44 | [diff] [blame] | 47 | void UpdatePlatformShortcuts( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 48 | const base::FilePath& web_app_path, |
[email protected] | 0085863a | 2013-12-06 21:19:03 | [diff] [blame] | 49 | const base::string16& /*old_app_title*/, |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 50 | std::unique_ptr<ShortcutInfo> shortcut_info, |
[email protected] | e6be3fe | 2014-04-11 13:17:51 | [diff] [blame] | 51 | const extensions::FileHandlersInfo& file_handlers_info) { |
anujk.sharma | 9fcea9a | 2015-04-22 06:57:49 | [diff] [blame] | 52 | DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
[email protected] | d81a63c0 | 2013-03-07 08:49:04 | [diff] [blame] | 53 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 54 | std::unique_ptr<base::Environment> env(base::Environment::Create()); |
[email protected] | d81a63c0 | 2013-03-07 08:49:04 | [diff] [blame] | 55 | |
| 56 | // Find out whether shortcuts are already installed. |
[email protected] | 9b1b5fe | 2014-05-15 08:23:17 | [diff] [blame] | 57 | ShortcutLocations creation_locations = |
[email protected] | 06bfeb1 | 2014-05-27 14:00:09 | [diff] [blame] | 58 | shell_integration_linux::GetExistingShortcutLocations( |
mgiuca | b21fe8ee | 2015-04-09 04:00:44 | [diff] [blame] | 59 | env.get(), shortcut_info->profile_path, shortcut_info->extension_id); |
[email protected] | da0349e | 2014-06-11 07:38:28 | [diff] [blame] | 60 | |
[email protected] | d81a63c0 | 2013-03-07 08:49:04 | [diff] [blame] | 61 | // Always create a hidden shortcut in applications if a visible one is not |
| 62 | // being created. This allows the operating system to identify the app, but |
| 63 | // not show it in the menu. |
[email protected] | da0349e | 2014-06-11 07:38:28 | [diff] [blame] | 64 | if (creation_locations.applications_menu_location == APP_MENU_LOCATION_NONE) |
| 65 | creation_locations.applications_menu_location = APP_MENU_LOCATION_HIDDEN; |
[email protected] | d81a63c0 | 2013-03-07 08:49:04 | [diff] [blame] | 66 | |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 67 | CreatePlatformShortcuts(web_app_path, std::move(shortcut_info), |
mgiuca | b21fe8ee | 2015-04-09 04:00:44 | [diff] [blame] | 68 | file_handlers_info, creation_locations, |
[email protected] | da0349e | 2014-06-11 07:38:28 | [diff] [blame] | 69 | SHORTCUT_CREATION_AUTOMATED); |
[email protected] | e66ba95 | 2012-10-09 09:59:44 | [diff] [blame] | 70 | } |
| 71 | |
[email protected] | f80bda0 | 2013-07-02 10:30:31 | [diff] [blame] | 72 | void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { |
[email protected] | 9aadaa4 | 2013-08-16 10:43:17 | [diff] [blame] | 73 | #if !defined(OS_CHROMEOS) |
[email protected] | 06bfeb1 | 2014-05-27 14:00:09 | [diff] [blame] | 74 | shell_integration_linux::DeleteAllDesktopShortcuts(profile_path); |
[email protected] | 9aadaa4 | 2013-08-16 10:43:17 | [diff] [blame] | 75 | #endif |
[email protected] | f80bda0 | 2013-07-02 10:30:31 | [diff] [blame] | 76 | } |
| 77 | |
[email protected] | b6b7222 | 2012-02-11 02:04:13 | [diff] [blame] | 78 | } // namespace internals |
[email protected] | e66ba95 | 2012-10-09 09:59:44 | [diff] [blame] | 79 | |
[email protected] | b6b7222 | 2012-02-11 02:04:13 | [diff] [blame] | 80 | } // namespace web_app |