| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <iostream> | 6 #include <iostream> |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "mojo/shell/child_process.h" | 15 #include "mojo/shell/child_process.h" |
| 16 #include "mojo/shell/context.h" | 16 #include "mojo/shell/context.h" |
| 17 #include "mojo/shell/init.h" | 17 #include "mojo/shell/init.h" |
| 18 #include "mojo/shell/mojo_url_resolver.h" | 18 #include "mojo/shell/mojo_url_resolver.h" |
| 19 #include "mojo/shell/switches.h" | 19 #include "mojo/shell/switches.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 #if defined(OS_LINUX) | 23 #if defined(OS_LINUX) |
| 24 // Copied from ui/gfx/switches.cc to avoid a dependency on //ui/gfx | 24 // Copied from ui/gfx/switches.cc to avoid a dependency on //ui/gfx |
| 25 const char kEnableHarfBuzzRenderText[] = "enable-harfbuzz-rendertext"; | 25 const char kEnableHarfBuzzRenderText[] = "enable-harfbuzz-rendertext"; |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 #if defined(OS_WIN) | |
| 29 void SplitString(const base::string16& str, std::vector<std::string>* argv) { | |
| 30 base::SplitString(base::UTF16ToUTF8(str), ' ', argv); | |
| 31 } | |
| 32 #elif defined(OS_POSIX) | |
| 33 void SplitString(const std::string& str, std::vector<std::string>* argv) { | |
| 34 base::SplitString(str, ' ', argv); | |
| 35 } | |
| 36 #endif | |
| 37 | |
| 38 bool IsEmpty(const std::string& s) { | 28 bool IsEmpty(const std::string& s) { |
| 39 return s.empty(); | 29 return s.empty(); |
| 40 } | 30 } |
| 41 | 31 |
| 42 // The value of app_url_and_args is "<mojo_app_url> [<args>...]", where args | 32 // The value of app_url_and_args is "<mojo_app_url> [<args>...]", where args |
| 43 // is a list of "configuration" arguments separated by spaces. If one or more | 33 // is a list of "configuration" arguments separated by spaces. If one or more |
| 44 // arguments are specified they will be available when the Mojo application | 34 // arguments are specified they will be available when the Mojo application |
| 45 // is initialized. See ApplicationImpl::args(). | 35 // is initialized. See ApplicationImpl::args(). |
| 46 GURL GetAppURLAndSetArgs(const base::CommandLine::StringType& app_url_and_args, | 36 GURL GetAppURLAndSetArgs(const std::string& app_url_and_args, |
| 47 mojo::shell::Context* context) { | 37 mojo::shell::Context* context) { |
| 48 // SplitString() returns empty strings for extra delimeter characters (' '). | 38 // SplitString() returns empty strings for extra delimeter characters (' '). |
| 49 std::vector<std::string> argv; | 39 std::vector<std::string> argv; |
| 50 SplitString(app_url_and_args, &argv); | 40 base::SplitString(app_url_and_args, ' ', &argv); |
| 51 argv.erase(std::remove_if(argv.begin(), argv.end(), IsEmpty), argv.end()); | 41 argv.erase(std::remove_if(argv.begin(), argv.end(), IsEmpty), argv.end()); |
| 52 | 42 |
| 53 if (argv.empty()) | 43 if (argv.empty()) |
| 54 return GURL::EmptyGURL(); | 44 return GURL::EmptyGURL(); |
| 55 GURL app_url(argv[0]); | 45 GURL app_url(argv[0]); |
| 56 if (argv.size() > 1) | 46 if (argv.size() > 1) |
| 57 context->application_manager()->SetArgsForURL(argv, app_url); | 47 context->application_manager()->SetArgsForURL(argv, app_url); |
| 58 return app_url; | 48 return app_url; |
| 59 } | 49 } |
| 60 | 50 |
| 61 void RunApps(mojo::shell::Context* context) { | 51 void RunApps(mojo::shell::Context* context) { |
| 62 const auto& command_line = *base::CommandLine::ForCurrentProcess(); | 52 const auto& command_line = *base::CommandLine::ForCurrentProcess(); |
| 63 for (const auto& arg : command_line.GetArgs()) | 53 for (const auto& arg : command_line.GetArgs()) { |
| 64 context->Run(GetAppURLAndSetArgs(arg, context)); | 54 std::string arg2; |
| 55 #if defined(OS_WIN) |
| 56 arg2 = base::UTF16ToUTF8(arg); |
| 57 #else |
| 58 arg2 = arg; |
| 59 #endif |
| 60 context->Run(GetAppURLAndSetArgs(arg2, context)); |
| 61 } |
| 65 } | 62 } |
| 66 | 63 |
| 67 void Usage() { | 64 void Usage() { |
| 68 std::cerr << "Launch Mojo applications.\n"; | 65 std::cerr << "Launch Mojo applications.\n"; |
| 69 std::cerr | 66 std::cerr |
| 70 << "Usage: mojo_shell" | 67 << "Usage: mojo_shell" |
| 71 << " [--" << switches::kArgsFor << "=<mojo-app>]" | 68 << " [--" << switches::kArgsFor << "=<mojo-app>]" |
| 72 << " [--" << switches::kContentHandlers << "=<handlers>]" | 69 << " [--" << switches::kContentHandlers << "=<handlers>]" |
| 73 << " [--" << switches::kEnableExternalApplications << "]" | 70 << " [--" << switches::kEnableExternalApplications << "]" |
| 74 << " [--" << switches::kDisableCache << "]" | 71 << " [--" << switches::kDisableCache << "]" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 if (IsArgsFor(argv[i], &args_for_value)) | 171 if (IsArgsFor(argv[i], &args_for_value)) |
| 175 GetAppURLAndSetArgs(args_for_value, &shell_context); | 172 GetAppURLAndSetArgs(args_for_value, &shell_context); |
| 176 } | 173 } |
| 177 | 174 |
| 178 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); | 175 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); |
| 179 message_loop.Run(); | 176 message_loop.Run(); |
| 180 } | 177 } |
| 181 } | 178 } |
| 182 return 0; | 179 return 0; |
| 183 } | 180 } |
| OLD | NEW |