diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-01 03:19:10 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-01 03:19:10 +0000 |
commit | fcc23e84efb0aa42e00f79d5fa1798b5604d7a28 (patch) | |
tree | 374fad3d8a1b0ea31fd0e5c74372c0e76c54f78d /chrome/browser/shell_integration_linux.cc | |
parent | b876c7db6bc09c93c9396c2995a5885f61dcdf9e (diff) | |
download | chromium_src-fcc23e84efb0aa42e00f79d5fa1798b5604d7a28.zip chromium_src-fcc23e84efb0aa42e00f79d5fa1798b5604d7a28.tar.gz chromium_src-fcc23e84efb0aa42e00f79d5fa1798b5604d7a28.tar.bz2 |
GTK: improve app mode .desktop file creation.
1) pass --user-data-dir when appropriate
2) don't overwrite old .desktop files that share the same name.
BUG=23353
Review URL: http://codereview.chromium.org/255016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27700 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/shell_integration_linux.cc')
-rw-r--r-- | chrome/browser/shell_integration_linux.cc | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc index 30eab5b..11f976e 100644 --- a/chrome/browser/shell_integration_linux.cc +++ b/chrome/browser/shell_integration_linux.cc @@ -29,6 +29,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" +#include "chrome/common/chrome_plugin_util.h" #include "chrome/common/chrome_switches.h" #include "googleurl/src/gurl.h" @@ -121,6 +122,8 @@ class CreateDesktopShortcutTask : public Task { FilePath shortcut_filename = ShellIntegration::GetDesktopShortcutFilename(shortcut_info_.url); + if (shortcut_filename.empty()) + return; std::string icon_name = CreateIcon(shortcut_filename); @@ -293,13 +296,28 @@ bool ShellIntegration::IsFirefoxDefaultBrowser() { FilePath ShellIntegration::GetDesktopShortcutFilename(const GURL& url) { // Use a prefix, because xdg-desktop-menu requires it. - std::wstring filename = std::wstring(chrome::kBrowserProcessExecutableName) + - L"-" + UTF8ToWide(url.spec()) + L".desktop"; - file_util::ReplaceIllegalCharacters(&filename, '_'); + std::wstring filename_wide = + std::wstring(chrome::kBrowserProcessExecutableName) + L"-" + + UTF8ToWide(url.spec()); + file_util::ReplaceIllegalCharacters(&filename_wide, '_'); + + FilePath desktop_path; + if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_path)) + return FilePath(); + + FilePath filepath = desktop_path.Append( + FilePath::FromWStringHack(filename_wide)); + FilePath alternative_filepath(filepath.value() + ".desktop"); + for (size_t i = 1; i < 100; ++i) { + if (file_util::PathExists(FilePath(alternative_filepath))) { + alternative_filepath = FilePath(filepath.value() + "_" + IntToString(i) + + ".desktop"); + } else { + return FilePath(alternative_filepath).BaseName(); + } + } - // Return BaseName to be absolutely sure we're not vulnerable to a directory - // traversal attack. - return FilePath::FromWStringHack(filename).BaseName(); + return FilePath(); } std::string ShellIntegration::GetDesktopFileContents( @@ -319,15 +337,9 @@ std::string ShellIntegration::GetDesktopFileContents( if (exec_tokenizer.token() != "%U") final_path += exec_tokenizer.token() + " "; } - std::wstring app_switch_wide(switches::kApp); - std::string app_switch(StringPrintf("\"--%s=%s\"", - WideToUTF8(app_switch_wide).c_str(), - url.spec().c_str())); - // Sanitize the command line string. - ReplaceSubstringsAfterOffset(&app_switch, 0, "%", "%%"); - ReplaceSubstringsAfterOffset(&app_switch, 0, ";", ""); - ReplaceSubstringsAfterOffset(&app_switch, 0, "$", ""); - output_buffer += std::string("Exec=") + final_path + app_switch + "\n"; + std::string switches; + CPB_GetCommandLineArgumentsCommon(url.spec().c_str(), &switches); + output_buffer += std::string("Exec=") + final_path + switches + "\n"; } else if (tokenizer.token().substr(0, 5) == "Name=") { std::string final_title = UTF16ToUTF8(title); // Make sure no endline characters can slip in and possibly introduce |