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