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