| 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 | 8 |
| 9 #if defined(USE_GLIB) | 9 #if defined(USE_GLIB) |
| 10 #include <glib.h> | 10 #include <glib.h> |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 | 652 |
| 653 // Determine whether there is a shortcut on desktop. | 653 // Determine whether there is a shortcut on desktop. |
| 654 if (!desktop_path.empty()) { | 654 if (!desktop_path.empty()) { |
| 655 locations.on_desktop = | 655 locations.on_desktop = |
| 656 base::PathExists(desktop_path.Append(shortcut_filename)); | 656 base::PathExists(desktop_path.Append(shortcut_filename)); |
| 657 } | 657 } |
| 658 | 658 |
| 659 // Determine whether there is a shortcut in the applications directory. | 659 // Determine whether there is a shortcut in the applications directory. |
| 660 std::string shortcut_contents; | 660 std::string shortcut_contents; |
| 661 if (GetExistingShortcutContents(env, shortcut_filename, &shortcut_contents)) { | 661 if (GetExistingShortcutContents(env, shortcut_filename, &shortcut_contents)) { |
| 662 // Whether this counts as "hidden" or "APP_MENU_LOCATION_SUBDIR_CHROMEAPPS" | 662 // If the shortcut contents contain NoDisplay=true, it should be hidden. |
| 663 // depends on whether it contains NoDisplay=true. Since these shortcuts are | 663 // Otherwise since these shortcuts are for apps, they are always in the |
| 664 // for apps, they are always in the "Chrome Apps" directory. | 664 // "Chrome Apps" directory. |
| 665 if (GetNoDisplayFromDesktopFile(shortcut_contents)) { | 665 locations.applications_menu_location = |
| 666 locations.hidden = true; | 666 GetNoDisplayFromDesktopFile(shortcut_contents) |
| 667 } else { | 667 ? web_app::APP_MENU_LOCATION_HIDDEN |
| 668 locations.applications_menu_location = | 668 : web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; |
| 669 web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; | |
| 670 } | |
| 671 } | 669 } |
| 672 | 670 |
| 673 return locations; | 671 return locations; |
| 674 } | 672 } |
| 675 | 673 |
| 676 bool GetExistingShortcutContents(base::Environment* env, | 674 bool GetExistingShortcutContents(base::Environment* env, |
| 677 const base::FilePath& desktop_filename, | 675 const base::FilePath& desktop_filename, |
| 678 std::string* output) { | 676 std::string* output) { |
| 679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 677 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 680 | 678 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 902 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 905 | 903 |
| 906 base::FilePath shortcut_filename; | 904 base::FilePath shortcut_filename; |
| 907 if (!shortcut_info.extension_id.empty()) { | 905 if (!shortcut_info.extension_id.empty()) { |
| 908 shortcut_filename = GetExtensionShortcutFilename( | 906 shortcut_filename = GetExtensionShortcutFilename( |
| 909 shortcut_info.profile_path, shortcut_info.extension_id); | 907 shortcut_info.profile_path, shortcut_info.extension_id); |
| 910 // For extensions we do not want duplicate shortcuts. So, delete any that | 908 // For extensions we do not want duplicate shortcuts. So, delete any that |
| 911 // already exist and replace them. | 909 // already exist and replace them. |
| 912 if (creation_locations.on_desktop) | 910 if (creation_locations.on_desktop) |
| 913 DeleteShortcutOnDesktop(shortcut_filename); | 911 DeleteShortcutOnDesktop(shortcut_filename); |
| 914 // The 'applications_menu_location' and 'hidden' locations are actually the | 912 |
| 915 // same place ('applications'). | |
| 916 if (creation_locations.applications_menu_location != | 913 if (creation_locations.applications_menu_location != |
| 917 web_app::APP_MENU_LOCATION_NONE || | 914 web_app::APP_MENU_LOCATION_NONE) { |
| 918 creation_locations.hidden) | |
| 919 DeleteShortcutInApplicationsMenu(shortcut_filename, base::FilePath()); | 915 DeleteShortcutInApplicationsMenu(shortcut_filename, base::FilePath()); |
| 916 } |
| 920 } else { | 917 } else { |
| 921 shortcut_filename = GetWebShortcutFilename(shortcut_info.url); | 918 shortcut_filename = GetWebShortcutFilename(shortcut_info.url); |
| 922 } | 919 } |
| 923 if (shortcut_filename.empty()) | 920 if (shortcut_filename.empty()) |
| 924 return false; | 921 return false; |
| 925 | 922 |
| 926 std::string icon_name = | 923 std::string icon_name = |
| 927 CreateShortcutIcon(shortcut_info.favicon, shortcut_filename); | 924 CreateShortcutIcon(shortcut_info.favicon, shortcut_filename); |
| 928 | 925 |
| 929 std::string app_name = | 926 std::string app_name = |
| (...skipping 14 matching lines...) Expand all Loading... |
| 944 shortcut_info.url, | 941 shortcut_info.url, |
| 945 shortcut_info.extension_id, | 942 shortcut_info.extension_id, |
| 946 shortcut_info.title, | 943 shortcut_info.title, |
| 947 icon_name, | 944 icon_name, |
| 948 shortcut_info.profile_path, | 945 shortcut_info.profile_path, |
| 949 "", | 946 "", |
| 950 false); | 947 false); |
| 951 success = CreateShortcutOnDesktop(shortcut_filename, contents); | 948 success = CreateShortcutOnDesktop(shortcut_filename, contents); |
| 952 } | 949 } |
| 953 | 950 |
| 954 if (creation_locations.applications_menu_location != | 951 if (creation_locations.applications_menu_location == |
| 955 web_app::APP_MENU_LOCATION_NONE || | 952 web_app::APP_MENU_LOCATION_NONE) { |
| 956 creation_locations.hidden) { | 953 return success; |
| 957 base::FilePath directory_filename; | |
| 958 std::string directory_contents; | |
| 959 switch (creation_locations.applications_menu_location) { | |
| 960 case web_app::APP_MENU_LOCATION_NONE: | |
| 961 case web_app::APP_MENU_LOCATION_ROOT: | |
| 962 break; | |
| 963 case web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS: | |
| 964 directory_filename = base::FilePath(kDirectoryFilename); | |
| 965 directory_contents = GetDirectoryFileContents( | |
| 966 ShellIntegration::GetAppShortcutsSubdirName(), ""); | |
| 967 break; | |
| 968 default: | |
| 969 NOTREACHED(); | |
| 970 break; | |
| 971 } | |
| 972 // Set NoDisplay=true if hidden but not in the applications menu. This will | |
| 973 // hide the application from user-facing menus. | |
| 974 std::string contents = GetDesktopFileContents( | |
| 975 chrome_exe_path, | |
| 976 app_name, | |
| 977 shortcut_info.url, | |
| 978 shortcut_info.extension_id, | |
| 979 shortcut_info.title, | |
| 980 icon_name, | |
| 981 shortcut_info.profile_path, | |
| 982 "", | |
| 983 creation_locations.applications_menu_location == | |
| 984 web_app::APP_MENU_LOCATION_NONE); | |
| 985 success = CreateShortcutInApplicationsMenu( | |
| 986 shortcut_filename, contents, directory_filename, directory_contents) && | |
| 987 success; | |
| 988 } | 954 } |
| 989 | 955 |
| 956 base::FilePath directory_filename; |
| 957 std::string directory_contents; |
| 958 switch (creation_locations.applications_menu_location) { |
| 959 case web_app::APP_MENU_LOCATION_ROOT: |
| 960 case web_app::APP_MENU_LOCATION_HIDDEN: |
| 961 break; |
| 962 case web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS: |
| 963 directory_filename = base::FilePath(kDirectoryFilename); |
| 964 directory_contents = GetDirectoryFileContents( |
| 965 ShellIntegration::GetAppShortcutsSubdirName(), ""); |
| 966 break; |
| 967 default: |
| 968 NOTREACHED(); |
| 969 break; |
| 970 } |
| 971 |
| 972 // Set NoDisplay=true if hidden. This will hide the application from |
| 973 // user-facing menus. |
| 974 std::string contents = GetDesktopFileContents( |
| 975 chrome_exe_path, |
| 976 app_name, |
| 977 shortcut_info.url, |
| 978 shortcut_info.extension_id, |
| 979 shortcut_info.title, |
| 980 icon_name, |
| 981 shortcut_info.profile_path, |
| 982 "", |
| 983 creation_locations.applications_menu_location == |
| 984 web_app::APP_MENU_LOCATION_HIDDEN); |
| 985 success = CreateShortcutInApplicationsMenu( |
| 986 shortcut_filename, contents, directory_filename, directory_contents) && |
| 987 success; |
| 988 |
| 990 return success; | 989 return success; |
| 991 } | 990 } |
| 992 | 991 |
| 993 bool CreateAppListDesktopShortcut( | 992 bool CreateAppListDesktopShortcut( |
| 994 const std::string& wm_class, | 993 const std::string& wm_class, |
| 995 const std::string& title) { | 994 const std::string& title) { |
| 996 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 995 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 997 | 996 |
| 998 base::FilePath desktop_name(kAppListDesktopName); | 997 base::FilePath desktop_name(kAppListDesktopName); |
| 999 base::FilePath shortcut_filename = desktop_name.AddExtension("desktop"); | 998 base::FilePath shortcut_filename = desktop_name.AddExtension("desktop"); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 for (std::vector<base::FilePath>::const_iterator it = | 1072 for (std::vector<base::FilePath>::const_iterator it = |
| 1074 shortcut_filenames_app_menu.begin(); | 1073 shortcut_filenames_app_menu.begin(); |
| 1075 it != shortcut_filenames_app_menu.end(); ++it) { | 1074 it != shortcut_filenames_app_menu.end(); ++it) { |
| 1076 DeleteShortcutInApplicationsMenu(*it, | 1075 DeleteShortcutInApplicationsMenu(*it, |
| 1077 base::FilePath(kDirectoryFilename)); | 1076 base::FilePath(kDirectoryFilename)); |
| 1078 } | 1077 } |
| 1079 } | 1078 } |
| 1080 } | 1079 } |
| 1081 | 1080 |
| 1082 } // namespace shell_integration_linux | 1081 } // namespace shell_integration_linux |
| OLD | NEW |