summaryrefslogtreecommitdiffstats
path: root/chrome/browser/shell_integration.cc
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 21:28:14 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 21:28:14 +0000
commitb10392939246b06c48eb5debc961839591ebe72a (patch)
treeb120033784ffddc693db30f71025b7eb0c5e26ac /chrome/browser/shell_integration.cc
parent8cfb591192035c18087296d931880149b2bf63a6 (diff)
downloadchromium_src-b10392939246b06c48eb5debc961839591ebe72a.zip
chromium_src-b10392939246b06c48eb5debc961839591ebe72a.tar.gz
chromium_src-b10392939246b06c48eb5debc961839591ebe72a.tar.bz2
Refactor GetCommandLineArgumentsCommon to not use strings.
Passing around command lines as strings is dangerous, because a given command line is interpretable only with respect to a given parser. This changes a function to instead pass a CommandLine object for carrying the arguments around, and relies on the callers to stringify that as necessary. It turns out that the Linux desktop file format has a well-defined syntax that is different than the syntax we were using. BUG=69467 Review URL: http://codereview.chromium.org/6624072 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77338 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/shell_integration.cc')
-rw-r--r--chrome/browser/shell_integration.cc41
1 files changed, 13 insertions, 28 deletions
diff --git a/chrome/browser/shell_integration.cc b/chrome/browser/shell_integration.cc
index cb5fde3..0b66d07 100644
--- a/chrome/browser/shell_integration.cc
+++ b/chrome/browser/shell_integration.cc
@@ -23,56 +23,41 @@ ShellIntegration::ShortcutInfo::ShortcutInfo()
ShellIntegration::ShortcutInfo::~ShortcutInfo() {}
-std::string ShellIntegration::GetCommandLineArgumentsCommon(
+// static
+CommandLine ShellIntegration::CommandLineArgsForLauncher(
const GURL& url,
const std::string& extension_app_id) {
- const CommandLine cmd = *CommandLine::ForCurrentProcess();
- std::wstring arguments_w;
+ const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
+ CommandLine new_cmd_line(CommandLine::NO_PROGRAM);
// Use the same UserDataDir for new launches that we currently have set.
- FilePath user_data_dir = cmd.GetSwitchValuePath(switches::kUserDataDir);
- if (!user_data_dir.value().empty()) {
+ FilePath user_data_dir = cmd_line.GetSwitchValuePath(switches::kUserDataDir);
+ if (!user_data_dir.empty()) {
// Make sure user_data_dir is an absolute path.
if (file_util::AbsolutePath(&user_data_dir) &&
file_util::PathExists(user_data_dir)) {
- // TODO: This is wrong in pathological quoting scenarios; we shouldn't be
- // passing around command lines as strings at all.
- arguments_w += std::wstring(L"--") + ASCIIToWide(switches::kUserDataDir) +
- L"=\"" + user_data_dir.ToWStringHack() + L"\" ";
+ new_cmd_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir);
}
}
#if defined(OS_CHROMEOS)
- FilePath profile = cmd.GetSwitchValuePath(switches::kLoginProfile);
- if (!profile.empty()) {
- arguments_w += std::wstring(L"--") + ASCIIToWide(switches::kLoginProfile) +
- L"=\"" + profile.ToWStringHack() + L"\" ";
- }
+ FilePath profile = cmd_line.GetSwitchValuePath(switches::kLoginProfile);
+ if (!profile.empty())
+ new_cmd_line.AppendSwitchPath(switches::kLoginProfile, profile);
#endif
// If |extension_app_id| is present, we use the kAppId switch rather than
// the kApp switch (the launch url will be read from the extension app
// during launch.
if (!extension_app_id.empty()) {
- arguments_w += std::wstring(L"--") + ASCIIToWide(switches::kAppId) +
- L"=\"" + ASCIIToWide(extension_app_id) + L"\"";
+ new_cmd_line.AppendSwitchASCII(switches::kAppId, extension_app_id);
} else {
// Use '--app=url' instead of just 'url' to launch the browser with minimal
// chrome.
// Note: Do not change this flag! Old Gears shortcuts will break if you do!
- std::string url_string = url.spec();
- ReplaceSubstringsAfterOffset(&url_string, 0, "\\", "%5C");
- ReplaceSubstringsAfterOffset(&url_string, 0, "\"", "%22");
- ReplaceSubstringsAfterOffset(&url_string, 0, ";", "%3B");
- ReplaceSubstringsAfterOffset(&url_string, 0, "$", "%24");
-#if defined(OS_WIN) // Windows shortcuts can't escape % so we use \x instead.
- ReplaceSubstringsAfterOffset(&url_string, 0, "%", "\\x");
-#endif
- std::wstring url_w = UTF8ToWide(url_string);
- arguments_w += std::wstring(L"--") + ASCIIToWide(switches::kApp) +
- L"=\"" + url_w + L"\"";
+ new_cmd_line.AppendSwitchASCII(switches::kApp, url.spec());
}
- return WideToUTF8(arguments_w);
+ return new_cmd_line;
}
///////////////////////////////////////////////////////////////////////////////