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 | |
| 9 #if defined(USE_GLIB) | |
| 8 #include <glib.h> | 10 #include <glib.h> |
| 11 #endif | |
| 12 | |
| 9 #include <stdlib.h> | 13 #include <stdlib.h> |
| 10 #include <sys/stat.h> | 14 #include <sys/stat.h> |
| 11 #include <sys/types.h> | 15 #include <sys/types.h> |
| 12 #include <unistd.h> | 16 #include <unistd.h> |
| 13 | 17 |
| 14 #include <string> | 18 #include <string> |
| 15 #include <vector> | 19 #include <vector> |
| 16 | 20 |
| 17 #include "base/base_paths.h" | 21 #include "base/base_paths.h" |
| 18 #include "base/command_line.h" | 22 #include "base/command_line.h" |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 | 441 |
| 438 // Allow any reply that starts with "yes". | 442 // Allow any reply that starts with "yes". |
| 439 return (reply.find("yes") == 0) ? ShellIntegration::IS_DEFAULT : | 443 return (reply.find("yes") == 0) ? ShellIntegration::IS_DEFAULT : |
| 440 ShellIntegration::NOT_DEFAULT; | 444 ShellIntegration::NOT_DEFAULT; |
| 441 #endif | 445 #endif |
| 442 } | 446 } |
| 443 | 447 |
| 444 // Get the value of NoDisplay from the [Desktop Entry] section of a .desktop | 448 // Get the value of NoDisplay from the [Desktop Entry] section of a .desktop |
| 445 // file, given in |shortcut_contents|. If the key is not found, returns false. | 449 // file, given in |shortcut_contents|. If the key is not found, returns false. |
| 446 bool GetNoDisplayFromDesktopFile(const std::string& shortcut_contents) { | 450 bool GetNoDisplayFromDesktopFile(const std::string& shortcut_contents) { |
| 451 #if defined(USE_OZONE) | |
|
Elliot Glaysher
2014/05/08 19:28:34
Because you're checking USE_GLIB in the header at
| |
| 452 NOTIMPLEMENTED(); | |
| 453 return false; | |
| 454 #else | |
| 447 // An empty file causes a crash with glib <= 2.32, so special case here. | 455 // An empty file causes a crash with glib <= 2.32, so special case here. |
| 448 if (shortcut_contents.empty()) | 456 if (shortcut_contents.empty()) |
| 449 return false; | 457 return false; |
| 450 | 458 |
| 451 GKeyFile* key_file = g_key_file_new(); | 459 GKeyFile* key_file = g_key_file_new(); |
| 452 GError* err = NULL; | 460 GError* err = NULL; |
| 453 if (!g_key_file_load_from_data(key_file, shortcut_contents.c_str(), | 461 if (!g_key_file_load_from_data(key_file, shortcut_contents.c_str(), |
| 454 shortcut_contents.size(), G_KEY_FILE_NONE, | 462 shortcut_contents.size(), G_KEY_FILE_NONE, |
| 455 &err)) { | 463 &err)) { |
| 456 LOG(WARNING) << "Unable to read desktop file template: " << err->message; | 464 LOG(WARNING) << "Unable to read desktop file template: " << err->message; |
| 457 g_error_free(err); | 465 g_error_free(err); |
| 458 g_key_file_free(key_file); | 466 g_key_file_free(key_file); |
| 459 return false; | 467 return false; |
| 460 } | 468 } |
| 461 | 469 |
| 462 bool nodisplay = false; | 470 bool nodisplay = false; |
| 463 char* nodisplay_c_string = g_key_file_get_string(key_file, kDesktopEntry, | 471 char* nodisplay_c_string = g_key_file_get_string(key_file, kDesktopEntry, |
| 464 "NoDisplay", &err); | 472 "NoDisplay", &err); |
| 465 if (nodisplay_c_string) { | 473 if (nodisplay_c_string) { |
| 466 if (!g_strcmp0(nodisplay_c_string, "true")) | 474 if (!g_strcmp0(nodisplay_c_string, "true")) |
| 467 nodisplay = true; | 475 nodisplay = true; |
| 468 g_free(nodisplay_c_string); | 476 g_free(nodisplay_c_string); |
| 469 } else { | 477 } else { |
| 470 g_error_free(err); | 478 g_error_free(err); |
| 471 } | 479 } |
| 472 | 480 |
| 473 g_key_file_free(key_file); | 481 g_key_file_free(key_file); |
| 474 return nodisplay; | 482 return nodisplay; |
| 483 #endif | |
| 475 } | 484 } |
| 476 | 485 |
| 477 // Gets the path to the Chrome executable or wrapper script. | 486 // Gets the path to the Chrome executable or wrapper script. |
| 478 // Returns an empty path if the executable path could not be found. | 487 // Returns an empty path if the executable path could not be found. |
| 479 base::FilePath GetChromeExePath() { | 488 base::FilePath GetChromeExePath() { |
| 480 // Try to get the name of the wrapper script that launched Chrome. | 489 // Try to get the name of the wrapper script that launched Chrome. |
| 481 scoped_ptr<base::Environment> environment(base::Environment::Create()); | 490 scoped_ptr<base::Environment> environment(base::Environment::Create()); |
| 482 std::string wrapper_script; | 491 std::string wrapper_script; |
| 483 if (environment->GetVar("CHROME_WRAPPER", &wrapper_script)) { | 492 if (environment->GetVar("CHROME_WRAPPER", &wrapper_script)) { |
| 484 return base::FilePath(wrapper_script); | 493 return base::FilePath(wrapper_script); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 } | 780 } |
| 772 | 781 |
| 773 std::string GetDesktopFileContentsForCommand( | 782 std::string GetDesktopFileContentsForCommand( |
| 774 const CommandLine& command_line, | 783 const CommandLine& command_line, |
| 775 const std::string& app_name, | 784 const std::string& app_name, |
| 776 const GURL& url, | 785 const GURL& url, |
| 777 const base::string16& title, | 786 const base::string16& title, |
| 778 const std::string& icon_name, | 787 const std::string& icon_name, |
| 779 const std::string& categories, | 788 const std::string& categories, |
| 780 bool no_display) { | 789 bool no_display) { |
| 790 #if defined(USE_OZONE) | |
| 791 NOTIMPLEMENTED(); | |
| 792 return std::string(""); | |
| 793 #else | |
| 781 // Although not required by the spec, Nautilus on Ubuntu Karmic creates its | 794 // Although not required by the spec, Nautilus on Ubuntu Karmic creates its |
| 782 // launchers with an xdg-open shebang. Follow that convention. | 795 // launchers with an xdg-open shebang. Follow that convention. |
| 783 std::string output_buffer = std::string(kXdgOpenShebang) + "\n"; | 796 std::string output_buffer = std::string(kXdgOpenShebang) + "\n"; |
| 784 | 797 |
| 785 // See http://standards.freedesktop.org/desktop-entry-spec/latest/ | 798 // See http://standards.freedesktop.org/desktop-entry-spec/latest/ |
| 786 GKeyFile* key_file = g_key_file_new(); | 799 GKeyFile* key_file = g_key_file_new(); |
| 787 | 800 |
| 788 // Set keys with fixed values. | 801 // Set keys with fixed values. |
| 789 g_key_file_set_string(key_file, kDesktopEntry, "Version", "1.0"); | 802 g_key_file_set_string(key_file, kDesktopEntry, "Version", "1.0"); |
| 790 g_key_file_set_string(key_file, kDesktopEntry, "Terminal", "false"); | 803 g_key_file_set_string(key_file, kDesktopEntry, "Terminal", "false"); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 837 // remove it to avoid double-newline after the shebang. | 850 // remove it to avoid double-newline after the shebang. |
| 838 output_buffer += (data_dump + 1); | 851 output_buffer += (data_dump + 1); |
| 839 } else { | 852 } else { |
| 840 output_buffer += data_dump; | 853 output_buffer += data_dump; |
| 841 } | 854 } |
| 842 g_free(data_dump); | 855 g_free(data_dump); |
| 843 } | 856 } |
| 844 | 857 |
| 845 g_key_file_free(key_file); | 858 g_key_file_free(key_file); |
| 846 return output_buffer; | 859 return output_buffer; |
| 860 #endif | |
| 847 } | 861 } |
| 848 | 862 |
| 849 std::string GetDirectoryFileContents(const base::string16& title, | 863 std::string GetDirectoryFileContents(const base::string16& title, |
| 850 const std::string& icon_name) { | 864 const std::string& icon_name) { |
| 865 #if defined(USE_OZONE) | |
| 866 NOTIMPLEMENTED(); | |
| 867 return std::string(""); | |
| 868 #else | |
| 851 // See http://standards.freedesktop.org/desktop-entry-spec/latest/ | 869 // See http://standards.freedesktop.org/desktop-entry-spec/latest/ |
| 852 GKeyFile* key_file = g_key_file_new(); | 870 GKeyFile* key_file = g_key_file_new(); |
| 853 | 871 |
| 854 g_key_file_set_string(key_file, kDesktopEntry, "Version", "1.0"); | 872 g_key_file_set_string(key_file, kDesktopEntry, "Version", "1.0"); |
| 855 g_key_file_set_string(key_file, kDesktopEntry, "Type", "Directory"); | 873 g_key_file_set_string(key_file, kDesktopEntry, "Type", "Directory"); |
| 856 std::string final_title = base::UTF16ToUTF8(title); | 874 std::string final_title = base::UTF16ToUTF8(title); |
| 857 g_key_file_set_string(key_file, kDesktopEntry, "Name", final_title.c_str()); | 875 g_key_file_set_string(key_file, kDesktopEntry, "Name", final_title.c_str()); |
| 858 if (!icon_name.empty()) { | 876 if (!icon_name.empty()) { |
| 859 g_key_file_set_string(key_file, kDesktopEntry, "Icon", icon_name.c_str()); | 877 g_key_file_set_string(key_file, kDesktopEntry, "Icon", icon_name.c_str()); |
| 860 } else { | 878 } else { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 872 // remove it to avoid double-newline after the shebang. | 890 // remove it to avoid double-newline after the shebang. |
| 873 output_buffer += (data_dump + 1); | 891 output_buffer += (data_dump + 1); |
| 874 } else { | 892 } else { |
| 875 output_buffer += data_dump; | 893 output_buffer += data_dump; |
| 876 } | 894 } |
| 877 g_free(data_dump); | 895 g_free(data_dump); |
| 878 } | 896 } |
| 879 | 897 |
| 880 g_key_file_free(key_file); | 898 g_key_file_free(key_file); |
| 881 return output_buffer; | 899 return output_buffer; |
| 900 #endif | |
| 882 } | 901 } |
| 883 | 902 |
| 884 bool CreateDesktopShortcut( | 903 bool CreateDesktopShortcut( |
| 885 const web_app::ShortcutInfo& shortcut_info, | 904 const web_app::ShortcutInfo& shortcut_info, |
| 886 const web_app::ShortcutLocations& creation_locations) { | 905 const web_app::ShortcutLocations& creation_locations) { |
| 887 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 888 | 907 |
| 889 base::FilePath shortcut_filename; | 908 base::FilePath shortcut_filename; |
| 890 if (!shortcut_info.extension_id.empty()) { | 909 if (!shortcut_info.extension_id.empty()) { |
| 891 shortcut_filename = GetExtensionShortcutFilename( | 910 shortcut_filename = GetExtensionShortcutFilename( |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1056 for (std::vector<base::FilePath>::const_iterator it = | 1075 for (std::vector<base::FilePath>::const_iterator it = |
| 1057 shortcut_filenames_app_menu.begin(); | 1076 shortcut_filenames_app_menu.begin(); |
| 1058 it != shortcut_filenames_app_menu.end(); ++it) { | 1077 it != shortcut_filenames_app_menu.end(); ++it) { |
| 1059 DeleteShortcutInApplicationsMenu(*it, | 1078 DeleteShortcutInApplicationsMenu(*it, |
| 1060 base::FilePath(kDirectoryFilename)); | 1079 base::FilePath(kDirectoryFilename)); |
| 1061 } | 1080 } |
| 1062 } | 1081 } |
| 1063 } | 1082 } |
| 1064 | 1083 |
| 1065 } // namespace ShellIntegrationLinux | 1084 } // namespace ShellIntegrationLinux |
| OLD | NEW |