| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 << requested_url.spec(); | 144 << requested_url.spec(); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void ApplicationManager::ConnectToApplicationImpl( | 147 void ApplicationManager::ConnectToApplicationImpl( |
| 148 const GURL& requested_url, | 148 const GURL& requested_url, |
| 149 const GURL& resolved_url, | 149 const GURL& resolved_url, |
| 150 const GURL& requestor_url, | 150 const GURL& requestor_url, |
| 151 InterfaceRequest<ServiceProvider> services, | 151 InterfaceRequest<ServiceProvider> services, |
| 152 ServiceProviderPtr exposed_services, | 152 ServiceProviderPtr exposed_services, |
| 153 ApplicationLoader* loader) { | 153 ApplicationLoader* loader) { |
| 154 ShellPtr shell_ptr; | 154 ApplicationPtr application; |
| 155 InterfaceRequest<Application> application_request = GetProxy(&application); |
| 155 ShellImpl* shell = | 156 ShellImpl* shell = |
| 156 new ShellImpl(GetProxy(&shell_ptr), this, requested_url, resolved_url); | 157 new ShellImpl(application.Pass(), this, requested_url, resolved_url); |
| 157 url_to_shell_impl_[resolved_url] = shell; | 158 url_to_shell_impl_[resolved_url] = shell; |
| 158 shell->client()->Initialize(GetArgsForURL(requested_url)); | 159 shell->InitializeApplication(GetArgsForURL(requested_url)); |
| 159 | 160 |
| 160 loader->Load(this, resolved_url, shell_ptr.Pass(), | 161 loader->Load(this, resolved_url, application_request.Pass(), |
| 161 base::Bind(&ApplicationManager::LoadWithContentHandler, | 162 base::Bind(&ApplicationManager::LoadWithContentHandler, |
| 162 weak_ptr_factory_.GetWeakPtr())); | 163 weak_ptr_factory_.GetWeakPtr())); |
| 163 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), | 164 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), |
| 164 exposed_services.Pass()); | 165 exposed_services.Pass()); |
| 165 } | 166 } |
| 166 | 167 |
| 167 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) { | 168 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) { |
| 168 const auto& shell_it = url_to_shell_impl_.find(url); | 169 const auto& shell_it = url_to_shell_impl_.find(url); |
| 169 if (shell_it != url_to_shell_impl_.end()) | 170 if (shell_it != url_to_shell_impl_.end()) |
| 170 return shell_it->second; | 171 return shell_it->second; |
| 171 return nullptr; | 172 return nullptr; |
| 172 } | 173 } |
| 173 | 174 |
| 174 void ApplicationManager::ConnectToClient( | 175 void ApplicationManager::ConnectToClient( |
| 175 ShellImpl* shell_impl, | 176 ShellImpl* shell_impl, |
| 176 const GURL& url, | 177 const GURL& url, |
| 177 const GURL& requestor_url, | 178 const GURL& requestor_url, |
| 178 InterfaceRequest<ServiceProvider> services, | 179 InterfaceRequest<ServiceProvider> services, |
| 179 ServiceProviderPtr exposed_services) { | 180 ServiceProviderPtr exposed_services) { |
| 180 shell_impl->ConnectToClient(requestor_url, services.Pass(), | 181 shell_impl->ConnectToClient(requestor_url, services.Pass(), |
| 181 exposed_services.Pass()); | 182 exposed_services.Pass()); |
| 182 } | 183 } |
| 183 | 184 |
| 184 void ApplicationManager::RegisterExternalApplication( | 185 void ApplicationManager::RegisterExternalApplication( |
| 185 const GURL& url, | 186 const GURL& url, |
| 186 const std::vector<std::string>& args, | 187 const std::vector<std::string>& args, |
| 187 ScopedMessagePipeHandle shell_handle) { | 188 ApplicationPtr application) { |
| 188 ShellImpl* shell_impl = | 189 ShellImpl* shell_impl = new ShellImpl(application.Pass(), this, url, url); |
| 189 new ShellImpl(MakeRequest<Shell>(shell_handle.Pass()), this, url, url); | |
| 190 url_to_shell_impl_[url] = shell_impl; | 190 url_to_shell_impl_[url] = shell_impl; |
| 191 | 191 |
| 192 if (args.empty()) | 192 if (args.empty()) |
| 193 shell_impl->client()->Initialize(GetArgsForURL(url)); | 193 shell_impl->InitializeApplication(GetArgsForURL(url)); |
| 194 else | 194 else |
| 195 shell_impl->client()->Initialize(Array<String>::From(args)); | 195 shell_impl->InitializeApplication(Array<String>::From(args)); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void ApplicationManager::LoadWithContentHandler( | 198 void ApplicationManager::LoadWithContentHandler( |
| 199 const GURL& content_handler_url, | 199 const GURL& content_handler_url, |
| 200 ScopedMessagePipeHandle shell_handle, | 200 InterfaceRequest<Application> application_request, |
| 201 URLResponsePtr url_response) { | 201 URLResponsePtr url_response) { |
| 202 ContentHandlerConnection* connection = NULL; | 202 ContentHandlerConnection* connection = NULL; |
| 203 URLToContentHandlerMap::iterator iter = | 203 URLToContentHandlerMap::iterator iter = |
| 204 url_to_content_handler_.find(content_handler_url); | 204 url_to_content_handler_.find(content_handler_url); |
| 205 if (iter != url_to_content_handler_.end()) { | 205 if (iter != url_to_content_handler_.end()) { |
| 206 connection = iter->second; | 206 connection = iter->second; |
| 207 } else { | 207 } else { |
| 208 connection = new ContentHandlerConnection(this, content_handler_url); | 208 connection = new ContentHandlerConnection(this, content_handler_url); |
| 209 url_to_content_handler_[content_handler_url] = connection; | 209 url_to_content_handler_[content_handler_url] = connection; |
| 210 } | 210 } |
| 211 | 211 |
| 212 connection->content_handler()->StartApplication( | 212 connection->content_handler()->StartApplication(application_request.Pass(), |
| 213 MakeProxy<Shell>(shell_handle.Pass()), url_response.Pass()); | 213 url_response.Pass()); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, | 216 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, |
| 217 const GURL& url) { | 217 const GURL& url) { |
| 218 URLToLoaderMap::iterator it = url_to_loader_.find(url); | 218 URLToLoaderMap::iterator it = url_to_loader_.find(url); |
| 219 if (it != url_to_loader_.end()) | 219 if (it != url_to_loader_.end()) |
| 220 delete it->second; | 220 delete it->second; |
| 221 url_to_loader_[url] = loader.release(); | 221 url_to_loader_[url] = loader.release(); |
| 222 } | 222 } |
| 223 | 223 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 return pipe.handle0.Pass(); | 284 return pipe.handle0.Pass(); |
| 285 } | 285 } |
| 286 | 286 |
| 287 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { | 287 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { |
| 288 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); | 288 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); |
| 289 if (args_it != url_to_args_.end()) | 289 if (args_it != url_to_args_.end()) |
| 290 return Array<String>::From(args_it->second); | 290 return Array<String>::From(args_it->second); |
| 291 return Array<String>(); | 291 return Array<String>(); |
| 292 } | 292 } |
| 293 } // namespace mojo | 293 } // namespace mojo |
| OLD | NEW |