Corrected mojo_shell --args-for switch handling. BUG=427938 R=davemoore@chromium.org Review URL: https://codereview.chromium.org/681363002
diff --git a/mojo/shell/desktop/mojo_main.cc b/mojo/shell/desktop/mojo_main.cc index 02be823..4807031 100644 --- a/mojo/shell/desktop/mojo_main.cc +++ b/mojo/shell/desktop/mojo_main.cc
@@ -105,6 +105,21 @@ return true; } +bool isArgsFor(const std::string& arg, std::string* value) { + const std::string kArgsForSwitches[] = { + "-" + std::string(switches::kArgsFor), + "--" + std::string(switches::kArgsFor), + }; + for (size_t i = 0; i < arraysize(kArgsForSwitches); i++) { + std::string argsfor_switch(kArgsForSwitches[i]); + if (arg.compare(0, argsfor_switch.size(), argsfor_switch) == 0) { + *value = arg.substr(argsfor_switch.size() + 1, std::string::npos); + return true; + } + } + return false; +} + } // namespace int main(int argc, char** argv) { @@ -157,9 +172,13 @@ return 0; } - for (const auto& kv : command_line.GetSwitches()) { - if (kv.first == switches::kArgsFor) - GetAppURLAndSetArgs(kv.second, &shell_context); + // The mojo_shell --args-for command-line switch is handled specially + // because it can appear more than once. The base::CommandLine class + // collapses multiple occurrences of the same switch. + for (int i = 1; i < argc; i++) { + std::string argsForValue; + if (isArgsFor(argv[i], &argsForValue)) + GetAppURLAndSetArgs(argsForValue, &shell_context); } message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context));