Chromium Code Reviews| Index: shell/application_manager/application_manager.cc |
| diff --git a/shell/application_manager/application_manager.cc b/shell/application_manager/application_manager.cc |
| index e6beb2117a3ad85e1ae4a3765d0b3d4686acd409..eaf8189d78d62f2ab6efe46ea8466953b859e8dc 100644 |
| --- a/shell/application_manager/application_manager.cc |
| +++ b/shell/application_manager/application_manager.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/logging.h" |
| #include "base/macros.h" |
| #include "base/stl_util.h" |
| +#include "base/strings/string_util.h" |
| #include "mojo/public/cpp/bindings/binding.h" |
| #include "mojo/public/cpp/bindings/error_handler.h" |
| #include "mojo/public/interfaces/application/shell.mojom.h" |
| @@ -24,6 +25,17 @@ namespace mojo { |
| namespace { |
| // Used by TestAPI. |
| bool has_created_instance = false; |
| + |
| +GURL StripQueryFromURL(const GURL& url) { |
| + GURL::Replacements repl; |
| + repl.SetQueryStr(""); |
| + std::string result = url.ReplaceComponents(repl).spec(); |
| + |
| + // Remove the dangling '?' because it's ugly. |
| + base::ReplaceChars(result, "?", "", &result); |
| + return GURL(result); |
| +} |
| + |
| } // namespace |
| ApplicationManager::Delegate::~Delegate() { |
| @@ -113,14 +125,14 @@ void ApplicationManager::ConnectToApplication( |
| // external applications can be registered for the unresolved mojo:foo urls. |
| GURL mapped_url = delegate_->ResolveMappings(requested_url); |
| - if (ConnectToRunningApplication(mapped_url, requestor_url, &services, |
| - &exposed_services)) { |
| + if (ConnectToRunningApplication(requested_url, mapped_url, requestor_url, |
|
qsr
2015/02/27 15:01:41
I think the URL that the application see should be
Aaron Boodman
2015/02/27 16:54:44
Done.
|
| + &services, &exposed_services)) { |
| return; |
| } |
| GURL resolved_url = delegate_->ResolveURL(mapped_url); |
| - if (ConnectToRunningApplication(resolved_url, requestor_url, &services, |
| - &exposed_services)) { |
| + if (ConnectToRunningApplication(requested_url, resolved_url, requestor_url, |
| + &services, &exposed_services)) { |
| return; |
| } |
| @@ -161,16 +173,20 @@ void ApplicationManager::ConnectToApplication( |
| } |
| bool ApplicationManager::ConnectToRunningApplication( |
| + const GURL& requested_url, |
| const GURL& application_url, |
| const GURL& requestor_url, |
| InterfaceRequest<ServiceProvider>* services, |
| ServiceProviderPtr* exposed_services) { |
| ShellImpl* shell_impl = GetShellImpl(application_url); |
|
qsr
2015/02/27 15:01:41
Any reason you do not always strip the query here?
Aaron Boodman
2015/02/27 16:54:44
Done.
|
| - if (!shell_impl) |
| - return false; |
| + if (!shell_impl) { |
| + shell_impl = GetShellImpl(StripQueryFromURL(application_url)); |
| + if (!shell_impl || !shell_impl->handles_query()) |
| + return false; |
| + } |
| - ConnectToClient(shell_impl, application_url, requestor_url, services->Pass(), |
| - exposed_services->Pass()); |
| + ConnectToClient(shell_impl, requested_url, application_url, requestor_url, |
| + services->Pass(), exposed_services->Pass()); |
| return true; |
| } |
| @@ -186,24 +202,29 @@ bool ApplicationManager::ConnectToApplicationWithLoader( |
| loader->Load(resolved_url, |
| RegisterShell(requested_url, resolved_url, requestor_url, |
| - services->Pass(), exposed_services->Pass())); |
| + services->Pass(), exposed_services->Pass(), |
| + ShellImpl::SHELL_DOES_NOT_HANDLE_QUERY)); |
| return true; |
| } |
| InterfaceRequest<Application> ApplicationManager::RegisterShell( |
| const GURL& requested_url, |
| - const GURL& resolved_url, |
| + GURL resolved_url, |
| const GURL& requestor_url, |
| InterfaceRequest<ServiceProvider> services, |
| - ServiceProviderPtr exposed_services) { |
| + ServiceProviderPtr exposed_services, |
| + ShellImpl::QueryHandlingBehavior query_behavior) { |
| + if (query_behavior == ShellImpl::SHELL_HANDLES_QUERY) |
| + resolved_url = StripQueryFromURL(resolved_url); |
| + |
| ApplicationPtr application; |
| InterfaceRequest<Application> application_request = GetProxy(&application); |
| - ShellImpl* shell = |
| - new ShellImpl(application.Pass(), this, requested_url, resolved_url); |
| + ShellImpl* shell = new ShellImpl(application.Pass(), this, requested_url, |
| + resolved_url, query_behavior); |
| url_to_shell_impl_[resolved_url] = shell; |
| shell->InitializeApplication(GetArgsForURL(requested_url)); |
| - ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), |
| - exposed_services.Pass()); |
| + ConnectToClient(shell, requested_url, resolved_url, requestor_url, |
| + services.Pass(), exposed_services.Pass()); |
| return application_request.Pass(); |
| } |
| @@ -216,11 +237,12 @@ ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) { |
| void ApplicationManager::ConnectToClient( |
| ShellImpl* shell_impl, |
| - const GURL& url, |
| + const GURL& requested_url, |
| + const GURL& resolved_url, // TODO(aa): Remove |
|
qsr
2015/02/27 15:01:41
I think that it is requested_url that we can do wi
Aaron Boodman
2015/02/27 16:54:44
Done.
|
| const GURL& requestor_url, |
| InterfaceRequest<ServiceProvider> services, |
| ServiceProviderPtr exposed_services) { |
| - shell_impl->ConnectToClient(requestor_url, services.Pass(), |
| + shell_impl->ConnectToClient(requested_url, requestor_url, services.Pass(), |
| exposed_services.Pass()); |
| } |
| @@ -250,21 +272,23 @@ void ApplicationManager::HandleFetchCallback( |
| // |
| // Also, it's possible the original URL was redirected to an app that is |
| // already running. |
| - if (ConnectToRunningApplication(fetcher->GetURL(), requestor_url, &services, |
| + if (ConnectToRunningApplication(requested_url, fetcher->GetURL(), |
| + requestor_url, &services, |
| &exposed_services)) { |
| return; |
| } |
| - InterfaceRequest<Application> application_request( |
| - RegisterShell(requested_url, fetcher->GetURL(), requestor_url, |
| - services.Pass(), exposed_services.Pass())); |
| - |
| // If the response begins with a #!mojo <content-handler-url>, use it. |
| GURL content_handler_url; |
| std::string shebang; |
| if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) { |
| LoadWithContentHandler( |
| - content_handler_url, application_request.Pass(), |
| + content_handler_url, |
| + // #!mojo means this is a first-class mojo application, so it handles |
| + // queries. |
| + RegisterShell(requested_url, fetcher->GetURL(), requestor_url, |
| + services.Pass(), exposed_services.Pass(), |
| + ShellImpl::SHELL_HANDLES_QUERY), |
| fetcher->AsURLResponse(blocking_pool_, |
| static_cast<int>(shebang.size()))); |
| return; |
| @@ -272,8 +296,13 @@ void ApplicationManager::HandleFetchCallback( |
| MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); |
| if (iter != mime_type_to_url_.end()) { |
| - LoadWithContentHandler(iter->second, application_request.Pass(), |
| - fetcher->AsURLResponse(blocking_pool_, 0)); |
| + // Legacy content doesn't get automatic query handling. |
| + LoadWithContentHandler( |
| + iter->second, |
| + RegisterShell(requested_url, fetcher->GetURL(), requestor_url, |
| + services.Pass(), exposed_services.Pass(), |
| + ShellImpl::SHELL_DOES_NOT_HANDLE_QUERY), |
| + fetcher->AsURLResponse(blocking_pool_, 0)); |
| return; |
| } |
| @@ -282,11 +311,16 @@ void ApplicationManager::HandleFetchCallback( |
| // header, or looking for some specific mojo signature prepended to the |
| // library. |
| - fetcher->AsPath(blocking_pool_, |
| - base::Bind(&ApplicationManager::RunNativeApplication, |
| - weak_ptr_factory_.GetWeakPtr(), |
| - base::Passed(application_request.Pass()), |
| - cleanup_behavior, base::Passed(fetcher.Pass()))); |
| + fetcher->AsPath( |
| + blocking_pool_, |
| + base::Bind( |
| + &ApplicationManager::RunNativeApplication, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + base::Passed(RegisterShell(requested_url, fetcher->GetURL(), |
| + requestor_url, services.Pass(), |
| + exposed_services.Pass(), |
| + ShellImpl::SHELL_HANDLES_QUERY).Pass()), |
| + cleanup_behavior, base::Passed(fetcher.Pass()))); |
| } |
| void ApplicationManager::RunNativeApplication( |
| @@ -322,7 +356,8 @@ void ApplicationManager::RegisterExternalApplication( |
| LOG(WARNING) << "--args-for provided for external application " << url |
| << " <ignored>"; |
| } |
| - ShellImpl* shell_impl = new ShellImpl(application.Pass(), this, url, url); |
| + ShellImpl* shell_impl = new ShellImpl(application.Pass(), this, url, url, |
| + ShellImpl::SHELL_DOES_NOT_HANDLE_QUERY); |
| url_to_shell_impl_[url] = shell_impl; |
| shell_impl->InitializeApplication(Array<String>::From(args)); |
| } |