| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/shell_integration_linux.h" | 5 #include "chrome/browser/shell_integration_linux.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 DefaultWebClientState IsDefaultProtocolClient(const std::string& protocol) { | 243 DefaultWebClientState IsDefaultProtocolClient(const std::string& protocol) { |
| 244 return GetIsDefaultWebClient(protocol); | 244 return GetIsDefaultWebClient(protocol); |
| 245 } | 245 } |
| 246 | 246 |
| 247 } // namespace shell_integration | 247 } // namespace shell_integration |
| 248 | 248 |
| 249 namespace shell_integration_linux { | 249 namespace shell_integration_linux { |
| 250 | 250 |
| 251 namespace { | 251 namespace { |
| 252 | 252 |
| 253 #if defined(ENABLE_APP_LIST) |
| 253 // The Categories for the App Launcher desktop shortcut. Should be the same as | 254 // The Categories for the App Launcher desktop shortcut. Should be the same as |
| 254 // the Chrome desktop shortcut, so they are in the same sub-menu. | 255 // the Chrome desktop shortcut, so they are in the same sub-menu. |
| 255 const char kAppListCategories[] = "Network;WebBrowser;"; | 256 const char kAppListCategories[] = "Network;WebBrowser;"; |
| 257 #endif |
| 256 | 258 |
| 257 std::string CreateShortcutIcon(const gfx::ImageFamily& icon_images, | 259 std::string CreateShortcutIcon(const gfx::ImageFamily& icon_images, |
| 258 const base::FilePath& shortcut_filename) { | 260 const base::FilePath& shortcut_filename) { |
| 259 if (icon_images.empty()) | 261 if (icon_images.empty()) |
| 260 return std::string(); | 262 return std::string(); |
| 261 | 263 |
| 262 // TODO(phajdan.jr): Report errors from this function, possibly as infobars. | 264 // TODO(phajdan.jr): Report errors from this function, possibly as infobars. |
| 263 base::ScopedTempDir temp_dir; | 265 base::ScopedTempDir temp_dir; |
| 264 if (!temp_dir.CreateUniqueTempDir()) | 266 if (!temp_dir.CreateUniqueTempDir()) |
| 265 return std::string(); | 267 return std::string(); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 return quoted_path; | 475 return quoted_path; |
| 474 } | 476 } |
| 475 | 477 |
| 476 const char kDesktopEntry[] = "Desktop Entry"; | 478 const char kDesktopEntry[] = "Desktop Entry"; |
| 477 | 479 |
| 478 const char kXdgOpenShebang[] = "#!/usr/bin/env xdg-open"; | 480 const char kXdgOpenShebang[] = "#!/usr/bin/env xdg-open"; |
| 479 #endif | 481 #endif |
| 480 | 482 |
| 481 const char kDirectoryFilename[] = "chrome-apps.directory"; | 483 const char kDirectoryFilename[] = "chrome-apps.directory"; |
| 482 | 484 |
| 485 #if defined(ENABLE_APP_LIST) |
| 483 #if defined(GOOGLE_CHROME_BUILD) | 486 #if defined(GOOGLE_CHROME_BUILD) |
| 484 const char kAppListDesktopName[] = "chrome-app-list"; | 487 const char kAppListDesktopName[] = "chrome-app-list"; |
| 485 #else // CHROMIUM_BUILD | 488 #else // CHROMIUM_BUILD |
| 486 const char kAppListDesktopName[] = "chromium-app-list"; | 489 const char kAppListDesktopName[] = "chromium-app-list"; |
| 487 #endif | 490 #endif |
| 491 #endif |
| 488 | 492 |
| 489 // Get the value of NoDisplay from the [Desktop Entry] section of a .desktop | 493 // Get the value of NoDisplay from the [Desktop Entry] section of a .desktop |
| 490 // file, given in |shortcut_contents|. If the key is not found, returns false. | 494 // file, given in |shortcut_contents|. If the key is not found, returns false. |
| 491 bool GetNoDisplayFromDesktopFile(const std::string& shortcut_contents) { | 495 bool GetNoDisplayFromDesktopFile(const std::string& shortcut_contents) { |
| 492 #if defined(USE_GLIB) | 496 #if defined(USE_GLIB) |
| 493 // An empty file causes a crash with glib <= 2.32, so special case here. | 497 // An empty file causes a crash with glib <= 2.32, so special case here. |
| 494 if (shortcut_contents.empty()) | 498 if (shortcut_contents.empty()) |
| 495 return false; | 499 return false; |
| 496 | 500 |
| 497 GKeyFile* key_file = g_key_file_new(); | 501 GKeyFile* key_file = g_key_file_new(); |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 "", | 969 "", |
| 966 creation_locations.applications_menu_location == | 970 creation_locations.applications_menu_location == |
| 967 web_app::APP_MENU_LOCATION_HIDDEN); | 971 web_app::APP_MENU_LOCATION_HIDDEN); |
| 968 success = CreateShortcutInApplicationsMenu( | 972 success = CreateShortcutInApplicationsMenu( |
| 969 shortcut_filename, contents, directory_filename, directory_contents) && | 973 shortcut_filename, contents, directory_filename, directory_contents) && |
| 970 success; | 974 success; |
| 971 | 975 |
| 972 return success; | 976 return success; |
| 973 } | 977 } |
| 974 | 978 |
| 979 #if defined(ENABLE_APP_LIST) |
| 975 bool CreateAppListDesktopShortcut( | 980 bool CreateAppListDesktopShortcut( |
| 976 const std::string& wm_class, | 981 const std::string& wm_class, |
| 977 const std::string& title) { | 982 const std::string& title) { |
| 978 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 983 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 979 | 984 |
| 980 base::FilePath desktop_name(kAppListDesktopName); | 985 base::FilePath desktop_name(kAppListDesktopName); |
| 981 base::FilePath shortcut_filename = desktop_name.AddExtension("desktop"); | 986 base::FilePath shortcut_filename = desktop_name.AddExtension("desktop"); |
| 982 | 987 |
| 983 // We do not want duplicate shortcuts. Delete any that already exist and | 988 // We do not want duplicate shortcuts. Delete any that already exist and |
| 984 // replace them. | 989 // replace them. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1004 GetDesktopFileContentsForCommand(command_line, | 1009 GetDesktopFileContentsForCommand(command_line, |
| 1005 wm_class, | 1010 wm_class, |
| 1006 GURL(), | 1011 GURL(), |
| 1007 base::UTF8ToUTF16(title), | 1012 base::UTF8ToUTF16(title), |
| 1008 icon_name, | 1013 icon_name, |
| 1009 kAppListCategories, | 1014 kAppListCategories, |
| 1010 false); | 1015 false); |
| 1011 return CreateShortcutInApplicationsMenu( | 1016 return CreateShortcutInApplicationsMenu( |
| 1012 shortcut_filename, contents, base::FilePath(), ""); | 1017 shortcut_filename, contents, base::FilePath(), ""); |
| 1013 } | 1018 } |
| 1019 #endif |
| 1014 | 1020 |
| 1015 void DeleteDesktopShortcuts(const base::FilePath& profile_path, | 1021 void DeleteDesktopShortcuts(const base::FilePath& profile_path, |
| 1016 const std::string& extension_id) { | 1022 const std::string& extension_id) { |
| 1017 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 1023 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 1018 | 1024 |
| 1019 base::FilePath shortcut_filename = GetExtensionShortcutFilename( | 1025 base::FilePath shortcut_filename = GetExtensionShortcutFilename( |
| 1020 profile_path, extension_id); | 1026 profile_path, extension_id); |
| 1021 DCHECK(!shortcut_filename.empty()); | 1027 DCHECK(!shortcut_filename.empty()); |
| 1022 | 1028 |
| 1023 DeleteShortcutOnDesktop(shortcut_filename); | 1029 DeleteShortcutOnDesktop(shortcut_filename); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1048 base::FilePath applications_menu = GetDataWriteLocation(env.get()); | 1054 base::FilePath applications_menu = GetDataWriteLocation(env.get()); |
| 1049 applications_menu = applications_menu.AppendASCII("applications"); | 1055 applications_menu = applications_menu.AppendASCII("applications"); |
| 1050 std::vector<base::FilePath> shortcut_filenames_app_menu = | 1056 std::vector<base::FilePath> shortcut_filenames_app_menu = |
| 1051 GetExistingProfileShortcutFilenames(profile_path, applications_menu); | 1057 GetExistingProfileShortcutFilenames(profile_path, applications_menu); |
| 1052 for (const auto& menu : shortcut_filenames_app_menu) { | 1058 for (const auto& menu : shortcut_filenames_app_menu) { |
| 1053 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); | 1059 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); |
| 1054 } | 1060 } |
| 1055 } | 1061 } |
| 1056 | 1062 |
| 1057 } // namespace shell_integration_linux | 1063 } // namespace shell_integration_linux |
| OLD | NEW |