| 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 "mojo/shell/application_manager/application_manager.h" | 5 #include "mojo/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 13 matching lines...) Expand all Loading... |
| 24 namespace mojo { | 24 namespace mojo { |
| 25 namespace shell { | 25 namespace shell { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Used by TestAPI. | 29 // Used by TestAPI. |
| 30 bool has_created_instance = false; | 30 bool has_created_instance = false; |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 ApplicationManager::Delegate::~Delegate() { | |
| 35 } | |
| 36 | |
| 37 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) { | |
| 38 return url; | |
| 39 } | |
| 40 | |
| 41 GURL ApplicationManager::Delegate::ResolveMappings(const GURL& url) { | |
| 42 return url; | |
| 43 } | |
| 44 | |
| 45 class ApplicationManager::ContentHandlerConnection : public ErrorHandler { | 34 class ApplicationManager::ContentHandlerConnection : public ErrorHandler { |
| 46 public: | 35 public: |
| 47 ContentHandlerConnection(ApplicationManager* manager, | 36 ContentHandlerConnection(ApplicationManager* manager, |
| 48 const GURL& content_handler_url) | 37 const GURL& content_handler_url) |
| 49 : manager_(manager), content_handler_url_(content_handler_url) { | 38 : manager_(manager), content_handler_url_(content_handler_url) { |
| 50 ServiceProviderPtr services; | 39 ServiceProviderPtr services; |
| 51 manager->ConnectToApplication(content_handler_url, GURL(), | 40 manager->ConnectToApplication(content_handler_url, GURL(), |
| 52 GetProxy(&services), nullptr, | 41 GetProxy(&services), nullptr, |
| 53 base::Closure()); | 42 base::Closure()); |
| 54 MessagePipe pipe; | 43 MessagePipe pipe; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 118 |
| 130 // We check both the mapped and resolved urls for existing shell_impls because | 119 // We check both the mapped and resolved urls for existing shell_impls because |
| 131 // external applications can be registered for the unresolved mojo:foo urls. | 120 // external applications can be registered for the unresolved mojo:foo urls. |
| 132 | 121 |
| 133 GURL mapped_url = delegate_->ResolveMappings(requested_url); | 122 GURL mapped_url = delegate_->ResolveMappings(requested_url); |
| 134 if (ConnectToRunningApplication(mapped_url, requestor_url, &services, | 123 if (ConnectToRunningApplication(mapped_url, requestor_url, &services, |
| 135 &exposed_services)) { | 124 &exposed_services)) { |
| 136 return; | 125 return; |
| 137 } | 126 } |
| 138 | 127 |
| 139 GURL resolved_url = delegate_->ResolveURL(mapped_url); | 128 GURL resolved_url = delegate_->ResolveMojoURL(mapped_url); |
| 140 if (ConnectToRunningApplication(resolved_url, requestor_url, &services, | 129 if (ConnectToRunningApplication(resolved_url, requestor_url, &services, |
| 141 &exposed_services)) { | 130 &exposed_services)) { |
| 142 return; | 131 return; |
| 143 } | 132 } |
| 144 | 133 |
| 145 // The application is not running, let's compute the parameters. | 134 // The application is not running, let's compute the parameters. |
| 146 if (ConnectToApplicationWithLoader(mapped_url, requestor_url, &services, | 135 if (ConnectToApplicationWithLoader(mapped_url, requestor_url, &services, |
| 147 &exposed_services, on_application_end, | 136 &exposed_services, on_application_end, |
| 148 pre_redirect_parameters, | 137 pre_redirect_parameters, |
| 149 GetLoaderForURL(mapped_url))) { | 138 GetLoaderForURL(mapped_url))) { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 if (it != scheme_to_loader_.end()) | 393 if (it != scheme_to_loader_.end()) |
| 405 delete it->second; | 394 delete it->second; |
| 406 scheme_to_loader_[scheme] = loader.release(); | 395 scheme_to_loader_[scheme] = loader.release(); |
| 407 } | 396 } |
| 408 | 397 |
| 409 void ApplicationManager::SetNativeOptionsForURL( | 398 void ApplicationManager::SetNativeOptionsForURL( |
| 410 const NativeRunnerFactory::Options& options, | 399 const NativeRunnerFactory::Options& options, |
| 411 const GURL& url) { | 400 const GURL& url) { |
| 412 DCHECK(!url.has_query()); // Precondition. | 401 DCHECK(!url.has_query()); // Precondition. |
| 413 // Apply mappings and resolution to get the resolved URL. | 402 // Apply mappings and resolution to get the resolved URL. |
| 414 GURL resolved_url = delegate_->ResolveURL(delegate_->ResolveMappings(url)); | 403 GURL resolved_url = |
| 404 delegate_->ResolveMojoURL(delegate_->ResolveMappings(url)); |
| 415 DCHECK(!resolved_url.has_query()); // Still shouldn't have query. | 405 DCHECK(!resolved_url.has_query()); // Still shouldn't have query. |
| 416 // TODO(vtl): We should probably also remove/disregard the query string (and | 406 // TODO(vtl): We should probably also remove/disregard the query string (and |
| 417 // maybe canonicalize in other ways). | 407 // maybe canonicalize in other ways). |
| 418 DVLOG(2) << "Storing native options for resolved URL " << resolved_url | 408 DVLOG(2) << "Storing native options for resolved URL " << resolved_url |
| 419 << " (original URL " << url << ")"; | 409 << " (original URL " << url << ")"; |
| 420 url_to_native_options_[resolved_url] = options; | 410 url_to_native_options_[resolved_url] = options; |
| 421 } | 411 } |
| 422 | 412 |
| 423 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) { | 413 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) { |
| 424 auto url_it = url_to_loader_.find(GetBaseURLAndQuery(url, nullptr)); | 414 auto url_it = url_to_loader_.find(GetBaseURLAndQuery(url, nullptr)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 return pipe.handle0.Pass(); | 454 return pipe.handle0.Pass(); |
| 465 } | 455 } |
| 466 | 456 |
| 467 void ApplicationManager::CleanupRunner(NativeRunner* runner) { | 457 void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
| 468 native_runners_.erase( | 458 native_runners_.erase( |
| 469 std::find(native_runners_.begin(), native_runners_.end(), runner)); | 459 std::find(native_runners_.begin(), native_runners_.end(), runner)); |
| 470 } | 460 } |
| 471 | 461 |
| 472 } // namespace shell | 462 } // namespace shell |
| 473 } // namespace mojo | 463 } // namespace mojo |
| OLD | NEW |