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

Unified Diff: shell/desktop/mojo_main.cc

Issue 816473002: Update mojo shell so that --args-for can be used on android (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 6 years 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 | « shell/command_line_util_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: shell/desktop/mojo_main.cc
diff --git a/shell/desktop/mojo_main.cc b/shell/desktop/mojo_main.cc
index 6d3e1ea73686c6ad2b071e2950609adbdac699d8..1712dcb9aef27afdd372a9863c311a6c389e9946 100644
--- a/shell/desktop/mojo_main.cc
+++ b/shell/desktop/mojo_main.cc
@@ -8,14 +8,11 @@
#include "base/at_exit.h"
#include "base/bind.h"
#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 "shell/child_process.h"
+#include "shell/command_line_util.h"
#include "shell/context.h"
#include "shell/init.h"
-#include "shell/mojo_url_resolver.h"
#include "shell/switches.h"
namespace {
@@ -25,49 +22,6 @@ namespace {
const char kEnableHarfBuzzRenderText[] = "enable-harfbuzz-rendertext";
#endif
-bool IsEmpty(const std::string& s) {
- return s.empty();
-}
-
-// 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 std::string& app_url_and_args,
- mojo::shell::Context* context) {
- // SplitString() returns empty strings for extra delimeter characters (' ').
- std::vector<std::string> argv;
- base::SplitString(app_url_and_args, ' ', &argv);
- argv.erase(std::remove_if(argv.begin(), argv.end(), IsEmpty), argv.end());
-
- if (argv.empty())
- return GURL::EmptyGURL();
- GURL app_url(argv[0]);
- if (!app_url.is_valid()) {
- LOG(ERROR) << "Error: invalid URL: " << argv[0];
- return app_url;
- }
- if (argv.size() > 1)
- context->application_manager()->SetArgsForURL(argv, app_url);
- return app_url;
-}
-
-void RunApps(mojo::shell::Context* context) {
- const auto& command_line = *base::CommandLine::ForCurrentProcess();
- for (const auto& arg : command_line.GetArgs()) {
- std::string arg2;
-#if defined(OS_WIN)
- arg2 = base::UTF16ToUTF8(arg);
-#else
- arg2 = arg;
-#endif
- GURL url = GetAppURLAndSetArgs(arg2, context);
- if (!url.is_valid())
- return;
- context->Run(GetAppURLAndSetArgs(arg2, context));
- }
-}
-
void Usage() {
std::cerr << "Launch Mojo applications.\n";
std::cerr
@@ -89,21 +43,6 @@ void Usage() {
<< "application/javascript,mojo:js_content_handler\n";
}
-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) {
@@ -160,12 +99,12 @@ int main(int argc, char** argv) {
// 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 args_for_value;
- if (IsArgsFor(argv[i], &args_for_value))
- GetAppURLAndSetArgs(args_for_value, &shell_context);
+ ApplyApplicationArgs(&shell_context, argv[i]);
}
- message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context));
+ message_loop.PostTask(
+ FROM_HERE,
+ base::Bind(&mojo::shell::RunCommandLineApps, &shell_context));
message_loop.Run();
}
}
« no previous file with comments | « shell/command_line_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698