| 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 29 matching lines...) Expand all Loading... |
| 40 return v2; | 40 return v2; |
| 41 if (!v2.size()) | 41 if (!v2.size()) |
| 42 return v1; | 42 return v1; |
| 43 std::vector<std::string> result(v1); | 43 std::vector<std::string> result(v1); |
| 44 result.insert(result.end(), v1.begin(), v1.end()); | 44 result.insert(result.end(), v1.begin(), v1.end()); |
| 45 return result; | 45 return result; |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 ApplicationManager::Delegate::~Delegate() { | |
| 51 } | |
| 52 | |
| 53 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) { | |
| 54 return url; | |
| 55 } | |
| 56 | |
| 57 GURL ApplicationManager::Delegate::ResolveMappings(const GURL& url) { | |
| 58 return url; | |
| 59 } | |
| 60 | |
| 61 class ApplicationManager::ContentHandlerConnection : public mojo::ErrorHandler { | 50 class ApplicationManager::ContentHandlerConnection : public mojo::ErrorHandler { |
| 62 public: | 51 public: |
| 63 ContentHandlerConnection(ApplicationManager* manager, | 52 ContentHandlerConnection(ApplicationManager* manager, |
| 64 const GURL& content_handler_url) | 53 const GURL& content_handler_url) |
| 65 : manager_(manager), content_handler_url_(content_handler_url) { | 54 : manager_(manager), content_handler_url_(content_handler_url) { |
| 66 ServiceProviderPtr services; | 55 ServiceProviderPtr services; |
| 67 manager->ConnectToApplication(content_handler_url, GURL(), | 56 manager->ConnectToApplication(content_handler_url, GURL(), |
| 68 mojo::GetProxy(&services), nullptr, | 57 mojo::GetProxy(&services), nullptr, |
| 69 base::Closure()); | 58 base::Closure()); |
| 70 mojo::MessagePipe pipe; | 59 mojo::MessagePipe pipe; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 135 |
| 147 // We check both the mapped and resolved urls for existing shell_impls because | 136 // We check both the mapped and resolved urls for existing shell_impls because |
| 148 // external applications can be registered for the unresolved mojo:foo urls. | 137 // external applications can be registered for the unresolved mojo:foo urls. |
| 149 | 138 |
| 150 GURL mapped_url = delegate_->ResolveMappings(requested_url); | 139 GURL mapped_url = delegate_->ResolveMappings(requested_url); |
| 151 if (ConnectToRunningApplication(mapped_url, requestor_url, &services, | 140 if (ConnectToRunningApplication(mapped_url, requestor_url, &services, |
| 152 &exposed_services)) { | 141 &exposed_services)) { |
| 153 return; | 142 return; |
| 154 } | 143 } |
| 155 | 144 |
| 156 GURL resolved_url = delegate_->ResolveURL(mapped_url); | 145 GURL resolved_url = delegate_->ResolveMojoURL(mapped_url); |
| 157 if (ConnectToRunningApplication(resolved_url, requestor_url, &services, | 146 if (ConnectToRunningApplication(resolved_url, requestor_url, &services, |
| 158 &exposed_services)) { | 147 &exposed_services)) { |
| 159 return; | 148 return; |
| 160 } | 149 } |
| 161 | 150 |
| 162 // The application is not running, let's compute the parameters. | 151 // The application is not running, let's compute the parameters. |
| 163 std::vector<std::string> parameters = | 152 std::vector<std::string> parameters = |
| 164 Concatenate(pre_redirect_parameters, GetArgsForURL(resolved_url)); | 153 Concatenate(pre_redirect_parameters, GetArgsForURL(resolved_url)); |
| 165 | 154 |
| 166 if (ConnectToApplicationWithLoader(mapped_url, requestor_url, &services, | 155 if (ConnectToApplicationWithLoader(mapped_url, requestor_url, &services, |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 } | 415 } |
| 427 | 416 |
| 428 void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args, | 417 void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args, |
| 429 const GURL& url) { | 418 const GURL& url) { |
| 430 url_to_args_[url].insert(url_to_args_[url].end(), args.begin(), args.end()); | 419 url_to_args_[url].insert(url_to_args_[url].end(), args.begin(), args.end()); |
| 431 GURL mapped_url = delegate_->ResolveMappings(url); | 420 GURL mapped_url = delegate_->ResolveMappings(url); |
| 432 if (mapped_url != url) { | 421 if (mapped_url != url) { |
| 433 url_to_args_[mapped_url].insert(url_to_args_[mapped_url].end(), | 422 url_to_args_[mapped_url].insert(url_to_args_[mapped_url].end(), |
| 434 args.begin(), args.end()); | 423 args.begin(), args.end()); |
| 435 } | 424 } |
| 436 GURL resolved_url = delegate_->ResolveURL(mapped_url); | 425 GURL resolved_url = delegate_->ResolveMojoURL(mapped_url); |
| 437 if (resolved_url != mapped_url) { | 426 if (resolved_url != mapped_url) { |
| 438 url_to_args_[resolved_url].insert(url_to_args_[resolved_url].end(), | 427 url_to_args_[resolved_url].insert(url_to_args_[resolved_url].end(), |
| 439 args.begin(), args.end()); | 428 args.begin(), args.end()); |
| 440 } | 429 } |
| 441 } | 430 } |
| 442 | 431 |
| 443 void ApplicationManager::SetNativeOptionsForURL( | 432 void ApplicationManager::SetNativeOptionsForURL( |
| 444 const NativeRunnerFactory::Options& options, | 433 const NativeRunnerFactory::Options& options, |
| 445 const GURL& url) { | 434 const GURL& url) { |
| 446 DCHECK(!url.has_query()); // Precondition. | 435 DCHECK(!url.has_query()); // Precondition. |
| 447 // Apply mappings and resolution to get the resolved URL. | 436 // Apply mappings and resolution to get the resolved URL. |
| 448 GURL resolved_url = delegate_->ResolveURL(delegate_->ResolveMappings(url)); | 437 GURL resolved_url = |
| 438 delegate_->ResolveMojoURL(delegate_->ResolveMappings(url)); |
| 449 DCHECK(!resolved_url.has_query()); // Still shouldn't have query. | 439 DCHECK(!resolved_url.has_query()); // Still shouldn't have query. |
| 450 // TODO(vtl): We should probably also remove/disregard the query string (and | 440 // TODO(vtl): We should probably also remove/disregard the query string (and |
| 451 // maybe canonicalize in other ways). | 441 // maybe canonicalize in other ways). |
| 452 DVLOG(2) << "Storing native options for resolved URL " << resolved_url | 442 DVLOG(2) << "Storing native options for resolved URL " << resolved_url |
| 453 << " (original URL " << url << ")"; | 443 << " (original URL " << url << ")"; |
| 454 url_to_native_options_[resolved_url] = options; | 444 url_to_native_options_[resolved_url] = options; |
| 455 } | 445 } |
| 456 | 446 |
| 457 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) { | 447 ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) { |
| 458 auto url_it = url_to_loader_.find(GetBaseURLAndQuery(url, nullptr)); | 448 auto url_it = url_to_loader_.find(GetBaseURLAndQuery(url, nullptr)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 return args_it->second; | 494 return args_it->second; |
| 505 return std::vector<std::string>(); | 495 return std::vector<std::string>(); |
| 506 } | 496 } |
| 507 | 497 |
| 508 void ApplicationManager::CleanupRunner(NativeRunner* runner) { | 498 void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
| 509 native_runners_.erase( | 499 native_runners_.erase( |
| 510 std::find(native_runners_.begin(), native_runners_.end(), runner)); | 500 std::find(native_runners_.begin(), native_runners_.end(), runner)); |
| 511 } | 501 } |
| 512 | 502 |
| 513 } // namespace shell | 503 } // namespace shell |
| OLD | NEW |