| Index: mojo/shell/application_manager.cc
|
| diff --git a/mojo/shell/application_manager.cc b/mojo/shell/application_manager.cc
|
| index 7ca0d392c2ea1c208f3ab120155761e7ab32f01e..715e6e77c7499a044ddefd538fefdd940354d6b7 100644
|
| --- a/mojo/shell/application_manager.cc
|
| +++ b/mojo/shell/application_manager.cc
|
| @@ -73,23 +73,36 @@
|
|
|
| void ApplicationManager::ConnectToApplication(
|
| scoped_ptr<ConnectToApplicationParams> params) {
|
| + GURL original_url = params->app_url();
|
| + URLRequestPtr original_url_request = params->TakeAppURLRequest();
|
| +
|
| TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication",
|
| TRACE_EVENT_SCOPE_THREAD, "original_url",
|
| - params->app_url().spec());
|
| - DCHECK(params->app_url().is_valid());
|
| -
|
| - // Connect to an existing matching instance, if possible.
|
| + original_url.spec());
|
| + DCHECK(original_url.is_valid());
|
| + DCHECK(original_url_request);
|
| +
|
| + // We need to look for running instances based on both the unresolved and
|
| + // resolved urls.
|
| if (ConnectToRunningApplication(¶ms))
|
| return;
|
|
|
| - ApplicationLoader* loader = GetLoaderForURL(params->app_url());
|
| + GURL resolved_url = package_manager_->ResolveURL(original_url);
|
| + params->SetURLInfo(resolved_url);
|
| + if (ConnectToRunningApplication(¶ms))
|
| + return;
|
| +
|
| + // The application is not running, let's compute the parameters.
|
| + // NOTE: Set URL info using |original_url_request| instead of |original_url|
|
| + // because it may contain more information (e.g., it is a POST request).
|
| + params->SetURLInfo(original_url_request.Pass());
|
| + ApplicationLoader* loader = GetLoaderForURL(resolved_url);
|
| if (loader) {
|
| - GURL url = params->app_url();
|
| - loader->Load(url, CreateInstance(params.Pass(), nullptr));
|
| - return;
|
| - }
|
| -
|
| - URLRequestPtr original_url_request = params->TakeAppURLRequest();
|
| + ConnectToApplicationWithLoader(¶ms, resolved_url, loader);
|
| + return;
|
| + }
|
| +
|
| + original_url_request = params->TakeAppURLRequest();
|
| auto callback =
|
| base::Bind(&ApplicationManager::HandleFetchCallback,
|
| weak_ptr_factory_.GetWeakPtr(), base::Passed(¶ms));
|
| @@ -105,6 +118,16 @@
|
|
|
| instance->ConnectToClient(params->Pass());
|
| return true;
|
| +}
|
| +
|
| +void ApplicationManager::ConnectToApplicationWithLoader(
|
| + scoped_ptr<ConnectToApplicationParams>* params,
|
| + const GURL& resolved_url,
|
| + ApplicationLoader* loader) {
|
| + if (!(*params)->app_url().SchemeIs("mojo"))
|
| + (*params)->SetURLInfo(resolved_url);
|
| +
|
| + loader->Load(resolved_url, CreateInstance(params->Pass(), nullptr));
|
| }
|
|
|
| InterfaceRequest<Application> ApplicationManager::CreateInstance(
|
| @@ -130,8 +153,10 @@
|
|
|
| ApplicationInstance* ApplicationManager::GetApplicationInstance(
|
| const Identity& identity) const {
|
| - const auto& it = identity_to_instance_.find(identity);
|
| - return it != identity_to_instance_.end() ? it->second : nullptr;
|
| + const auto& instance_it = identity_to_instance_.find(identity);
|
| + if (instance_it != identity_to_instance_.end())
|
| + return instance_it->second;
|
| + return nullptr;
|
| }
|
|
|
| void ApplicationManager::HandleFetchCallback(
|
| @@ -161,8 +186,14 @@
|
| // We already checked if the application was running before we fetched it, but
|
| // it might have started while the fetch was outstanding. We don't want to
|
| // have two copies of the app running, so check again.
|
| + //
|
| + // Also, it's possible the original URL was redirected to an app that is
|
| + // already running.
|
| if (ConnectToRunningApplication(¶ms))
|
| return;
|
| +
|
| + if (params->app_url().scheme() != "mojo")
|
| + params->SetURLInfo(fetcher->GetURL());
|
|
|
| Identity originator_identity = params->originator_identity();
|
| CapabilityFilter originator_filter = params->originator_filter();
|
|
|