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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } | 284 } |
285 quoted += '"'; | 285 quoted += '"'; |
286 | 286 |
287 return quoted; | 287 return quoted; |
288 } | 288 } |
289 | 289 |
290 // Quote a command line so it is suitable for use as the Exec key in a desktop | 290 // Quote a command line so it is suitable for use as the Exec key in a desktop |
291 // file. Note: This should be used instead of GetCommandLineString, which does | 291 // file. Note: This should be used instead of GetCommandLineString, which does |
292 // not properly quote the string; this function is designed for the Exec key. | 292 // not properly quote the string; this function is designed for the Exec key. |
293 std::string QuoteCommandLineForDesktopFileExec( | 293 std::string QuoteCommandLineForDesktopFileExec( |
294 const CommandLine& command_line) { | 294 const base::CommandLine& command_line) { |
295 // http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html | 295 // http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html |
296 | 296 |
297 std::string quoted_path = ""; | 297 std::string quoted_path = ""; |
298 const CommandLine::StringVector& argv = command_line.argv(); | 298 const base::CommandLine::StringVector& argv = command_line.argv(); |
299 for (CommandLine::StringVector::const_iterator i = argv.begin(); | 299 for (base::CommandLine::StringVector::const_iterator i = argv.begin(); |
300 i != argv.end(); ++i) { | 300 i != argv.end(); ++i) { |
301 if (i != argv.begin()) | 301 if (i != argv.begin()) |
302 quoted_path += " "; | 302 quoted_path += " "; |
303 quoted_path += QuoteArgForDesktopFileExec(*i); | 303 quoted_path += QuoteArgForDesktopFileExec(*i); |
304 } | 304 } |
305 | 305 |
306 return quoted_path; | 306 return quoted_path; |
307 } | 307 } |
308 | 308 |
309 const char kDesktopEntry[] = "Desktop Entry"; | 309 const char kDesktopEntry[] = "Desktop Entry"; |
(...skipping 26 matching lines...) Expand all Loading... |
336 return false; | 336 return false; |
337 | 337 |
338 base::FilePath chrome_version_path = chrome_dir.Append(script); | 338 base::FilePath chrome_version_path = chrome_dir.Append(script); |
339 *chrome_version = chrome_version_path.value(); | 339 *chrome_version = chrome_version_path.value(); |
340 | 340 |
341 // Check if this is different to the one on path. | 341 // Check if this is different to the one on path. |
342 std::vector<std::string> argv; | 342 std::vector<std::string> argv; |
343 argv.push_back("which"); | 343 argv.push_back("which"); |
344 argv.push_back(script); | 344 argv.push_back(script); |
345 std::string path_version; | 345 std::string path_version; |
346 if (base::GetAppOutput(CommandLine(argv), &path_version)) { | 346 if (base::GetAppOutput(base::CommandLine(argv), &path_version)) { |
347 // Remove trailing newline | 347 // Remove trailing newline |
348 path_version.erase(path_version.length() - 1, 1); | 348 path_version.erase(path_version.length() - 1, 1); |
349 base::FilePath path_version_path(path_version); | 349 base::FilePath path_version_path(path_version); |
350 return (chrome_version_path != path_version_path); | 350 return (chrome_version_path != path_version_path); |
351 } | 351 } |
352 return false; | 352 return false; |
353 } | 353 } |
354 | 354 |
355 // Value returned by xdg-settings if it can't understand our request. | 355 // Value returned by xdg-settings if it can't understand our request. |
356 const int EXIT_XDG_SETTINGS_SYNTAX_ERROR = 1; | 356 const int EXIT_XDG_SETTINGS_SYNTAX_ERROR = 1; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 if (protocol.empty()) { | 414 if (protocol.empty()) { |
415 argv.push_back(kXdgSettingsDefaultBrowser); | 415 argv.push_back(kXdgSettingsDefaultBrowser); |
416 } else { | 416 } else { |
417 argv.push_back(kXdgSettingsDefaultSchemeHandler); | 417 argv.push_back(kXdgSettingsDefaultSchemeHandler); |
418 argv.push_back(protocol); | 418 argv.push_back(protocol); |
419 } | 419 } |
420 argv.push_back(shell_integration_linux::GetDesktopName(env.get())); | 420 argv.push_back(shell_integration_linux::GetDesktopName(env.get())); |
421 | 421 |
422 std::string reply; | 422 std::string reply; |
423 int success_code; | 423 int success_code; |
424 bool ran_ok = base::GetAppOutputWithExitCode(CommandLine(argv), &reply, | 424 bool ran_ok = base::GetAppOutputWithExitCode(base::CommandLine(argv), &reply, |
425 &success_code); | 425 &success_code); |
426 if (ran_ok && success_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) { | 426 if (ran_ok && success_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) { |
427 if (GetChromeVersionOfScript(kXdgSettings, &argv[0])) { | 427 if (GetChromeVersionOfScript(kXdgSettings, &argv[0])) { |
428 ran_ok = base::GetAppOutputWithExitCode(CommandLine(argv), &reply, | 428 ran_ok = base::GetAppOutputWithExitCode(base::CommandLine(argv), &reply, |
429 &success_code); | 429 &success_code); |
430 } | 430 } |
431 } | 431 } |
432 | 432 |
433 if (!ran_ok || success_code != EXIT_SUCCESS) { | 433 if (!ran_ok || success_code != EXIT_SUCCESS) { |
434 // xdg-settings failed: we can't determine or set the default browser. | 434 // xdg-settings failed: we can't determine or set the default browser. |
435 return ShellIntegration::UNKNOWN_DEFAULT; | 435 return ShellIntegration::UNKNOWN_DEFAULT; |
436 } | 436 } |
437 | 437 |
438 // Allow any reply that starts with "yes". | 438 // Allow any reply that starts with "yes". |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 534 |
535 // static | 535 // static |
536 bool ShellIntegration::IsFirefoxDefaultBrowser() { | 536 bool ShellIntegration::IsFirefoxDefaultBrowser() { |
537 std::vector<std::string> argv; | 537 std::vector<std::string> argv; |
538 argv.push_back(kXdgSettings); | 538 argv.push_back(kXdgSettings); |
539 argv.push_back("get"); | 539 argv.push_back("get"); |
540 argv.push_back(kXdgSettingsDefaultBrowser); | 540 argv.push_back(kXdgSettingsDefaultBrowser); |
541 | 541 |
542 std::string browser; | 542 std::string browser; |
543 // We don't care about the return value here. | 543 // We don't care about the return value here. |
544 base::GetAppOutput(CommandLine(argv), &browser); | 544 base::GetAppOutput(base::CommandLine(argv), &browser); |
545 return browser.find("irefox") != std::string::npos; | 545 return browser.find("irefox") != std::string::npos; |
546 } | 546 } |
547 | 547 |
548 namespace shell_integration_linux { | 548 namespace shell_integration_linux { |
549 | 549 |
550 bool GetDataWriteLocation(base::Environment* env, base::FilePath* search_path) { | 550 bool GetDataWriteLocation(base::Environment* env, base::FilePath* search_path) { |
551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
552 | 552 |
553 std::string xdg_data_home; | 553 std::string xdg_data_home; |
554 std::string home; | 554 std::string home; |
(...skipping 25 matching lines...) Expand all Loading... |
580 } | 580 } |
581 } else { | 581 } else { |
582 search_paths.push_back(base::FilePath("/usr/local/share")); | 582 search_paths.push_back(base::FilePath("/usr/local/share")); |
583 search_paths.push_back(base::FilePath("/usr/share")); | 583 search_paths.push_back(base::FilePath("/usr/share")); |
584 } | 584 } |
585 | 585 |
586 return search_paths; | 586 return search_paths; |
587 } | 587 } |
588 | 588 |
589 std::string GetProgramClassName() { | 589 std::string GetProgramClassName() { |
590 DCHECK(CommandLine::InitializedForCurrentProcess()); | 590 DCHECK(base::CommandLine::InitializedForCurrentProcess()); |
591 // Get the res_name component from argv[0]. | 591 // Get the res_name component from argv[0]. |
592 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 592 const base::CommandLine* command_line = |
| 593 base::CommandLine::ForCurrentProcess(); |
593 std::string class_name = command_line->GetProgram().BaseName().value(); | 594 std::string class_name = command_line->GetProgram().BaseName().value(); |
594 if (!class_name.empty()) | 595 if (!class_name.empty()) |
595 class_name[0] = base::ToUpperASCII(class_name[0]); | 596 class_name[0] = base::ToUpperASCII(class_name[0]); |
596 return class_name; | 597 return class_name; |
597 } | 598 } |
598 | 599 |
599 std::string GetDesktopName(base::Environment* env) { | 600 std::string GetDesktopName(base::Environment* env) { |
600 #if defined(GOOGLE_CHROME_BUILD) | 601 #if defined(GOOGLE_CHROME_BUILD) |
601 chrome::VersionInfo::Channel product_channel( | 602 chrome::VersionInfo::Channel product_channel( |
602 chrome::VersionInfo::GetChannel()); | 603 chrome::VersionInfo::GetChannel()); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 std::string GetDesktopFileContents( | 762 std::string GetDesktopFileContents( |
762 const base::FilePath& chrome_exe_path, | 763 const base::FilePath& chrome_exe_path, |
763 const std::string& app_name, | 764 const std::string& app_name, |
764 const GURL& url, | 765 const GURL& url, |
765 const std::string& extension_id, | 766 const std::string& extension_id, |
766 const base::string16& title, | 767 const base::string16& title, |
767 const std::string& icon_name, | 768 const std::string& icon_name, |
768 const base::FilePath& profile_path, | 769 const base::FilePath& profile_path, |
769 const std::string& categories, | 770 const std::string& categories, |
770 bool no_display) { | 771 bool no_display) { |
771 CommandLine cmd_line = ShellIntegration::CommandLineArgsForLauncher( | 772 base::CommandLine cmd_line = |
772 url, extension_id, profile_path); | 773 ShellIntegration::CommandLineArgsForLauncher(url, extension_id, |
| 774 profile_path); |
773 cmd_line.SetProgram(chrome_exe_path); | 775 cmd_line.SetProgram(chrome_exe_path); |
774 return GetDesktopFileContentsForCommand(cmd_line, app_name, url, title, | 776 return GetDesktopFileContentsForCommand(cmd_line, app_name, url, title, |
775 icon_name, categories, no_display); | 777 icon_name, categories, no_display); |
776 } | 778 } |
777 | 779 |
778 std::string GetDesktopFileContentsForCommand( | 780 std::string GetDesktopFileContentsForCommand( |
779 const CommandLine& command_line, | 781 const base::CommandLine& command_line, |
780 const std::string& app_name, | 782 const std::string& app_name, |
781 const GURL& url, | 783 const GURL& url, |
782 const base::string16& title, | 784 const base::string16& title, |
783 const std::string& icon_name, | 785 const std::string& icon_name, |
784 const std::string& categories, | 786 const std::string& categories, |
785 bool no_display) { | 787 bool no_display) { |
786 #if defined(USE_GLIB) | 788 #if defined(USE_GLIB) |
787 // Although not required by the spec, Nautilus on Ubuntu Karmic creates its | 789 // Although not required by the spec, Nautilus on Ubuntu Karmic creates its |
788 // launchers with an xdg-open shebang. Follow that convention. | 790 // launchers with an xdg-open shebang. Follow that convention. |
789 std::string output_buffer = std::string(kXdgOpenShebang) + "\n"; | 791 std::string output_buffer = std::string(kXdgOpenShebang) + "\n"; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 } | 1010 } |
1009 | 1011 |
1010 gfx::ImageFamily icon_images; | 1012 gfx::ImageFamily icon_images; |
1011 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); | 1013 ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); |
1012 icon_images.Add(*resource_bundle.GetImageSkiaNamed(IDR_APP_LIST_16)); | 1014 icon_images.Add(*resource_bundle.GetImageSkiaNamed(IDR_APP_LIST_16)); |
1013 icon_images.Add(*resource_bundle.GetImageSkiaNamed(IDR_APP_LIST_32)); | 1015 icon_images.Add(*resource_bundle.GetImageSkiaNamed(IDR_APP_LIST_32)); |
1014 icon_images.Add(*resource_bundle.GetImageSkiaNamed(IDR_APP_LIST_48)); | 1016 icon_images.Add(*resource_bundle.GetImageSkiaNamed(IDR_APP_LIST_48)); |
1015 icon_images.Add(*resource_bundle.GetImageSkiaNamed(IDR_APP_LIST_256)); | 1017 icon_images.Add(*resource_bundle.GetImageSkiaNamed(IDR_APP_LIST_256)); |
1016 std::string icon_name = CreateShortcutIcon(icon_images, desktop_name); | 1018 std::string icon_name = CreateShortcutIcon(icon_images, desktop_name); |
1017 | 1019 |
1018 CommandLine command_line(chrome_exe_path); | 1020 base::CommandLine command_line(chrome_exe_path); |
1019 command_line.AppendSwitch(switches::kShowAppList); | 1021 command_line.AppendSwitch(switches::kShowAppList); |
1020 std::string contents = | 1022 std::string contents = |
1021 GetDesktopFileContentsForCommand(command_line, | 1023 GetDesktopFileContentsForCommand(command_line, |
1022 wm_class, | 1024 wm_class, |
1023 GURL(), | 1025 GURL(), |
1024 base::UTF8ToUTF16(title), | 1026 base::UTF8ToUTF16(title), |
1025 icon_name, | 1027 icon_name, |
1026 kAppListCategories, | 1028 kAppListCategories, |
1027 false); | 1029 false); |
1028 return CreateShortcutInApplicationsMenu( | 1030 return CreateShortcutInApplicationsMenu( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 for (std::vector<base::FilePath>::const_iterator it = | 1074 for (std::vector<base::FilePath>::const_iterator it = |
1073 shortcut_filenames_app_menu.begin(); | 1075 shortcut_filenames_app_menu.begin(); |
1074 it != shortcut_filenames_app_menu.end(); ++it) { | 1076 it != shortcut_filenames_app_menu.end(); ++it) { |
1075 DeleteShortcutInApplicationsMenu(*it, | 1077 DeleteShortcutInApplicationsMenu(*it, |
1076 base::FilePath(kDirectoryFilename)); | 1078 base::FilePath(kDirectoryFilename)); |
1077 } | 1079 } |
1078 } | 1080 } |
1079 } | 1081 } |
1080 | 1082 |
1081 } // namespace shell_integration_linux | 1083 } // namespace shell_integration_linux |
OLD | NEW |