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