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/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 78 } |
79 | 79 |
80 ApplicationManager::TestAPI::~TestAPI() { | 80 ApplicationManager::TestAPI::~TestAPI() { |
81 } | 81 } |
82 | 82 |
83 bool ApplicationManager::TestAPI::HasCreatedInstance() { | 83 bool ApplicationManager::TestAPI::HasCreatedInstance() { |
84 return has_created_instance; | 84 return has_created_instance; |
85 } | 85 } |
86 | 86 |
87 bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const { | 87 bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const { |
88 return manager_->url_to_shell_impl_.find(url) != | 88 return manager_->identity_to_shell_impl_.find(Identity(url)) != |
89 manager_->url_to_shell_impl_.end(); | 89 manager_->identity_to_shell_impl_.end(); |
90 } | 90 } |
91 | 91 |
92 ApplicationManager::ApplicationManager(Delegate* delegate) | 92 ApplicationManager::ApplicationManager(Delegate* delegate) |
93 : delegate_(delegate), weak_ptr_factory_(this) { | 93 : delegate_(delegate), weak_ptr_factory_(this) { |
94 } | 94 } |
95 | 95 |
96 ApplicationManager::~ApplicationManager() { | 96 ApplicationManager::~ApplicationManager() { |
97 STLDeleteValues(&url_to_content_handler_); | 97 STLDeleteValues(&url_to_content_handler_); |
98 TerminateShellConnections(); | 98 TerminateShellConnections(); |
99 STLDeleteValues(&url_to_loader_); | 99 STLDeleteValues(&url_to_loader_); |
100 STLDeleteValues(&scheme_to_loader_); | 100 STLDeleteValues(&scheme_to_loader_); |
101 } | 101 } |
102 | 102 |
103 void ApplicationManager::TerminateShellConnections() { | 103 void ApplicationManager::TerminateShellConnections() { |
104 STLDeleteValues(&url_to_shell_impl_); | 104 STLDeleteValues(&identity_to_shell_impl_); |
105 } | 105 } |
106 | 106 |
107 void ApplicationManager::ConnectToApplication( | 107 void ApplicationManager::ConnectToApplication( |
108 const GURL& requested_url, | 108 const GURL& requested_url, |
109 const GURL& requestor_url, | 109 const GURL& requestor_url, |
110 InterfaceRequest<ServiceProvider> services, | 110 InterfaceRequest<ServiceProvider> services, |
111 ServiceProviderPtr exposed_services) { | 111 ServiceProviderPtr exposed_services) { |
112 DCHECK(requested_url.is_valid()); | 112 DCHECK(requested_url.is_valid()); |
113 | 113 |
114 // We check both the mapped and resolved urls for existing shell_impls because | 114 // We check both the mapped and resolved urls for existing shell_impls because |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 services->Pass(), exposed_services->Pass())); | 192 services->Pass(), exposed_services->Pass())); |
193 return true; | 193 return true; |
194 } | 194 } |
195 | 195 |
196 InterfaceRequest<Application> ApplicationManager::RegisterShell( | 196 InterfaceRequest<Application> ApplicationManager::RegisterShell( |
197 const GURL& original_url, | 197 const GURL& original_url, |
198 const GURL& resolved_url, | 198 const GURL& resolved_url, |
199 const GURL& requestor_url, | 199 const GURL& requestor_url, |
200 InterfaceRequest<ServiceProvider> services, | 200 InterfaceRequest<ServiceProvider> services, |
201 ServiceProviderPtr exposed_services) { | 201 ServiceProviderPtr exposed_services) { |
202 GURL app_url = GetBaseURLAndQuery(resolved_url, nullptr); | 202 Identity app_url_and_identity(resolved_url); |
203 | 203 |
204 ApplicationPtr application; | 204 ApplicationPtr application; |
205 InterfaceRequest<Application> application_request = GetProxy(&application); | 205 InterfaceRequest<Application> application_request = GetProxy(&application); |
206 ShellImpl* shell = | 206 ShellImpl* shell = new ShellImpl(application.Pass(), this, original_url, |
207 new ShellImpl(application.Pass(), this, original_url, app_url); | 207 app_url_and_identity); |
208 url_to_shell_impl_[app_url] = shell; | 208 identity_to_shell_impl_[app_url_and_identity] = shell; |
209 shell->InitializeApplication(GetArgsForURL(original_url)); | 209 shell->InitializeApplication(GetArgsForURL(original_url)); |
210 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), | 210 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), |
211 exposed_services.Pass()); | 211 exposed_services.Pass()); |
212 return application_request.Pass(); | 212 return application_request.Pass(); |
213 } | 213 } |
214 | 214 |
215 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) { | 215 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) { |
216 const auto& shell_it = url_to_shell_impl_.find(url); | 216 const auto& shell_it = identity_to_shell_impl_.find(Identity(url)); |
217 if (shell_it != url_to_shell_impl_.end()) | 217 if (shell_it != identity_to_shell_impl_.end()) |
218 return shell_it->second; | 218 return shell_it->second; |
219 return nullptr; | 219 return nullptr; |
220 } | 220 } |
221 | 221 |
222 void ApplicationManager::ConnectToClient( | 222 void ApplicationManager::ConnectToClient( |
223 ShellImpl* shell_impl, | 223 ShellImpl* shell_impl, |
224 const GURL& resolved_url, | 224 const GURL& resolved_url, |
225 const GURL& requestor_url, | 225 const GURL& requestor_url, |
226 InterfaceRequest<ServiceProvider> services, | 226 InterfaceRequest<ServiceProvider> services, |
227 ServiceProviderPtr exposed_services) { | 227 ServiceProviderPtr exposed_services) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 330 |
331 void ApplicationManager::RegisterExternalApplication( | 331 void ApplicationManager::RegisterExternalApplication( |
332 const GURL& url, | 332 const GURL& url, |
333 const std::vector<std::string>& args, | 333 const std::vector<std::string>& args, |
334 ApplicationPtr application) { | 334 ApplicationPtr application) { |
335 const auto& args_it = url_to_args_.find(url); | 335 const auto& args_it = url_to_args_.find(url); |
336 if (args_it != url_to_args_.end()) { | 336 if (args_it != url_to_args_.end()) { |
337 LOG(WARNING) << "--args-for provided for external application " << url | 337 LOG(WARNING) << "--args-for provided for external application " << url |
338 << " <ignored>"; | 338 << " <ignored>"; |
339 } | 339 } |
340 ShellImpl* shell_impl = new ShellImpl(application.Pass(), this, url, url); | 340 Identity url_and_identity(url); |
341 url_to_shell_impl_[url] = shell_impl; | 341 ShellImpl* shell_impl = |
| 342 new ShellImpl(application.Pass(), this, url, url_and_identity); |
| 343 identity_to_shell_impl_[url_and_identity] = shell_impl; |
342 shell_impl->InitializeApplication(Array<String>::From(args)); | 344 shell_impl->InitializeApplication(Array<String>::From(args)); |
343 } | 345 } |
344 | 346 |
345 void ApplicationManager::RegisterContentHandler( | 347 void ApplicationManager::RegisterContentHandler( |
346 const std::string& mime_type, | 348 const std::string& mime_type, |
347 const GURL& content_handler_url) { | 349 const GURL& content_handler_url) { |
348 DCHECK(content_handler_url.is_valid()) | 350 DCHECK(content_handler_url.is_valid()) |
349 << "Content handler URL is invalid for mime type " << mime_type; | 351 << "Content handler URL is invalid for mime type " << mime_type; |
350 mime_type_to_url_[mime_type] = content_handler_url; | 352 mime_type_to_url_[mime_type] = content_handler_url; |
351 } | 353 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 if (url_it != url_to_loader_.end()) | 409 if (url_it != url_to_loader_.end()) |
408 return url_it->second; | 410 return url_it->second; |
409 auto scheme_it = scheme_to_loader_.find(url.scheme()); | 411 auto scheme_it = scheme_to_loader_.find(url.scheme()); |
410 if (scheme_it != scheme_to_loader_.end()) | 412 if (scheme_it != scheme_to_loader_.end()) |
411 return scheme_it->second; | 413 return scheme_it->second; |
412 return nullptr; | 414 return nullptr; |
413 } | 415 } |
414 | 416 |
415 void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) { | 417 void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) { |
416 // Called from ~ShellImpl, so we do not need to call Destroy here. | 418 // Called from ~ShellImpl, so we do not need to call Destroy here. |
417 const GURL url = shell_impl->url(); | 419 const Identity url_and_identity = shell_impl->url_and_identity(); |
418 const GURL requested_url = shell_impl->requested_url(); | 420 const GURL requested_url = shell_impl->requested_url(); |
419 // Remove the shell. | 421 // Remove the shell. |
420 URLToShellImplMap::iterator it = url_to_shell_impl_.find(url); | 422 auto it = identity_to_shell_impl_.find(url_and_identity); |
421 DCHECK(it != url_to_shell_impl_.end()); | 423 DCHECK(it != identity_to_shell_impl_.end()); |
422 delete it->second; | 424 delete it->second; |
423 url_to_shell_impl_.erase(it); | 425 identity_to_shell_impl_.erase(it); |
424 delegate_->OnApplicationError(requested_url); | 426 delegate_->OnApplicationError(requested_url); |
425 } | 427 } |
426 | 428 |
427 void ApplicationManager::OnContentHandlerError( | 429 void ApplicationManager::OnContentHandlerError( |
428 ContentHandlerConnection* content_handler) { | 430 ContentHandlerConnection* content_handler) { |
429 // Remove the mapping to the content handler. | 431 // Remove the mapping to the content handler. |
430 auto it = | 432 auto it = |
431 url_to_content_handler_.find(content_handler->content_handler_url()); | 433 url_to_content_handler_.find(content_handler->content_handler_url()); |
432 DCHECK(it != url_to_content_handler_.end()); | 434 DCHECK(it != url_to_content_handler_.end()); |
433 delete it->second; | 435 delete it->second; |
(...skipping 17 matching lines...) Expand all Loading... |
451 return Array<String>(); | 453 return Array<String>(); |
452 } | 454 } |
453 | 455 |
454 void ApplicationManager::CleanupRunner(NativeRunner* runner) { | 456 void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
455 native_runners_.erase( | 457 native_runners_.erase( |
456 std::find(native_runners_.begin(), native_runners_.end(), runner)); | 458 std::find(native_runners_.begin(), native_runners_.end(), runner)); |
457 } | 459 } |
458 | 460 |
459 } // namespace shell | 461 } // namespace shell |
460 } // namespace mojo | 462 } // namespace mojo |
OLD | NEW |