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/shell", [ | 5 define("mojo/services/public/js/shell", [ |
6 "mojo/public/js/core", | 6 "mojo/public/js/core", |
| 7 "mojo/public/js/connection", |
7 "mojo/public/interfaces/application/shell.mojom", | 8 "mojo/public/interfaces/application/shell.mojom", |
8 "mojo/public/interfaces/application/service_provider.mojom", | 9 "mojo/public/interfaces/application/service_provider.mojom", |
9 "mojo/services/public/js/service_provider", | 10 "mojo/services/public/js/service_provider" |
10 ], function(coreModule, shellInterfaceModule, spInterfaceModule, spModule) { | 11 ], function(core, |
| 12 connection, |
| 13 shellMojom, |
| 14 serviceProviderMojom, |
| 15 serviceProvider) { |
| 16 |
| 17 const ServiceProvider = serviceProvider.ServiceProvider; |
| 18 const ServiceProviderInterface = serviceProviderMojom.ServiceProvider; |
| 19 const ShellInterface = shellMojom.Shell; |
11 | 20 |
12 class Shell { | 21 class Shell { |
13 constructor(shellHandle, app) { | 22 constructor(shellHandle, app) { |
14 this.shellHandle = shellHandle; | 23 this.shellHandle = shellHandle; |
15 this.proxy = new shellInterfaceModule.Shell.proxyClass(shellHandle); | 24 this.proxy = connection.bindProxyHandle( |
16 this.proxy.client$ = app; | 25 shellHandle, ShellInterface.client, ShellInterface); |
| 26 this.proxy.local$ = app; // The app is the shell's client. |
| 27 // TODO: call this serviceProviders_ |
17 this.applications_ = new Map(); | 28 this.applications_ = new Map(); |
18 } | 29 } |
19 | 30 |
20 connectToApplication(url) { | 31 connectToApplication(url) { |
21 var application = this.applications_.get(url); | 32 var application = this.applications_.get(url); |
22 if (application) | 33 if (application) |
23 return application; | 34 return application; |
24 | 35 |
25 var spProxy = new spInterfaceModule.ServiceProvider.proxyClass; | 36 var returnValue = {}; |
26 this.proxy.connectToApplication(url, spProxy); | 37 this.proxy.connectToApplication(url, returnValue); |
27 application = new spModule.ServiceProvider(spProxy); | 38 application = new ServiceProvider(returnValue.remote$); |
28 this.applications_.set(url, application); | 39 this.applications_.set(url, application); |
29 return application; | 40 return application; |
30 } | 41 } |
31 | 42 |
32 connectToService(url, service, client) { | 43 connectToService(url, service, client) { |
33 return this.connectToApplication(url).connectToService(service, client); | 44 return this.connectToApplication(url).requestService(service, client); |
34 }; | 45 }; |
35 | 46 |
36 close() { | 47 close() { |
37 this.applications_.forEach(function(application, url) { | 48 this.applications_.forEach(function(application, url) { |
38 application.close(); | 49 application.close(); |
39 }); | 50 }); |
40 this.applications_.clear(); | 51 this.applications_.clear(); |
41 coreModule.close(this.shellHandle); | 52 core.close(this.shellHandle); |
42 } | 53 } |
43 } | 54 } |
44 | 55 |
45 var exports = {}; | 56 var exports = {}; |
46 exports.Shell = Shell; | 57 exports.Shell = Shell; |
47 return exports; | 58 return exports; |
48 }); | 59 }); |
OLD | NEW |