| 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 define("mojo/services/public/js/application", [ | 5 define("mojo/services/public/js/application", [ |
| 6 "mojo/public/js/bindings", | 6 "mojo/public/js/bindings", |
| 7 "mojo/public/js/core", | 7 "mojo/public/js/core", |
| 8 "mojo/public/js/connection", | 8 "mojo/public/js/connection", |
| 9 "mojo/public/js/threading", | 9 "mojo/public/js/threading", |
| 10 "mojo/public/interfaces/application/application.mojom", | 10 "mojo/public/interfaces/application/application.mojom", |
| 11 "mojo/services/public/js/service_exchange", | 11 "mojo/services/public/js/service_provider", |
| 12 "mojo/services/public/js/shell", | 12 "mojo/services/public/js/shell", |
| 13 ], function(bindings, core, connection, threading, applicationMojom, serviceExch
ange, shell) { | 13 ], function(bindings, core, connection, threading, applicationMojom, serviceProv
ider, shell) { |
| 14 | 14 |
| 15 const ApplicationInterface = applicationMojom.Application; | 15 const ApplicationInterface = applicationMojom.Application; |
| 16 const ProxyBindings = bindings.ProxyBindings; | 16 const ProxyBindings = bindings.ProxyBindings; |
| 17 const ServiceExchange = serviceExchange.ServiceExchange; | 17 const ServiceProvider = serviceProvider.ServiceProvider; |
| 18 const Shell = shell.Shell; | 18 const Shell = shell.Shell; |
| 19 | 19 |
| 20 class Application { | 20 class Application { |
| 21 constructor(appRequestHandle, url) { | 21 constructor(appRequestHandle, url) { |
| 22 this.url = url; | 22 this.url = url; |
| 23 this.serviceExchanges = []; | 23 this.serviceProviders = []; |
| 24 this.exposedServiceProviders = []; |
| 24 this.appRequestHandle_ = appRequestHandle; | 25 this.appRequestHandle_ = appRequestHandle; |
| 25 this.appStub_ = | 26 this.appStub_ = |
| 26 connection.bindHandleToStub(appRequestHandle, ApplicationInterface); | 27 connection.bindHandleToStub(appRequestHandle, ApplicationInterface); |
| 27 bindings.StubBindings(this.appStub_).delegate = { | 28 bindings.StubBindings(this.appStub_).delegate = { |
| 28 initialize: this.doInitialize.bind(this), | 29 initialize: this.doInitialize.bind(this), |
| 29 acceptConnection: this.doAcceptConnection.bind(this), | 30 acceptConnection: this.doAcceptConnection.bind(this), |
| 30 }; | 31 }; |
| 31 } | 32 } |
| 32 | 33 |
| 33 doInitialize(shellProxy, args) { | 34 doInitialize(shellProxy, args) { |
| 34 this.shellProxy_ = shellProxy; | 35 this.shellProxy_ = shellProxy; |
| 35 this.shell = new Shell(shellProxy); | 36 this.shell = new Shell(shellProxy); |
| 36 this.initialize(args); | 37 this.initialize(args); |
| 37 } | 38 } |
| 38 | 39 |
| 39 initialize(args) { | 40 initialize(args) {} |
| 41 |
| 42 // The mojom signature of this function is: |
| 43 // AcceptConnection(string requestor_url, |
| 44 // ServiceProvider&? services, |
| 45 // ServiceProvider? exposed_services); |
| 46 // |
| 47 // We want to bind |services| to our js implementation of ServiceProvider |
| 48 // and store |exposed_services| so we can request services of the connecting |
| 49 // application. |
| 50 doAcceptConnection(requestorUrl, servicesRequest, exposedServicesProxy) { |
| 51 // Construct a new js ServiceProvider that can make outgoing calls on |
| 52 // exposedServicesProxy. |
| 53 var serviceProvider = |
| 54 new ServiceProvider(servicesRequest, exposedServicesProxy); |
| 55 this.serviceProviders.push(serviceProvider); |
| 56 this.acceptConnection(requestorUrl, serviceProvider); |
| 40 } | 57 } |
| 41 | 58 |
| 42 // Implements AcceptConnection() from Application.mojom. Calls | 59 acceptConnection(requestorUrl, serviceProvider) {} |
| 43 // this.acceptConnection() with a JS ServiceExchange instead of a pair | |
| 44 // of Mojo ServiceProviders. | |
| 45 doAcceptConnection(requestorUrl, servicesRequest, exposedServicesProxy) { | |
| 46 var serviceExchange = | |
| 47 new ServiceExchange(servicesRequest, exposedServicesProxy); | |
| 48 this.serviceExchanges.push(serviceExchange); | |
| 49 this.acceptConnection(requestorUrl, serviceExchange); | |
| 50 } | |
| 51 | |
| 52 // Subclasses override this method to request or provide services for | |
| 53 // ConnectToApplication() calls from requestorURL. | |
| 54 acceptConnection(requestorUrl, serviceExchange) { | |
| 55 } | |
| 56 | 60 |
| 57 quit() { | 61 quit() { |
| 58 this.serviceExchanges.forEach(function(exch) { | 62 this.serviceProviders.forEach(function(sp) { |
| 59 exch.close(); | 63 sp.close(); |
| 60 }); | 64 }); |
| 61 this.shell.close(); | 65 this.shell.close(); |
| 62 core.close(this.appRequestHandle_); | 66 core.close(this.appRequestHandle_); |
| 63 threading.quit(); | 67 threading.quit(); |
| 64 } | 68 } |
| 65 } | 69 } |
| 66 | 70 |
| 67 var exports = {}; | 71 var exports = {}; |
| 68 exports.Application = Application; | 72 exports.Application = Application; |
| 69 return exports; | 73 return exports; |
| 70 }); | 74 }); |
| OLD | NEW |