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 17 matching lines...) Expand all Loading... |
28 | 28 |
29 // Used by TestAPI. | 29 // Used by TestAPI. |
30 bool has_created_instance = false; | 30 bool has_created_instance = false; |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 class ApplicationManager::ContentHandlerConnection : public ErrorHandler { | 34 class ApplicationManager::ContentHandlerConnection : public ErrorHandler { |
35 public: | 35 public: |
36 ContentHandlerConnection(ApplicationManager* manager, | 36 ContentHandlerConnection(ApplicationManager* manager, |
37 const GURL& content_handler_url, | 37 const GURL& content_handler_url, |
| 38 const GURL& requestor_url, |
38 const std::string& qualifier) | 39 const std::string& qualifier) |
39 : manager_(manager), | 40 : manager_(manager), |
40 content_handler_url_(content_handler_url), | 41 content_handler_url_(content_handler_url), |
41 content_handler_qualifier_(qualifier) { | 42 content_handler_qualifier_(qualifier) { |
42 ServiceProviderPtr services; | 43 ServiceProviderPtr services; |
43 manager->ConnectToApplicationWithParameters( | 44 manager->ConnectToApplicationWithParameters( |
44 content_handler_url, qualifier, GURL(), GetProxy(&services), nullptr, | 45 content_handler_url, qualifier, requestor_url, GetProxy(&services), |
45 base::Closure(), std::vector<std::string>()); | 46 nullptr, base::Closure(), std::vector<std::string>()); |
46 MessagePipe pipe; | 47 MessagePipe pipe; |
47 content_handler_.Bind(pipe.handle0.Pass()); | 48 content_handler_.Bind(pipe.handle0.Pass()); |
48 services->ConnectToService(ContentHandler::Name_, pipe.handle1.Pass()); | 49 services->ConnectToService(ContentHandler::Name_, pipe.handle1.Pass()); |
49 content_handler_.set_error_handler(this); | 50 content_handler_.set_error_handler(this); |
50 } | 51 } |
51 | 52 |
52 ContentHandler* content_handler() { return content_handler_.get(); } | 53 ContentHandler* content_handler() { return content_handler_.get(); } |
53 | 54 |
54 GURL content_handler_url() { return content_handler_url_; } | 55 GURL content_handler_url() { return content_handler_url_; } |
55 std::string content_handler_qualifier() { return content_handler_qualifier_; } | 56 std::string content_handler_qualifier() { return content_handler_qualifier_; } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 default_loader_.get())) { | 159 default_loader_.get())) { |
159 return; | 160 return; |
160 } | 161 } |
161 | 162 |
162 auto callback = base::Bind( | 163 auto callback = base::Bind( |
163 &ApplicationManager::HandleFetchCallback, weak_ptr_factory_.GetWeakPtr(), | 164 &ApplicationManager::HandleFetchCallback, weak_ptr_factory_.GetWeakPtr(), |
164 requested_url, qualifier, requestor_url, base::Passed(services.Pass()), | 165 requested_url, qualifier, requestor_url, base::Passed(services.Pass()), |
165 base::Passed(exposed_services.Pass()), on_application_end, | 166 base::Passed(exposed_services.Pass()), on_application_end, |
166 pre_redirect_parameters); | 167 pre_redirect_parameters); |
167 | 168 |
| 169 if (delegate_->CreateFetcher( |
| 170 resolved_url, |
| 171 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE))) { |
| 172 return; |
| 173 } |
| 174 |
168 if (resolved_url.SchemeIsFile()) { | 175 if (resolved_url.SchemeIsFile()) { |
169 new LocalFetcher( | 176 new LocalFetcher( |
170 resolved_url, GetBaseURLAndQuery(resolved_url, nullptr), | 177 resolved_url, GetBaseURLAndQuery(resolved_url, nullptr), |
171 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE)); | 178 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE)); |
172 return; | 179 return; |
173 } | 180 } |
174 | 181 |
175 if (!network_service_) | 182 if (!network_service_) |
176 ConnectToService(GURL("mojo:network_service"), &network_service_); | 183 ConnectToService(GURL("mojo:network_service"), &network_service_); |
177 | 184 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 311 |
305 InterfaceRequest<Application> request( | 312 InterfaceRequest<Application> request( |
306 RegisterShell(app_url, qualifier, requestor_url, services.Pass(), | 313 RegisterShell(app_url, qualifier, requestor_url, services.Pass(), |
307 exposed_services.Pass(), on_application_end, parameters)); | 314 exposed_services.Pass(), on_application_end, parameters)); |
308 | 315 |
309 // If the response begins with a #!mojo <content-handler-url>, use it. | 316 // If the response begins with a #!mojo <content-handler-url>, use it. |
310 GURL content_handler_url; | 317 GURL content_handler_url; |
311 std::string shebang; | 318 std::string shebang; |
312 if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) { | 319 if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) { |
313 LoadWithContentHandler( | 320 LoadWithContentHandler( |
314 content_handler_url, qualifier, request.Pass(), | 321 content_handler_url, requestor_url, qualifier, request.Pass(), |
315 fetcher->AsURLResponse(blocking_pool_, | 322 fetcher->AsURLResponse(blocking_pool_, |
316 static_cast<int>(shebang.size()))); | 323 static_cast<int>(shebang.size()))); |
317 return; | 324 return; |
318 } | 325 } |
319 | 326 |
320 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); | 327 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); |
321 if (iter != mime_type_to_url_.end()) { | 328 if (iter != mime_type_to_url_.end()) { |
322 LoadWithContentHandler(iter->second, qualifier, request.Pass(), | 329 LoadWithContentHandler(iter->second, requestor_url, qualifier, |
| 330 request.Pass(), |
323 fetcher->AsURLResponse(blocking_pool_, 0)); | 331 fetcher->AsURLResponse(blocking_pool_, 0)); |
324 return; | 332 return; |
325 } | 333 } |
326 | 334 |
327 auto alias_iter = application_package_alias_.find(app_url); | 335 auto alias_iter = application_package_alias_.find(app_url); |
328 if (alias_iter != application_package_alias_.end()) { | 336 if (alias_iter != application_package_alias_.end()) { |
329 // We replace the qualifier with the one our package alias requested. | 337 // We replace the qualifier with the one our package alias requested. |
330 URLResponsePtr response(URLResponse::New()); | 338 URLResponsePtr response(URLResponse::New()); |
331 response->url = String::From(app_url.spec()); | 339 response->url = String::From(app_url.spec()); |
332 | 340 |
333 std::string qualifier; | 341 std::string qualifier; |
334 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 342 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
335 switches::kEnableMultiprocess)) { | 343 switches::kEnableMultiprocess)) { |
336 // Why can't we use this in single process mode? Because of | 344 // Why can't we use this in single process mode? Because of |
337 // base::AtExitManager. If you link in ApplicationRunnerChromium into | 345 // base::AtExitManager. If you link in ApplicationRunnerChromium into |
338 // your code, and then we make initialize multiple copies of the | 346 // your code, and then we make initialize multiple copies of the |
339 // application, we end up with multiple AtExitManagers and will check on | 347 // application, we end up with multiple AtExitManagers and will check on |
340 // the second one being created. | 348 // the second one being created. |
341 // | 349 // |
342 // Why doesn't that happen when running different apps? Because | 350 // Why doesn't that happen when running different apps? Because |
343 // your_thing.mojo!base::AtExitManager and | 351 // your_thing.mojo!base::AtExitManager and |
344 // my_thing.mojo!base::AtExitManager are different symbols. | 352 // my_thing.mojo!base::AtExitManager are different symbols. |
345 qualifier = alias_iter->second.second; | 353 qualifier = alias_iter->second.second; |
346 } | 354 } |
347 | 355 |
348 LoadWithContentHandler(alias_iter->second.first, qualifier, request.Pass(), | 356 LoadWithContentHandler(alias_iter->second.first, requestor_url, qualifier, |
349 response.Pass()); | 357 request.Pass(), response.Pass()); |
350 return; | 358 return; |
351 } | 359 } |
352 | 360 |
353 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo | 361 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo |
354 // application. That could either mean looking for the platform-specific dll | 362 // application. That could either mean looking for the platform-specific dll |
355 // header, or looking for some specific mojo signature prepended to the | 363 // header, or looking for some specific mojo signature prepended to the |
356 // library. | 364 // library. |
357 // TODO(vtl): (Maybe this should be done by the factory/runner?) | 365 // TODO(vtl): (Maybe this should be done by the factory/runner?) |
358 | 366 |
359 GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr); | 367 GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 void ApplicationManager::RegisterApplicationPackageAlias( | 418 void ApplicationManager::RegisterApplicationPackageAlias( |
411 const GURL& alias, | 419 const GURL& alias, |
412 const GURL& content_handler_package, | 420 const GURL& content_handler_package, |
413 const std::string& qualifier) { | 421 const std::string& qualifier) { |
414 application_package_alias_[alias] = | 422 application_package_alias_[alias] = |
415 std::make_pair(content_handler_package, qualifier); | 423 std::make_pair(content_handler_package, qualifier); |
416 } | 424 } |
417 | 425 |
418 void ApplicationManager::LoadWithContentHandler( | 426 void ApplicationManager::LoadWithContentHandler( |
419 const GURL& content_handler_url, | 427 const GURL& content_handler_url, |
| 428 const GURL& requestor_url, |
420 const std::string& qualifier, | 429 const std::string& qualifier, |
421 InterfaceRequest<Application> application_request, | 430 InterfaceRequest<Application> application_request, |
422 URLResponsePtr url_response) { | 431 URLResponsePtr url_response) { |
423 ContentHandlerConnection* connection = nullptr; | 432 ContentHandlerConnection* connection = nullptr; |
424 std::pair<GURL, std::string> key(content_handler_url, qualifier); | 433 std::pair<GURL, std::string> key(content_handler_url, qualifier); |
425 URLToContentHandlerMap::iterator iter = url_to_content_handler_.find(key); | 434 URLToContentHandlerMap::iterator iter = url_to_content_handler_.find(key); |
426 if (iter != url_to_content_handler_.end()) { | 435 if (iter != url_to_content_handler_.end()) { |
427 connection = iter->second; | 436 connection = iter->second; |
428 } else { | 437 } else { |
429 connection = | 438 connection = new ContentHandlerConnection(this, content_handler_url, |
430 new ContentHandlerConnection(this, content_handler_url, qualifier); | 439 requestor_url, qualifier); |
431 url_to_content_handler_[key] = connection; | 440 url_to_content_handler_[key] = connection; |
432 } | 441 } |
433 | 442 |
434 connection->content_handler()->StartApplication(application_request.Pass(), | 443 connection->content_handler()->StartApplication(application_request.Pass(), |
435 url_response.Pass()); | 444 url_response.Pass()); |
436 } | 445 } |
437 | 446 |
438 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, | 447 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, |
439 const GURL& url) { | 448 const GURL& url) { |
440 URLToLoaderMap::iterator it = url_to_loader_.find(url); | 449 URLToLoaderMap::iterator it = url_to_loader_.find(url); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 return pipe.handle0.Pass(); | 521 return pipe.handle0.Pass(); |
513 } | 522 } |
514 | 523 |
515 void ApplicationManager::CleanupRunner(NativeRunner* runner) { | 524 void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
516 native_runners_.erase( | 525 native_runners_.erase( |
517 std::find(native_runners_.begin(), native_runners_.end(), runner)); | 526 std::find(native_runners_.begin(), native_runners_.end(), runner)); |
518 } | 527 } |
519 | 528 |
520 } // namespace shell | 529 } // namespace shell |
521 } // namespace mojo | 530 } // namespace mojo |
OLD | NEW |