Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: shell/command_line_util.cc

Issue 873253003: Resolve URLs passed on the command line relative to the CWD. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « shell/command_line_util.h ('k') | shell/command_line_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "shell/context.h" 13 #include "shell/context.h"
14 #include "shell/switches.h" 14 #include "shell/switches.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 namespace shell { 17 namespace shell {
18 18
19 namespace { 19 namespace {
20 GURL GetAppURLAndSetArgs(const std::string& app_url_and_args, 20 GURL GetAppURLAndSetArgs(const std::string& app_url_and_args,
21 Context* context) { 21 Context* context) {
22 std::vector<std::string> args; 22 std::vector<std::string> args;
23 GURL app_url = GetAppURLAndArgs(app_url_and_args, &args); 23 GURL app_url = GetAppURLAndArgs(context, app_url_and_args, &args);
24 24
25 if (args.size() > 1) 25 if (args.size() > 1)
26 context->application_manager()->SetArgsForURL(args, app_url); 26 context->application_manager()->SetArgsForURL(args, app_url);
27 return app_url; 27 return app_url;
28 } 28 }
29 } // namespace 29 } // namespace
30 30
31 bool ParseArgsFor(const std::string& arg, std::string* value) { 31 bool ParseArgsFor(const std::string& arg, std::string* value) {
32 const std::string kArgsForSwitches[] = { 32 const std::string kArgsForSwitches[] = {
33 "-" + std::string(switches::kArgsFor) + "=", 33 "-" + std::string(switches::kArgsFor) + "=",
34 "--" + std::string(switches::kArgsFor) + "=", 34 "--" + std::string(switches::kArgsFor) + "=",
35 }; 35 };
36 for (size_t i = 0; i < arraysize(kArgsForSwitches); i++) { 36 for (size_t i = 0; i < arraysize(kArgsForSwitches); i++) {
37 const std::string& argsfor_switch = kArgsForSwitches[i]; 37 const std::string& argsfor_switch = kArgsForSwitches[i];
38 if (arg.compare(0, argsfor_switch.size(), argsfor_switch) == 0) { 38 if (arg.compare(0, argsfor_switch.size(), argsfor_switch) == 0) {
39 *value = arg.substr(argsfor_switch.size(), std::string::npos); 39 *value = arg.substr(argsfor_switch.size(), std::string::npos);
40 return true; 40 return true;
41 } 41 }
42 } 42 }
43 return false; 43 return false;
44 } 44 }
45 45
46 GURL GetAppURLAndArgs(const std::string& app_url_and_args, 46 GURL GetAppURLAndArgs(Context* context,
47 const std::string& app_url_and_args,
47 std::vector<std::string>* args) { 48 std::vector<std::string>* args) {
48 // SplitString() returns empty strings for extra delimeter characters (' '). 49 // SplitString() returns empty strings for extra delimeter characters (' ').
49 base::SplitString(app_url_and_args, ' ', args); 50 base::SplitString(app_url_and_args, ' ', args);
50 args->erase(std::remove_if(args->begin(), args->end(), 51 args->erase(std::remove_if(args->begin(), args->end(),
51 std::mem_fun_ref(&std::string::empty)), 52 std::mem_fun_ref(&std::string::empty)),
52 args->end()); 53 args->end());
53 54
54 if (args->empty()) 55 if (args->empty())
55 return GURL(); 56 return GURL();
56 GURL app_url((*args)[0]); 57 GURL app_url = context->ResolveCommandLineURL((*args)[0]);
57 if (!app_url.is_valid()) { 58 if (!app_url.is_valid()) {
58 LOG(ERROR) << "Error: invalid URL: " << (*args)[0]; 59 LOG(ERROR) << "Error: invalid URL: " << (*args)[0];
59 return app_url; 60 return app_url;
60 } 61 }
61 if (args->size() == 1) 62 if (args->size() == 1)
62 args->clear(); 63 args->clear();
63 return app_url; 64 return app_url;
64 } 65 }
65 66
66 void ApplyApplicationArgs(Context* context, const std::string& args) { 67 void ApplyApplicationArgs(Context* context, const std::string& args) {
(...skipping 13 matching lines...) Expand all
80 #endif 81 #endif
81 GURL url = GetAppURLAndSetArgs(arg2, context); 82 GURL url = GetAppURLAndSetArgs(arg2, context);
82 if (!url.is_valid()) 83 if (!url.is_valid())
83 return; 84 return;
84 context->Run(url); 85 context->Run(url);
85 } 86 }
86 } 87 }
87 88
88 } // namespace shell 89 } // namespace shell
89 } // namespace mojo 90 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/command_line_util.h ('k') | shell/command_line_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698