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.
5 define("mojo/services/public/js/application", [
6 "mojo/public/js/bindings",
8 "mojo/public/js/connection",
9 "mojo/public/js/threading",
10 "mojo/public/interfaces/application/application.mojom",
11 "mojo/services/public/js/service_exchange",
12 "mojo/services/public/js/shell",
13 ], function(bindings, core, connection, threading, applicationMojom, serviceExchange, shell) {
15 const ApplicationInterface = applicationMojom.Application;
16 const ProxyBindings = bindings.ProxyBindings;
17 const ServiceExchange = serviceExchange.ServiceExchange;
18 const Shell = shell.Shell;
21 constructor(appRequestHandle, url) {
23 this.serviceExchanges = [];
24 this.appRequestHandle_ = appRequestHandle;
26 connection.bindHandleToStub(appRequestHandle, ApplicationInterface);
27 bindings.StubBindings(this.appStub_).delegate = {
28 initialize: this.doInitialize.bind(this),
29 acceptConnection: this.doAcceptConnection.bind(this),
33 doInitialize(shellProxy, args, url) {
34 this.shellProxy_ = shellProxy;
35 this.shell = new Shell(shellProxy);
36 this.initialize(args);
42 // Implements AcceptConnection() from Application.mojom. Calls
43 // this.acceptConnection() with a JS ServiceExchange instead of a pair
44 // of Mojo ServiceProviders.
45 doAcceptConnection(requestorUrl, servicesRequest, exposedServicesProxy) {
47 new ServiceExchange(servicesRequest, exposedServicesProxy);
48 this.serviceExchanges.push(serviceExchange);
49 this.acceptConnection(requestorUrl, serviceExchange);
52 // Subclasses override this method to request or provide services for
53 // ConnectToApplication() calls from requestorURL.
54 acceptConnection(requestorUrl, serviceExchange) {
58 this.serviceExchanges.forEach(function(exch) {
62 core.close(this.appRequestHandle_);
68 exports.Application = Application;