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