OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "shell/command_line_util.h" | 5 #include "shell/command_line_util.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
| 8 #include <string> |
| 9 #include <vector> |
8 | 10 |
9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/strings/string_split.h" | 13 #include "base/strings/string_tokenizer.h" |
12 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
13 #include "shell/context.h" | 15 #include "shell/context.h" |
14 #include "shell/switches.h" | 16 #include "shell/switches.h" |
15 | 17 |
16 namespace shell { | 18 namespace shell { |
17 | 19 |
18 namespace { | 20 namespace { |
19 GURL GetAppURLAndSetArgs(const std::string& app_url_and_args, | 21 GURL GetAppURLAndSetArgs(const std::string& app_url_and_args, |
20 Context* context) { | 22 Context* context) { |
21 std::vector<std::string> args; | 23 std::vector<std::string> args; |
(...skipping 17 matching lines...) Expand all Loading... |
39 return true; | 41 return true; |
40 } | 42 } |
41 } | 43 } |
42 return false; | 44 return false; |
43 } | 45 } |
44 | 46 |
45 GURL GetAppURLAndArgs(Context* context, | 47 GURL GetAppURLAndArgs(Context* context, |
46 const std::string& app_url_and_args, | 48 const std::string& app_url_and_args, |
47 std::vector<std::string>* args) { | 49 std::vector<std::string>* args) { |
48 // SplitString() returns empty strings for extra delimeter characters (' '). | 50 // SplitString() returns empty strings for extra delimeter characters (' '). |
49 base::SplitString(app_url_and_args, ' ', args); | 51 base::StringTokenizer tokenizer = |
| 52 base::StringTokenizer(app_url_and_args, " "); |
| 53 tokenizer.set_quote_chars("'\""); |
| 54 while (tokenizer.GetNext()) { |
| 55 args->push_back(tokenizer.token()); |
| 56 } |
50 args->erase(std::remove_if(args->begin(), args->end(), | 57 args->erase(std::remove_if(args->begin(), args->end(), |
51 [](const std::string& a) { return a.empty(); }), | 58 [](const std::string& a) { return a.empty(); }), |
52 args->end()); | 59 args->end()); |
53 | 60 |
54 if (args->empty()) | 61 if (args->empty()) |
55 return GURL(); | 62 return GURL(); |
56 GURL app_url = context->ResolveCommandLineURL((*args)[0]); | 63 GURL app_url = context->ResolveCommandLineURL((*args)[0]); |
57 if (!app_url.is_valid()) { | 64 if (!app_url.is_valid()) { |
58 LOG(ERROR) << "Error: invalid URL: " << (*args)[0]; | 65 LOG(ERROR) << "Error: invalid URL: " << (*args)[0]; |
59 return app_url; | 66 return app_url; |
(...skipping 12 matching lines...) Expand all Loading... |
72 const auto& command_line = *base::CommandLine::ForCurrentProcess(); | 79 const auto& command_line = *base::CommandLine::ForCurrentProcess(); |
73 for (const auto& arg : command_line.GetArgs()) { | 80 for (const auto& arg : command_line.GetArgs()) { |
74 GURL url = GetAppURLAndSetArgs(arg, context); | 81 GURL url = GetAppURLAndSetArgs(arg, context); |
75 if (!url.is_valid()) | 82 if (!url.is_valid()) |
76 return; | 83 return; |
77 context->Run(url); | 84 context->Run(url); |
78 } | 85 } |
79 } | 86 } |
80 | 87 |
81 } // namespace shell | 88 } // namespace shell |
OLD | NEW |