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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 const char kXdgSettingsDefaultSchemeHandler[] = "default-url-scheme-handler"; | 316 const char kXdgSettingsDefaultSchemeHandler[] = "default-url-scheme-handler"; |
317 | 317 |
318 const char kDirectoryFilename[] = "chrome-apps.directory"; | 318 const char kDirectoryFilename[] = "chrome-apps.directory"; |
319 | 319 |
320 #if defined(GOOGLE_CHROME_BUILD) | 320 #if defined(GOOGLE_CHROME_BUILD) |
321 const char kAppListDesktopName[] = "chrome-app-list"; | 321 const char kAppListDesktopName[] = "chrome-app-list"; |
322 #else // CHROMIUM_BUILD | 322 #else // CHROMIUM_BUILD |
323 const char kAppListDesktopName[] = "chromium-app-list"; | 323 const char kAppListDesktopName[] = "chromium-app-list"; |
324 #endif | 324 #endif |
325 | 325 |
326 } // namespace | |
327 | |
328 namespace { | |
329 | |
330 // Utility function to get the path to the version of a script shipped with | 326 // Utility function to get the path to the version of a script shipped with |
331 // Chrome. |script| gives the name of the script. |chrome_version| returns the | 327 // Chrome. |script| gives the name of the script. |chrome_version| returns the |
332 // path to the Chrome version of the script, and the return value of the | 328 // path to the Chrome version of the script, and the return value of the |
333 // function is true if the function is successful and the Chrome version is | 329 // function is true if the function is successful and the Chrome version is |
334 // not the script found on the PATH. | 330 // not the script found on the PATH. |
335 bool GetChromeVersionOfScript(const std::string& script, | 331 bool GetChromeVersionOfScript(const std::string& script, |
336 std::string* chrome_version) { | 332 std::string* chrome_version) { |
337 // Get the path to the Chrome version. | 333 // Get the path to the Chrome version. |
338 base::FilePath chrome_dir; | 334 base::FilePath chrome_dir; |
339 if (!PathService::Get(base::DIR_EXE, &chrome_dir)) | 335 if (!PathService::Get(base::DIR_EXE, &chrome_dir)) |
340 return false; | 336 return false; |
341 | 337 |
342 base::FilePath chrome_version_path = chrome_dir.Append(script); | 338 base::FilePath chrome_version_path = chrome_dir.Append(script); |
343 *chrome_version = chrome_version_path.value(); | 339 *chrome_version = chrome_version_path.value(); |
344 | 340 |
345 // Check if this is different to the one on path. | 341 // Check if this is different to the one on path. |
346 std::vector<std::string> argv; | 342 std::vector<std::string> argv; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 375 |
380 std::vector<std::string> argv; | 376 std::vector<std::string> argv; |
381 argv.push_back(kXdgSettings); | 377 argv.push_back(kXdgSettings); |
382 argv.push_back("set"); | 378 argv.push_back("set"); |
383 if (protocol.empty()) { | 379 if (protocol.empty()) { |
384 argv.push_back(kXdgSettingsDefaultBrowser); | 380 argv.push_back(kXdgSettingsDefaultBrowser); |
385 } else { | 381 } else { |
386 argv.push_back(kXdgSettingsDefaultSchemeHandler); | 382 argv.push_back(kXdgSettingsDefaultSchemeHandler); |
387 argv.push_back(protocol); | 383 argv.push_back(protocol); |
388 } | 384 } |
389 argv.push_back(ShellIntegrationLinux::GetDesktopName(env.get())); | 385 argv.push_back(shell_integration_linux::GetDesktopName(env.get())); |
390 | 386 |
391 int exit_code; | 387 int exit_code; |
392 bool ran_ok = LaunchXdgUtility(argv, &exit_code); | 388 bool ran_ok = LaunchXdgUtility(argv, &exit_code); |
393 if (ran_ok && exit_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) { | 389 if (ran_ok && exit_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) { |
394 if (GetChromeVersionOfScript(kXdgSettings, &argv[0])) { | 390 if (GetChromeVersionOfScript(kXdgSettings, &argv[0])) { |
395 ran_ok = LaunchXdgUtility(argv, &exit_code); | 391 ran_ok = LaunchXdgUtility(argv, &exit_code); |
396 } | 392 } |
397 } | 393 } |
398 | 394 |
399 return ran_ok && exit_code == EXIT_SUCCESS; | 395 return ran_ok && exit_code == EXIT_SUCCESS; |
(...skipping 14 matching lines...) Expand all Loading... |
414 | 410 |
415 std::vector<std::string> argv; | 411 std::vector<std::string> argv; |
416 argv.push_back(kXdgSettings); | 412 argv.push_back(kXdgSettings); |
417 argv.push_back("check"); | 413 argv.push_back("check"); |
418 if (protocol.empty()) { | 414 if (protocol.empty()) { |
419 argv.push_back(kXdgSettingsDefaultBrowser); | 415 argv.push_back(kXdgSettingsDefaultBrowser); |
420 } else { | 416 } else { |
421 argv.push_back(kXdgSettingsDefaultSchemeHandler); | 417 argv.push_back(kXdgSettingsDefaultSchemeHandler); |
422 argv.push_back(protocol); | 418 argv.push_back(protocol); |
423 } | 419 } |
424 argv.push_back(ShellIntegrationLinux::GetDesktopName(env.get())); | 420 argv.push_back(shell_integration_linux::GetDesktopName(env.get())); |
425 | 421 |
426 std::string reply; | 422 std::string reply; |
427 int success_code; | 423 int success_code; |
428 bool ran_ok = base::GetAppOutputWithExitCode(CommandLine(argv), &reply, | 424 bool ran_ok = base::GetAppOutputWithExitCode(CommandLine(argv), &reply, |
429 &success_code); | 425 &success_code); |
430 if (ran_ok && success_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) { | 426 if (ran_ok && success_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) { |
431 if (GetChromeVersionOfScript(kXdgSettings, &argv[0])) { | 427 if (GetChromeVersionOfScript(kXdgSettings, &argv[0])) { |
432 ran_ok = base::GetAppOutputWithExitCode(CommandLine(argv), &reply, | 428 ran_ok = base::GetAppOutputWithExitCode(CommandLine(argv), &reply, |
433 &success_code); | 429 &success_code); |
434 } | 430 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 if (environment->GetVar("CHROME_WRAPPER", &wrapper_script)) { | 488 if (environment->GetVar("CHROME_WRAPPER", &wrapper_script)) { |
493 return base::FilePath(wrapper_script); | 489 return base::FilePath(wrapper_script); |
494 } | 490 } |
495 | 491 |
496 // Just return the name of the executable path for Chrome. | 492 // Just return the name of the executable path for Chrome. |
497 base::FilePath chrome_exe_path; | 493 base::FilePath chrome_exe_path; |
498 PathService::Get(base::FILE_EXE, &chrome_exe_path); | 494 PathService::Get(base::FILE_EXE, &chrome_exe_path); |
499 return chrome_exe_path; | 495 return chrome_exe_path; |
500 } | 496 } |
501 | 497 |
502 } // namespace | 498 } // namespace |
503 | 499 |
504 // static | 500 // static |
505 ShellIntegration::DefaultWebClientSetPermission | 501 ShellIntegration::DefaultWebClientSetPermission |
506 ShellIntegration::CanSetAsDefaultBrowser() { | 502 ShellIntegration::CanSetAsDefaultBrowser() { |
507 return SET_DEFAULT_UNATTENDED; | 503 return SET_DEFAULT_UNATTENDED; |
508 } | 504 } |
509 | 505 |
510 // static | 506 // static |
511 bool ShellIntegration::SetAsDefaultBrowser() { | 507 bool ShellIntegration::SetAsDefaultBrowser() { |
512 return SetDefaultWebClient(std::string()); | 508 return SetDefaultWebClient(std::string()); |
513 } | 509 } |
514 | 510 |
515 // static | 511 // static |
516 bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) { | 512 bool ShellIntegration::SetAsDefaultProtocolClient( |
| 513 const std::string& protocol) { |
517 return SetDefaultWebClient(protocol); | 514 return SetDefaultWebClient(protocol); |
518 } | 515 } |
519 | 516 |
520 // static | 517 // static |
521 ShellIntegration::DefaultWebClientState ShellIntegration::GetDefaultBrowser() { | 518 ShellIntegration::DefaultWebClientState |
| 519 ShellIntegration::GetDefaultBrowser() { |
522 return GetIsDefaultWebClient(std::string()); | 520 return GetIsDefaultWebClient(std::string()); |
523 } | 521 } |
524 | 522 |
525 // static | 523 // static |
526 base::string16 ShellIntegration::GetApplicationNameForProtocol( | 524 base::string16 ShellIntegration::GetApplicationNameForProtocol( |
527 const GURL& url) { | 525 const GURL& url) { |
528 return base::ASCIIToUTF16("xdg-open"); | 526 return base::ASCIIToUTF16("xdg-open"); |
529 } | 527 } |
530 | 528 |
531 // static | 529 // static |
532 ShellIntegration::DefaultWebClientState | 530 ShellIntegration::DefaultWebClientState |
533 ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { | 531 ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { |
534 return GetIsDefaultWebClient(protocol); | 532 return GetIsDefaultWebClient(protocol); |
535 } | 533 } |
536 | 534 |
537 // static | 535 // static |
538 bool ShellIntegration::IsFirefoxDefaultBrowser() { | 536 bool ShellIntegration::IsFirefoxDefaultBrowser() { |
539 std::vector<std::string> argv; | 537 std::vector<std::string> argv; |
540 argv.push_back(kXdgSettings); | 538 argv.push_back(kXdgSettings); |
541 argv.push_back("get"); | 539 argv.push_back("get"); |
542 argv.push_back(kXdgSettingsDefaultBrowser); | 540 argv.push_back(kXdgSettingsDefaultBrowser); |
543 | 541 |
544 std::string browser; | 542 std::string browser; |
545 // We don't care about the return value here. | 543 // We don't care about the return value here. |
546 base::GetAppOutput(CommandLine(argv), &browser); | 544 base::GetAppOutput(CommandLine(argv), &browser); |
547 return browser.find("irefox") != std::string::npos; | 545 return browser.find("irefox") != std::string::npos; |
548 } | 546 } |
549 | 547 |
550 namespace ShellIntegrationLinux { | 548 namespace shell_integration_linux { |
551 | 549 |
552 bool GetDataWriteLocation(base::Environment* env, base::FilePath* search_path) { | 550 bool GetDataWriteLocation(base::Environment* env, base::FilePath* search_path) { |
553 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
554 | 552 |
555 std::string xdg_data_home; | 553 std::string xdg_data_home; |
556 std::string home; | 554 std::string home; |
557 if (env->GetVar("XDG_DATA_HOME", &xdg_data_home) && !xdg_data_home.empty()) { | 555 if (env->GetVar("XDG_DATA_HOME", &xdg_data_home) && !xdg_data_home.empty()) { |
558 *search_path = base::FilePath(xdg_data_home); | 556 *search_path = base::FilePath(xdg_data_home); |
559 return true; | 557 return true; |
560 } else if (env->GetVar("HOME", &home) && !home.empty()) { | 558 } else if (env->GetVar("HOME", &home) && !home.empty()) { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 } else { | 847 } else { |
850 output_buffer += data_dump; | 848 output_buffer += data_dump; |
851 } | 849 } |
852 g_free(data_dump); | 850 g_free(data_dump); |
853 } | 851 } |
854 | 852 |
855 g_key_file_free(key_file); | 853 g_key_file_free(key_file); |
856 return output_buffer; | 854 return output_buffer; |
857 #else | 855 #else |
858 NOTIMPLEMENTED(); | 856 NOTIMPLEMENTED(); |
859 return std::string(""); | 857 return std::string(); |
860 #endif | 858 #endif |
861 } | 859 } |
862 | 860 |
863 std::string GetDirectoryFileContents(const base::string16& title, | 861 std::string GetDirectoryFileContents(const base::string16& title, |
864 const std::string& icon_name) { | 862 const std::string& icon_name) { |
865 #if defined(USE_GLIB) | 863 #if defined(USE_GLIB) |
866 // See http://standards.freedesktop.org/desktop-entry-spec/latest/ | 864 // See http://standards.freedesktop.org/desktop-entry-spec/latest/ |
867 GKeyFile* key_file = g_key_file_new(); | 865 GKeyFile* key_file = g_key_file_new(); |
868 | 866 |
869 g_key_file_set_string(key_file, kDesktopEntry, "Version", "1.0"); | 867 g_key_file_set_string(key_file, kDesktopEntry, "Version", "1.0"); |
(...skipping 19 matching lines...) Expand all Loading... |
889 } else { | 887 } else { |
890 output_buffer += data_dump; | 888 output_buffer += data_dump; |
891 } | 889 } |
892 g_free(data_dump); | 890 g_free(data_dump); |
893 } | 891 } |
894 | 892 |
895 g_key_file_free(key_file); | 893 g_key_file_free(key_file); |
896 return output_buffer; | 894 return output_buffer; |
897 #else | 895 #else |
898 NOTIMPLEMENTED(); | 896 NOTIMPLEMENTED(); |
899 return std::string(""); | 897 return std::string(); |
900 #endif | 898 #endif |
901 } | 899 } |
902 | 900 |
903 bool CreateDesktopShortcut( | 901 bool CreateDesktopShortcut( |
904 const web_app::ShortcutInfo& shortcut_info, | 902 const web_app::ShortcutInfo& shortcut_info, |
905 const web_app::ShortcutLocations& creation_locations) { | 903 const web_app::ShortcutLocations& creation_locations) { |
906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 904 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
907 | 905 |
908 base::FilePath shortcut_filename; | 906 base::FilePath shortcut_filename; |
909 if (!shortcut_info.extension_id.empty()) { | 907 if (!shortcut_info.extension_id.empty()) { |
(...skipping 23 matching lines...) Expand all Loading... |
933 | 931 |
934 bool success = true; | 932 bool success = true; |
935 | 933 |
936 base::FilePath chrome_exe_path = GetChromeExePath(); | 934 base::FilePath chrome_exe_path = GetChromeExePath(); |
937 if (chrome_exe_path.empty()) { | 935 if (chrome_exe_path.empty()) { |
938 LOG(WARNING) << "Could not get executable path."; | 936 LOG(WARNING) << "Could not get executable path."; |
939 return false; | 937 return false; |
940 } | 938 } |
941 | 939 |
942 if (creation_locations.on_desktop) { | 940 if (creation_locations.on_desktop) { |
943 std::string contents = ShellIntegrationLinux::GetDesktopFileContents( | 941 std::string contents = GetDesktopFileContents( |
944 chrome_exe_path, | 942 chrome_exe_path, |
945 app_name, | 943 app_name, |
946 shortcut_info.url, | 944 shortcut_info.url, |
947 shortcut_info.extension_id, | 945 shortcut_info.extension_id, |
948 shortcut_info.title, | 946 shortcut_info.title, |
949 icon_name, | 947 icon_name, |
950 shortcut_info.profile_path, | 948 shortcut_info.profile_path, |
951 "", | 949 "", |
952 false); | 950 false); |
953 success = CreateShortcutOnDesktop(shortcut_filename, contents); | 951 success = CreateShortcutOnDesktop(shortcut_filename, contents); |
954 } | 952 } |
955 | 953 |
956 if (creation_locations.applications_menu_location != | 954 if (creation_locations.applications_menu_location != |
957 web_app::APP_MENU_LOCATION_NONE || | 955 web_app::APP_MENU_LOCATION_NONE || |
958 creation_locations.hidden) { | 956 creation_locations.hidden) { |
959 base::FilePath directory_filename; | 957 base::FilePath directory_filename; |
960 std::string directory_contents; | 958 std::string directory_contents; |
961 switch (creation_locations.applications_menu_location) { | 959 switch (creation_locations.applications_menu_location) { |
962 case web_app::APP_MENU_LOCATION_NONE: | 960 case web_app::APP_MENU_LOCATION_NONE: |
963 case web_app::APP_MENU_LOCATION_ROOT: | 961 case web_app::APP_MENU_LOCATION_ROOT: |
964 break; | 962 break; |
965 case web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS: | 963 case web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS: |
966 directory_filename = base::FilePath(kDirectoryFilename); | 964 directory_filename = base::FilePath(kDirectoryFilename); |
967 directory_contents = ShellIntegrationLinux::GetDirectoryFileContents( | 965 directory_contents = GetDirectoryFileContents( |
968 ShellIntegration::GetAppShortcutsSubdirName(), ""); | 966 ShellIntegration::GetAppShortcutsSubdirName(), ""); |
969 break; | 967 break; |
970 default: | 968 default: |
971 NOTREACHED(); | 969 NOTREACHED(); |
972 break; | 970 break; |
973 } | 971 } |
974 // Set NoDisplay=true if hidden but not in the applications menu. This will | 972 // Set NoDisplay=true if hidden but not in the applications menu. This will |
975 // hide the application from user-facing menus. | 973 // hide the application from user-facing menus. |
976 std::string contents = ShellIntegrationLinux::GetDesktopFileContents( | 974 std::string contents = GetDesktopFileContents( |
977 chrome_exe_path, | 975 chrome_exe_path, |
978 app_name, | 976 app_name, |
979 shortcut_info.url, | 977 shortcut_info.url, |
980 shortcut_info.extension_id, | 978 shortcut_info.extension_id, |
981 shortcut_info.title, | 979 shortcut_info.title, |
982 icon_name, | 980 icon_name, |
983 shortcut_info.profile_path, | 981 shortcut_info.profile_path, |
984 "", | 982 "", |
985 creation_locations.applications_menu_location == | 983 creation_locations.applications_menu_location == |
986 web_app::APP_MENU_LOCATION_NONE); | 984 web_app::APP_MENU_LOCATION_NONE); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 GetExistingProfileShortcutFilenames(profile_path, applications_menu); | 1072 GetExistingProfileShortcutFilenames(profile_path, applications_menu); |
1075 for (std::vector<base::FilePath>::const_iterator it = | 1073 for (std::vector<base::FilePath>::const_iterator it = |
1076 shortcut_filenames_app_menu.begin(); | 1074 shortcut_filenames_app_menu.begin(); |
1077 it != shortcut_filenames_app_menu.end(); ++it) { | 1075 it != shortcut_filenames_app_menu.end(); ++it) { |
1078 DeleteShortcutInApplicationsMenu(*it, | 1076 DeleteShortcutInApplicationsMenu(*it, |
1079 base::FilePath(kDirectoryFilename)); | 1077 base::FilePath(kDirectoryFilename)); |
1080 } | 1078 } |
1081 } | 1079 } |
1082 } | 1080 } |
1083 | 1081 |
1084 } // namespace ShellIntegrationLinux | 1082 } // namespace shell_integration_linux |
OLD | NEW |