| 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 "mojo/application_manager/application_manager.h" | 5 #include "mojo/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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) { | 46 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) { |
| 47 return url; | 47 return url; |
| 48 } | 48 } |
| 49 | 49 |
| 50 class ApplicationManager::ContentHandlerConnection : public ErrorHandler { | 50 class ApplicationManager::ContentHandlerConnection : public ErrorHandler { |
| 51 public: | 51 public: |
| 52 ContentHandlerConnection(ApplicationManager* manager, | 52 ContentHandlerConnection(ApplicationManager* manager, |
| 53 const GURL& content_handler_url) | 53 const GURL& content_handler_url) |
| 54 : manager_(manager), content_handler_url_(content_handler_url) { | 54 : manager_(manager), content_handler_url_(content_handler_url) { |
| 55 ServiceProviderPtr service_provider; | 55 ServiceProviderPtr services; |
| 56 StubServiceProvider* service_provider_impl = | 56 manager->ConnectToApplication(content_handler_url, GURL(), |
| 57 BindToProxy(new StubServiceProvider, &service_provider); | 57 GetProxy(&services), nullptr); |
| 58 manager->ConnectToApplication( | 58 mojo::ConnectToService(services.get(), &content_handler_); |
| 59 content_handler_url, GURL(), service_provider.Pass()); | |
| 60 mojo::ConnectToService(service_provider_impl->client(), &content_handler_); | |
| 61 content_handler_.set_error_handler(this); | 59 content_handler_.set_error_handler(this); |
| 62 } | 60 } |
| 63 | 61 |
| 64 ContentHandler* content_handler() { return content_handler_.get(); } | 62 ContentHandler* content_handler() { return content_handler_.get(); } |
| 65 | 63 |
| 66 GURL content_handler_url() { return content_handler_url_; } | 64 GURL content_handler_url() { return content_handler_url_; } |
| 67 | 65 |
| 68 private: | 66 private: |
| 69 // ErrorHandler implementation: | 67 // ErrorHandler implementation: |
| 70 void OnConnectionError() override { manager_->OnContentHandlerError(this); } | 68 void OnConnectionError() override { manager_->OnContentHandlerError(this); } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 STLDeleteValues(&scheme_to_loader_); | 103 STLDeleteValues(&scheme_to_loader_); |
| 106 } | 104 } |
| 107 | 105 |
| 108 void ApplicationManager::TerminateShellConnections() { | 106 void ApplicationManager::TerminateShellConnections() { |
| 109 STLDeleteValues(&url_to_shell_impl_); | 107 STLDeleteValues(&url_to_shell_impl_); |
| 110 } | 108 } |
| 111 | 109 |
| 112 void ApplicationManager::ConnectToApplication( | 110 void ApplicationManager::ConnectToApplication( |
| 113 const GURL& requested_url, | 111 const GURL& requested_url, |
| 114 const GURL& requestor_url, | 112 const GURL& requestor_url, |
| 115 ServiceProviderPtr service_provider) { | 113 InterfaceRequest<ServiceProvider> services, |
| 114 ServiceProviderPtr exposed_services) { |
| 116 DCHECK(requested_url.is_valid()); | 115 DCHECK(requested_url.is_valid()); |
| 117 ApplicationLoader* loader = GetLoaderForURL(requested_url, | 116 ApplicationLoader* loader = GetLoaderForURL(requested_url, |
| 118 DONT_INCLUDE_DEFAULT_LOADER); | 117 DONT_INCLUDE_DEFAULT_LOADER); |
| 119 if (loader) { | 118 if (loader) { |
| 120 ConnectToApplicationImpl(requested_url, requested_url, requestor_url, | 119 ConnectToApplicationImpl(requested_url, requested_url, requestor_url, |
| 121 service_provider.Pass(), loader); | 120 services.Pass(), exposed_services.Pass(), loader); |
| 122 return; | 121 return; |
| 123 } | 122 } |
| 124 | 123 |
| 125 GURL resolved_url = delegate_->ResolveURL(requested_url); | 124 GURL resolved_url = delegate_->ResolveURL(requested_url); |
| 126 loader = GetLoaderForURL(resolved_url, INCLUDE_DEFAULT_LOADER); | 125 loader = GetLoaderForURL(resolved_url, INCLUDE_DEFAULT_LOADER); |
| 127 if (loader) { | 126 if (loader) { |
| 128 ConnectToApplicationImpl(requested_url, resolved_url, requestor_url, | 127 ConnectToApplicationImpl(requested_url, resolved_url, requestor_url, |
| 129 service_provider.Pass(), loader); | 128 services.Pass(), exposed_services.Pass(), loader); |
| 130 return; | 129 return; |
| 131 } | 130 } |
| 132 | 131 |
| 133 LOG(WARNING) << "Could not find loader to load application: " | 132 LOG(WARNING) << "Could not find loader to load application: " |
| 134 << requested_url.spec(); | 133 << requested_url.spec(); |
| 135 } | 134 } |
| 136 | 135 |
| 137 void ApplicationManager::ConnectToApplicationImpl( | 136 void ApplicationManager::ConnectToApplicationImpl( |
| 138 const GURL& requested_url, | 137 const GURL& requested_url, |
| 139 const GURL& resolved_url, | 138 const GURL& resolved_url, |
| 140 const GURL& requestor_url, | 139 const GURL& requestor_url, |
| 141 ServiceProviderPtr service_provider, | 140 InterfaceRequest<ServiceProvider> services, |
| 141 ServiceProviderPtr exposed_services, |
| 142 ApplicationLoader* loader) { | 142 ApplicationLoader* loader) { |
| 143 ShellImpl* shell = nullptr; | 143 ShellImpl* shell = nullptr; |
| 144 URLToShellImplMap::const_iterator shell_it = | 144 URLToShellImplMap::const_iterator shell_it = |
| 145 url_to_shell_impl_.find(resolved_url); | 145 url_to_shell_impl_.find(resolved_url); |
| 146 if (shell_it != url_to_shell_impl_.end()) { | 146 if (shell_it != url_to_shell_impl_.end()) { |
| 147 shell = shell_it->second; | 147 shell = shell_it->second; |
| 148 } else { | 148 } else { |
| 149 MessagePipe pipe; | 149 MessagePipe pipe; |
| 150 shell = | 150 shell = |
| 151 new ShellImpl(pipe.handle0.Pass(), this, requested_url, resolved_url); | 151 new ShellImpl(pipe.handle0.Pass(), this, requested_url, resolved_url); |
| 152 url_to_shell_impl_[resolved_url] = shell; | 152 url_to_shell_impl_[resolved_url] = shell; |
| 153 shell->client()->Initialize(GetArgsForURL(requested_url)); | 153 shell->client()->Initialize(GetArgsForURL(requested_url)); |
| 154 | 154 |
| 155 loader->Load(this, resolved_url, pipe.handle1.Pass(), | 155 loader->Load(this, resolved_url, pipe.handle1.Pass(), |
| 156 base::Bind(&ApplicationManager::LoadWithContentHandler, | 156 base::Bind(&ApplicationManager::LoadWithContentHandler, |
| 157 weak_ptr_factory_.GetWeakPtr())); | 157 weak_ptr_factory_.GetWeakPtr())); |
| 158 } | 158 } |
| 159 ConnectToClient(shell, resolved_url, requestor_url, service_provider.Pass()); | 159 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), |
| 160 exposed_services.Pass()); |
| 160 } | 161 } |
| 161 | 162 |
| 162 void ApplicationManager::ConnectToClient(ShellImpl* shell_impl, | 163 void ApplicationManager::ConnectToClient( |
| 163 const GURL& url, | 164 ShellImpl* shell_impl, |
| 164 const GURL& requestor_url, | 165 const GURL& url, |
| 165 ServiceProviderPtr service_provider) { | 166 const GURL& requestor_url, |
| 166 shell_impl->ConnectToClient(requestor_url, service_provider.Pass()); | 167 InterfaceRequest<ServiceProvider> services, |
| 168 ServiceProviderPtr exposed_services) { |
| 169 shell_impl->ConnectToClient(requestor_url, services.Pass(), |
| 170 exposed_services.Pass()); |
| 167 } | 171 } |
| 168 | 172 |
| 169 void ApplicationManager::RegisterExternalApplication( | 173 void ApplicationManager::RegisterExternalApplication( |
| 170 const GURL& url, | 174 const GURL& url, |
| 171 ScopedMessagePipeHandle shell_handle) { | 175 ScopedMessagePipeHandle shell_handle) { |
| 172 ShellImpl* shell_impl = new ShellImpl(shell_handle.Pass(), this, url, url); | 176 ShellImpl* shell_impl = new ShellImpl(shell_handle.Pass(), this, url, url); |
| 173 url_to_shell_impl_[url] = shell_impl; | 177 url_to_shell_impl_[url] = shell_impl; |
| 174 shell_impl->client()->Initialize(GetArgsForURL(url)); | 178 shell_impl->client()->Initialize(GetArgsForURL(url)); |
| 175 } | 179 } |
| 176 | 180 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 auto it = | 253 auto it = |
| 250 url_to_content_handler_.find(content_handler->content_handler_url()); | 254 url_to_content_handler_.find(content_handler->content_handler_url()); |
| 251 DCHECK(it != url_to_content_handler_.end()); | 255 DCHECK(it != url_to_content_handler_.end()); |
| 252 delete it->second; | 256 delete it->second; |
| 253 url_to_content_handler_.erase(it); | 257 url_to_content_handler_.erase(it); |
| 254 } | 258 } |
| 255 | 259 |
| 256 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( | 260 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( |
| 257 const GURL& application_url, | 261 const GURL& application_url, |
| 258 const std::string& interface_name) { | 262 const std::string& interface_name) { |
| 259 StubServiceProvider* stub_sp = new StubServiceProvider; | 263 ServiceProviderPtr services; |
| 260 ServiceProviderPtr spp; | 264 ConnectToApplication(application_url, GURL(), GetProxy(&services), nullptr); |
| 261 BindToProxy(stub_sp, &spp); | |
| 262 ConnectToApplication(application_url, GURL(), spp.Pass()); | |
| 263 MessagePipe pipe; | 265 MessagePipe pipe; |
| 264 stub_sp->GetRemoteServiceProvider()->ConnectToService(interface_name, | 266 services->ConnectToService(interface_name, pipe.handle1.Pass()); |
| 265 pipe.handle1.Pass()); | |
| 266 return pipe.handle0.Pass(); | 267 return pipe.handle0.Pass(); |
| 267 } | 268 } |
| 268 | 269 |
| 269 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { | 270 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { |
| 270 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); | 271 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); |
| 271 if (args_it != url_to_args_.end()) | 272 if (args_it != url_to_args_.end()) |
| 272 return Array<String>::From(args_it->second); | 273 return Array<String>::From(args_it->second); |
| 273 return Array<String>(); | 274 return Array<String>(); |
| 274 } | 275 } |
| 275 } // namespace mojo | 276 } // namespace mojo |
| OLD | NEW |