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