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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/shell/BUILD.gn ('k') | mojo/shell/mojo_url_resolver.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/desktop/mojo_main.cc
diff --git a/mojo/shell/desktop/mojo_main.cc b/mojo/shell/desktop/mojo_main.cc
index 6d4a6d9a81165d421c75a385772a70428484ba36..4738e3c14850dbefe8f31830f79b12668b65617a 100644
--- a/mojo/shell/desktop/mojo_main.cc
+++ b/mojo/shell/desktop/mojo_main.cc
@@ -15,6 +15,7 @@
#include "mojo/shell/child_process.h"
#include "mojo/shell/context.h"
#include "mojo/shell/init.h"
+#include "mojo/shell/mojo_url_resolver.h"
#include "mojo/shell/switches.h"
#if defined(COMPONENT_BUILD)
@@ -70,20 +71,38 @@ void RunApps(mojo::shell::Context* context) {
void Usage() {
std::cerr << "Launch Mojo applications.\n";
std::cerr
- << "Usage: mojo_shell"
- << " [--" << switches::kArgsFor << "=<mojo-app>]"
- << " [--" << switches::kContentHandlers << "=<handlers>]"
- << " [--" << switches::kEnableExternalApplications << "]"
- << " [--" << switches::kDisableCache << "]"
- << " [--" << switches::kEnableMultiprocess << "]"
- << " [--" << switches::kOrigin << "=<url-lib-path>]"
- << " <mojo-app> ...\n\n"
- << "A <mojo-app> is a Mojo URL or a Mojo URL and arguments within quotes.\n"
- << "Example: mojo_shell \"mojo://mojo_js_standalone test.js\".\n"
- << "<url-lib-path> is searched for shared libraries named by mojo URLs.\n"
- << "The value of <handlers> is a comma separated list like:\n"
- << "text/html,mojo://mojo_html_viewer,"
- << "application/javascript,mojo://mojo_js_content_handler\n";
+ << "Usage: mojo_shell"
+ << " [--" << switches::kArgsFor << "=<mojo-app>]"
+ << " [--" << switches::kContentHandlers << "=<handlers>]"
+ << " [--" << switches::kEnableExternalApplications << "]"
+ << " [--" << switches::kDisableCache << "]"
+ << " [--" << switches::kEnableMultiprocess << "]"
+ << " [--" << switches::kOrigin << "=<url-lib-path>]"
+ << " [--" << switches::kURLMappings << "=from1=to1,from2=to2]"
+ << " <mojo-app> ...\n\n"
+ << "A <mojo-app> is a Mojo URL or a Mojo URL and arguments within "
+ << "quotes.\n"
+ << "Example: mojo_shell \"mojo://mojo_js_standalone test.js\".\n"
+ << "<url-lib-path> is searched for shared libraries named by mojo URLs.\n"
+ << "The value of <handlers> is a comma separated list like:\n"
+ << "text/html,mojo://mojo_html_viewer,"
+ << "application/javascript,mojo://mojo_js_content_handler\n";
+}
+
+bool ConfigureURLMappings(const std::string& mappings,
+ mojo::shell::MojoURLResolver* resolver) {
+ base::StringPairs pairs;
+ if (!base::SplitStringIntoKeyValuePairs(mappings, '=', ',', &pairs))
+ return false;
+ using StringPair = std::pair<std::string, std::string>;
+ for (const StringPair& pair : pairs) {
+ const GURL from(pair.first);
+ const GURL to(pair.second);
+ if (!from.is_valid() || !to.is_valid())
+ return false;
+ resolver->AddCustomMapping(from, to);
+ }
+ return true;
}
} // namespace
@@ -130,6 +149,14 @@ int main(int argc, char** argv) {
GURL(command_line.GetSwitchValueASCII(switches::kOrigin)));
}
+ if (command_line.HasSwitch(switches::kURLMappings) &&
+ !ConfigureURLMappings(
+ command_line.GetSwitchValueASCII(switches::kURLMappings),
+ shell_context.mojo_url_resolver())) {
+ Usage();
+ return 0;
+ }
+
for (const auto& kv : command_line.GetSwitches()) {
if (kv.first == switches::kArgsFor)
GetAppURLAndSetArgs(kv.second, &shell_context);
« 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