Chromium Code Reviews| 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 <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 GetLoaderForURL(resolved_url))) { | 135 GetLoaderForURL(resolved_url))) { |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 | 138 |
| 139 if (ConnectToApplicationWithLoader(requested_url, resolved_url, requestor_url, | 139 if (ConnectToApplicationWithLoader(requested_url, resolved_url, requestor_url, |
| 140 &services, &exposed_services, | 140 &services, &exposed_services, |
| 141 default_loader_.get())) { | 141 default_loader_.get())) { |
| 142 return; | 142 return; |
| 143 } | 143 } |
| 144 | 144 |
| 145 InterfaceRequest<Application> application_request = | |
| 146 RegisterShell(requested_url, resolved_url, requestor_url, services.Pass(), | |
| 147 exposed_services.Pass()); | |
| 148 | |
| 149 auto callback = base::Bind(&ApplicationManager::HandleFetchCallback, | 145 auto callback = base::Bind(&ApplicationManager::HandleFetchCallback, |
| 150 weak_ptr_factory_.GetWeakPtr(), | 146 weak_ptr_factory_.GetWeakPtr(), requested_url, |
| 151 base::Passed(application_request.Pass())); | 147 requestor_url, base::Passed(services.Pass()), |
| 148 base::Passed(exposed_services.Pass())); | |
| 152 | 149 |
| 153 if (resolved_url.SchemeIsFile()) { | 150 if (resolved_url.SchemeIsFile()) { |
| 154 new LocalFetcher(resolved_url, | 151 new LocalFetcher(resolved_url, |
| 155 base::Bind(callback, NativeRunner::DontDeleteAppPath)); | 152 base::Bind(callback, NativeRunner::DontDeleteAppPath)); |
| 156 return; | 153 return; |
| 157 } | 154 } |
| 158 | 155 |
| 159 if (!network_service_) | 156 if (!network_service_) |
| 160 ConnectToService(GURL("mojo:network_service"), &network_service_); | 157 ConnectToService(GURL("mojo:network_service"), &network_service_); |
| 161 | 158 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 ShellImpl* shell_impl, | 218 ShellImpl* shell_impl, |
| 222 const GURL& url, | 219 const GURL& url, |
| 223 const GURL& requestor_url, | 220 const GURL& requestor_url, |
| 224 InterfaceRequest<ServiceProvider> services, | 221 InterfaceRequest<ServiceProvider> services, |
| 225 ServiceProviderPtr exposed_services) { | 222 ServiceProviderPtr exposed_services) { |
| 226 shell_impl->ConnectToClient(requestor_url, services.Pass(), | 223 shell_impl->ConnectToClient(requestor_url, services.Pass(), |
| 227 exposed_services.Pass()); | 224 exposed_services.Pass()); |
| 228 } | 225 } |
| 229 | 226 |
| 230 void ApplicationManager::HandleFetchCallback( | 227 void ApplicationManager::HandleFetchCallback( |
| 231 InterfaceRequest<Application> application_request, | 228 const GURL& requested_url, |
| 229 const GURL& requestor_url, | |
| 230 InterfaceRequest<ServiceProvider> services, | |
| 231 ServiceProviderPtr exposed_services, | |
| 232 NativeRunner::CleanupBehavior cleanup_behavior, | 232 NativeRunner::CleanupBehavior cleanup_behavior, |
| 233 scoped_ptr<Fetcher> fetcher) { | 233 scoped_ptr<Fetcher> fetcher) { |
| 234 if (!fetcher) { | 234 if (!fetcher) { |
| 235 // Network error. Drop |application_request| to tell requestor. | 235 // Network error. Drop |application_request| to tell requestor. |
| 236 return; | 236 return; |
| 237 } | 237 } |
| 238 | 238 |
| 239 GURL redirect_url = fetcher->GetRedirectURL(); | |
| 240 if (!redirect_url.is_empty()) { | |
| 241 // And around we go again... Whee! | |
|
qsr
2015/02/26 10:41:56
Is there any advantage to try to use the url_loade
| |
| 242 ConnectToApplication(redirect_url, requestor_url, services.Pass(), | |
| 243 exposed_services.Pass()); | |
| 244 return; | |
| 245 } | |
| 246 | |
| 247 // We already checked if the application was running before we fetched it, but | |
| 248 // it might have started while the fetch was outstanding. We don't want to | |
| 249 // have two copies of the app running, so check again. | |
| 250 // | |
| 251 // Also, it's possible the original URL was redirected to an app that is | |
| 252 // already running. | |
| 253 if (ConnectToRunningApplication(fetcher->GetURL(), requestor_url, &services, | |
| 254 &exposed_services)) { | |
| 255 return; | |
| 256 } | |
| 257 | |
| 258 InterfaceRequest<Application> application_request( | |
| 259 RegisterShell(requested_url, fetcher->GetURL(), requestor_url, | |
| 260 services.Pass(), exposed_services.Pass())); | |
| 261 | |
| 239 // If the response begins with a #!mojo <content-handler-url>, use it. | 262 // If the response begins with a #!mojo <content-handler-url>, use it. |
| 240 GURL url; | 263 GURL content_handler_url; |
| 241 std::string shebang; | 264 std::string shebang; |
| 242 if (fetcher->PeekContentHandler(&shebang, &url)) { | 265 if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) { |
| 243 LoadWithContentHandler( | 266 LoadWithContentHandler( |
| 244 url, application_request.Pass(), | 267 content_handler_url, application_request.Pass(), |
| 245 fetcher->AsURLResponse(blocking_pool_, | 268 fetcher->AsURLResponse(blocking_pool_, |
| 246 static_cast<int>(shebang.size()))); | 269 static_cast<int>(shebang.size()))); |
| 247 return; | 270 return; |
| 248 } | 271 } |
| 249 | 272 |
| 250 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); | 273 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); |
| 251 if (iter != mime_type_to_url_.end()) { | 274 if (iter != mime_type_to_url_.end()) { |
| 252 LoadWithContentHandler(iter->second, application_request.Pass(), | 275 LoadWithContentHandler(iter->second, application_request.Pass(), |
| 253 fetcher->AsURLResponse(blocking_pool_, 0)); | 276 fetcher->AsURLResponse(blocking_pool_, 0)); |
| 254 return; | 277 return; |
| 255 } | 278 } |
| 256 | 279 |
| 257 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo | 280 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo |
| 258 // application. That could either mean looking for the platform-specific dll | 281 // application. That could either mean looking for the platform-specific dll |
| 259 // header, or looking for some specific mojo signature prepended to the | 282 // header, or looking for some specific mojo signature prepended to the |
| 260 // library. | 283 // library. |
| 261 | 284 |
| 262 fetcher->AsPath(blocking_pool_, | 285 fetcher->AsPath(blocking_pool_, |
| 263 base::Bind(&ApplicationManager::RunNativeApplication, | 286 base::Bind(&ApplicationManager::RunNativeApplication, |
| 264 weak_ptr_factory_.GetWeakPtr(), | 287 weak_ptr_factory_.GetWeakPtr(), |
| 265 base::Passed(application_request.Pass()), | 288 base::Passed(application_request.Pass()), |
| 266 cleanup_behavior, base::Passed(fetcher.Pass()))); | 289 cleanup_behavior, base::Passed(fetcher.Pass()))); |
|
qsr
2015/02/26 10:41:56
I think this is an undefined behavior. You have no
| |
| 267 } | 290 } |
| 268 | 291 |
| 269 void ApplicationManager::RunNativeApplication( | 292 void ApplicationManager::RunNativeApplication( |
| 270 InterfaceRequest<Application> application_request, | 293 InterfaceRequest<Application> application_request, |
| 271 NativeRunner::CleanupBehavior cleanup_behavior, | 294 NativeRunner::CleanupBehavior cleanup_behavior, |
| 272 scoped_ptr<Fetcher> fetcher, | 295 scoped_ptr<Fetcher> fetcher, |
| 273 const base::FilePath& path, | 296 const base::FilePath& path, |
| 274 bool path_exists) { | 297 bool path_exists) { |
| 275 // We only passed fetcher to keep it alive. Done with it now. | 298 // We only passed fetcher to keep it alive. Done with it now. |
| 276 fetcher.reset(); | 299 fetcher.reset(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 return Array<String>::From(args_it->second); | 423 return Array<String>::From(args_it->second); |
| 401 return Array<String>(); | 424 return Array<String>(); |
| 402 } | 425 } |
| 403 | 426 |
| 404 void ApplicationManager::CleanupRunner(NativeRunner* runner) { | 427 void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
| 405 native_runners_.erase( | 428 native_runners_.erase( |
| 406 std::find(native_runners_.begin(), native_runners_.end(), runner)); | 429 std::find(native_runners_.begin(), native_runners_.end(), runner)); |
| 407 } | 430 } |
| 408 | 431 |
| 409 } // namespace mojo | 432 } // namespace mojo |
| OLD | NEW |