Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: mojo/public/js/bindings.js

Issue 2820783002: Add associated interfaces & bindings. (Closed)
Patch Set: Change Router.prototype.accept. Add a TODO for endpoint client not attached. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/js/associated_bindings.js ('k') | mojo/public/js/codec.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/public/js/bindings", [ 5 define("mojo/public/js/bindings", [
6 "mojo/public/js/core", 6 "mojo/public/js/core",
7 "mojo/public/js/interface_types", 7 "mojo/public/js/interface_types",
8 "mojo/public/js/lib/interface_endpoint_client", 8 "mojo/public/js/lib/interface_endpoint_client",
9 "mojo/public/js/router", 9 "mojo/public/js/router",
10 ], function(core, types, interfaceEndpointClient, router) { 10 ], function(core, types, interfaceEndpointClient, router) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 if (ptrInfoOrHandle instanceof types.InterfacePtrInfo) { 47 if (ptrInfoOrHandle instanceof types.InterfacePtrInfo) {
48 this.version = ptrInfoOrHandle.version; 48 this.version = ptrInfoOrHandle.version;
49 this.handle_ = ptrInfoOrHandle.handle; 49 this.handle_ = ptrInfoOrHandle.handle;
50 } else { 50 } else {
51 this.handle_ = ptrInfoOrHandle; 51 this.handle_ = ptrInfoOrHandle;
52 } 52 }
53 }; 53 };
54 54
55 InterfacePtrController.prototype.isBound = function() { 55 InterfacePtrController.prototype.isBound = function() {
56 return this.router_ !== null || this.handle_ !== null; 56 return this.interfaceEndpointClient_ !== null || this.handle_ !== null;
57 }; 57 };
58 58
59 // Although users could just discard the object, reset() closes the pipe 59 // Although users could just discard the object, reset() closes the pipe
60 // immediately. 60 // immediately.
61 InterfacePtrController.prototype.reset = function() { 61 InterfacePtrController.prototype.reset = function() {
62 this.version = 0; 62 this.version = 0;
63 if (this.interfaceEndpointClient_) { 63 if (this.interfaceEndpointClient_) {
64 this.interfaceEndpointClient_.close(); 64 this.interfaceEndpointClient_.close();
65 this.interfaceEndpointClient_ = null; 65 this.interfaceEndpointClient_ = null;
66 } 66 }
67 if (this.router_) { 67 if (this.router_) {
68 this.router_.close(); 68 this.router_.close();
69 this.router_ = null; 69 this.router_ = null;
70 70
71 this.proxy_ = null; 71 this.proxy_ = null;
72 } 72 }
73 if (this.handle_) { 73 if (this.handle_) {
74 core.close(this.handle_); 74 core.close(this.handle_);
75 this.handle_ = null; 75 this.handle_ = null;
76 } 76 }
77 }; 77 };
78 78
79 InterfacePtrController.prototype.resetWithReason = function(reason) { 79 InterfacePtrController.prototype.resetWithReason = function(reason) {
80 this.configureProxyIfNecessary_(); 80 if (this.isBound()) {
81 this.interfaceEndpointClient_.close(reason); 81 this.configureProxyIfNecessary_();
82 this.interfaceEndpointClient_ = null; 82 this.interfaceEndpointClient_.close(reason);
83 this.interfaceEndpointClient_ = null;
84 }
83 this.reset(); 85 this.reset();
84 }; 86 };
85 87
86 InterfacePtrController.prototype.setConnectionErrorHandler = function( 88 InterfacePtrController.prototype.setConnectionErrorHandler = function(
87 callback) { 89 callback) {
88 if (!this.isBound()) 90 if (!this.isBound())
89 throw new Error("Cannot set connection error handler if not bound."); 91 throw new Error("Cannot set connection error handler if not bound.");
90 92
91 this.configureProxyIfNecessary_(); 93 this.configureProxyIfNecessary_();
92 this.interfaceEndpointClient_.setConnectionErrorHandler(callback); 94 this.interfaceEndpointClient_.setConnectionErrorHandler(callback);
(...skipping 23 matching lines...) Expand all
116 118
117 InterfacePtrController.prototype.waitForNextMessageForTesting = function() { 119 InterfacePtrController.prototype.waitForNextMessageForTesting = function() {
118 this.configureProxyIfNecessary_(); 120 this.configureProxyIfNecessary_();
119 this.router_.waitForNextMessageForTesting(); 121 this.router_.waitForNextMessageForTesting();
120 }; 122 };
121 123
122 InterfacePtrController.prototype.configureProxyIfNecessary_ = function() { 124 InterfacePtrController.prototype.configureProxyIfNecessary_ = function() {
123 if (!this.handle_) 125 if (!this.handle_)
124 return; 126 return;
125 127
126 this.router_ = new router.Router(this.handle_); 128 this.router_ = new router.Router(this.handle_, true);
127 this.handle_ = null; 129 this.handle_ = null;
128 130
129 this.interfaceEndpointClient_ = new InterfaceEndpointClient( 131 this.interfaceEndpointClient_ = new InterfaceEndpointClient(
130 this.router_.createLocalEndpointHandle(types.kMasterInterfaceId), 132 this.router_.createLocalEndpointHandle(types.kMasterInterfaceId));
131 this.router_);
132 133
133 this.interfaceEndpointClient_ .setPayloadValidators([ 134 this.interfaceEndpointClient_ .setPayloadValidators([
134 this.interfaceType_.validateResponse]); 135 this.interfaceType_.validateResponse]);
135 this.proxy_ = new this.interfaceType_.proxyClass( 136 this.proxy_ = new this.interfaceType_.proxyClass(
136 this.interfaceEndpointClient_); 137 this.interfaceEndpointClient_);
137 }; 138 };
138 139
139 InterfacePtrController.prototype.queryVersion = function() { 140 InterfacePtrController.prototype.queryVersion = function() {
140 function onQueryVersion(version) { 141 function onQueryVersion(version) {
141 this.version = version; 142 this.version = version;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 var handle = requestOrHandle instanceof types.InterfaceRequest ? 201 var handle = requestOrHandle instanceof types.InterfaceRequest ?
201 requestOrHandle.handle : requestOrHandle; 202 requestOrHandle.handle : requestOrHandle;
202 if (!core.isHandle(handle)) 203 if (!core.isHandle(handle))
203 return; 204 return;
204 205
205 this.router_ = new router.Router(handle); 206 this.router_ = new router.Router(handle);
206 207
207 this.stub_ = new this.interfaceType_.stubClass(this.impl_); 208 this.stub_ = new this.interfaceType_.stubClass(this.impl_);
208 this.interfaceEndpointClient_ = new InterfaceEndpointClient( 209 this.interfaceEndpointClient_ = new InterfaceEndpointClient(
209 this.router_.createLocalEndpointHandle(types.kMasterInterfaceId), 210 this.router_.createLocalEndpointHandle(types.kMasterInterfaceId),
210 this.router_, this.interfaceType_.kVersion); 211 this.stub_, this.interfaceType_.kVersion);
211 this.interfaceEndpointClient_.setIncomingReceiver(this.stub_); 212
212 this.interfaceEndpointClient_ .setPayloadValidators([ 213 this.interfaceEndpointClient_ .setPayloadValidators([
213 this.interfaceType_.validateRequest]); 214 this.interfaceType_.validateRequest]);
214 }; 215 };
215 216
216 Binding.prototype.close = function() { 217 Binding.prototype.close = function() {
217 if (!this.isBound()) 218 if (!this.isBound())
218 return; 219 return;
219 220
220 if (this.interfaceEndpointClient_) { 221 if (this.interfaceEndpointClient_) {
221 this.interfaceEndpointClient_.close(); 222 this.interfaceEndpointClient_.close();
222 this.interfaceEndpointClient_ = null; 223 this.interfaceEndpointClient_ = null;
223 } 224 }
224 225
225 this.router_.close(); 226 this.router_.close();
226 this.router_ = null; 227 this.router_ = null;
227 this.stub_ = null; 228 this.stub_ = null;
228 }; 229 };
229 230
230 Binding.prototype.closeWithReason = function(reason) { 231 Binding.prototype.closeWithReason = function(reason) {
231 if (this.interfaceEndpointClient_) { 232 if (this.interfaceEndpointClient_) {
232 this.interfaceEndpointClient_.close(reason); 233 this.interfaceEndpointClient_.close(reason);
233 this.interfaceEndpointClient_ = null; 234 this.interfaceEndpointClient_ = null;
234 } 235 }
235 this.close(); 236 this.close();
236 }; 237 };
237 238
238 Binding.prototype.setConnectionErrorHandler 239 Binding.prototype.setConnectionErrorHandler = function(callback) {
239 = function(callback) {
240 if (!this.isBound()) { 240 if (!this.isBound()) {
241 throw new Error("Cannot set connection error handler if not bound."); 241 throw new Error("Cannot set connection error handler if not bound.");
242 } 242 }
243 this.interfaceEndpointClient_.setConnectionErrorHandler(callback); 243 this.interfaceEndpointClient_.setConnectionErrorHandler(callback);
244 }; 244 };
245 245
246 Binding.prototype.unbind = function() { 246 Binding.prototype.unbind = function() {
247 if (!this.isBound()) 247 if (!this.isBound())
248 return new types.InterfaceRequest(null); 248 return new types.InterfaceRequest(null);
249 249
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 var exports = {}; 313 var exports = {};
314 exports.InterfacePtrInfo = types.InterfacePtrInfo; 314 exports.InterfacePtrInfo = types.InterfacePtrInfo;
315 exports.InterfaceRequest = types.InterfaceRequest; 315 exports.InterfaceRequest = types.InterfaceRequest;
316 exports.makeRequest = makeRequest; 316 exports.makeRequest = makeRequest;
317 exports.InterfacePtrController = InterfacePtrController; 317 exports.InterfacePtrController = InterfacePtrController;
318 exports.Binding = Binding; 318 exports.Binding = Binding;
319 exports.BindingSet = BindingSet; 319 exports.BindingSet = BindingSet;
320 320
321 return exports; 321 return exports;
322 }); 322 });
OLDNEW
« no previous file with comments | « mojo/public/js/associated_bindings.js ('k') | mojo/public/js/codec.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698