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 "shell/child_process.h" |
16 #include "mojo/shell/context.h" | 16 #include "shell/context.h" |
17 #include "mojo/shell/init.h" | 17 #include "shell/init.h" |
18 #include "mojo/shell/mojo_url_resolver.h" | 18 #include "shell/mojo_url_resolver.h" |
19 #include "mojo/shell/switches.h" | 19 #include "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 bool IsEmpty(const std::string& s) { | 28 bool IsEmpty(const std::string& s) { |
29 return s.empty(); | 29 return s.empty(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 << "quotes.\n" | 84 << "quotes.\n" |
85 << "Example: mojo_shell \"mojo:js_standalone test.js\".\n" | 85 << "Example: mojo_shell \"mojo:js_standalone test.js\".\n" |
86 << "<url-lib-path> is searched for shared libraries named by mojo URLs.\n" | 86 << "<url-lib-path> is searched for shared libraries named by mojo URLs.\n" |
87 << "The value of <handlers> is a comma separated list like:\n" | 87 << "The value of <handlers> is a comma separated list like:\n" |
88 << "text/html,mojo:html_viewer," | 88 << "text/html,mojo:html_viewer," |
89 << "application/javascript,mojo:js_content_handler\n"; | 89 << "application/javascript,mojo:js_content_handler\n"; |
90 } | 90 } |
91 | 91 |
92 bool IsArgsFor(const std::string& arg, std::string* value) { | 92 bool IsArgsFor(const std::string& arg, std::string* value) { |
93 const std::string kArgsForSwitches[] = { | 93 const std::string kArgsForSwitches[] = { |
94 "-" + std::string(switches::kArgsFor), | 94 "-" + std::string(switches::kArgsFor), |
95 "--" + std::string(switches::kArgsFor), | 95 "--" + std::string(switches::kArgsFor), |
96 }; | 96 }; |
97 for (size_t i = 0; i < arraysize(kArgsForSwitches); i++) { | 97 for (size_t i = 0; i < arraysize(kArgsForSwitches); i++) { |
98 std::string argsfor_switch(kArgsForSwitches[i]); | 98 std::string argsfor_switch(kArgsForSwitches[i]); |
99 if (arg.compare(0, argsfor_switch.size(), argsfor_switch) == 0) { | 99 if (arg.compare(0, argsfor_switch.size(), argsfor_switch) == 0) { |
100 *value = arg.substr(argsfor_switch.size() + 1, std::string::npos); | 100 *value = arg.substr(argsfor_switch.size() + 1, std::string::npos); |
101 return true; | 101 return true; |
102 } | 102 } |
103 } | 103 } |
104 return false; | 104 return false; |
105 } | 105 } |
106 | 106 |
107 } // namespace | 107 } // namespace |
108 | 108 |
109 int main(int argc, char** argv) { | 109 int main(int argc, char** argv) { |
110 base::AtExitManager at_exit; | 110 base::AtExitManager at_exit; |
111 base::CommandLine::Init(argc, argv); | 111 base::CommandLine::Init(argc, argv); |
112 | 112 |
113 const base::CommandLine& command_line = | 113 const base::CommandLine& command_line = |
114 *base::CommandLine::ForCurrentProcess(); | 114 *base::CommandLine::ForCurrentProcess(); |
115 | 115 |
116 const std::set<std::string> all_switches = switches::GetAllSwitches(); | 116 const std::set<std::string> all_switches = switches::GetAllSwitches(); |
117 const base::CommandLine::SwitchMap switches = command_line.GetSwitches(); | 117 const base::CommandLine::SwitchMap switches = command_line.GetSwitches(); |
118 bool found_unknown_switch = false; | 118 bool found_unknown_switch = false; |
119 for (const auto& s : switches) { | 119 for (const auto& s : switches) { |
120 if (all_switches.find(s.first) == all_switches.end()) { | 120 if (all_switches.find(s.first) == all_switches.end()) { |
121 std::cerr << "unknown switch: " << s.first << std::endl; | 121 std::cerr << "unknown switch: " << s.first << std::endl; |
122 found_unknown_switch = true; | 122 found_unknown_switch = true; |
123 } | 123 } |
124 } | 124 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 if (IsArgsFor(argv[i], &args_for_value)) | 164 if (IsArgsFor(argv[i], &args_for_value)) |
165 GetAppURLAndSetArgs(args_for_value, &shell_context); | 165 GetAppURLAndSetArgs(args_for_value, &shell_context); |
166 } | 166 } |
167 | 167 |
168 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); | 168 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); |
169 message_loop.Run(); | 169 message_loop.Run(); |
170 } | 170 } |
171 } | 171 } |
172 return 0; | 172 return 0; |
173 } | 173 } |
OLD | NEW |