| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 GURL GetAppURLAndSetArgs(const std::string& app_url_and_args, | 36 GURL GetAppURLAndSetArgs(const std::string& app_url_and_args, |
| 37 mojo::shell::Context* context) { | 37 mojo::shell::Context* context) { |
| 38 // SplitString() returns empty strings for extra delimeter characters (' '). | 38 // SplitString() returns empty strings for extra delimeter characters (' '). |
| 39 std::vector<std::string> argv; | 39 std::vector<std::string> argv; |
| 40 base::SplitString(app_url_and_args, ' ', &argv); | 40 base::SplitString(app_url_and_args, ' ', &argv); |
| 41 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()); |
| 42 | 42 |
| 43 if (argv.empty()) | 43 if (argv.empty()) |
| 44 return GURL::EmptyGURL(); | 44 return GURL::EmptyGURL(); |
| 45 GURL app_url(argv[0]); | 45 GURL app_url(argv[0]); |
| 46 if (!app_url.is_valid()) { |
| 47 LOG(ERROR) << "Error: invalid URL: " << argv[0]; |
| 48 return app_url; |
| 49 } |
| 46 if (argv.size() > 1) | 50 if (argv.size() > 1) |
| 47 context->application_manager()->SetArgsForURL(argv, app_url); | 51 context->application_manager()->SetArgsForURL(argv, app_url); |
| 48 return app_url; | 52 return app_url; |
| 49 } | 53 } |
| 50 | 54 |
| 51 void RunApps(mojo::shell::Context* context) { | 55 void RunApps(mojo::shell::Context* context) { |
| 52 const auto& command_line = *base::CommandLine::ForCurrentProcess(); | 56 const auto& command_line = *base::CommandLine::ForCurrentProcess(); |
| 53 for (const auto& arg : command_line.GetArgs()) { | 57 for (const auto& arg : command_line.GetArgs()) { |
| 54 std::string arg2; | 58 std::string arg2; |
| 55 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
| 56 arg2 = base::UTF16ToUTF8(arg); | 60 arg2 = base::UTF16ToUTF8(arg); |
| 57 #else | 61 #else |
| 58 arg2 = arg; | 62 arg2 = arg; |
| 59 #endif | 63 #endif |
| 64 GURL url = GetAppURLAndSetArgs(arg2, context); |
| 65 if (!url.is_valid()) |
| 66 return; |
| 60 context->Run(GetAppURLAndSetArgs(arg2, context)); | 67 context->Run(GetAppURLAndSetArgs(arg2, context)); |
| 61 } | 68 } |
| 62 } | 69 } |
| 63 | 70 |
| 64 void Usage() { | 71 void Usage() { |
| 65 std::cerr << "Launch Mojo applications.\n"; | 72 std::cerr << "Launch Mojo applications.\n"; |
| 66 std::cerr | 73 std::cerr |
| 67 << "Usage: mojo_shell" | 74 << "Usage: mojo_shell" |
| 68 << " [--" << switches::kArgsFor << "=<mojo-app>]" | 75 << " [--" << switches::kArgsFor << "=<mojo-app>]" |
| 69 << " [--" << switches::kContentHandlers << "=<handlers>]" | 76 << " [--" << switches::kContentHandlers << "=<handlers>]" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 if (IsArgsFor(argv[i], &args_for_value)) | 164 if (IsArgsFor(argv[i], &args_for_value)) |
| 158 GetAppURLAndSetArgs(args_for_value, &shell_context); | 165 GetAppURLAndSetArgs(args_for_value, &shell_context); |
| 159 } | 166 } |
| 160 | 167 |
| 161 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); | 168 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); |
| 162 message_loop.Run(); | 169 message_loop.Run(); |
| 163 } | 170 } |
| 164 } | 171 } |
| 165 return 0; | 172 return 0; |
| 166 } | 173 } |
| OLD | NEW |