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

Side by Side Diff: mojo/shell/desktop/mojo_main.cc

Issue 658503003: Enables specifying mojo url mapping on command line (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 6 years, 2 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 | « mojo/shell/BUILD.gn ('k') | mojo/shell/mojo_url_resolver.h » ('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 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 "mojo/shell/child_process.h"
16 #include "mojo/shell/context.h" 16 #include "mojo/shell/context.h"
17 #include "mojo/shell/init.h" 17 #include "mojo/shell/init.h"
18 #include "mojo/shell/mojo_url_resolver.h"
18 #include "mojo/shell/switches.h" 19 #include "mojo/shell/switches.h"
19 20
20 #if defined(COMPONENT_BUILD) 21 #if defined(COMPONENT_BUILD)
21 #include "ui/gl/gl_surface.h" 22 #include "ui/gl/gl_surface.h"
22 #endif 23 #endif
23 24
24 namespace { 25 namespace {
25 26
26 #if defined(OS_LINUX) 27 #if defined(OS_LINUX)
27 // Copied from ui/gfx/switches.cc to avoid a dependency on //ui/gfx 28 // Copied from ui/gfx/switches.cc to avoid a dependency on //ui/gfx
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 64
64 void RunApps(mojo::shell::Context* context) { 65 void RunApps(mojo::shell::Context* context) {
65 const auto& command_line = *base::CommandLine::ForCurrentProcess(); 66 const auto& command_line = *base::CommandLine::ForCurrentProcess();
66 for (const auto& arg : command_line.GetArgs()) 67 for (const auto& arg : command_line.GetArgs())
67 context->Run(GetAppURLAndSetArgs(arg, context)); 68 context->Run(GetAppURLAndSetArgs(arg, context));
68 } 69 }
69 70
70 void Usage() { 71 void Usage() {
71 std::cerr << "Launch Mojo applications.\n"; 72 std::cerr << "Launch Mojo applications.\n";
72 std::cerr 73 std::cerr
73 << "Usage: mojo_shell" 74 << "Usage: mojo_shell"
74 << " [--" << switches::kArgsFor << "=<mojo-app>]" 75 << " [--" << switches::kArgsFor << "=<mojo-app>]"
75 << " [--" << switches::kContentHandlers << "=<handlers>]" 76 << " [--" << switches::kContentHandlers << "=<handlers>]"
76 << " [--" << switches::kEnableExternalApplications << "]" 77 << " [--" << switches::kEnableExternalApplications << "]"
77 << " [--" << switches::kDisableCache << "]" 78 << " [--" << switches::kDisableCache << "]"
78 << " [--" << switches::kEnableMultiprocess << "]" 79 << " [--" << switches::kEnableMultiprocess << "]"
79 << " [--" << switches::kOrigin << "=<url-lib-path>]" 80 << " [--" << switches::kOrigin << "=<url-lib-path>]"
80 << " <mojo-app> ...\n\n" 81 << " [--" << switches::kURLMappings << "=from1=to1,from2=to2]"
81 << "A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes.\n" 82 << " <mojo-app> ...\n\n"
82 << "Example: mojo_shell \"mojo://mojo_js_standalone test.js\".\n" 83 << "A <mojo-app> is a Mojo URL or a Mojo URL and arguments within "
83 << "<url-lib-path> is searched for shared libraries named by mojo URLs.\n" 84 << "quotes.\n"
84 << "The value of <handlers> is a comma separated list like:\n" 85 << "Example: mojo_shell \"mojo://mojo_js_standalone test.js\".\n"
85 << "text/html,mojo://mojo_html_viewer," 86 << "<url-lib-path> is searched for shared libraries named by mojo URLs.\n"
86 << "application/javascript,mojo://mojo_js_content_handler\n"; 87 << "The value of <handlers> is a comma separated list like:\n"
88 << "text/html,mojo://mojo_html_viewer,"
89 << "application/javascript,mojo://mojo_js_content_handler\n";
90 }
91
92 bool ConfigureURLMappings(const std::string& mappings,
93 mojo::shell::MojoURLResolver* resolver) {
94 base::StringPairs pairs;
95 if (!base::SplitStringIntoKeyValuePairs(mappings, '=', ',', &pairs))
96 return false;
97 using StringPair = std::pair<std::string, std::string>;
98 for (const StringPair& pair : pairs) {
99 const GURL from(pair.first);
100 const GURL to(pair.second);
101 if (!from.is_valid() || !to.is_valid())
102 return false;
103 resolver->AddCustomMapping(from, to);
104 }
105 return true;
87 } 106 }
88 107
89 } // namespace 108 } // namespace
90 109
91 int main(int argc, char** argv) { 110 int main(int argc, char** argv) {
92 base::AtExitManager at_exit; 111 base::AtExitManager at_exit;
93 base::CommandLine::Init(argc, argv); 112 base::CommandLine::Init(argc, argv);
94 113
95 const base::CommandLine& command_line = 114 const base::CommandLine& command_line =
96 *base::CommandLine::ForCurrentProcess(); 115 *base::CommandLine::ForCurrentProcess();
(...skipping 26 matching lines...) Expand all
123 mojo::shell::Context shell_context; 142 mojo::shell::Context shell_context;
124 { 143 {
125 base::MessageLoop message_loop; 144 base::MessageLoop message_loop;
126 shell_context.Init(); 145 shell_context.Init();
127 146
128 if (command_line.HasSwitch(switches::kOrigin)) { 147 if (command_line.HasSwitch(switches::kOrigin)) {
129 shell_context.mojo_url_resolver()->SetBaseURL( 148 shell_context.mojo_url_resolver()->SetBaseURL(
130 GURL(command_line.GetSwitchValueASCII(switches::kOrigin))); 149 GURL(command_line.GetSwitchValueASCII(switches::kOrigin)));
131 } 150 }
132 151
152 if (command_line.HasSwitch(switches::kURLMappings) &&
153 !ConfigureURLMappings(
154 command_line.GetSwitchValueASCII(switches::kURLMappings),
155 shell_context.mojo_url_resolver())) {
156 Usage();
157 return 0;
158 }
159
133 for (const auto& kv : command_line.GetSwitches()) { 160 for (const auto& kv : command_line.GetSwitches()) {
134 if (kv.first == switches::kArgsFor) 161 if (kv.first == switches::kArgsFor)
135 GetAppURLAndSetArgs(kv.second, &shell_context); 162 GetAppURLAndSetArgs(kv.second, &shell_context);
136 } 163 }
137 164
138 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); 165 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context));
139 message_loop.Run(); 166 message_loop.Run();
140 } 167 }
141 } 168 }
142 return 0; 169 return 0;
143 } 170 }
OLDNEW
« no previous file with comments | « mojo/shell/BUILD.gn ('k') | mojo/shell/mojo_url_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698