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> |
| 6 |
5 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
6 #include "base/bind.h" | 8 #include "base/bind.h" |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
12 #include "mojo/shell/child_process.h" | 14 #include "mojo/shell/child_process.h" |
13 #include "mojo/shell/context.h" | 15 #include "mojo/shell/context.h" |
14 #include "mojo/shell/init.h" | 16 #include "mojo/shell/init.h" |
(...skipping 13 matching lines...) Expand all Loading... |
28 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
29 void SplitString(const base::string16& str, std::vector<std::string>* argv) { | 31 void SplitString(const base::string16& str, std::vector<std::string>* argv) { |
30 base::SplitString(base::UTF16ToUTF8(str), ' ', argv); | 32 base::SplitString(base::UTF16ToUTF8(str), ' ', argv); |
31 } | 33 } |
32 #elif defined(OS_POSIX) | 34 #elif defined(OS_POSIX) |
33 void SplitString(const std::string& str, std::vector<std::string>* argv) { | 35 void SplitString(const std::string& str, std::vector<std::string>* argv) { |
34 base::SplitString(str, ' ', argv); | 36 base::SplitString(str, ' ', argv); |
35 } | 37 } |
36 #endif | 38 #endif |
37 | 39 |
| 40 bool is_empty(const std::string& s) { |
| 41 return s.empty(); |
| 42 } |
| 43 |
38 // The value of app_url_and_args is "<mojo_app_url> [<args>...]", where args | 44 // The value of app_url_and_args is "<mojo_app_url> [<args>...]", where args |
39 // is a list of "configuration" arguments separated by spaces. If one or more | 45 // is a list of "configuration" arguments separated by spaces. If one or more |
40 // arguments are specified they will be available when the Mojo application | 46 // arguments are specified they will be available when the Mojo application |
41 // is initialized. See ApplicationImpl::args(). | 47 // is initialized. See ApplicationImpl::args(). |
42 GURL GetAppURLAndSetArgs(const base::CommandLine::StringType& app_url_and_args, | 48 GURL GetAppURLAndSetArgs(const base::CommandLine::StringType& app_url_and_args, |
43 mojo::shell::Context* context) { | 49 mojo::shell::Context* context) { |
| 50 // SplitString() returns empty strings for extra delimeter characters (' '). |
44 std::vector<std::string> argv; | 51 std::vector<std::string> argv; |
45 SplitString(app_url_and_args, &argv); | 52 SplitString(app_url_and_args, &argv); |
| 53 argv.erase(std::remove_if(argv.begin(), argv.end(), is_empty), argv.end()); |
| 54 |
46 if (argv.empty()) | 55 if (argv.empty()) |
47 return GURL::EmptyGURL(); | 56 return GURL::EmptyGURL(); |
48 GURL app_url(argv[0]); | 57 GURL app_url(argv[0]); |
49 if (argv.size() > 1) | 58 if (argv.size() > 1) |
50 context->application_manager()->SetArgsForURL(argv, app_url); | 59 context->application_manager()->SetArgsForURL(argv, app_url); |
51 return app_url; | 60 return app_url; |
52 } | 61 } |
53 | 62 |
54 void RunApps(mojo::shell::Context* context) { | 63 void RunApps(mojo::shell::Context* context) { |
55 const auto& command_line = *base::CommandLine::ForCurrentProcess(); | 64 const auto& command_line = *base::CommandLine::ForCurrentProcess(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 if (kv.first == switches::kArgsFor) | 107 if (kv.first == switches::kArgsFor) |
99 GetAppURLAndSetArgs(kv.second, &shell_context); | 108 GetAppURLAndSetArgs(kv.second, &shell_context); |
100 } | 109 } |
101 | 110 |
102 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); | 111 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); |
103 message_loop.Run(); | 112 message_loop.Run(); |
104 } | 113 } |
105 } | 114 } |
106 return 0; | 115 return 0; |
107 } | 116 } |
OLD | NEW |