| OLD | NEW |
| 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/application_manager/application_manager.h" | 5 #include "shell/application_manager/application_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 ConnectToApplicationWithParameters(requested_url, requestor_url, | 125 ConnectToApplicationWithParameters(requested_url, requestor_url, |
| 126 services.Pass(), exposed_services.Pass(), | 126 services.Pass(), exposed_services.Pass(), |
| 127 std::vector<std::string>()); | 127 std::vector<std::string>()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void ApplicationManager::ConnectToApplicationWithParameters( | 130 void ApplicationManager::ConnectToApplicationWithParameters( |
| 131 const GURL& requested_url, | 131 const GURL& requested_url, |
| 132 const GURL& requestor_url, | 132 const GURL& requestor_url, |
| 133 InterfaceRequest<ServiceProvider> services, | 133 InterfaceRequest<ServiceProvider> services, |
| 134 ServiceProviderPtr exposed_services, | 134 ServiceProviderPtr exposed_services, |
| 135 const std::vector<std::string>& parameters) { | 135 const std::vector<std::string>& pre_redirect_parameters) { |
| 136 DCHECK(requested_url.is_valid()); | 136 DCHECK(requested_url.is_valid()); |
| 137 | 137 |
| 138 // We check both the mapped and resolved urls for existing shell_impls because | 138 // We check both the mapped and resolved urls for existing shell_impls because |
| 139 // external applications can be registered for the unresolved mojo:foo urls. | 139 // external applications can be registered for the unresolved mojo:foo urls. |
| 140 | 140 |
| 141 GURL mapped_url = delegate_->ResolveMappings(requested_url); | 141 GURL mapped_url = delegate_->ResolveMappings(requested_url); |
| 142 if (ConnectToRunningApplication(mapped_url, requestor_url, &services, | 142 if (ConnectToRunningApplication(mapped_url, requestor_url, &services, |
| 143 &exposed_services)) { | 143 &exposed_services)) { |
| 144 return; | 144 return; |
| 145 } | 145 } |
| 146 | 146 |
| 147 GURL resolved_url = delegate_->ResolveURL(mapped_url); | 147 GURL resolved_url = delegate_->ResolveURL(mapped_url); |
| 148 if (ConnectToRunningApplication(resolved_url, requestor_url, &services, | 148 if (ConnectToRunningApplication(resolved_url, requestor_url, &services, |
| 149 &exposed_services)) { | 149 &exposed_services)) { |
| 150 return; | 150 return; |
| 151 } | 151 } |
| 152 | 152 |
| 153 // The application is not running, let's compute the parameters. |
| 154 std::vector<std::string> parameters = |
| 155 Concatenate(pre_redirect_parameters, GetArgsForURL(resolved_url)); |
| 156 |
| 153 if (ConnectToApplicationWithLoader(requested_url, mapped_url, requestor_url, | 157 if (ConnectToApplicationWithLoader(requested_url, mapped_url, requestor_url, |
| 154 &services, &exposed_services, parameters, | 158 &services, &exposed_services, parameters, |
| 155 GetLoaderForURL(mapped_url))) { | 159 GetLoaderForURL(mapped_url))) { |
| 156 return; | 160 return; |
| 157 } | 161 } |
| 158 | 162 |
| 159 if (ConnectToApplicationWithLoader(requested_url, resolved_url, requestor_url, | 163 if (ConnectToApplicationWithLoader(requested_url, resolved_url, requestor_url, |
| 160 &services, &exposed_services, parameters, | 164 &services, &exposed_services, parameters, |
| 161 GetLoaderForURL(resolved_url))) { | 165 GetLoaderForURL(resolved_url))) { |
| 162 return; | 166 return; |
| 163 } | 167 } |
| 164 | 168 |
| 165 if (ConnectToApplicationWithLoader(requested_url, resolved_url, requestor_url, | 169 if (ConnectToApplicationWithLoader(requested_url, resolved_url, requestor_url, |
| 166 &services, &exposed_services, parameters, | 170 &services, &exposed_services, parameters, |
| 167 default_loader_.get())) { | 171 default_loader_.get())) { |
| 168 return; | 172 return; |
| 169 } | 173 } |
| 170 | 174 |
| 171 auto callback = base::Bind( | 175 auto callback = base::Bind(&ApplicationManager::HandleFetchCallback, |
| 172 &ApplicationManager::HandleFetchCallback, weak_ptr_factory_.GetWeakPtr(), | 176 weak_ptr_factory_.GetWeakPtr(), requested_url, |
| 173 requested_url, requestor_url, base::Passed(services.Pass()), | 177 requestor_url, base::Passed(services.Pass()), |
| 174 base::Passed(exposed_services.Pass()), | 178 base::Passed(exposed_services.Pass()), parameters); |
| 175 Concatenate(parameters, GetArgsForURL(resolved_url))); | |
| 176 | 179 |
| 177 if (resolved_url.SchemeIsFile()) { | 180 if (resolved_url.SchemeIsFile()) { |
| 178 new LocalFetcher(resolved_url, GetBaseURLAndQuery(resolved_url, nullptr), | 181 new LocalFetcher(resolved_url, GetBaseURLAndQuery(resolved_url, nullptr), |
| 179 base::Bind(callback, NativeRunner::DontDeleteAppPath)); | 182 base::Bind(callback, NativeRunner::DontDeleteAppPath)); |
| 180 return; | 183 return; |
| 181 } | 184 } |
| 182 | 185 |
| 183 if (!network_service_) | 186 if (!network_service_) |
| 184 ConnectToService(GURL("mojo:network_service"), &network_service_); | 187 ConnectToService(GURL("mojo:network_service"), &network_service_); |
| 185 | 188 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 InterfaceRequest<ServiceProvider> services, | 236 InterfaceRequest<ServiceProvider> services, |
| 234 ServiceProviderPtr exposed_services, | 237 ServiceProviderPtr exposed_services, |
| 235 const std::vector<std::string>& parameters) { | 238 const std::vector<std::string>& parameters) { |
| 236 Identity app_identity(resolved_url); | 239 Identity app_identity(resolved_url); |
| 237 | 240 |
| 238 ApplicationPtr application; | 241 ApplicationPtr application; |
| 239 InterfaceRequest<Application> application_request = GetProxy(&application); | 242 InterfaceRequest<Application> application_request = GetProxy(&application); |
| 240 ShellImpl* shell = | 243 ShellImpl* shell = |
| 241 new ShellImpl(application.Pass(), this, original_url, app_identity); | 244 new ShellImpl(application.Pass(), this, original_url, app_identity); |
| 242 identity_to_shell_impl_[app_identity] = shell; | 245 identity_to_shell_impl_[app_identity] = shell; |
| 243 shell->InitializeApplication(Array<String>::From( | 246 shell->InitializeApplication(Array<String>::From(parameters)); |
| 244 Concatenate(parameters, GetArgsForURL(app_identity.url)))); | |
| 245 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), | 247 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), |
| 246 exposed_services.Pass()); | 248 exposed_services.Pass()); |
| 247 return application_request.Pass(); | 249 return application_request.Pass(); |
| 248 } | 250 } |
| 249 | 251 |
| 250 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) { | 252 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) { |
| 251 const auto& shell_it = identity_to_shell_impl_.find(Identity(url)); | 253 const auto& shell_it = identity_to_shell_impl_.find(Identity(url)); |
| 252 if (shell_it != identity_to_shell_impl_.end()) | 254 if (shell_it != identity_to_shell_impl_.end()) |
| 253 return shell_it->second; | 255 return shell_it->second; |
| 254 return nullptr; | 256 return nullptr; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 return std::vector<std::string>(); | 505 return std::vector<std::string>(); |
| 504 } | 506 } |
| 505 | 507 |
| 506 void ApplicationManager::CleanupRunner(NativeRunner* runner) { | 508 void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
| 507 native_runners_.erase( | 509 native_runners_.erase( |
| 508 std::find(native_runners_.begin(), native_runners_.end(), runner)); | 510 std::find(native_runners_.begin(), native_runners_.end(), runner)); |
| 509 } | 511 } |
| 510 | 512 |
| 511 } // namespace shell | 513 } // namespace shell |
| 512 } // namespace mojo | 514 } // namespace mojo |
| OLD | NEW |