OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 import "dart:sky.internals" as internals; | 5 // TODO(abarth): Remove this file once clients migrate to the new location. |
6 | 6 export '../mojo/embedder.dart'; |
7 import "package:mojo/application.dart"; | |
8 import "package:mojo/bindings.dart" as bindings; | |
9 import "package:mojo/core.dart" as core; | |
10 import "package:mojom/mojo/service_provider.mojom.dart"; | |
11 import "package:mojom/mojo/shell.mojom.dart"; | |
12 import "package:mojom/mojo/service_registry.mojom.dart"; | |
13 | |
14 final _EmbedderImpl embedder = new _EmbedderImpl(); | |
15 | |
16 class _EmbedderImpl { | |
17 ApplicationConnection _connection; | |
18 ServiceRegistryProxy _serviceRegistry; | |
19 ShellProxy _shell; | |
20 bool _internalsHasNoShell = false; | |
21 | |
22 ShellProxy get shell { | |
23 if (_internalsHasNoShell || _shell != null) return _shell; | |
24 | |
25 try { | |
26 _shell = new ShellProxy.fromHandle( | |
27 new core.MojoHandle(internals.takeShellProxyHandle())); | |
28 } catch (e) { | |
29 _internalsHasNoShell = true; | |
30 } | |
31 return _shell; | |
32 } | |
33 | |
34 ApplicationConnection get connection { | |
35 if (_connection == null) { | |
36 var stubHandle = | |
37 new core.MojoHandle(internals.takeServicesProvidedToEmbedder()); | |
38 var proxyHandle = | |
39 new core.MojoHandle(internals.takeServicesProvidedByEmbedder()); | |
40 _connection = new ApplicationConnection(stubHandle.isValid | |
41 ? new ServiceProviderStub.fromHandle(stubHandle) | |
42 : null, proxyHandle.isValid | |
43 ? new ServiceProviderProxy.fromHandle(proxyHandle) | |
44 : null); | |
45 } | |
46 return _connection; | |
47 } | |
48 | |
49 ApplicationConnection connectToApplication(String url) { | |
50 var proxy = new ServiceProviderProxy.unbound(); | |
51 var stub = new ServiceProviderStub.unbound(); | |
52 shell.ptr.connectToApplication(url, proxy, stub); | |
53 return new ApplicationConnection(stub, proxy); | |
54 } | |
55 | |
56 void connectToService(String url, bindings.ProxyBase proxy) { | |
57 var appSp = new ServiceProviderProxy.unbound(); | |
58 shell.ptr.connectToApplication(url, appSp, null); | |
59 var pipe = new core.MojoMessagePipe(); | |
60 proxy.impl.bind(pipe.endpoints[0]); | |
61 appSp.ptr.connectToService(proxy.name, pipe.endpoints[1]); | |
62 appSp.close(); | |
63 } | |
64 | |
65 ServiceRegistryProxy get serviceRegistry { | |
66 if (_serviceRegistry == null) { | |
67 _serviceRegistry = new ServiceRegistryProxy.fromHandle( | |
68 new core.MojoHandle(internals.takeServiceRegistry())); | |
69 } | |
70 return _serviceRegistry; | |
71 } | |
72 } | |
OLD | NEW |