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

Side by Side Diff: shell/command_line_util.cc

Issue 1467263002: Fix URL duplication when SetArgsForURL is called mutliple times. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month 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
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 shell { 16 namespace shell {
17 17
18 namespace { 18 namespace {
19 GURL GetAppURLAndSetArgs(const std::string& app_url_and_args, 19 GURL GetAppURLAndSetArgs(const std::string& app_url_and_args,
20 Context* context) { 20 Context* context) {
21 std::vector<std::string> args; 21 std::vector<std::string> args;
22 GURL app_url = GetAppURLAndArgs(context, app_url_and_args, &args); 22 GURL app_url = GetAppURLAndArgs(context, app_url_and_args, &args);
23 23
24 if (args.size() > 1) 24 if (!args.empty())
25 context->application_manager()->SetArgsForURL(args, app_url); 25 context->application_manager()->SetArgsForURL(args, app_url);
26 return app_url; 26 return app_url;
27 } 27 }
28 } // namespace 28 } // namespace
29 29
30 bool ParseArgsFor(const std::string& arg, std::string* value) { 30 bool ParseArgsFor(const std::string& arg, std::string* value) {
31 const std::string kArgsForSwitches[] = { 31 const std::string kArgsForSwitches[] = {
32 "-" + std::string(switches::kArgsFor) + "=", 32 "-" + std::string(switches::kArgsFor) + "=",
33 "--" + std::string(switches::kArgsFor) + "=", 33 "--" + std::string(switches::kArgsFor) + "=",
34 }; 34 };
(...skipping 16 matching lines...) Expand all
51 [](const std::string& a) { return a.empty(); }), 51 [](const std::string& a) { return a.empty(); }),
52 args->end()); 52 args->end());
53 53
54 if (args->empty()) 54 if (args->empty())
55 return GURL(); 55 return GURL();
56 GURL app_url = context->ResolveCommandLineURL((*args)[0]); 56 GURL app_url = context->ResolveCommandLineURL((*args)[0]);
57 if (!app_url.is_valid()) { 57 if (!app_url.is_valid()) {
58 LOG(ERROR) << "Error: invalid URL: " << (*args)[0]; 58 LOG(ERROR) << "Error: invalid URL: " << (*args)[0];
59 return app_url; 59 return app_url;
60 } 60 }
61 if (args->size() == 1) 61 args->erase(args->begin());
62 args->clear();
63 return app_url; 62 return app_url;
64 } 63 }
65 64
66 void ApplyApplicationArgs(Context* context, const std::string& args) { 65 void ApplyApplicationArgs(Context* context, const std::string& args) {
67 std::string args_for_value; 66 std::string args_for_value;
68 if (ParseArgsFor(args, &args_for_value)) 67 if (ParseArgsFor(args, &args_for_value))
69 GetAppURLAndSetArgs(args_for_value, context); 68 GetAppURLAndSetArgs(args_for_value, context);
70 } 69 }
71 70
72 void RunCommandLineApps(Context* context) { 71 void RunCommandLineApps(Context* context) {
73 const auto& command_line = *base::CommandLine::ForCurrentProcess(); 72 const auto& command_line = *base::CommandLine::ForCurrentProcess();
74 for (const auto& arg : command_line.GetArgs()) { 73 for (const auto& arg : command_line.GetArgs()) {
75 GURL url = GetAppURLAndSetArgs(arg, context); 74 GURL url = GetAppURLAndSetArgs(arg, context);
76 if (!url.is_valid()) 75 if (!url.is_valid())
77 return; 76 return;
78 context->Run(url); 77 context->Run(url);
79 } 78 }
80 } 79 }
81 80
82 } // namespace shell 81 } // namespace shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698