Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1250)

Unified Diff: mojo/shell/desktop/mojo_main.cc

Issue 617943002: Enable setting configuration arguments for Mojo applications with mojo_shell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use base::string16 instead std::wstring Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/examples/wget/wget.cc ('k') | mojo/shell/switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/desktop/mojo_main.cc
diff --git a/mojo/shell/desktop/mojo_main.cc b/mojo/shell/desktop/mojo_main.cc
index 5710cbb3243daccd2bb74a4233ca87c2104cad59..0331d3e793daec370661af9b24a1a57698d36970 100644
--- a/mojo/shell/desktop/mojo_main.cc
+++ b/mojo/shell/desktop/mojo_main.cc
@@ -7,6 +7,8 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "base/strings/string_split.h"
+#include "base/strings/utf_string_conversions.h"
#include "mojo/shell/child_process.h"
#include "mojo/shell/context.h"
#include "mojo/shell/init.h"
@@ -23,15 +25,36 @@ namespace {
const char kEnableHarfBuzzRenderText[] = "enable-harfbuzz-rendertext";
#endif
+#if defined(OS_WIN)
+void SplitString(const base::string16& str, std::vector<std::string>* argv) {
+ base::SplitString(base::UTF16ToUTF8(str), ' ', argv);
+}
+#elif defined(OS_POSIX)
+void SplitString(const std::string& str, std::vector<std::string>* argv) {
+ base::SplitString(str, ' ', argv);
+}
+#endif
+
+// The value of app_url_and_args is "<mojo_app_url> [<args>...]", where args
+// is a list of "configuration" arguments separated by spaces. If one or more
+// arguments are specified they will be available when the Mojo application
+// is initialized. See ApplicationImpl::args().
+GURL GetAppURLAndSetArgs(const base::CommandLine::StringType& app_url_and_args,
+ mojo::shell::Context* context) {
+ std::vector<std::string> argv;
+ SplitString(app_url_and_args, &argv);
+ if (argv.empty())
+ return GURL::EmptyGURL();
+ GURL app_url(argv[0]);
+ if (argv.size() > 1)
+ context->application_manager()->SetArgsForURL(argv, app_url);
+ return app_url;
+}
+
void RunApps(mojo::shell::Context* context) {
- const base::CommandLine& command_line =
- *base::CommandLine::ForCurrentProcess();
- base::CommandLine::StringVector args = command_line.GetArgs();
- for (base::CommandLine::StringVector::const_iterator it = args.begin();
- it != args.end();
- ++it) {
- context->Run(GURL(*it));
- }
+ const auto& command_line = *base::CommandLine::ForCurrentProcess();
+ for (const auto& arg : command_line.GetArgs())
+ context->Run(GetAppURLAndSetArgs(arg, context));
}
} // namespace
@@ -71,6 +94,11 @@ int main(int argc, char** argv) {
GURL(command_line.GetSwitchValueASCII(switches::kOrigin)));
}
+ for (const auto& kv : command_line.GetSwitches()) {
+ if (kv.first == switches::kArgsFor)
+ GetAppURLAndSetArgs(kv.second, &shell_context);
+ }
+
message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context));
message_loop.Run();
}
« no previous file with comments | « mojo/examples/wget/wget.cc ('k') | mojo/shell/switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698