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