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 part of application; | 5 part of application; |
6 | 6 |
7 class _ApplicationImpl extends application_mojom.Application { | 7 class _ApplicationImpl implements application_mojom.Application { |
| 8 application_mojom.ApplicationStub _stub; |
8 shell_mojom.ShellProxy shell; | 9 shell_mojom.ShellProxy shell; |
9 Application _application; | 10 Application _application; |
10 | 11 |
11 _ApplicationImpl( | 12 _ApplicationImpl(Application application, |
12 Application application, core.MojoMessagePipeEndpoint endpoint) | 13 core.MojoMessagePipeEndpoint endpoint) { |
13 : _application = application, super(endpoint) { | 14 _application = application; |
14 super.delegate = this; | 15 _stub = new application_mojom.ApplicationStub.fromEndpoint(endpoint) |
| 16 ..delegate = this |
| 17 ..listen(); |
15 } | 18 } |
16 | 19 |
17 _ApplicationImpl.fromHandle(Application application, core.MojoHandle handle) | 20 _ApplicationImpl.fromHandle(Application application, core.MojoHandle handle) { |
18 : _application = application, super.fromHandle(handle) { | 21 _application = application; |
19 super.delegate = this; | 22 _stub = new application_mojom.ApplicationStub.fromHandle(handle) |
| 23 ..delegate = this |
| 24 ..listen(); |
20 } | 25 } |
21 | 26 |
22 void initialize( | 27 void initialize( |
23 shell_mojom.ShellProxy shellProxy, List<String> args, String url) { | 28 bindings.ProxyBase shellProxy, List<String> args, String url) { |
24 assert(shell == null); | 29 assert(shell == null); |
25 shell = shellProxy; | 30 shell = shellProxy; |
26 _application.initialize(args, url); | 31 _application.initialize(args, url); |
27 } | 32 } |
28 | 33 |
29 void acceptConnection( | 34 void acceptConnection(String requestorUrl, |
30 String requestorUrl, | 35 ServiceProviderStub services, |
31 ServiceProviderStub services, | 36 bindings.ProxyBase exposedServices) => |
32 ServiceProviderProxy exposedServices) => | 37 _application._acceptConnection(requestorUrl, services, exposedServices); |
33 _application._acceptConnection(requestorUrl, services, exposedServices); | |
34 | 38 |
35 void requestQuit() => _application._requestQuitAndClose(); | 39 void requestQuit() => _application._requestQuitAndClose(); |
36 | 40 |
37 void close({bool nodefer: false}) => shell.close(); | 41 void close({bool nodefer: false}) => shell.close(); |
38 } | 42 } |
39 | 43 |
40 // TODO(zra): Better documentation and examples. | 44 // TODO(zra): Better documentation and examples. |
41 // To implement, do the following: | 45 // To implement, do the following: |
42 // - Optionally override initialize() to process command-line args. | 46 // - Optionally override initialize() to process command-line args. |
43 // - Optionally override acceptConnection() if services are to be provided. | 47 // - Optionally override acceptConnection() if services are to be provided. |
(...skipping 10 matching lines...) Expand all Loading... |
54 Application.fromHandle(core.MojoHandle appHandle) { | 58 Application.fromHandle(core.MojoHandle appHandle) { |
55 _applicationConnections = []; | 59 _applicationConnections = []; |
56 _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle); | 60 _applicationImpl = new _ApplicationImpl.fromHandle(this, appHandle); |
57 } | 61 } |
58 | 62 |
59 void initialize(List<String> args, String url) {} | 63 void initialize(List<String> args, String url) {} |
60 | 64 |
61 // TODO(skydart): This is a temporary fix to allow sky application to consume | 65 // TODO(skydart): This is a temporary fix to allow sky application to consume |
62 // mojo services. Do not use for any other purpose. | 66 // mojo services. Do not use for any other purpose. |
63 void initializeFromShellProxy(shell_mojom.ShellProxy shellProxy, | 67 void initializeFromShellProxy(shell_mojom.ShellProxy shellProxy, |
64 List<String> args, String url) { | 68 List<String> args, String url) => |
65 _applicationImpl.initialize(shellProxy, args, url); | 69 _applicationImpl.initialize(shellProxy, args, url); |
66 } | |
67 | 70 |
68 // Returns a connection to the app at |url|. | 71 // Returns a connection to the app at |url|. |
69 ApplicationConnection connectToApplication(String url) { | 72 ApplicationConnection connectToApplication(String url) { |
70 var proxy = new ServiceProviderProxy.unbound(); | 73 var proxy = new ServiceProviderProxy.unbound(); |
71 var stub = new ServiceProviderStub.unbound(); | 74 var stub = new ServiceProviderStub.unbound(); |
72 _applicationImpl.shell.connectToApplication(url, proxy, stub); | 75 _applicationImpl.shell.ptr.connectToApplication(url, proxy, stub); |
73 var connection = new ApplicationConnection(stub, proxy); | 76 var connection = new ApplicationConnection(stub, proxy); |
74 _applicationConnections.add(connection); | 77 _applicationConnections.add(connection); |
75 return connection; | 78 return connection; |
76 } | 79 } |
77 | 80 |
78 void connectToService(String url, bindings.Proxy proxy) { | 81 void connectToService(String url, bindings.ProxyBase proxy) { |
79 connectToApplication(url).requestService(proxy); | 82 connectToApplication(url).requestService(proxy); |
80 } | 83 } |
81 | 84 |
82 void requestQuit() {} | 85 void requestQuit() {} |
83 | 86 |
84 listen() => _applicationImpl.listen(); | |
85 | |
86 void _requestQuitAndClose() { | 87 void _requestQuitAndClose() { |
87 requestQuit(); | 88 requestQuit(); |
88 close(); | 89 close(); |
89 } | 90 } |
90 | 91 |
91 void close() { | 92 void close() { |
92 assert(_applicationImpl != null); | 93 assert(_applicationImpl != null); |
93 _applicationConnections.forEach((c) => c.close()); | 94 _applicationConnections.forEach((c) => c.close()); |
94 _applicationConnections.clear(); | 95 _applicationConnections.clear(); |
95 _applicationImpl.close(); | 96 _applicationImpl.close(); |
96 } | 97 } |
97 | 98 |
98 void _acceptConnection( | 99 void _acceptConnection( |
99 String requestorUrl, | 100 String requestorUrl, |
100 ServiceProviderStub services, | 101 ServiceProviderStub services, |
101 ServiceProviderProxy exposedServices) { | 102 ServiceProviderProxy exposedServices) { |
102 var connection = new ApplicationConnection(services, exposedServices); | 103 var connection = new ApplicationConnection(services, exposedServices); |
103 _applicationConnections.add(connection); | 104 _applicationConnections.add(connection); |
104 acceptConnection(requestorUrl, connection); | 105 acceptConnection(requestorUrl, connection); |
105 } | 106 } |
106 | 107 |
107 // Override this method to provide services on |connection|. | 108 // Override this method to provide services on |connection|. |
108 // If you provide at least one service or set fallbackServiceProvider, | 109 // If you provide at least one service or set fallbackServiceProvider, |
109 // then you must invoke connection.listen(). | 110 // then you must invoke connection.listen(). |
110 void acceptConnection(String requestorUrl, ApplicationConnection connection) { | 111 void acceptConnection(String requestorUrl, ApplicationConnection connection) { |
111 } | 112 } |
112 } | 113 } |
OLD | NEW |