James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Przemysław Pietrzkiewicz | 6384d09 | 2015-01-15 16:03:17 -0800 | [diff] [blame] | 5 | #include "shell/application_manager/application_manager.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 6 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 7 | #include "base/bind.h" |
Scott Violet | ef1cb8c | 2015-03-13 14:01:39 -0700 | [diff] [blame] | 8 | #include "base/command_line.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 9 | #include "base/logging.h" |
| 10 | #include "base/macros.h" |
Aaron Boodman | b34bcbf | 2015-03-02 10:05:31 -0800 | [diff] [blame] | 11 | #include "base/strings/string_util.h" |
James Robinson | 6bbb9e0 | 2015-03-27 13:42:35 -0700 | [diff] [blame] | 12 | #include "base/trace_event/trace_event.h" |
James Robinson | 43fd683 | 2014-11-12 16:24:27 -0800 | [diff] [blame] | 13 | #include "mojo/public/cpp/bindings/binding.h" |
Viet-Trung Luu | 08e339a | 2015-10-10 01:03:09 -0700 | [diff] [blame] | 14 | #include "mojo/services/authenticating_url_loader_interceptor/interfaces/authenticating_url_loader_interceptor_meta_factory.mojom.h" |
| 15 | #include "mojo/services/authentication/interfaces/authentication.mojom.h" |
| 16 | #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 17 | #include "shell/application_manager/fetcher.h" |
| 18 | #include "shell/application_manager/local_fetcher.h" |
| 19 | #include "shell/application_manager/network_fetcher.h" |
Benjamin Lerman | 05eccab | 2015-03-05 15:29:39 +0100 | [diff] [blame] | 20 | #include "shell/application_manager/query_util.h" |
Viet-Trung Luu | 3f2970c | 2015-03-05 10:21:56 -0800 | [diff] [blame] | 21 | #include "shell/application_manager/shell_impl.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 22 | |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 23 | using mojo::Application; |
| 24 | using mojo::ApplicationPtr; |
| 25 | using mojo::InterfaceRequest; |
| 26 | using mojo::ServiceProvider; |
| 27 | using mojo::ServiceProviderPtr; |
| 28 | |
Viet-Trung Luu | 36faa4d | 2015-03-04 18:08:18 -0800 | [diff] [blame] | 29 | namespace shell { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 30 | |
| 31 | namespace { |
Viet-Trung Luu | fbf0a4e | 2015-03-04 14:37:27 -0800 | [diff] [blame] | 32 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 33 | // Used by TestAPI. |
| 34 | bool has_created_instance = false; |
Aaron Boodman | b34bcbf | 2015-03-02 10:05:31 -0800 | [diff] [blame] | 35 | |
Benjamin Lerman | acf32fb | 2015-03-24 10:54:37 +0100 | [diff] [blame] | 36 | std::vector<std::string> Concatenate(const std::vector<std::string>& v1, |
| 37 | const std::vector<std::string>& v2) { |
| 38 | if (!v1.size()) |
| 39 | return v2; |
| 40 | if (!v2.size()) |
| 41 | return v1; |
| 42 | std::vector<std::string> result(v1); |
| 43 | result.insert(result.end(), v1.begin(), v1.end()); |
| 44 | return result; |
| 45 | } |
| 46 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 47 | } // namespace |
| 48 | |
Viet-Trung Luu | 01e64cf | 2015-07-08 09:55:53 -0700 | [diff] [blame] | 49 | class ApplicationManager::ContentHandlerConnection { |
Benjamin Lerman | 7c05714 | 2014-10-31 18:23:10 +0100 | [diff] [blame] | 50 | public: |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 51 | ContentHandlerConnection(ApplicationManager* manager, |
Benjamin Lerman | 7c05714 | 2014-10-31 18:23:10 +0100 | [diff] [blame] | 52 | const GURL& content_handler_url) |
| 53 | : manager_(manager), content_handler_url_(content_handler_url) { |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 54 | ServiceProviderPtr services; |
James Robinson | 3217bf3 | 2015-01-14 14:33:07 -0800 | [diff] [blame] | 55 | manager->ConnectToApplication(content_handler_url, GURL(), |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 56 | mojo::GetProxy(&services), nullptr, |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 57 | base::Closure()); |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 58 | mojo::MessagePipe pipe; |
yzshen | 5bae223 | 2015-05-04 14:47:01 -0700 | [diff] [blame] | 59 | content_handler_.Bind( |
| 60 | mojo::InterfacePtrInfo<mojo::ContentHandler>(pipe.handle0.Pass(), 0u)); |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 61 | services->ConnectToService(mojo::ContentHandler::Name_, |
| 62 | pipe.handle1.Pass()); |
Viet-Trung Luu | 01e64cf | 2015-07-08 09:55:53 -0700 | [diff] [blame] | 63 | content_handler_.set_connection_error_handler( |
| 64 | [this]() { manager_->OnContentHandlerError(this); }); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 65 | } |
Viet-Trung Luu | 01e64cf | 2015-07-08 09:55:53 -0700 | [diff] [blame] | 66 | ~ContentHandlerConnection() {} |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 67 | |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 68 | mojo::ContentHandler* content_handler() { return content_handler_.get(); } |
Benjamin Lerman | 7c05714 | 2014-10-31 18:23:10 +0100 | [diff] [blame] | 69 | |
| 70 | GURL content_handler_url() { return content_handler_url_; } |
| 71 | |
| 72 | private: |
Benjamin Lerman | 7c05714 | 2014-10-31 18:23:10 +0100 | [diff] [blame] | 73 | ApplicationManager* manager_; |
| 74 | GURL content_handler_url_; |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 75 | mojo::ContentHandlerPtr content_handler_; |
Benjamin Lerman | 7c05714 | 2014-10-31 18:23:10 +0100 | [diff] [blame] | 76 | |
| 77 | DISALLOW_COPY_AND_ASSIGN(ContentHandlerConnection); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | // static |
| 81 | ApplicationManager::TestAPI::TestAPI(ApplicationManager* manager) |
| 82 | : manager_(manager) { |
| 83 | } |
| 84 | |
| 85 | ApplicationManager::TestAPI::~TestAPI() { |
| 86 | } |
| 87 | |
| 88 | bool ApplicationManager::TestAPI::HasCreatedInstance() { |
| 89 | return has_created_instance; |
| 90 | } |
| 91 | |
| 92 | bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const { |
Benjamin Lerman | 71f5607 | 2015-03-12 15:04:50 +0100 | [diff] [blame] | 93 | return manager_->identity_to_shell_impl_.find(Identity(url)) != |
| 94 | manager_->identity_to_shell_impl_.end(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Viet-Trung Luu | 988b4be | 2015-05-15 13:00:15 -0700 | [diff] [blame] | 97 | ApplicationManager::ApplicationManager(const Options& options, |
| 98 | Delegate* delegate) |
| 99 | : options_(options), |
| 100 | delegate_(delegate), |
Viet-Trung Luu | 768bef7 | 2015-05-14 15:20:45 -0700 | [diff] [blame] | 101 | blocking_pool_(nullptr), |
Colin Blundell | 8ca4d65 | 2015-06-05 16:41:30 +0200 | [diff] [blame] | 102 | initialized_authentication_interceptor_(false), |
Viet-Trung Luu | 768bef7 | 2015-05-14 15:20:45 -0700 | [diff] [blame] | 103 | weak_ptr_factory_(this) { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | ApplicationManager::~ApplicationManager() { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | void ApplicationManager::TerminateShellConnections() { |
Viet-Trung Luu | b3cadd2 | 2015-05-14 15:57:05 -0700 | [diff] [blame] | 110 | identity_to_shell_impl_.clear(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 111 | } |
| 112 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 113 | void ApplicationManager::ConnectToApplication( |
Aaron Boodman | cd7b911 | 2014-11-06 21:44:49 -0800 | [diff] [blame] | 114 | const GURL& requested_url, |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 115 | const GURL& requestor_url, |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 116 | InterfaceRequest<ServiceProvider> services, |
| 117 | ServiceProviderPtr exposed_services, |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 118 | const base::Closure& on_application_end) { |
| 119 | ConnectToApplicationWithParameters( |
| 120 | requested_url, requestor_url, services.Pass(), exposed_services.Pass(), |
| 121 | on_application_end, std::vector<std::string>()); |
Benjamin Lerman | acf32fb | 2015-03-24 10:54:37 +0100 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | void ApplicationManager::ConnectToApplicationWithParameters( |
| 125 | const GURL& requested_url, |
| 126 | const GURL& requestor_url, |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 127 | InterfaceRequest<ServiceProvider> services, |
| 128 | ServiceProviderPtr exposed_services, |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 129 | const base::Closure& on_application_end, |
Benjamin Lerman | 128ca7d | 2015-03-24 12:02:49 +0100 | [diff] [blame] | 130 | const std::vector<std::string>& pre_redirect_parameters) { |
Benjamin Lerman | 9354566 | 2015-08-03 11:51:19 +0200 | [diff] [blame] | 131 | TRACE_EVENT_INSTANT2( |
James Robinson | 6bbb9e0 | 2015-03-27 13:42:35 -0700 | [diff] [blame] | 132 | "mojo_shell", "ApplicationManager::ConnectToApplicationWithParameters", |
Benjamin Lerman | 9354566 | 2015-08-03 11:51:19 +0200 | [diff] [blame] | 133 | TRACE_EVENT_SCOPE_THREAD, "requested_url", requested_url.spec(), |
| 134 | "requestor_url", requestor_url.spec()); |
Alexandre Zani | 22190df | 2014-11-21 10:02:28 -0800 | [diff] [blame] | 135 | DCHECK(requested_url.is_valid()); |
Dave Moore | 0504d06 | 2015-01-23 15:33:29 -0800 | [diff] [blame] | 136 | |
| 137 | // We check both the mapped and resolved urls for existing shell_impls because |
| 138 | // external applications can be registered for the unresolved mojo:foo urls. |
Aaron Boodman | bfc1118 | 2015-02-19 12:42:19 -0800 | [diff] [blame] | 139 | |
| 140 | GURL mapped_url = delegate_->ResolveMappings(requested_url); |
| 141 | if (ConnectToRunningApplication(mapped_url, requestor_url, &services, |
| 142 | &exposed_services)) { |
Dave Moore | 0504d06 | 2015-01-23 15:33:29 -0800 | [diff] [blame] | 143 | return; |
| 144 | } |
| 145 | |
Benjamin Lerman | 605969e | 2015-04-30 13:51:04 +0200 | [diff] [blame] | 146 | GURL resolved_url = delegate_->ResolveMojoURL(mapped_url); |
Aaron Boodman | bfc1118 | 2015-02-19 12:42:19 -0800 | [diff] [blame] | 147 | if (ConnectToRunningApplication(resolved_url, requestor_url, &services, |
| 148 | &exposed_services)) { |
Dave Moore | 0504d06 | 2015-01-23 15:33:29 -0800 | [diff] [blame] | 149 | return; |
| 150 | } |
| 151 | |
Benjamin Lerman | 128ca7d | 2015-03-24 12:02:49 +0100 | [diff] [blame] | 152 | // The application is not running, let's compute the parameters. |
| 153 | std::vector<std::string> parameters = |
| 154 | Concatenate(pre_redirect_parameters, GetArgsForURL(resolved_url)); |
| 155 | |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 156 | if (ConnectToApplicationWithLoader(mapped_url, requestor_url, &services, |
| 157 | &exposed_services, on_application_end, |
| 158 | parameters, GetLoaderForURL(mapped_url))) { |
Aaron Boodman | cd7b911 | 2014-11-06 21:44:49 -0800 | [diff] [blame] | 159 | return; |
| 160 | } |
| 161 | |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 162 | if (ConnectToApplicationWithLoader( |
| 163 | resolved_url, requestor_url, &services, &exposed_services, |
| 164 | on_application_end, parameters, GetLoaderForURL(resolved_url))) { |
Aaron Boodman | bfc1118 | 2015-02-19 12:42:19 -0800 | [diff] [blame] | 165 | return; |
| 166 | } |
| 167 | |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 168 | if (ConnectToApplicationWithLoader(resolved_url, requestor_url, &services, |
| 169 | &exposed_services, on_application_end, |
| 170 | parameters, default_loader_.get())) { |
Aaron Boodman | bfc1118 | 2015-02-19 12:42:19 -0800 | [diff] [blame] | 171 | return; |
| 172 | } |
| 173 | |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 174 | auto callback = base::Bind( |
| 175 | &ApplicationManager::HandleFetchCallback, weak_ptr_factory_.GetWeakPtr(), |
| 176 | requestor_url, base::Passed(services.Pass()), |
Benjamin Lerman | 4abbaff | 2015-09-01 16:24:06 +0200 | [diff] [blame] | 177 | base::Passed(exposed_services.Pass()), on_application_end, parameters); |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 178 | |
| 179 | if (resolved_url.SchemeIsFile()) { |
Benjamin Lerman | 5d429aa | 2015-05-07 16:21:00 +0200 | [diff] [blame] | 180 | new LocalFetcher(resolved_url, GetBaseURLAndQuery(resolved_url, nullptr), |
| 181 | callback); |
Aaron Boodman | cd7b911 | 2014-11-06 21:44:49 -0800 | [diff] [blame] | 182 | return; |
| 183 | } |
| 184 | |
Colin Blundell | 82e1c7e | 2015-05-26 15:37:46 +0200 | [diff] [blame] | 185 | if (!url_response_disk_cache_) { |
Benjamin Lerman | 5d429aa | 2015-05-07 16:21:00 +0200 | [diff] [blame] | 186 | ConnectToService(GURL("mojo:url_response_disk_cache"), |
| 187 | &url_response_disk_cache_); |
Benjamin Lerman | d15e3f4 | 2015-09-17 11:26:18 +0200 | [diff] [blame] | 188 | ConnectToService(GURL("mojo:network_service"), &network_service_); |
| 189 | ConnectToService(GURL("mojo:network_service"), |
| 190 | &authenticating_network_service_); |
Benjamin Lerman | 5d429aa | 2015-05-07 16:21:00 +0200 | [diff] [blame] | 191 | } |
Scott Violet | ef1cb8c | 2015-03-13 14:01:39 -0700 | [diff] [blame] | 192 | |
Benjamin Lerman | d15e3f4 | 2015-09-17 11:26:18 +0200 | [diff] [blame] | 193 | mojo::NetworkService* network_service = authenticating_network_service_.get(); |
Colin Blundell | 82e1c7e | 2015-05-26 15:37:46 +0200 | [diff] [blame] | 194 | |
Colin Blundell | 8ca4d65 | 2015-06-05 16:41:30 +0200 | [diff] [blame] | 195 | // NOTE: Attempting to initialize the apps used authentication for while |
| 196 | // connecting to those apps would result in a recursive loop, so it has to be |
| 197 | // explicitly avoided here. What this means in practice is that these apps |
| 198 | // cannot themselves require authentication to obtain. |
Benjamin Lerman | d15e3f4 | 2015-09-17 11:26:18 +0200 | [diff] [blame] | 199 | if (EndsWith(resolved_url.path(), "/authentication.mojo", true) || |
| 200 | EndsWith(resolved_url.path(), |
| 201 | "/authenticating_url_loader_interceptor.mojo", true)) { |
| 202 | network_service = network_service_.get(); |
| 203 | } else if (!initialized_authentication_interceptor_) { |
Colin Blundell | 82e1c7e | 2015-05-26 15:37:46 +0200 | [diff] [blame] | 204 | authentication::AuthenticationServicePtr authentication_service; |
| 205 | ConnectToService(GURL("mojo:authentication"), &authentication_service); |
Colin Blundell | cde1f38 | 2015-06-08 14:13:54 +0200 | [diff] [blame] | 206 | mojo::AuthenticatingURLLoaderInterceptorMetaFactoryPtr |
| 207 | interceptor_meta_factory; |
| 208 | ConnectToService(GURL("mojo:authenticating_url_loader_interceptor"), |
| 209 | &interceptor_meta_factory); |
Colin Blundell | 8ca4d65 | 2015-06-05 16:41:30 +0200 | [diff] [blame] | 210 | mojo::URLLoaderInterceptorFactoryPtr interceptor_factory; |
Colin Blundell | cde1f38 | 2015-06-08 14:13:54 +0200 | [diff] [blame] | 211 | interceptor_meta_factory->CreateURLLoaderInterceptorFactory( |
Colin Blundell | 8ca4d65 | 2015-06-05 16:41:30 +0200 | [diff] [blame] | 212 | GetProxy(&interceptor_factory), authentication_service.Pass()); |
Benjamin Lerman | d15e3f4 | 2015-09-17 11:26:18 +0200 | [diff] [blame] | 213 | authenticating_network_service_->RegisterURLLoaderInterceptor( |
| 214 | interceptor_factory.Pass()); |
Colin Blundell | 8ca4d65 | 2015-06-05 16:41:30 +0200 | [diff] [blame] | 215 | initialized_authentication_interceptor_ = true; |
Colin Blundell | 82e1c7e | 2015-05-26 15:37:46 +0200 | [diff] [blame] | 216 | } |
| 217 | |
Benjamin Lerman | 9a25850 | 2015-09-17 16:53:28 +0200 | [diff] [blame] | 218 | new NetworkFetcher(options_.disable_cache, options_.force_offline_by_default, |
| 219 | resolved_url, url_response_disk_cache_.get(), |
| 220 | network_service, callback); |
Aaron Boodman | cd7b911 | 2014-11-06 21:44:49 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Aaron Boodman | bfc1118 | 2015-02-19 12:42:19 -0800 | [diff] [blame] | 223 | bool ApplicationManager::ConnectToRunningApplication( |
Aaron Boodman | b34bcbf | 2015-03-02 10:05:31 -0800 | [diff] [blame] | 224 | const GURL& resolved_url, |
Aaron Boodman | bfc1118 | 2015-02-19 12:42:19 -0800 | [diff] [blame] | 225 | const GURL& requestor_url, |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 226 | InterfaceRequest<ServiceProvider>* services, |
| 227 | ServiceProviderPtr* exposed_services) { |
Benjamin Lerman | 05eccab | 2015-03-05 15:29:39 +0100 | [diff] [blame] | 228 | GURL application_url = GetBaseURLAndQuery(resolved_url, nullptr); |
Aaron Boodman | bfc1118 | 2015-02-19 12:42:19 -0800 | [diff] [blame] | 229 | ShellImpl* shell_impl = GetShellImpl(application_url); |
| 230 | if (!shell_impl) |
| 231 | return false; |
| 232 | |
Aaron Boodman | b34bcbf | 2015-03-02 10:05:31 -0800 | [diff] [blame] | 233 | ConnectToClient(shell_impl, resolved_url, requestor_url, services->Pass(), |
Aaron Boodman | bfc1118 | 2015-02-19 12:42:19 -0800 | [diff] [blame] | 234 | exposed_services->Pass()); |
| 235 | return true; |
| 236 | } |
| 237 | |
| 238 | bool ApplicationManager::ConnectToApplicationWithLoader( |
Aaron Boodman | bfc1118 | 2015-02-19 12:42:19 -0800 | [diff] [blame] | 239 | const GURL& resolved_url, |
| 240 | const GURL& requestor_url, |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 241 | InterfaceRequest<ServiceProvider>* services, |
| 242 | ServiceProviderPtr* exposed_services, |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 243 | const base::Closure& on_application_end, |
Benjamin Lerman | acf32fb | 2015-03-24 10:54:37 +0100 | [diff] [blame] | 244 | const std::vector<std::string>& parameters, |
Aaron Boodman | bfc1118 | 2015-02-19 12:42:19 -0800 | [diff] [blame] | 245 | ApplicationLoader* loader) { |
| 246 | if (!loader) |
| 247 | return false; |
| 248 | |
Benjamin Lerman | acf32fb | 2015-03-24 10:54:37 +0100 | [diff] [blame] | 249 | loader->Load( |
| 250 | resolved_url, |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 251 | RegisterShell(resolved_url, requestor_url, services->Pass(), |
| 252 | exposed_services->Pass(), on_application_end, parameters)); |
Aaron Boodman | bfc1118 | 2015-02-19 12:42:19 -0800 | [diff] [blame] | 253 | return true; |
| 254 | } |
| 255 | |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 256 | InterfaceRequest<Application> ApplicationManager::RegisterShell( |
Benjamin Lerman | 5170129 | 2014-11-21 10:53:37 +0100 | [diff] [blame] | 257 | const GURL& resolved_url, |
| 258 | const GURL& requestor_url, |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 259 | InterfaceRequest<ServiceProvider> services, |
| 260 | ServiceProviderPtr exposed_services, |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 261 | const base::Closure& on_application_end, |
Benjamin Lerman | acf32fb | 2015-03-24 10:54:37 +0100 | [diff] [blame] | 262 | const std::vector<std::string>& parameters) { |
Benjamin Lerman | 71f5607 | 2015-03-12 15:04:50 +0100 | [diff] [blame] | 263 | Identity app_identity(resolved_url); |
Aaron Boodman | b34bcbf | 2015-03-02 10:05:31 -0800 | [diff] [blame] | 264 | |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 265 | mojo::ApplicationPtr application; |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 266 | InterfaceRequest<Application> application_request = |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 267 | mojo::GetProxy(&application); |
Dave Moore | 0504d06 | 2015-01-23 15:33:29 -0800 | [diff] [blame] | 268 | ShellImpl* shell = |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 269 | new ShellImpl(application.Pass(), this, app_identity, on_application_end); |
Viet-Trung Luu | b3cadd2 | 2015-05-14 15:57:05 -0700 | [diff] [blame] | 270 | identity_to_shell_impl_[app_identity] = make_scoped_ptr(shell); |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 271 | shell->InitializeApplication(mojo::Array<mojo::String>::From(parameters)); |
James Robinson | 3217bf3 | 2015-01-14 14:33:07 -0800 | [diff] [blame] | 272 | ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), |
| 273 | exposed_services.Pass()); |
Viet-Trung Luu | b792c80 | 2015-10-27 11:27:35 -0700 | [diff] [blame] | 274 | return application_request; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Dave Moore | 0504d06 | 2015-01-23 15:33:29 -0800 | [diff] [blame] | 277 | ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) { |
Benjamin Lerman | 71f5607 | 2015-03-12 15:04:50 +0100 | [diff] [blame] | 278 | const auto& shell_it = identity_to_shell_impl_.find(Identity(url)); |
| 279 | if (shell_it != identity_to_shell_impl_.end()) |
Viet-Trung Luu | b3cadd2 | 2015-05-14 15:57:05 -0700 | [diff] [blame] | 280 | return shell_it->second.get(); |
Dave Moore | 0504d06 | 2015-01-23 15:33:29 -0800 | [diff] [blame] | 281 | return nullptr; |
| 282 | } |
| 283 | |
James Robinson | 3217bf3 | 2015-01-14 14:33:07 -0800 | [diff] [blame] | 284 | void ApplicationManager::ConnectToClient( |
| 285 | ShellImpl* shell_impl, |
Aaron Boodman | b34bcbf | 2015-03-02 10:05:31 -0800 | [diff] [blame] | 286 | const GURL& resolved_url, |
James Robinson | 3217bf3 | 2015-01-14 14:33:07 -0800 | [diff] [blame] | 287 | const GURL& requestor_url, |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 288 | InterfaceRequest<ServiceProvider> services, |
| 289 | ServiceProviderPtr exposed_services) { |
Aaron Boodman | b34bcbf | 2015-03-02 10:05:31 -0800 | [diff] [blame] | 290 | shell_impl->ConnectToClient(resolved_url, requestor_url, services.Pass(), |
James Robinson | 3217bf3 | 2015-01-14 14:33:07 -0800 | [diff] [blame] | 291 | exposed_services.Pass()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 294 | void ApplicationManager::HandleFetchCallback( |
Aaron Boodman | df23d13 | 2015-02-25 13:43:19 -0800 | [diff] [blame] | 295 | const GURL& requestor_url, |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 296 | InterfaceRequest<ServiceProvider> services, |
| 297 | ServiceProviderPtr exposed_services, |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 298 | const base::Closure& on_application_end, |
Benjamin Lerman | acf32fb | 2015-03-24 10:54:37 +0100 | [diff] [blame] | 299 | const std::vector<std::string>& parameters, |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 300 | scoped_ptr<Fetcher> fetcher) { |
| 301 | if (!fetcher) { |
| 302 | // Network error. Drop |application_request| to tell requestor. |
| 303 | return; |
| 304 | } |
| 305 | |
Aaron Boodman | df23d13 | 2015-02-25 13:43:19 -0800 | [diff] [blame] | 306 | GURL redirect_url = fetcher->GetRedirectURL(); |
| 307 | if (!redirect_url.is_empty()) { |
| 308 | // And around we go again... Whee! |
Benjamin Lerman | acf32fb | 2015-03-24 10:54:37 +0100 | [diff] [blame] | 309 | ConnectToApplicationWithParameters(redirect_url, requestor_url, |
| 310 | services.Pass(), exposed_services.Pass(), |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 311 | on_application_end, parameters); |
Aaron Boodman | df23d13 | 2015-02-25 13:43:19 -0800 | [diff] [blame] | 312 | return; |
| 313 | } |
| 314 | |
| 315 | // We already checked if the application was running before we fetched it, but |
| 316 | // it might have started while the fetch was outstanding. We don't want to |
| 317 | // have two copies of the app running, so check again. |
| 318 | // |
| 319 | // Also, it's possible the original URL was redirected to an app that is |
| 320 | // already running. |
| 321 | if (ConnectToRunningApplication(fetcher->GetURL(), requestor_url, &services, |
| 322 | &exposed_services)) { |
| 323 | return; |
| 324 | } |
| 325 | |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 326 | InterfaceRequest<Application> request( |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 327 | RegisterShell(fetcher->GetURL(), requestor_url, services.Pass(), |
| 328 | exposed_services.Pass(), on_application_end, parameters)); |
Aaron Boodman | df23d13 | 2015-02-25 13:43:19 -0800 | [diff] [blame] | 329 | |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 330 | // If the response begins with a #!mojo <content-handler-url>, use it. |
Aaron Boodman | df23d13 | 2015-02-25 13:43:19 -0800 | [diff] [blame] | 331 | GURL content_handler_url; |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 332 | std::string shebang; |
Aaron Boodman | df23d13 | 2015-02-25 13:43:19 -0800 | [diff] [blame] | 333 | if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) { |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 334 | LoadWithContentHandler( |
Aaron Boodman | b34bcbf | 2015-03-02 10:05:31 -0800 | [diff] [blame] | 335 | content_handler_url, request.Pass(), |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 336 | fetcher->AsURLResponse(blocking_pool_, |
| 337 | static_cast<int>(shebang.size()))); |
| 338 | return; |
| 339 | } |
| 340 | |
Viet-Trung Luu | b3cadd2 | 2015-05-14 15:57:05 -0700 | [diff] [blame] | 341 | auto it = mime_type_to_url_.find(fetcher->MimeType()); |
| 342 | if (it != mime_type_to_url_.end()) { |
| 343 | LoadWithContentHandler(it->second, request.Pass(), |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 344 | fetcher->AsURLResponse(blocking_pool_, 0)); |
| 345 | return; |
| 346 | } |
| 347 | |
| 348 | // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo |
| 349 | // application. That could either mean looking for the platform-specific dll |
| 350 | // header, or looking for some specific mojo signature prepended to the |
| 351 | // library. |
Viet-Trung Luu | fbf0a4e | 2015-03-04 14:37:27 -0800 | [diff] [blame] | 352 | // TODO(vtl): (Maybe this should be done by the factory/runner?) |
| 353 | |
Viet-Trung Luu | 915cdc5 | 2015-03-09 09:55:30 -0700 | [diff] [blame] | 354 | GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr); |
Viet-Trung Luu | 64bb17c | 2015-10-02 17:02:04 -0700 | [diff] [blame] | 355 | NativeApplicationOptions options; |
Viet-Trung Luu | 915cdc5 | 2015-03-09 09:55:30 -0700 | [diff] [blame] | 356 | if (url_to_native_options_.find(base_resolved_url) != |
Viet-Trung Luu | fbf0a4e | 2015-03-04 14:37:27 -0800 | [diff] [blame] | 357 | url_to_native_options_.end()) { |
| 358 | DVLOG(2) << "Applying stored native options to resolved URL " |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 359 | << fetcher->GetURL(); |
Viet-Trung Luu | 915cdc5 | 2015-03-09 09:55:30 -0700 | [diff] [blame] | 360 | options = url_to_native_options_[base_resolved_url]; |
Viet-Trung Luu | fbf0a4e | 2015-03-04 14:37:27 -0800 | [diff] [blame] | 361 | } |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 362 | |
Benjamin Lerman | 4abbaff | 2015-09-01 16:24:06 +0200 | [diff] [blame] | 363 | TRACE_EVENT_ASYNC_BEGIN1("mojo_shell", "ApplicationManager::RetrievePath", |
| 364 | fetcher.get(), "url", fetcher->GetURL().spec()); |
Aaron Boodman | b34bcbf | 2015-03-02 10:05:31 -0800 | [diff] [blame] | 365 | fetcher->AsPath( |
| 366 | blocking_pool_, |
| 367 | base::Bind(&ApplicationManager::RunNativeApplication, |
| 368 | weak_ptr_factory_.GetWeakPtr(), base::Passed(request.Pass()), |
Benjamin Lerman | 5d429aa | 2015-05-07 16:21:00 +0200 | [diff] [blame] | 369 | options, base::Passed(fetcher.Pass()))); |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void ApplicationManager::RunNativeApplication( |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 373 | InterfaceRequest<Application> application_request, |
Viet-Trung Luu | 64bb17c | 2015-10-02 17:02:04 -0700 | [diff] [blame] | 374 | const NativeApplicationOptions& options, |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 375 | scoped_ptr<Fetcher> fetcher, |
| 376 | const base::FilePath& path, |
| 377 | bool path_exists) { |
Benjamin Lerman | 4abbaff | 2015-09-01 16:24:06 +0200 | [diff] [blame] | 378 | TRACE_EVENT_ASYNC_END0("mojo_shell", "ApplicationManager::RetrievePath", |
| 379 | fetcher.get()); |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 380 | // We only passed fetcher to keep it alive. Done with it now. |
| 381 | fetcher.reset(); |
| 382 | |
| 383 | DCHECK(application_request.is_pending()); |
| 384 | |
| 385 | if (!path_exists) { |
| 386 | LOG(ERROR) << "Library not started because library path '" << path.value() |
| 387 | << "' does not exist."; |
| 388 | return; |
| 389 | } |
| 390 | |
James Robinson | 6bbb9e0 | 2015-03-27 13:42:35 -0700 | [diff] [blame] | 391 | TRACE_EVENT1("mojo_shell", "ApplicationManager::RunNativeApplication", "path", |
| 392 | path.AsUTF8Unsafe()); |
Viet-Trung Luu | fbf0a4e | 2015-03-04 14:37:27 -0800 | [diff] [blame] | 393 | NativeRunner* runner = native_runner_factory_->Create(options).release(); |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 394 | native_runners_.push_back(runner); |
Benjamin Lerman | 5d429aa | 2015-05-07 16:21:00 +0200 | [diff] [blame] | 395 | runner->Start(path, application_request.Pass(), |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 396 | base::Bind(&ApplicationManager::CleanupRunner, |
| 397 | weak_ptr_factory_.GetWeakPtr(), runner)); |
| 398 | } |
| 399 | |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 400 | void ApplicationManager::RegisterContentHandler( |
| 401 | const std::string& mime_type, |
| 402 | const GURL& content_handler_url) { |
| 403 | DCHECK(content_handler_url.is_valid()) |
| 404 | << "Content handler URL is invalid for mime type " << mime_type; |
| 405 | mime_type_to_url_[mime_type] = content_handler_url; |
| 406 | } |
| 407 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 408 | void ApplicationManager::LoadWithContentHandler( |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 409 | const GURL& content_handler_url, |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 410 | InterfaceRequest<Application> application_request, |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 411 | mojo::URLResponsePtr url_response) { |
Viet-Trung Luu | 36faa4d | 2015-03-04 18:08:18 -0800 | [diff] [blame] | 412 | ContentHandlerConnection* connection = nullptr; |
Viet-Trung Luu | b3cadd2 | 2015-05-14 15:57:05 -0700 | [diff] [blame] | 413 | auto it = url_to_content_handler_.find(content_handler_url); |
| 414 | if (it != url_to_content_handler_.end()) { |
| 415 | connection = it->second.get(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 416 | } else { |
| 417 | connection = new ContentHandlerConnection(this, content_handler_url); |
Viet-Trung Luu | b3cadd2 | 2015-05-14 15:57:05 -0700 | [diff] [blame] | 418 | url_to_content_handler_[content_handler_url] = make_scoped_ptr(connection); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 419 | } |
| 420 | |
James Robinson | e5ae9e4 | 2015-01-26 17:53:08 -0800 | [diff] [blame] | 421 | connection->content_handler()->StartApplication(application_request.Pass(), |
| 422 | url_response.Pass()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, |
| 426 | const GURL& url) { |
Viet-Trung Luu | b3cadd2 | 2015-05-14 15:57:05 -0700 | [diff] [blame] | 427 | url_to_loader_[url] = loader.Pass(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | void ApplicationManager::SetLoaderForScheme( |
| 431 | scoped_ptr<ApplicationLoader> loader, |
| 432 | const std::string& scheme) { |
Viet-Trung Luu | b3cadd2 | 2015-05-14 15:57:05 -0700 | [diff] [blame] | 433 | scheme_to_loader_[scheme] = loader.Pass(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | void ApplicationManager::SetArgsForURL(const std::vector<std::string>& args, |
| 437 | const GURL& url) { |
Benjamin Lerman | acf32fb | 2015-03-24 10:54:37 +0100 | [diff] [blame] | 438 | url_to_args_[url].insert(url_to_args_[url].end(), args.begin(), args.end()); |
| 439 | GURL mapped_url = delegate_->ResolveMappings(url); |
| 440 | if (mapped_url != url) { |
| 441 | url_to_args_[mapped_url].insert(url_to_args_[mapped_url].end(), |
| 442 | args.begin(), args.end()); |
| 443 | } |
Benjamin Lerman | 605969e | 2015-04-30 13:51:04 +0200 | [diff] [blame] | 444 | GURL resolved_url = delegate_->ResolveMojoURL(mapped_url); |
Benjamin Lerman | acf32fb | 2015-03-24 10:54:37 +0100 | [diff] [blame] | 445 | if (resolved_url != mapped_url) { |
| 446 | url_to_args_[resolved_url].insert(url_to_args_[resolved_url].end(), |
| 447 | args.begin(), args.end()); |
| 448 | } |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Viet-Trung Luu | 64bb17c | 2015-10-02 17:02:04 -0700 | [diff] [blame] | 451 | NativeApplicationOptions* ApplicationManager::GetNativeApplicationOptionsForURL( |
Viet-Trung Luu | fbf0a4e | 2015-03-04 14:37:27 -0800 | [diff] [blame] | 452 | const GURL& url) { |
Viet-Trung Luu | 915cdc5 | 2015-03-09 09:55:30 -0700 | [diff] [blame] | 453 | DCHECK(!url.has_query()); // Precondition. |
Viet-Trung Luu | fbf0a4e | 2015-03-04 14:37:27 -0800 | [diff] [blame] | 454 | // Apply mappings and resolution to get the resolved URL. |
Benjamin Lerman | 605969e | 2015-04-30 13:51:04 +0200 | [diff] [blame] | 455 | GURL resolved_url = |
| 456 | delegate_->ResolveMojoURL(delegate_->ResolveMappings(url)); |
Viet-Trung Luu | fbf0a4e | 2015-03-04 14:37:27 -0800 | [diff] [blame] | 457 | // TODO(vtl): We should probably also remove/disregard the query string (and |
| 458 | // maybe canonicalize in other ways). |
Viet-Trung Luu | 64bb17c | 2015-10-02 17:02:04 -0700 | [diff] [blame] | 459 | DCHECK(!resolved_url.has_query()); // Still shouldn't have query. |
| 460 | return &url_to_native_options_[resolved_url]; |
Viet-Trung Luu | fbf0a4e | 2015-03-04 14:37:27 -0800 | [diff] [blame] | 461 | } |
| 462 | |
Aaron Boodman | bfc1118 | 2015-02-19 12:42:19 -0800 | [diff] [blame] | 463 | ApplicationLoader* ApplicationManager::GetLoaderForURL(const GURL& url) { |
Benjamin Lerman | 05eccab | 2015-03-05 15:29:39 +0100 | [diff] [blame] | 464 | auto url_it = url_to_loader_.find(GetBaseURLAndQuery(url, nullptr)); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 465 | if (url_it != url_to_loader_.end()) |
Viet-Trung Luu | b3cadd2 | 2015-05-14 15:57:05 -0700 | [diff] [blame] | 466 | return url_it->second.get(); |
Aaron Boodman | cd7b911 | 2014-11-06 21:44:49 -0800 | [diff] [blame] | 467 | auto scheme_it = scheme_to_loader_.find(url.scheme()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 468 | if (scheme_it != scheme_to_loader_.end()) |
Viet-Trung Luu | b3cadd2 | 2015-05-14 15:57:05 -0700 | [diff] [blame] | 469 | return scheme_it->second.get(); |
Viet-Trung Luu | 36faa4d | 2015-03-04 18:08:18 -0800 | [diff] [blame] | 470 | return nullptr; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) { |
| 474 | // Called from ~ShellImpl, so we do not need to call Destroy here. |
Benjamin Lerman | 71f5607 | 2015-03-12 15:04:50 +0100 | [diff] [blame] | 475 | const Identity identity = shell_impl->identity(); |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 476 | base::Closure on_application_end = shell_impl->on_application_end(); |
Benjamin Lerman | 7c05714 | 2014-10-31 18:23:10 +0100 | [diff] [blame] | 477 | // Remove the shell. |
Benjamin Lerman | 71f5607 | 2015-03-12 15:04:50 +0100 | [diff] [blame] | 478 | auto it = identity_to_shell_impl_.find(identity); |
| 479 | DCHECK(it != identity_to_shell_impl_.end()); |
Benjamin Lerman | 71f5607 | 2015-03-12 15:04:50 +0100 | [diff] [blame] | 480 | identity_to_shell_impl_.erase(it); |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 481 | if (!on_application_end.is_null()) |
| 482 | on_application_end.Run(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Benjamin Lerman | 7c05714 | 2014-10-31 18:23:10 +0100 | [diff] [blame] | 485 | void ApplicationManager::OnContentHandlerError( |
| 486 | ContentHandlerConnection* content_handler) { |
| 487 | // Remove the mapping to the content handler. |
| 488 | auto it = |
| 489 | url_to_content_handler_.find(content_handler->content_handler_url()); |
| 490 | DCHECK(it != url_to_content_handler_.end()); |
Benjamin Lerman | 7c05714 | 2014-10-31 18:23:10 +0100 | [diff] [blame] | 491 | url_to_content_handler_.erase(it); |
| 492 | } |
| 493 | |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 494 | mojo::ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 495 | const GURL& application_url, |
| 496 | const std::string& interface_name) { |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 497 | ServiceProviderPtr services; |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 498 | ConnectToApplication(application_url, GURL(), mojo::GetProxy(&services), |
| 499 | nullptr, base::Closure()); |
| 500 | mojo::MessagePipe pipe; |
James Robinson | 3217bf3 | 2015-01-14 14:33:07 -0800 | [diff] [blame] | 501 | services->ConnectToService(interface_name, pipe.handle1.Pass()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 502 | return pipe.handle0.Pass(); |
| 503 | } |
Benjamin Lerman | 7c05714 | 2014-10-31 18:23:10 +0100 | [diff] [blame] | 504 | |
Benjamin Lerman | acf32fb | 2015-03-24 10:54:37 +0100 | [diff] [blame] | 505 | std::vector<std::string> ApplicationManager::GetArgsForURL(const GURL& url) { |
Dave Moore | c5ee10b | 2015-01-29 09:44:24 -0800 | [diff] [blame] | 506 | const auto& args_it = url_to_args_.find(url); |
Benjamin Lerman | 7c05714 | 2014-10-31 18:23:10 +0100 | [diff] [blame] | 507 | if (args_it != url_to_args_.end()) |
Benjamin Lerman | acf32fb | 2015-03-24 10:54:37 +0100 | [diff] [blame] | 508 | return args_it->second; |
| 509 | return std::vector<std::string>(); |
Benjamin Lerman | 7c05714 | 2014-10-31 18:23:10 +0100 | [diff] [blame] | 510 | } |
Aaron Boodman | 5e7f904 | 2015-02-24 17:37:34 -0800 | [diff] [blame] | 511 | |
| 512 | void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
| 513 | native_runners_.erase( |
| 514 | std::find(native_runners_.begin(), native_runners_.end(), runner)); |
| 515 | } |
| 516 | |
Viet-Trung Luu | 36faa4d | 2015-03-04 18:08:18 -0800 | [diff] [blame] | 517 | } // namespace shell |