blob: bdd38f130b9eec58b45e196f22eac1acac130537 [file] [log] [blame]
James Robinsonf5713182015-01-13 17:41:34 -08001// 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 Pietrzkiewicz6384d092015-01-15 16:03:17 -08005#include "shell/application_manager/shell_impl.h"
James Robinsonf5713182015-01-13 17:41:34 -08006
Viet-Trung Luu71447c82015-11-16 16:59:09 -08007#include <utility>
8
James Robinson94ade6b2015-08-25 13:02:06 -07009#include "mojo/converters/url/url_type_converters.h"
Viet-Trung Luu08e339a2015-10-10 01:03:09 -070010#include "mojo/services/content_handler/interfaces/content_handler.mojom.h"
Przemysław Pietrzkiewicz6384d092015-01-15 16:03:17 -080011#include "shell/application_manager/application_manager.h"
James Robinsonf5713182015-01-13 17:41:34 -080012
Viet-Trung Luu71447c82015-11-16 16:59:09 -080013using mojo::ApplicationConnector;
14using mojo::ApplicationPtr;
15using mojo::Array;
16using mojo::InterfaceRequest;
Vardhan Mudunuruc3575c42016-02-11 15:08:21 -080017using mojo::InterfaceHandle;
Viet-Trung Luue377a9e2015-04-09 13:53:21 -070018using mojo::ServiceProvider;
19using mojo::ServiceProviderPtr;
Viet-Trung Luu71447c82015-11-16 16:59:09 -080020using mojo::Shell;
21using mojo::ShellPtr;
22using mojo::String;
Viet-Trung Luue377a9e2015-04-09 13:53:21 -070023
Viet-Trung Luu36faa4d2015-03-04 18:08:18 -080024namespace shell {
James Robinsonf5713182015-01-13 17:41:34 -080025
Viet-Trung Luu71447c82015-11-16 16:59:09 -080026// ShellImpl::ApplicationConnectorImpl -----------------------------------------
27
28ShellImpl::ApplicationConnectorImpl::ApplicationConnectorImpl(Shell* shell)
29 : shell_(shell) {}
30
31ShellImpl::ApplicationConnectorImpl::~ApplicationConnectorImpl() {}
32
33void ShellImpl::ApplicationConnectorImpl::ConnectToApplication(
34 const String& app_url,
35 InterfaceRequest<ServiceProvider> services,
Vardhan Mudunuruc3575c42016-02-11 15:08:21 -080036 InterfaceHandle<mojo::ServiceProvider> exposed_services) {
Viet-Trung Luu71447c82015-11-16 16:59:09 -080037 shell_->ConnectToApplication(app_url, std::move(services),
38 std::move(exposed_services));
39}
40
41void ShellImpl::ApplicationConnectorImpl::Duplicate(
42 InterfaceRequest<ApplicationConnector> application_connector_request) {
43 bindings_.AddBinding(this, std::move(application_connector_request));
44}
45
46// ShellImpl -------------------------------------------------------------------
47
48ShellImpl::ShellImpl(ApplicationPtr application,
James Robinsonf5713182015-01-13 17:41:34 -080049 ApplicationManager* manager,
Benjamin Lerman993869e2015-03-24 13:35:28 +010050 const Identity& identity,
51 const base::Closure& on_application_end)
James Robinsonfcb27832015-01-23 12:44:15 -080052 : manager_(manager),
Benjamin Lerman71f56072015-03-12 15:04:50 +010053 identity_(identity),
Benjamin Lerman993869e2015-03-24 13:35:28 +010054 on_application_end_(on_application_end),
Viet-Trung Luu71447c82015-11-16 16:59:09 -080055 application_(std::move(application)),
Viet-Trung Luu199850d2015-11-16 15:20:58 -080056 binding_(this),
57 application_connector_impl_(this) {
Viet-Trung Luu01e64cf2015-07-08 09:55:53 -070058 binding_.set_connection_error_handler(
59 [this]() { manager_->OnShellImplError(this); });
James Robinsonf5713182015-01-13 17:41:34 -080060}
61
62ShellImpl::~ShellImpl() {
63}
64
Viet-Trung Luu71447c82015-11-16 16:59:09 -080065void 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 Robinsone5ae9e42015-01-26 17:53:08 -080070}
71
Viet-Trung Luud588c942016-05-09 16:49:45 -070072void 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 Robinsonf5713182015-01-13 17:41:34 -080078}
79
Vardhan Mudunuruc3575c42016-02-11 15:08:21 -080080void ShellImpl::ConnectToApplication(
81 const String& app_url,
82 InterfaceRequest<ServiceProvider> services,
83 InterfaceHandle<mojo::ServiceProvider> exposed_services) {
James Robinsonf5713182015-01-13 17:41:34 -080084 GURL app_gurl(app_url);
85 if (!app_gurl.is_valid()) {
86 LOG(ERROR) << "Error: invalid URL: " << app_url;
87 return;
88 }
Viet-Trung Luud588c942016-05-09 16:49:45 -070089 LOG_IF(ERROR, exposed_services) << "exposed_services no longer supported!";
Viet-Trung Luu71447c82015-11-16 16:59:09 -080090 manager_->ConnectToApplication(app_gurl, identity_.url, std::move(services),
Viet-Trung Luud588c942016-05-09 16:49:45 -070091 base::Closure());
James Robinsonf5713182015-01-13 17:41:34 -080092}
93
Viet-Trung Luu199850d2015-11-16 15:20:58 -080094void ShellImpl::CreateApplicationConnector(
Viet-Trung Luu71447c82015-11-16 16:59:09 -080095 InterfaceRequest<ApplicationConnector> application_connector_request) {
96 application_connector_impl_.Duplicate(
97 std::move(application_connector_request));
Viet-Trung Luu199850d2015-11-16 15:20:58 -080098}
99
Viet-Trung Luu36faa4d2015-03-04 18:08:18 -0800100} // namespace shell