James Robinson | f571318 | 2015-01-13 17:41:34 -0800 | [diff] [blame] | 1 | // Copyright 2015 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/shell_impl.h" |
James Robinson | f571318 | 2015-01-13 17:41:34 -0800 | [diff] [blame] | 6 | |
Viet-Trung Luu | 71447c8 | 2015-11-16 16:59:09 -0800 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
James Robinson | 94ade6b | 2015-08-25 13:02:06 -0700 | [diff] [blame] | 9 | #include "mojo/converters/url/url_type_converters.h" |
Viet-Trung Luu | 08e339a | 2015-10-10 01:03:09 -0700 | [diff] [blame] | 10 | #include "mojo/services/content_handler/interfaces/content_handler.mojom.h" |
Przemysław Pietrzkiewicz | 6384d09 | 2015-01-15 16:03:17 -0800 | [diff] [blame] | 11 | #include "shell/application_manager/application_manager.h" |
James Robinson | f571318 | 2015-01-13 17:41:34 -0800 | [diff] [blame] | 12 | |
Viet-Trung Luu | 71447c8 | 2015-11-16 16:59:09 -0800 | [diff] [blame] | 13 | using mojo::ApplicationConnector; |
| 14 | using mojo::ApplicationPtr; |
| 15 | using mojo::Array; |
| 16 | using mojo::InterfaceRequest; |
Vardhan Mudunuru | c3575c4 | 2016-02-11 15:08:21 -0800 | [diff] [blame] | 17 | using mojo::InterfaceHandle; |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 18 | using mojo::ServiceProvider; |
| 19 | using mojo::ServiceProviderPtr; |
Viet-Trung Luu | 71447c8 | 2015-11-16 16:59:09 -0800 | [diff] [blame] | 20 | using mojo::Shell; |
| 21 | using mojo::ShellPtr; |
| 22 | using mojo::String; |
Viet-Trung Luu | e377a9e | 2015-04-09 13:53:21 -0700 | [diff] [blame] | 23 | |
Viet-Trung Luu | 36faa4d | 2015-03-04 18:08:18 -0800 | [diff] [blame] | 24 | namespace shell { |
James Robinson | f571318 | 2015-01-13 17:41:34 -0800 | [diff] [blame] | 25 | |
Viet-Trung Luu | 71447c8 | 2015-11-16 16:59:09 -0800 | [diff] [blame] | 26 | // ShellImpl::ApplicationConnectorImpl ----------------------------------------- |
| 27 | |
| 28 | ShellImpl::ApplicationConnectorImpl::ApplicationConnectorImpl(Shell* shell) |
| 29 | : shell_(shell) {} |
| 30 | |
| 31 | ShellImpl::ApplicationConnectorImpl::~ApplicationConnectorImpl() {} |
| 32 | |
| 33 | void ShellImpl::ApplicationConnectorImpl::ConnectToApplication( |
| 34 | const String& app_url, |
| 35 | InterfaceRequest<ServiceProvider> services, |
Vardhan Mudunuru | c3575c4 | 2016-02-11 15:08:21 -0800 | [diff] [blame] | 36 | InterfaceHandle<mojo::ServiceProvider> exposed_services) { |
Viet-Trung Luu | 71447c8 | 2015-11-16 16:59:09 -0800 | [diff] [blame] | 37 | shell_->ConnectToApplication(app_url, std::move(services), |
| 38 | std::move(exposed_services)); |
| 39 | } |
| 40 | |
| 41 | void ShellImpl::ApplicationConnectorImpl::Duplicate( |
| 42 | InterfaceRequest<ApplicationConnector> application_connector_request) { |
| 43 | bindings_.AddBinding(this, std::move(application_connector_request)); |
| 44 | } |
| 45 | |
| 46 | // ShellImpl ------------------------------------------------------------------- |
| 47 | |
| 48 | ShellImpl::ShellImpl(ApplicationPtr application, |
James Robinson | f571318 | 2015-01-13 17:41:34 -0800 | [diff] [blame] | 49 | ApplicationManager* manager, |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 50 | const Identity& identity, |
| 51 | const base::Closure& on_application_end) |
James Robinson | fcb2783 | 2015-01-23 12:44:15 -0800 | [diff] [blame] | 52 | : manager_(manager), |
Benjamin Lerman | 71f5607 | 2015-03-12 15:04:50 +0100 | [diff] [blame] | 53 | identity_(identity), |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 54 | on_application_end_(on_application_end), |
Viet-Trung Luu | 71447c8 | 2015-11-16 16:59:09 -0800 | [diff] [blame] | 55 | application_(std::move(application)), |
Viet-Trung Luu | 199850d | 2015-11-16 15:20:58 -0800 | [diff] [blame] | 56 | binding_(this), |
| 57 | application_connector_impl_(this) { |
Viet-Trung Luu | 01e64cf | 2015-07-08 09:55:53 -0700 | [diff] [blame] | 58 | binding_.set_connection_error_handler( |
| 59 | [this]() { manager_->OnShellImplError(this); }); |
James Robinson | f571318 | 2015-01-13 17:41:34 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | ShellImpl::~ShellImpl() { |
| 63 | } |
| 64 | |
Viet-Trung Luu | 71447c8 | 2015-11-16 16:59:09 -0800 | [diff] [blame] | 65 | void ShellImpl::InitializeApplication(Array<String> args) { |
| 66 | ShellPtr shell; |
| 67 | binding_.Bind(GetProxy(&shell)); |
| 68 | application_->Initialize(std::move(shell), std::move(args), |
| 69 | identity_.url.spec()); |
James Robinson | e5ae9e4 | 2015-01-26 17:53:08 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Viet-Trung Luu | d588c94 | 2016-05-09 16:49:45 -0700 | [diff] [blame] | 72 | void ShellImpl::ConnectToClient(const GURL& requested_url, |
| 73 | const GURL& requestor_url, |
| 74 | InterfaceRequest<ServiceProvider> services) { |
| 75 | application_->AcceptConnection(String::From(requestor_url), |
| 76 | std::move(services), nullptr, |
| 77 | requested_url.spec()); |
James Robinson | f571318 | 2015-01-13 17:41:34 -0800 | [diff] [blame] | 78 | } |
| 79 | |
Vardhan Mudunuru | c3575c4 | 2016-02-11 15:08:21 -0800 | [diff] [blame] | 80 | void ShellImpl::ConnectToApplication( |
| 81 | const String& app_url, |
| 82 | InterfaceRequest<ServiceProvider> services, |
| 83 | InterfaceHandle<mojo::ServiceProvider> exposed_services) { |
James Robinson | f571318 | 2015-01-13 17:41:34 -0800 | [diff] [blame] | 84 | GURL app_gurl(app_url); |
| 85 | if (!app_gurl.is_valid()) { |
| 86 | LOG(ERROR) << "Error: invalid URL: " << app_url; |
| 87 | return; |
| 88 | } |
Viet-Trung Luu | d588c94 | 2016-05-09 16:49:45 -0700 | [diff] [blame] | 89 | LOG_IF(ERROR, exposed_services) << "exposed_services no longer supported!"; |
Viet-Trung Luu | 71447c8 | 2015-11-16 16:59:09 -0800 | [diff] [blame] | 90 | manager_->ConnectToApplication(app_gurl, identity_.url, std::move(services), |
Viet-Trung Luu | d588c94 | 2016-05-09 16:49:45 -0700 | [diff] [blame] | 91 | base::Closure()); |
James Robinson | f571318 | 2015-01-13 17:41:34 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Viet-Trung Luu | 199850d | 2015-11-16 15:20:58 -0800 | [diff] [blame] | 94 | void ShellImpl::CreateApplicationConnector( |
Viet-Trung Luu | 71447c8 | 2015-11-16 16:59:09 -0800 | [diff] [blame] | 95 | InterfaceRequest<ApplicationConnector> application_connector_request) { |
| 96 | application_connector_impl_.Duplicate( |
| 97 | std::move(application_connector_request)); |
Viet-Trung Luu | 199850d | 2015-11-16 15:20:58 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Viet-Trung Luu | 36faa4d | 2015-03-04 18:08:18 -0800 | [diff] [blame] | 100 | } // namespace shell |