Chromium Code Reviews| 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 <glib.h> | 8 #include <glib.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "base/posix/eintr_wrapper.h" | 29 #include "base/posix/eintr_wrapper.h" |
| 30 #include "base/process/kill.h" | 30 #include "base/process/kill.h" |
| 31 #include "base/process/launch.h" | 31 #include "base/process/launch.h" |
| 32 #include "base/strings/string_number_conversions.h" | 32 #include "base/strings/string_number_conversions.h" |
| 33 #include "base/strings/string_tokenizer.h" | 33 #include "base/strings/string_tokenizer.h" |
| 34 #include "base/strings/string_util.h" | 34 #include "base/strings/string_util.h" |
| 35 #include "base/strings/utf_string_conversions.h" | 35 #include "base/strings/utf_string_conversions.h" |
| 36 #include "base/threading/thread.h" | 36 #include "base/threading/thread.h" |
| 37 #include "base/threading/thread_restrictions.h" | 37 #include "base/threading/thread_restrictions.h" |
| 38 #include "build/build_config.h" | 38 #include "build/build_config.h" |
| 39 #include "chrome/browser/web_applications/web_app.h" | |
|
calamity
2014/04/14 04:23:01
#include "chrome/browser/shell_integration.h" for
jackhou1
2014/04/14 05:49:19
Done.
| |
| 40 #include "chrome/common/chrome_constants.h" | 39 #include "chrome/common/chrome_constants.h" |
| 41 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
| 42 #include "chrome/common/chrome_version_info.h" | 41 #include "chrome/common/chrome_version_info.h" |
| 43 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 44 #include "grit/chrome_unscaled_resources.h" | 43 #include "grit/chrome_unscaled_resources.h" |
| 45 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
| 46 #include "ui/gfx/image/image_family.h" | 45 #include "ui/gfx/image/image_family.h" |
| 47 #include "url/gurl.h" | 46 #include "url/gurl.h" |
| 48 | 47 |
| 49 using content::BrowserThread; | 48 using content::BrowserThread; |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 } | 608 } |
| 610 | 609 |
| 611 std::string GetIconName() { | 610 std::string GetIconName() { |
| 612 #if defined(GOOGLE_CHROME_BUILD) | 611 #if defined(GOOGLE_CHROME_BUILD) |
| 613 return "google-chrome"; | 612 return "google-chrome"; |
| 614 #else // CHROMIUM_BUILD | 613 #else // CHROMIUM_BUILD |
| 615 return "chromium-browser"; | 614 return "chromium-browser"; |
| 616 #endif | 615 #endif |
| 617 } | 616 } |
| 618 | 617 |
| 619 ShellIntegration::ShortcutLocations GetExistingShortcutLocations( | 618 web_app::ShortcutLocations GetExistingShortcutLocations( |
| 620 base::Environment* env, | 619 base::Environment* env, |
| 621 const base::FilePath& profile_path, | 620 const base::FilePath& profile_path, |
| 622 const std::string& extension_id) { | 621 const std::string& extension_id) { |
| 623 base::FilePath desktop_path; | 622 base::FilePath desktop_path; |
| 624 // If Get returns false, just leave desktop_path empty. | 623 // If Get returns false, just leave desktop_path empty. |
| 625 PathService::Get(base::DIR_USER_DESKTOP, &desktop_path); | 624 PathService::Get(base::DIR_USER_DESKTOP, &desktop_path); |
| 626 return GetExistingShortcutLocations(env, profile_path, extension_id, | 625 return GetExistingShortcutLocations(env, profile_path, extension_id, |
| 627 desktop_path); | 626 desktop_path); |
| 628 } | 627 } |
| 629 | 628 |
| 630 ShellIntegration::ShortcutLocations GetExistingShortcutLocations( | 629 web_app::ShortcutLocations GetExistingShortcutLocations( |
| 631 base::Environment* env, | 630 base::Environment* env, |
| 632 const base::FilePath& profile_path, | 631 const base::FilePath& profile_path, |
| 633 const std::string& extension_id, | 632 const std::string& extension_id, |
| 634 const base::FilePath& desktop_path) { | 633 const base::FilePath& desktop_path) { |
| 635 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 636 | 635 |
| 637 base::FilePath shortcut_filename = GetExtensionShortcutFilename( | 636 base::FilePath shortcut_filename = GetExtensionShortcutFilename( |
| 638 profile_path, extension_id); | 637 profile_path, extension_id); |
| 639 DCHECK(!shortcut_filename.empty()); | 638 DCHECK(!shortcut_filename.empty()); |
| 640 ShellIntegration::ShortcutLocations locations; | 639 web_app::ShortcutLocations locations; |
| 641 | 640 |
| 642 // Determine whether there is a shortcut on desktop. | 641 // Determine whether there is a shortcut on desktop. |
| 643 if (!desktop_path.empty()) { | 642 if (!desktop_path.empty()) { |
| 644 locations.on_desktop = | 643 locations.on_desktop = |
| 645 base::PathExists(desktop_path.Append(shortcut_filename)); | 644 base::PathExists(desktop_path.Append(shortcut_filename)); |
| 646 } | 645 } |
| 647 | 646 |
| 648 // Determine whether there is a shortcut in the applications directory. | 647 // Determine whether there is a shortcut in the applications directory. |
| 649 std::string shortcut_contents; | 648 std::string shortcut_contents; |
| 650 if (GetExistingShortcutContents(env, shortcut_filename, &shortcut_contents)) { | 649 if (GetExistingShortcutContents(env, shortcut_filename, &shortcut_contents)) { |
| 651 // Whether this counts as "hidden" or "APP_MENU_LOCATION_SUBDIR_CHROMEAPPS" | 650 // Whether this counts as "hidden" or "APP_MENU_LOCATION_SUBDIR_CHROMEAPPS" |
| 652 // depends on whether it contains NoDisplay=true. Since these shortcuts are | 651 // depends on whether it contains NoDisplay=true. Since these shortcuts are |
| 653 // for apps, they are always in the "Chrome Apps" directory. | 652 // for apps, they are always in the "Chrome Apps" directory. |
| 654 if (GetNoDisplayFromDesktopFile(shortcut_contents)) { | 653 if (GetNoDisplayFromDesktopFile(shortcut_contents)) { |
| 655 locations.hidden = true; | 654 locations.hidden = true; |
| 656 } else { | 655 } else { |
| 657 locations.applications_menu_location = | 656 locations.applications_menu_location = |
| 658 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; | 657 web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS; |
| 659 } | 658 } |
| 660 } | 659 } |
| 661 | 660 |
| 662 return locations; | 661 return locations; |
| 663 } | 662 } |
| 664 | 663 |
| 665 bool GetExistingShortcutContents(base::Environment* env, | 664 bool GetExistingShortcutContents(base::Environment* env, |
| 666 const base::FilePath& desktop_filename, | 665 const base::FilePath& desktop_filename, |
| 667 std::string* output) { | 666 std::string* output) { |
| 668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 output_buffer += data_dump; | 862 output_buffer += data_dump; |
| 864 } | 863 } |
| 865 g_free(data_dump); | 864 g_free(data_dump); |
| 866 } | 865 } |
| 867 | 866 |
| 868 g_key_file_free(key_file); | 867 g_key_file_free(key_file); |
| 869 return output_buffer; | 868 return output_buffer; |
| 870 } | 869 } |
| 871 | 870 |
| 872 bool CreateDesktopShortcut( | 871 bool CreateDesktopShortcut( |
| 873 const ShellIntegration::ShortcutInfo& shortcut_info, | 872 const web_app::ShortcutInfo& shortcut_info, |
| 874 const ShellIntegration::ShortcutLocations& creation_locations) { | 873 const web_app::ShortcutLocations& creation_locations) { |
| 875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 874 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 876 | 875 |
| 877 base::FilePath shortcut_filename; | 876 base::FilePath shortcut_filename; |
| 878 if (!shortcut_info.extension_id.empty()) { | 877 if (!shortcut_info.extension_id.empty()) { |
| 879 shortcut_filename = GetExtensionShortcutFilename( | 878 shortcut_filename = GetExtensionShortcutFilename( |
| 880 shortcut_info.profile_path, shortcut_info.extension_id); | 879 shortcut_info.profile_path, shortcut_info.extension_id); |
| 881 // For extensions we do not want duplicate shortcuts. So, delete any that | 880 // For extensions we do not want duplicate shortcuts. So, delete any that |
| 882 // already exist and replace them. | 881 // already exist and replace them. |
| 883 if (creation_locations.on_desktop) | 882 if (creation_locations.on_desktop) |
| 884 DeleteShortcutOnDesktop(shortcut_filename); | 883 DeleteShortcutOnDesktop(shortcut_filename); |
| 885 // The 'applications_menu_location' and 'hidden' locations are actually the | 884 // The 'applications_menu_location' and 'hidden' locations are actually the |
| 886 // same place ('applications'). | 885 // same place ('applications'). |
| 887 if (creation_locations.applications_menu_location != | 886 if (creation_locations.applications_menu_location != |
| 888 ShellIntegration::APP_MENU_LOCATION_NONE || | 887 web_app::APP_MENU_LOCATION_NONE || |
| 889 creation_locations.hidden) | 888 creation_locations.hidden) |
| 890 DeleteShortcutInApplicationsMenu(shortcut_filename, base::FilePath()); | 889 DeleteShortcutInApplicationsMenu(shortcut_filename, base::FilePath()); |
| 891 } else { | 890 } else { |
| 892 shortcut_filename = GetWebShortcutFilename(shortcut_info.url); | 891 shortcut_filename = GetWebShortcutFilename(shortcut_info.url); |
| 893 } | 892 } |
| 894 if (shortcut_filename.empty()) | 893 if (shortcut_filename.empty()) |
| 895 return false; | 894 return false; |
| 896 | 895 |
| 897 std::string icon_name = | 896 std::string icon_name = |
| 898 CreateShortcutIcon(shortcut_info.favicon, shortcut_filename); | 897 CreateShortcutIcon(shortcut_info.favicon, shortcut_filename); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 915 shortcut_info.url, | 914 shortcut_info.url, |
| 916 shortcut_info.extension_id, | 915 shortcut_info.extension_id, |
| 917 shortcut_info.title, | 916 shortcut_info.title, |
| 918 icon_name, | 917 icon_name, |
| 919 shortcut_info.profile_path, | 918 shortcut_info.profile_path, |
| 920 false); | 919 false); |
| 921 success = CreateShortcutOnDesktop(shortcut_filename, contents); | 920 success = CreateShortcutOnDesktop(shortcut_filename, contents); |
| 922 } | 921 } |
| 923 | 922 |
| 924 if (creation_locations.applications_menu_location != | 923 if (creation_locations.applications_menu_location != |
| 925 ShellIntegration::APP_MENU_LOCATION_NONE || | 924 web_app::APP_MENU_LOCATION_NONE || |
| 926 creation_locations.hidden) { | 925 creation_locations.hidden) { |
| 927 base::FilePath directory_filename; | 926 base::FilePath directory_filename; |
| 928 std::string directory_contents; | 927 std::string directory_contents; |
| 929 switch (creation_locations.applications_menu_location) { | 928 switch (creation_locations.applications_menu_location) { |
| 930 case ShellIntegration::APP_MENU_LOCATION_NONE: | 929 case web_app::APP_MENU_LOCATION_NONE: |
| 931 case ShellIntegration::APP_MENU_LOCATION_ROOT: | 930 case web_app::APP_MENU_LOCATION_ROOT: |
| 932 break; | 931 break; |
| 933 case ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS: | 932 case web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS: |
| 934 directory_filename = base::FilePath(kDirectoryFilename); | 933 directory_filename = base::FilePath(kDirectoryFilename); |
| 935 directory_contents = ShellIntegrationLinux::GetDirectoryFileContents( | 934 directory_contents = ShellIntegrationLinux::GetDirectoryFileContents( |
| 936 ShellIntegration::GetAppShortcutsSubdirName(), ""); | 935 ShellIntegration::GetAppShortcutsSubdirName(), ""); |
| 937 break; | 936 break; |
| 938 default: | 937 default: |
| 939 NOTREACHED(); | 938 NOTREACHED(); |
| 940 break; | 939 break; |
| 941 } | 940 } |
| 942 // Set NoDisplay=true if hidden but not in the applications menu. This will | 941 // Set NoDisplay=true if hidden but not in the applications menu. This will |
| 943 // hide the application from user-facing menus. | 942 // hide the application from user-facing menus. |
| 944 std::string contents = ShellIntegrationLinux::GetDesktopFileContents( | 943 std::string contents = ShellIntegrationLinux::GetDesktopFileContents( |
| 945 chrome_exe_path, | 944 chrome_exe_path, |
| 946 app_name, | 945 app_name, |
| 947 shortcut_info.url, | 946 shortcut_info.url, |
| 948 shortcut_info.extension_id, | 947 shortcut_info.extension_id, |
| 949 shortcut_info.title, | 948 shortcut_info.title, |
| 950 icon_name, | 949 icon_name, |
| 951 shortcut_info.profile_path, | 950 shortcut_info.profile_path, |
| 952 creation_locations.applications_menu_location == | 951 creation_locations.applications_menu_location == |
| 953 ShellIntegration::APP_MENU_LOCATION_NONE); | 952 web_app::APP_MENU_LOCATION_NONE); |
| 954 success = CreateShortcutInApplicationsMenu( | 953 success = CreateShortcutInApplicationsMenu( |
| 955 shortcut_filename, contents, directory_filename, directory_contents) && | 954 shortcut_filename, contents, directory_filename, directory_contents) && |
| 956 success; | 955 success; |
| 957 } | 956 } |
| 958 | 957 |
| 959 return success; | 958 return success; |
| 960 } | 959 } |
| 961 | 960 |
| 962 bool CreateAppListDesktopShortcut( | 961 bool CreateAppListDesktopShortcut( |
| 963 const std::string& wm_class, | 962 const std::string& wm_class, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1037 for (std::vector<base::FilePath>::const_iterator it = | 1036 for (std::vector<base::FilePath>::const_iterator it = |
| 1038 shortcut_filenames_app_menu.begin(); | 1037 shortcut_filenames_app_menu.begin(); |
| 1039 it != shortcut_filenames_app_menu.end(); ++it) { | 1038 it != shortcut_filenames_app_menu.end(); ++it) { |
| 1040 DeleteShortcutInApplicationsMenu(*it, | 1039 DeleteShortcutInApplicationsMenu(*it, |
| 1041 base::FilePath(kDirectoryFilename)); | 1040 base::FilePath(kDirectoryFilename)); |
| 1042 } | 1041 } |
| 1043 } | 1042 } |
| 1044 } | 1043 } |
| 1045 | 1044 |
| 1046 } // namespace ShellIntegrationLinux | 1045 } // namespace ShellIntegrationLinux |
| OLD | NEW |