OLD | NEW |
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 "shell/context.h" | 5 #include "shell/context.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers | 96 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers |
97 << ": '" << parts[i + 1] << "' is not a valid URL."; | 97 << ": '" << parts[i + 1] << "' is not a valid URL."; |
98 return; | 98 return; |
99 } | 99 } |
100 // TODO(eseidel): We should also validate that the mimetype is valid | 100 // TODO(eseidel): We should also validate that the mimetype is valid |
101 // net/base/mime_util.h could do this, but we don't want to depend on net. | 101 // net/base/mime_util.h could do this, but we don't want to depend on net. |
102 loader->RegisterContentHandler(parts[i], url); | 102 loader->RegisterContentHandler(parts[i], url); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 bool ConfigureURLMappings(base::CommandLine* command_line, | 106 bool ConfigureURLMappings(base::CommandLine* command_line, Context* context) { |
107 Context* context) { | |
108 URLResolver* resolver = context->url_resolver(); | 107 URLResolver* resolver = context->url_resolver(); |
109 | 108 |
110 // Configure the resolution of unknown mojo: URLs. | 109 // Configure the resolution of unknown mojo: URLs. |
111 GURL base_url; | 110 GURL base_url; |
112 if (command_line->HasSwitch(switches::kOrigin)) | 111 if (command_line->HasSwitch(switches::kOrigin)) |
113 base_url = GURL(command_line->GetSwitchValueASCII(switches::kOrigin)); | 112 base_url = GURL(command_line->GetSwitchValueASCII(switches::kOrigin)); |
114 else | 113 else |
115 // Use the shell's file root if the base was not specified. | 114 // Use the shell's file root if the base was not specified. |
116 base_url = context->ResolveShellFileURL(""); | 115 base_url = context->ResolveShellFileURL(""); |
117 | 116 |
118 if (!base_url.is_valid()) | 117 if (!base_url.is_valid()) |
119 return false; | 118 return false; |
120 | 119 |
121 resolver->SetMojoBaseURL(base_url); | 120 resolver->SetMojoBaseURL(base_url); |
122 | 121 |
123 // The network service must be loaded from the filesystem. | 122 // The network service must be loaded from the filesystem. |
124 // This mapping is done before the command line URL mapping are processed, so | 123 // This mapping is done before the command line URL mapping are processed, so |
125 // that it can be overridden. | 124 // that it can be overridden. |
126 resolver->AddURLMapping( | 125 resolver->AddURLMapping( |
127 GURL("mojo:network_service"), | 126 GURL("mojo:network_service"), |
128 context->ResolveShellFileURL("file:network_service.mojo")); | 127 context->ResolveShellFileURL("file:network_service.mojo")); |
129 | 128 |
130 // Command line URL mapping. | 129 // Command line URL mapping. |
131 if (command_line->HasSwitch(switches::kURLMappings)) { | 130 if (command_line->HasSwitch(switches::kURLMappings)) { |
132 const std::string mappings = | 131 const std::string mappings = |
133 command_line->GetSwitchValueASCII(switches::kURLMappings); | 132 command_line->GetSwitchValueASCII(switches::kURLMappings); |
134 | 133 |
135 base::StringPairs pairs; | 134 base::StringPairs pairs; |
136 if (!base::SplitStringIntoKeyValuePairs(mappings, '=', ',', &pairs)) | 135 if (!base::SplitStringIntoKeyValuePairs(mappings, '=', ',', &pairs)) |
137 return false; | 136 return false; |
138 using StringPair = std::pair<std::string, std::string>; | 137 using StringPair = std::pair<std::string, std::string>; |
139 for (const StringPair& pair : pairs) { | 138 for (const StringPair& pair : pairs) { |
140 const GURL from(pair.first); | 139 const GURL from(pair.first); |
141 const GURL to = context->ResolveCommandLineURL(pair.second); | 140 const GURL to = context->ResolveCommandLineURL(pair.second); |
142 if (!from.is_valid() || !to.is_valid()) | 141 if (!from.is_valid() || !to.is_valid()) |
143 return false; | 142 return false; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 ScopedMessagePipeHandle Context::ConnectToServiceByName( | 289 ScopedMessagePipeHandle Context::ConnectToServiceByName( |
291 const GURL& application_url, | 290 const GURL& application_url, |
292 const std::string& service_name) { | 291 const std::string& service_name) { |
293 app_urls_.insert(application_url); | 292 app_urls_.insert(application_url); |
294 return application_manager_.ConnectToServiceByName(application_url, | 293 return application_manager_.ConnectToServiceByName(application_url, |
295 service_name).Pass(); | 294 service_name).Pass(); |
296 } | 295 } |
297 | 296 |
298 } // namespace shell | 297 } // namespace shell |
299 } // namespace mojo | 298 } // namespace mojo |
OLD | NEW |