| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, |
| 107 Context* context) { | 107 Context* context) { |
| 108 MojoURLResolver* resolver = context->mojo_url_resolver(); | 108 URLResolver* resolver = context->url_resolver(); |
| 109 | 109 |
| 110 // Configure the resolution of unknown mojo: URLs. | 110 // Configure the resolution of unknown mojo: URLs. |
| 111 GURL base_url; | 111 GURL base_url; |
| 112 if (command_line->HasSwitch(switches::kOrigin)) | 112 if (command_line->HasSwitch(switches::kOrigin)) |
| 113 base_url = GURL(command_line->GetSwitchValueASCII(switches::kOrigin)); | 113 base_url = GURL(command_line->GetSwitchValueASCII(switches::kOrigin)); |
| 114 else | 114 else |
| 115 // Use the shell's file root if the base was not specified. | 115 // Use the shell's file root if the base was not specified. |
| 116 base_url = context->ResolveShellFileURL(""); | 116 base_url = context->ResolveShellFileURL(""); |
| 117 | 117 |
| 118 if (!base_url.is_valid()) | 118 if (!base_url.is_valid()) |
| 119 return false; | 119 return false; |
| 120 | 120 |
| 121 resolver->SetBaseURL(base_url); | 121 resolver->SetMojoBaseURL(base_url); |
| 122 | 122 |
| 123 // The network service must be loaded from the filesystem. | 123 // The network service must be loaded from the filesystem. |
| 124 // This mapping is done before the command line URL mapping are processed, so | 124 // This mapping is done before the command line URL mapping are processed, so |
| 125 // that it can be overridden. | 125 // that it can be overridden. |
| 126 resolver->AddCustomMapping( | 126 resolver->AddURLMapping( |
| 127 GURL("mojo:network_service"), | 127 GURL("mojo:network_service"), |
| 128 context->ResolveShellFileURL("file:network_service.mojo")); | 128 context->ResolveShellFileURL("file:network_service.mojo")); |
| 129 | 129 |
| 130 // Command line URL mapping. | 130 // Command line URL mapping. |
| 131 if (command_line->HasSwitch(switches::kURLMappings)) { | 131 if (command_line->HasSwitch(switches::kURLMappings)) { |
| 132 const std::string mappings = | 132 const std::string mappings = |
| 133 command_line->GetSwitchValueASCII(switches::kURLMappings); | 133 command_line->GetSwitchValueASCII(switches::kURLMappings); |
| 134 | 134 |
| 135 base::StringPairs pairs; | 135 base::StringPairs pairs; |
| 136 if (!base::SplitStringIntoKeyValuePairs(mappings, '=', ',', &pairs)) | 136 if (!base::SplitStringIntoKeyValuePairs(mappings, '=', ',', &pairs)) |
| 137 return false; | 137 return false; |
| 138 using StringPair = std::pair<std::string, std::string>; | 138 using StringPair = std::pair<std::string, std::string>; |
| 139 for (const StringPair& pair : pairs) { | 139 for (const StringPair& pair : pairs) { |
| 140 const GURL from(pair.first); | 140 const GURL from(pair.first); |
| 141 const GURL to = context->ResolveCommandLineURL(pair.second); | 141 const GURL to = context->ResolveCommandLineURL(pair.second); |
| 142 if (!from.is_valid() || !to.is_valid()) | 142 if (!from.is_valid() || !to.is_valid()) |
| 143 return false; | 143 return false; |
| 144 resolver->AddCustomMapping(from, to); | 144 resolver->AddURLMapping(from, to); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 return true; | 147 return true; |
| 148 } | 148 } |
| 149 | 149 |
| 150 class TracingServiceProvider : public ServiceProvider { | 150 class TracingServiceProvider : public ServiceProvider { |
| 151 public: | 151 public: |
| 152 explicit TracingServiceProvider(InterfaceRequest<ServiceProvider> request) | 152 explicit TracingServiceProvider(InterfaceRequest<ServiceProvider> request) |
| 153 : binding_(this, request.Pass()) {} | 153 : binding_(this, request.Pass()) {} |
| 154 ~TracingServiceProvider() override {} | 154 ~TracingServiceProvider() override {} |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 264 |
| 265 void Context::OnApplicationError(const GURL& url) { | 265 void Context::OnApplicationError(const GURL& url) { |
| 266 if (app_urls_.find(url) != app_urls_.end()) { | 266 if (app_urls_.find(url) != app_urls_.end()) { |
| 267 app_urls_.erase(url); | 267 app_urls_.erase(url); |
| 268 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) | 268 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) |
| 269 base::MessageLoop::current()->Quit(); | 269 base::MessageLoop::current()->Quit(); |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 | 272 |
| 273 GURL Context::ResolveURL(const GURL& url) { | 273 GURL Context::ResolveURL(const GURL& url) { |
| 274 return mojo_url_resolver_.Resolve(url); | 274 return url_resolver_.ResolveMojoURL(url); |
| 275 } | 275 } |
| 276 | 276 |
| 277 GURL Context::ResolveMappings(const GURL& url) { | 277 GURL Context::ResolveMappings(const GURL& url) { |
| 278 return mojo_url_resolver_.ApplyCustomMappings(url); | 278 return url_resolver_.ApplyURLMappings(url); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void Context::Run(const GURL& url) { | 281 void Context::Run(const GURL& url) { |
| 282 ServiceProviderPtr services; | 282 ServiceProviderPtr services; |
| 283 ServiceProviderPtr exposed_services; | 283 ServiceProviderPtr exposed_services; |
| 284 | 284 |
| 285 app_urls_.insert(url); | 285 app_urls_.insert(url); |
| 286 application_manager_.ConnectToApplication(url, GURL(), GetProxy(&services), | 286 application_manager_.ConnectToApplication(url, GURL(), GetProxy(&services), |
| 287 exposed_services.Pass()); | 287 exposed_services.Pass()); |
| 288 } | 288 } |
| 289 | 289 |
| 290 ScopedMessagePipeHandle Context::ConnectToServiceByName( | 290 ScopedMessagePipeHandle Context::ConnectToServiceByName( |
| 291 const GURL& application_url, | 291 const GURL& application_url, |
| 292 const std::string& service_name) { | 292 const std::string& service_name) { |
| 293 app_urls_.insert(application_url); | 293 app_urls_.insert(application_url); |
| 294 return application_manager_.ConnectToServiceByName(application_url, | 294 return application_manager_.ConnectToServiceByName(application_url, |
| 295 service_name).Pass(); | 295 service_name).Pass(); |
| 296 } | 296 } |
| 297 | 297 |
| 298 } // namespace shell | 298 } // namespace shell |
| 299 } // namespace mojo | 299 } // namespace mojo |
| OLD | NEW |