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/shell/application_manager.h" | 5 #include "mojo/shell/application_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 STLDeleteValues(&url_to_loader_); | 66 STLDeleteValues(&url_to_loader_); |
67 STLDeleteValues(&scheme_to_loader_); | 67 STLDeleteValues(&scheme_to_loader_); |
68 } | 68 } |
69 | 69 |
70 void ApplicationManager::TerminateShellConnections() { | 70 void ApplicationManager::TerminateShellConnections() { |
71 STLDeleteValues(&identity_to_instance_); | 71 STLDeleteValues(&identity_to_instance_); |
72 } | 72 } |
73 | 73 |
74 void ApplicationManager::ConnectToApplication( | 74 void ApplicationManager::ConnectToApplication( |
75 ApplicationInstance* originator, | 75 ApplicationInstance* originator, |
76 mojo::URLRequestPtr requested_url, | 76 URLRequestPtr requested_url, |
77 const std::string& qualifier, | 77 const std::string& qualifier, |
78 const GURL& requestor_url, | 78 const GURL& requestor_url, |
79 InterfaceRequest<ServiceProvider> services, | 79 InterfaceRequest<ServiceProvider> services, |
80 ServiceProviderPtr exposed_services, | 80 ServiceProviderPtr exposed_services, |
81 const CapabilityFilter& filter, | 81 const CapabilityFilter& capability_filter, |
82 const base::Closure& on_application_end, | 82 const base::Closure& on_application_end, |
83 const Shell::ConnectToApplicationCallback& connect_callback) { | 83 const Shell::ConnectToApplicationCallback& connect_callback) { |
84 GURL requested_gurl(requested_url->url.To<std::string>()); | 84 DCHECK(requestor_url.is_empty()); |
85 TRACE_EVENT_INSTANT1( | 85 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
86 "mojo_shell", "ApplicationManager::ConnectToApplication", | 86 params->SetOriginatorInfo(originator); |
87 TRACE_EVENT_SCOPE_THREAD, "requested_url", requested_gurl.spec()); | 87 params->SetURLInfo(requested_url.Pass()); |
88 DCHECK(requested_gurl.is_valid()); | 88 params->set_qualifier(qualifier); |
| 89 params->set_services(services.Pass()); |
| 90 params->set_exposed_services(exposed_services.Pass()); |
| 91 params->set_filter(capability_filter); |
| 92 params->set_on_application_end(on_application_end); |
| 93 params->set_connect_callback(connect_callback); |
| 94 |
| 95 ConnectToApplication(params.Pass()); |
| 96 } |
| 97 |
| 98 void ApplicationManager::ConnectToApplication( |
| 99 scoped_ptr<ConnectToApplicationParams> params) { |
| 100 GURL original_url = params->app_url(); |
| 101 URLRequestPtr original_url_request = params->TakeAppURLRequest(); |
| 102 |
| 103 TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication", |
| 104 TRACE_EVENT_SCOPE_THREAD, "original_url", |
| 105 original_url.spec()); |
| 106 DCHECK(original_url.is_valid()); |
| 107 DCHECK(original_url_request); |
89 | 108 |
90 // We check both the mapped and resolved urls for existing instances because | 109 // We check both the mapped and resolved urls for existing instances because |
91 // external applications can be registered for the unresolved mojo:foo urls. | 110 // external applications can be registered for the unresolved mojo:foo urls. |
92 | 111 |
93 GURL mapped_url = delegate_->ResolveMappings(requested_gurl); | 112 GURL mapped_url = delegate_->ResolveMappings(original_url); |
94 if (ConnectToRunningApplication(originator, mapped_url, qualifier, | 113 params->SetURLInfo(mapped_url); |
95 requestor_url, &services, &exposed_services, | 114 if (ConnectToRunningApplication(¶ms)) |
96 filter, connect_callback)) { | 115 return; |
| 116 |
| 117 GURL resolved_url = delegate_->ResolveMojoURL(mapped_url); |
| 118 params->SetURLInfo(resolved_url); |
| 119 if (ConnectToRunningApplication(¶ms)) |
| 120 return; |
| 121 |
| 122 // The application is not running, let's compute the parameters. |
| 123 // NOTE: Set URL info using |original_url_request| instead of |original_url| |
| 124 // because it may contain more information (e.g., it is a POST request). |
| 125 params->SetURLInfo(original_url_request.Pass()); |
| 126 if (ConnectToApplicationWithLoader(¶ms, mapped_url, |
| 127 GetLoaderForURL(mapped_url))) { |
97 return; | 128 return; |
98 } | 129 } |
99 | 130 |
100 GURL resolved_url = delegate_->ResolveMojoURL(mapped_url); | 131 if (ConnectToApplicationWithLoader(¶ms, resolved_url, |
101 if (ConnectToRunningApplication(originator, resolved_url, qualifier, | 132 GetLoaderForURL(resolved_url))) { |
102 requestor_url, &services, &exposed_services, | |
103 filter, connect_callback)) { | |
104 return; | 133 return; |
105 } | 134 } |
106 | 135 |
107 // The application is not running, let's compute the parameters. | 136 if (ConnectToApplicationWithLoader(¶ms, resolved_url, |
108 if (ConnectToApplicationWithLoader( | 137 default_loader_.get())) { |
109 originator, requested_gurl, qualifier, mapped_url, requestor_url, | |
110 &services, &exposed_services, filter, on_application_end, | |
111 connect_callback, GetLoaderForURL(mapped_url))) { | |
112 return; | 138 return; |
113 } | 139 } |
114 | 140 |
115 if (ConnectToApplicationWithLoader( | 141 original_url_request = params->TakeAppURLRequest(); |
116 originator, requested_gurl, qualifier, resolved_url, requestor_url, | 142 auto callback = |
117 &services, &exposed_services, filter, on_application_end, | 143 base::Bind(&ApplicationManager::HandleFetchCallback, |
118 connect_callback, GetLoaderForURL(resolved_url))) { | 144 weak_ptr_factory_.GetWeakPtr(), base::Passed(¶ms)); |
119 return; | |
120 } | |
121 | |
122 if (ConnectToApplicationWithLoader( | |
123 originator, requested_gurl, qualifier, resolved_url, requestor_url, | |
124 &services, &exposed_services, filter, on_application_end, | |
125 connect_callback, default_loader_.get())) { | |
126 return; | |
127 } | |
128 | |
129 auto callback = base::Bind( | |
130 &ApplicationManager::HandleFetchCallback, weak_ptr_factory_.GetWeakPtr(), | |
131 originator, requested_gurl, qualifier, requestor_url, | |
132 base::Passed(services.Pass()), base::Passed(exposed_services.Pass()), | |
133 filter, on_application_end, connect_callback); | |
134 | 145 |
135 if (delegate_->CreateFetcher( | 146 if (delegate_->CreateFetcher( |
136 resolved_url, | 147 resolved_url, |
137 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE))) { | 148 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE))) { |
138 return; | 149 return; |
139 } | 150 } |
140 | 151 |
141 if (resolved_url.SchemeIsFile()) { | 152 if (resolved_url.SchemeIsFile()) { |
142 // LocalFetcher uses the network service to infer MIME types from URLs. | 153 // LocalFetcher uses the network service to infer MIME types from URLs. |
143 // Skip this for mojo URLs to avoid recursively loading the network service. | 154 // Skip this for mojo URLs to avoid recursively loading the network service. |
144 if (!network_service_ && !requested_gurl.SchemeIs("mojo")) | 155 if (!network_service_ && !original_url.SchemeIs("mojo")) |
145 ConnectToService(GURL("mojo:network_service"), &network_service_); | 156 ConnectToService(GURL("mojo:network_service"), &network_service_); |
146 new LocalFetcher( | 157 new LocalFetcher( |
147 network_service_.get(), resolved_url, | 158 network_service_.get(), resolved_url, |
148 GetBaseURLAndQuery(resolved_url, nullptr), | 159 GetBaseURLAndQuery(resolved_url, nullptr), |
149 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE)); | 160 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE)); |
150 return; | 161 return; |
151 } | 162 } |
152 | 163 |
153 if (mapped_url.SchemeIs("mojo") && | 164 if (mapped_url.SchemeIs("mojo") && |
154 base::CommandLine::ForCurrentProcess()->HasSwitch( | 165 base::CommandLine::ForCurrentProcess()->HasSwitch( |
155 switches::kUseUpdater)) { | 166 switches::kUseUpdater)) { |
156 ConnectToService(GURL("mojo:updater"), &updater_); | 167 ConnectToService(GURL("mojo:updater"), &updater_); |
157 new UpdateFetcher( | 168 new UpdateFetcher( |
158 mapped_url, updater_.get(), | 169 mapped_url, updater_.get(), |
159 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE)); | 170 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE)); |
160 return; | 171 return; |
161 } | 172 } |
162 | 173 |
163 if (!url_loader_factory_) | 174 if (!url_loader_factory_) |
164 ConnectToService(GURL("mojo:network_service"), &url_loader_factory_); | 175 ConnectToService(GURL("mojo:network_service"), &url_loader_factory_); |
165 | 176 |
166 const NativeApplicationCleanup cleanup = | 177 const NativeApplicationCleanup cleanup = |
167 base::CommandLine::ForCurrentProcess()->HasSwitch( | 178 base::CommandLine::ForCurrentProcess()->HasSwitch( |
168 switches::kDontDeleteOnDownload) | 179 switches::kDontDeleteOnDownload) |
169 ? NativeApplicationCleanup::DONT_DELETE | 180 ? NativeApplicationCleanup::DONT_DELETE |
170 : NativeApplicationCleanup::DELETE; | 181 : NativeApplicationCleanup::DELETE; |
171 | 182 |
172 if (requested_gurl.SchemeIs("mojo")) { | 183 if (original_url.SchemeIs("mojo")) { |
173 // Use the resolved mojo URL in the request to support origin mapping, etc. | 184 // Use the resolved mojo URL in the request to support origin mapping, etc. |
174 mojo::URLRequestPtr resolved_url_request(mojo::URLRequest::New()); | 185 URLRequestPtr resolved_url_request(URLRequest::New()); |
175 resolved_url_request->url = resolved_url.spec(); | 186 resolved_url_request->url = resolved_url.spec(); |
176 new NetworkFetcher(disable_cache_, resolved_url_request.Pass(), | 187 new NetworkFetcher(disable_cache_, resolved_url_request.Pass(), |
177 url_loader_factory_.get(), | 188 url_loader_factory_.get(), |
178 base::Bind(callback, cleanup)); | 189 base::Bind(callback, cleanup)); |
179 return; | 190 return; |
180 } | 191 } |
181 | 192 |
182 new NetworkFetcher(disable_cache_, requested_url.Pass(), | 193 new NetworkFetcher(disable_cache_, original_url_request.Pass(), |
183 url_loader_factory_.get(), base::Bind(callback, cleanup)); | 194 url_loader_factory_.get(), base::Bind(callback, cleanup)); |
184 } | 195 } |
185 | 196 |
186 bool ApplicationManager::ConnectToRunningApplication( | 197 bool ApplicationManager::ConnectToRunningApplication( |
187 ApplicationInstance* originator, | 198 scoped_ptr<ConnectToApplicationParams>* params) { |
188 const GURL& resolved_url, | 199 ApplicationInstance* instance = GetApplicationInstance( |
189 const std::string& qualifier, | 200 Identity((*params)->app_url(), (*params)->qualifier())); |
190 const GURL& requestor_url, | |
191 InterfaceRequest<ServiceProvider>* services, | |
192 ServiceProviderPtr* exposed_services, | |
193 const CapabilityFilter& filter, | |
194 const Shell::ConnectToApplicationCallback& connect_callback) { | |
195 ApplicationInstance* instance = | |
196 GetApplicationInstance(Identity(resolved_url, qualifier)); | |
197 if (!instance) | 201 if (!instance) |
198 return false; | 202 return false; |
199 | 203 |
200 instance->ConnectToClient(originator, resolved_url, requestor_url, | 204 instance->ConnectToClient(params->Pass()); |
201 services->Pass(), exposed_services->Pass(), filter, | |
202 connect_callback); | |
203 return true; | 205 return true; |
204 } | 206 } |
205 | 207 |
206 bool ApplicationManager::ConnectToApplicationWithLoader( | 208 bool ApplicationManager::ConnectToApplicationWithLoader( |
207 ApplicationInstance* originator, | 209 scoped_ptr<ConnectToApplicationParams>* params, |
208 const GURL& requested_url, | |
209 const std::string& qualifier, | |
210 const GURL& resolved_url, | 210 const GURL& resolved_url, |
211 const GURL& requestor_url, | |
212 InterfaceRequest<ServiceProvider>* services, | |
213 ServiceProviderPtr* exposed_services, | |
214 const CapabilityFilter& filter, | |
215 const base::Closure& on_application_end, | |
216 const Shell::ConnectToApplicationCallback& connect_callback, | |
217 ApplicationLoader* loader) { | 211 ApplicationLoader* loader) { |
218 if (!loader) | 212 if (!loader) |
219 return false; | 213 return false; |
220 | 214 |
221 const GURL app_url = | 215 if (!(*params)->app_url().SchemeIs("mojo")) |
222 requested_url.SchemeIs("mojo") ? requested_url : resolved_url; | 216 (*params)->SetURLInfo(resolved_url); |
223 | 217 |
224 loader->Load( | 218 loader->Load(resolved_url, RegisterInstance(params->Pass(), nullptr)); |
225 resolved_url, | |
226 RegisterInstance(originator, app_url, qualifier, requestor_url, | |
227 services->Pass(), exposed_services->Pass(), filter, | |
228 on_application_end, connect_callback, nullptr)); | |
229 return true; | 219 return true; |
230 } | 220 } |
231 | 221 |
232 InterfaceRequest<Application> ApplicationManager::RegisterInstance( | 222 InterfaceRequest<Application> ApplicationManager::RegisterInstance( |
233 ApplicationInstance* originator, | 223 scoped_ptr<ConnectToApplicationParams> params, |
234 const GURL& app_url, | |
235 const std::string& qualifier, | |
236 const GURL& requestor_url, | |
237 InterfaceRequest<ServiceProvider> services, | |
238 ServiceProviderPtr exposed_services, | |
239 const CapabilityFilter& filter, | |
240 const base::Closure& on_application_end, | |
241 const Shell::ConnectToApplicationCallback& connect_callback, | |
242 ApplicationInstance** resulting_instance) { | 224 ApplicationInstance** resulting_instance) { |
243 Identity app_identity(app_url, qualifier); | 225 Identity app_identity(params->app_url(), params->qualifier()); |
244 | 226 |
245 ApplicationPtr application; | 227 ApplicationPtr application; |
246 InterfaceRequest<Application> application_request = GetProxy(&application); | 228 InterfaceRequest<Application> application_request = GetProxy(&application); |
247 ApplicationInstance* instance = new ApplicationInstance( | 229 ApplicationInstance* instance = new ApplicationInstance( |
248 application.Pass(), this, | 230 application.Pass(), this, params->originator_identity(), app_identity, |
249 originator ? originator->identity() : Identity(GURL()), app_identity, | 231 params->filter(), Shell::kInvalidContentHandlerID, |
250 filter, Shell::kInvalidContentHandlerID, on_application_end); | 232 params->on_application_end()); |
251 DCHECK(identity_to_instance_.find(app_identity) == | 233 DCHECK(identity_to_instance_.find(app_identity) == |
252 identity_to_instance_.end()); | 234 identity_to_instance_.end()); |
253 identity_to_instance_[app_identity] = instance; | 235 identity_to_instance_[app_identity] = instance; |
254 instance->InitializeApplication(); | 236 instance->InitializeApplication(); |
255 instance->ConnectToClient(originator, app_url, requestor_url, services.Pass(), | 237 instance->ConnectToClient(params.Pass()); |
256 exposed_services.Pass(), filter, connect_callback); | |
257 if (resulting_instance) | 238 if (resulting_instance) |
258 *resulting_instance = instance; | 239 *resulting_instance = instance; |
259 return application_request.Pass(); | 240 return application_request.Pass(); |
260 } | 241 } |
261 | 242 |
262 ApplicationInstance* ApplicationManager::GetApplicationInstance( | 243 ApplicationInstance* ApplicationManager::GetApplicationInstance( |
263 const Identity& identity) const { | 244 const Identity& identity) const { |
264 const auto& instance_it = identity_to_instance_.find(identity); | 245 const auto& instance_it = identity_to_instance_.find(identity); |
265 if (instance_it != identity_to_instance_.end()) | 246 if (instance_it != identity_to_instance_.end()) |
266 return instance_it->second; | 247 return instance_it->second; |
267 return nullptr; | 248 return nullptr; |
268 } | 249 } |
269 | 250 |
270 void ApplicationManager::HandleFetchCallback( | 251 void ApplicationManager::HandleFetchCallback( |
271 ApplicationInstance* originator, | 252 scoped_ptr<ConnectToApplicationParams> params, |
272 const GURL& requested_url, | |
273 const std::string& qualifier, | |
274 const GURL& requestor_url, | |
275 InterfaceRequest<ServiceProvider> services, | |
276 ServiceProviderPtr exposed_services, | |
277 const CapabilityFilter& filter, | |
278 const base::Closure& on_application_end, | |
279 const Shell::ConnectToApplicationCallback& connect_callback, | |
280 NativeApplicationCleanup cleanup, | 253 NativeApplicationCleanup cleanup, |
281 scoped_ptr<Fetcher> fetcher) { | 254 scoped_ptr<Fetcher> fetcher) { |
282 if (!fetcher) { | 255 if (!fetcher) { |
283 // Network error. Drop |application_request| to tell requestor. | 256 // Network error. Drop |params| to tell the requestor. |
284 connect_callback.Run(Shell::kInvalidContentHandlerID); | 257 params->connect_callback().Run(Shell::kInvalidContentHandlerID); |
285 return; | 258 return; |
286 } | 259 } |
287 | 260 |
288 GURL redirect_url = fetcher->GetRedirectURL(); | 261 GURL redirect_url = fetcher->GetRedirectURL(); |
289 if (!redirect_url.is_empty()) { | 262 if (!redirect_url.is_empty()) { |
290 // And around we go again... Whee! | 263 // And around we go again... Whee! |
291 // TODO(sky): this loses |requested_url|. | 264 // TODO(sky): this loses the original URL info. |
292 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 265 URLRequestPtr new_request = URLRequest::New(); |
293 request->url = mojo::String::From(redirect_url.spec()); | 266 new_request->url = redirect_url.spec(); |
294 HttpHeaderPtr header = HttpHeader::New(); | 267 HttpHeaderPtr header = HttpHeader::New(); |
295 header->name = "Referer"; | 268 header->name = "Referer"; |
296 header->value = fetcher->GetRedirectReferer().spec(); | 269 header->value = fetcher->GetRedirectReferer().spec(); |
297 request->headers.push_back(header.Pass()); | 270 new_request->headers.push_back(header.Pass()); |
298 ConnectToApplication(originator, request.Pass(), qualifier, requestor_url, | 271 params->SetURLInfo(new_request.Pass()); |
299 services.Pass(), exposed_services.Pass(), filter, | 272 ConnectToApplication(params.Pass()); |
300 on_application_end, connect_callback); | |
301 return; | 273 return; |
302 } | 274 } |
303 | 275 |
304 // We already checked if the application was running before we fetched it, but | 276 // We already checked if the application was running before we fetched it, but |
305 // it might have started while the fetch was outstanding. We don't want to | 277 // it might have started while the fetch was outstanding. We don't want to |
306 // have two copies of the app running, so check again. | 278 // have two copies of the app running, so check again. |
307 // | 279 // |
308 // Also, it's possible the original URL was redirected to an app that is | 280 // Also, it's possible the original URL was redirected to an app that is |
309 // already running. | 281 // already running. |
310 if (ConnectToRunningApplication(originator, requested_url, qualifier, | 282 if (ConnectToRunningApplication(¶ms)) |
311 requestor_url, &services, &exposed_services, | |
312 filter, connect_callback)) { | |
313 return; | 283 return; |
314 } | |
315 | 284 |
316 const GURL app_url = | 285 if (params->app_url().scheme() != "mojo") |
317 requested_url.scheme() == "mojo" ? requested_url : fetcher->GetURL(); | 286 params->SetURLInfo(fetcher->GetURL()); |
318 | 287 |
| 288 Identity originator_identity = params->originator_identity(); |
| 289 CapabilityFilter originator_filter = params->originator_filter(); |
| 290 CapabilityFilter filter = params->filter(); |
| 291 GURL app_url = params->app_url(); |
| 292 std::string qualifier = params->qualifier(); |
| 293 Shell::ConnectToApplicationCallback connect_callback = |
| 294 params->connect_callback(); |
| 295 params->set_connect_callback(EmptyConnectCallback()); |
319 ApplicationInstance* app = nullptr; | 296 ApplicationInstance* app = nullptr; |
320 InterfaceRequest<Application> request( | 297 InterfaceRequest<Application> request(RegisterInstance(params.Pass(), &app)); |
321 RegisterInstance(originator, app_url, qualifier, requestor_url, | |
322 services.Pass(), exposed_services.Pass(), filter, | |
323 on_application_end, EmptyConnectCallback(), &app)); | |
324 | 298 |
325 // For resources that are loaded with content handlers, we group app instances | 299 // For resources that are loaded with content handlers, we group app instances |
326 // by site. | 300 // by site. |
327 | 301 |
328 // If the response begins with a #!mojo <content-handler-url>, use it. | 302 // If the response begins with a #!mojo <content-handler-url>, use it. |
329 GURL content_handler_url; | 303 GURL content_handler_url; |
330 std::string shebang; | 304 std::string shebang; |
331 bool enable_multi_process = base::CommandLine::ForCurrentProcess()->HasSwitch( | 305 bool enable_multi_process = base::CommandLine::ForCurrentProcess()->HasSwitch( |
332 switches::kEnableMultiprocess); | 306 switches::kEnableMultiprocess); |
333 | 307 |
334 if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) { | 308 if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) { |
335 URLResponsePtr response(fetcher->AsURLResponse( | 309 URLResponsePtr response(fetcher->AsURLResponse( |
336 blocking_pool_, static_cast<int>(shebang.size()))); | 310 blocking_pool_, static_cast<int>(shebang.size()))); |
337 std::string site = | 311 std::string site = |
338 enable_multi_process ? response->site.To<std::string>() : std::string(); | 312 enable_multi_process ? response->site.To<std::string>() : std::string(); |
339 LoadWithContentHandler(originator, content_handler_url, requestor_url, site, | 313 LoadWithContentHandler(originator_identity, originator_filter, |
340 filter, connect_callback, app, request.Pass(), | 314 content_handler_url, site, filter, connect_callback, |
341 response.Pass()); | 315 app, request.Pass(), response.Pass()); |
342 return; | 316 return; |
343 } | 317 } |
344 | 318 |
345 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); | 319 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); |
346 if (iter != mime_type_to_url_.end()) { | 320 if (iter != mime_type_to_url_.end()) { |
347 URLResponsePtr response(fetcher->AsURLResponse(blocking_pool_, 0)); | 321 URLResponsePtr response(fetcher->AsURLResponse(blocking_pool_, 0)); |
348 std::string site = | 322 std::string site = |
349 enable_multi_process ? response->site.To<std::string>() : std::string(); | 323 enable_multi_process ? response->site.To<std::string>() : std::string(); |
350 LoadWithContentHandler(originator, iter->second, requestor_url, site, | 324 LoadWithContentHandler(originator_identity, originator_filter, iter->second, |
351 filter, connect_callback, app, request.Pass(), | 325 site, filter, connect_callback, app, request.Pass(), |
352 response.Pass()); | 326 response.Pass()); |
353 return; | 327 return; |
354 } | 328 } |
355 | 329 |
356 auto alias_iter = application_package_alias_.find(app_url); | 330 auto alias_iter = application_package_alias_.find(app_url); |
357 if (alias_iter != application_package_alias_.end()) { | 331 if (alias_iter != application_package_alias_.end()) { |
358 // We replace the qualifier with the one our package alias requested. | 332 // We replace the qualifier with the one our package alias requested. |
359 URLResponsePtr response(URLResponse::New()); | 333 URLResponsePtr response(URLResponse::New()); |
360 response->url = String::From(app_url.spec()); | 334 response->url = app_url.spec(); |
361 | 335 |
362 std::string qualifier; | 336 std::string qualifier; |
363 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 337 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
364 switches::kEnableMultiprocess)) { | 338 switches::kEnableMultiprocess)) { |
365 // Why can't we use this in single process mode? Because of | 339 // Why can't we use this in single process mode? Because of |
366 // base::AtExitManager. If you link in ApplicationRunner into | 340 // base::AtExitManager. If you link in ApplicationRunner into |
367 // your code, and then we make initialize multiple copies of the | 341 // your code, and then we make initialize multiple copies of the |
368 // application, we end up with multiple AtExitManagers and will check on | 342 // application, we end up with multiple AtExitManagers and will check on |
369 // the second one being created. | 343 // the second one being created. |
370 // | 344 // |
371 // Why doesn't that happen when running different apps? Because | 345 // Why doesn't that happen when running different apps? Because |
372 // your_thing.mojo!base::AtExitManager and | 346 // your_thing.mojo!base::AtExitManager and |
373 // my_thing.mojo!base::AtExitManager are different symbols. | 347 // my_thing.mojo!base::AtExitManager are different symbols. |
374 qualifier = alias_iter->second.second; | 348 qualifier = alias_iter->second.second; |
375 } | 349 } |
376 | 350 |
377 LoadWithContentHandler(originator, alias_iter->second.first, requestor_url, | 351 LoadWithContentHandler(originator_identity, originator_filter, |
378 qualifier, filter, connect_callback, app, | 352 alias_iter->second.first, qualifier, filter, |
379 request.Pass(), response.Pass()); | 353 connect_callback, app, request.Pass(), |
| 354 response.Pass()); |
380 return; | 355 return; |
381 } | 356 } |
382 | 357 |
383 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo | 358 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo |
384 // application. That could either mean looking for the platform-specific dll | 359 // application. That could either mean looking for the platform-specific dll |
385 // header, or looking for some specific mojo signature prepended to the | 360 // header, or looking for some specific mojo signature prepended to the |
386 // library. | 361 // library. |
387 // TODO(vtl): (Maybe this should be done by the factory/runner?) | 362 // TODO(vtl): (Maybe this should be done by the factory/runner?) |
388 | 363 |
389 GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr); | 364 GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 428 |
454 void ApplicationManager::RegisterApplicationPackageAlias( | 429 void ApplicationManager::RegisterApplicationPackageAlias( |
455 const GURL& alias, | 430 const GURL& alias, |
456 const GURL& content_handler_package, | 431 const GURL& content_handler_package, |
457 const std::string& qualifier) { | 432 const std::string& qualifier) { |
458 application_package_alias_[alias] = | 433 application_package_alias_[alias] = |
459 std::make_pair(content_handler_package, qualifier); | 434 std::make_pair(content_handler_package, qualifier); |
460 } | 435 } |
461 | 436 |
462 void ApplicationManager::LoadWithContentHandler( | 437 void ApplicationManager::LoadWithContentHandler( |
463 ApplicationInstance* originator, | 438 const Identity& originator_identity, |
| 439 const CapabilityFilter& originator_filter, |
464 const GURL& content_handler_url, | 440 const GURL& content_handler_url, |
465 const GURL& requestor_url, | |
466 const std::string& qualifier, | 441 const std::string& qualifier, |
467 const CapabilityFilter& filter, | 442 const CapabilityFilter& filter, |
468 const Shell::ConnectToApplicationCallback& connect_callback, | 443 const Shell::ConnectToApplicationCallback& connect_callback, |
469 ApplicationInstance* app, | 444 ApplicationInstance* app, |
470 InterfaceRequest<Application> application_request, | 445 InterfaceRequest<Application> application_request, |
471 URLResponsePtr url_response) { | 446 URLResponsePtr url_response) { |
472 ContentHandlerConnection* connection = nullptr; | 447 ContentHandlerConnection* connection = nullptr; |
473 std::pair<GURL, std::string> key(content_handler_url, qualifier); | 448 std::pair<GURL, std::string> key(content_handler_url, qualifier); |
474 // TODO(beng): Figure out the extent to which capability filter should be | 449 // TODO(beng): Figure out the extent to which capability filter should be |
475 // factored into handler identity. | 450 // factored into handler identity. |
476 URLToContentHandlerMap::iterator iter = url_to_content_handler_.find(key); | 451 URLToContentHandlerMap::iterator iter = url_to_content_handler_.find(key); |
477 if (iter != url_to_content_handler_.end()) { | 452 if (iter != url_to_content_handler_.end()) { |
478 connection = iter->second; | 453 connection = iter->second; |
479 } else { | 454 } else { |
480 connection = new ContentHandlerConnection( | 455 connection = new ContentHandlerConnection( |
481 originator, this, content_handler_url, requestor_url, qualifier, filter, | 456 this, originator_identity, originator_filter, content_handler_url, |
482 ++content_handler_id_counter_); | 457 qualifier, filter, ++content_handler_id_counter_); |
483 url_to_content_handler_[key] = connection; | 458 url_to_content_handler_[key] = connection; |
484 } | 459 } |
485 | 460 |
486 app->set_requesting_content_handler_id(connection->id()); | 461 app->set_requesting_content_handler_id(connection->id()); |
487 connection->content_handler()->StartApplication(application_request.Pass(), | 462 connection->content_handler()->StartApplication(application_request.Pass(), |
488 url_response.Pass()); | 463 url_response.Pass()); |
489 connect_callback.Run(connection->id()); | 464 connect_callback.Run(connection->id()); |
490 } | 465 } |
491 | 466 |
492 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, | 467 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 | 532 |
558 void ApplicationManager::CleanupRunner(NativeRunner* runner) { | 533 void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
559 native_runners_.erase( | 534 native_runners_.erase( |
560 std::find(native_runners_.begin(), native_runners_.end(), runner)); | 535 std::find(native_runners_.begin(), native_runners_.end(), runner)); |
561 } | 536 } |
562 | 537 |
563 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( | 538 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( |
564 const GURL& application_url, | 539 const GURL& application_url, |
565 const std::string& interface_name) { | 540 const std::string& interface_name) { |
566 ServiceProviderPtr services; | 541 ServiceProviderPtr services; |
567 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 542 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
568 request->url = mojo::String::From(application_url.spec()); | 543 params->SetURLInfo(application_url); |
569 ConnectToApplication(nullptr, request.Pass(), std::string(), GURL(), | 544 params->set_services(GetProxy(&services)); |
570 GetProxy(&services), nullptr, | 545 params->set_filter(GetPermissiveCapabilityFilter()); |
571 GetPermissiveCapabilityFilter(), base::Closure(), | 546 ConnectToApplication(params.Pass()); |
572 EmptyConnectCallback()); | |
573 MessagePipe pipe; | 547 MessagePipe pipe; |
574 services->ConnectToService(interface_name, pipe.handle1.Pass()); | 548 services->ConnectToService(interface_name, pipe.handle1.Pass()); |
575 return pipe.handle0.Pass(); | 549 return pipe.handle0.Pass(); |
576 } | 550 } |
577 | 551 |
578 Shell::ConnectToApplicationCallback EmptyConnectCallback() { | 552 Shell::ConnectToApplicationCallback EmptyConnectCallback() { |
579 return base::Bind(&OnEmptyOnConnectCallback); | 553 return base::Bind(&OnEmptyOnConnectCallback); |
580 } | 554 } |
581 | 555 |
582 } // namespace shell | 556 } // namespace shell |
583 } // namespace mojo | 557 } // namespace mojo |
OLD | NEW |