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

Side by Side Diff: remoting/webapp/crd/js/client_plugin_impl.js

Issue 1015553003: Added more typechecking functions and unit tests for existing code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Class that wraps low-level details of interacting with the client plugin. 7 * Class that wraps low-level details of interacting with the client plugin.
8 * 8 *
9 * This abstracts a <embed> element and controls the plugin which does 9 * This abstracts a <embed> element and controls the plugin which does
10 * the actual remoting work. It also handles differences between 10 * the actual remoting work. It also handles differences between
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 var tokenize = function(str) { 205 var tokenize = function(str) {
206 /** @type {Array<string>} */ 206 /** @type {Array<string>} */
207 var tokens = str.match(/\S+/g); 207 var tokens = str.match(/\S+/g);
208 return tokens ? tokens : []; 208 return tokens ? tokens : [];
209 }; 209 };
210 210
211 if (this.connectionEventHandler_) { 211 if (this.connectionEventHandler_) {
212 var handler = this.connectionEventHandler_; 212 var handler = this.connectionEventHandler_;
213 213
214 if (message.method == 'sendOutgoingIq') { 214 if (message.method == 'sendOutgoingIq') {
215 handler.onOutgoingIq(getStringAttr(message.data, 'iq')); 215 handler.onOutgoingIq(base.getStringAttr(message.data, 'iq'));
216 216
217 } else if (message.method == 'logDebugMessage') { 217 } else if (message.method == 'logDebugMessage') {
218 handler.onDebugMessage(getStringAttr(message.data, 'message')); 218 handler.onDebugMessage(base.getStringAttr(message.data, 'message'));
219 219
220 } else if (message.method == 'onConnectionStatus') { 220 } else if (message.method == 'onConnectionStatus') {
221 var state = remoting.ClientSession.State.fromString( 221 var state = remoting.ClientSession.State.fromString(
222 getStringAttr(message.data, 'state')); 222 base.getStringAttr(message.data, 'state'));
223 var error = remoting.ClientSession.ConnectionError.fromString( 223 var error = remoting.ClientSession.ConnectionError.fromString(
224 getStringAttr(message.data, 'error')); 224 base.getStringAttr(message.data, 'error'));
225 handler.onConnectionStatusUpdate(state, error); 225 handler.onConnectionStatusUpdate(state, error);
226 226
227 } else if (message.method == 'onRouteChanged') { 227 } else if (message.method == 'onRouteChanged') {
228 var channel = getStringAttr(message.data, 'channel'); 228 var channel = base.getStringAttr(message.data, 'channel');
229 var connectionType = getStringAttr(message.data, 'connectionType'); 229 var connectionType = base.getStringAttr(message.data, 'connectionType');
230 handler.onRouteChanged(channel, connectionType); 230 handler.onRouteChanged(channel, connectionType);
231 231
232 } else if (message.method == 'onConnectionReady') { 232 } else if (message.method == 'onConnectionReady') {
233 var ready = getBooleanAttr(message.data, 'ready'); 233 var ready = base.getBooleanAttr(message.data, 'ready');
234 handler.onConnectionReady(ready); 234 handler.onConnectionReady(ready);
235 235
236 } else if (message.method == 'setCapabilities') { 236 } else if (message.method == 'setCapabilities') {
237 /** @type {!Array<string>} */ 237 /** @type {!Array<string>} */
238 var capabilities = tokenize(getStringAttr(message.data, 'capabilities')); 238 var capabilities = tokenize(
239 base.getStringAttr(message.data, 'capabilities'));
239 handler.onSetCapabilities(capabilities); 240 handler.onSetCapabilities(capabilities);
240 241
241 } else if (message.method == 'extensionMessage') { 242 } else if (message.method == 'extensionMessage') {
242 var extMsgType = getStringAttr(message.data, 'type'); 243 var extMsgType = base.getStringAttr(message.data, 'type');
243 var extMsgData = getStringAttr(message.data, 'data'); 244 var extMsgData = base.getStringAttr(message.data, 'data');
244 handler.onExtensionMessage(extMsgType, extMsgData); 245 handler.onExtensionMessage(extMsgType, extMsgData);
245 } 246 }
246 } 247 }
247 248
248 if (message.method == 'hello') { 249 if (message.method == 'hello') {
249 // Resize in case we had to enlarge it to support click-to-play. 250 // Resize in case we had to enlarge it to support click-to-play.
250 this.hidePluginForClickToPlay_(); 251 this.hidePluginForClickToPlay_();
251 this.pluginApiVersion_ = getNumberAttr(message.data, 'apiVersion'); 252 this.pluginApiVersion_ = base.getNumberAttr(message.data, 'apiVersion');
252 this.pluginApiMinVersion_ = getNumberAttr(message.data, 'apiMinVersion'); 253 this.pluginApiMinVersion_ =
254 base.getNumberAttr(message.data, 'apiMinVersion');
253 255
254 if (this.pluginApiVersion_ >= 7) { 256 if (this.pluginApiVersion_ >= 7) {
255 this.pluginApiFeatures_ = 257 this.pluginApiFeatures_ =
256 tokenize(getStringAttr(message.data, 'apiFeatures')); 258 tokenize(base.getStringAttr(message.data, 'apiFeatures'));
257 259
258 // Negotiate capabilities. 260 // Negotiate capabilities.
259 /** @type {!Array<string>} */ 261 /** @type {!Array<string>} */
260 var supportedCapabilities = []; 262 var supportedCapabilities = [];
261 if ('supportedCapabilities' in message.data) { 263 if ('supportedCapabilities' in message.data) {
262 supportedCapabilities = 264 supportedCapabilities =
263 tokenize(getStringAttr(message.data, 'supportedCapabilities')); 265 tokenize(base.getStringAttr(message.data, 'supportedCapabilities'));
264 } 266 }
265 // At the moment the webapp does not recognize any of 267 // At the moment the webapp does not recognize any of
266 // 'requestedCapabilities' capabilities (so they all should be disabled) 268 // 'requestedCapabilities' capabilities (so they all should be disabled)
267 // and do not care about any of 'supportedCapabilities' capabilities (so 269 // and do not care about any of 'supportedCapabilities' capabilities (so
268 // they all can be enabled). 270 // they all can be enabled).
269 // All the required capabilities (specified by the app) are added to this. 271 // All the required capabilities (specified by the app) are added to this.
270 this.capabilities_ = supportedCapabilities.concat( 272 this.capabilities_ = supportedCapabilities.concat(
271 this.requiredCapabilities_); 273 this.requiredCapabilities_);
272 } else if (this.pluginApiVersion_ >= 6) { 274 } else if (this.pluginApiVersion_ >= 6) {
273 this.pluginApiFeatures_ = ['highQualityScaling', 'injectKeyEvent']; 275 this.pluginApiFeatures_ = ['highQualityScaling', 'injectKeyEvent'];
274 } else { 276 } else {
275 this.pluginApiFeatures_ = ['highQualityScaling']; 277 this.pluginApiFeatures_ = ['highQualityScaling'];
276 } 278 }
277 this.helloReceived_ = true; 279 this.helloReceived_ = true;
278 if (this.onInitializedCallback_ != null) { 280 if (this.onInitializedCallback_ != null) {
279 this.onInitializedCallback_(true); 281 this.onInitializedCallback_(true);
280 this.onInitializedCallback_ = null; 282 this.onInitializedCallback_ = null;
281 } 283 }
282 284
283 } else if (message.method == 'onDesktopSize') { 285 } else if (message.method == 'onDesktopSize') {
284 this.hostDesktop_.onSizeUpdated(message); 286 this.hostDesktop_.onSizeUpdated(message);
285 } else if (message.method == 'onDesktopShape') { 287 } else if (message.method == 'onDesktopShape') {
286 this.hostDesktop_.onShapeUpdated(message); 288 this.hostDesktop_.onShapeUpdated(message);
287 } else if (message.method == 'onPerfStats') { 289 } else if (message.method == 'onPerfStats') {
288 // Return value is ignored. These calls will throw an error if the value 290 // Return value is ignored. These calls will throw an error if the value
289 // is not a number. 291 // is not a number.
290 getNumberAttr(message.data, 'videoBandwidth'); 292 base.getNumberAttr(message.data, 'videoBandwidth');
291 getNumberAttr(message.data, 'videoFrameRate'); 293 base.getNumberAttr(message.data, 'videoFrameRate');
292 getNumberAttr(message.data, 'captureLatency'); 294 base.getNumberAttr(message.data, 'captureLatency');
293 getNumberAttr(message.data, 'encodeLatency'); 295 base.getNumberAttr(message.data, 'encodeLatency');
294 getNumberAttr(message.data, 'decodeLatency'); 296 base.getNumberAttr(message.data, 'decodeLatency');
295 getNumberAttr(message.data, 'renderLatency'); 297 base.getNumberAttr(message.data, 'renderLatency');
296 getNumberAttr(message.data, 'roundtripLatency'); 298 base.getNumberAttr(message.data, 'roundtripLatency');
297 this.perfStats_ = 299 this.perfStats_ =
298 /** @type {remoting.ClientSession.PerfStats} */ (message.data); 300 /** @type {remoting.ClientSession.PerfStats} */ (message.data);
299 301
300 } else if (message.method == 'injectClipboardItem') { 302 } else if (message.method == 'injectClipboardItem') {
301 var mimetype = getStringAttr(message.data, 'mimeType'); 303 var mimetype = base.getStringAttr(message.data, 'mimeType');
302 var item = getStringAttr(message.data, 'item'); 304 var item = base.getStringAttr(message.data, 'item');
303 if (remoting.clipboard) { 305 if (remoting.clipboard) {
304 remoting.clipboard.fromHost(mimetype, item); 306 remoting.clipboard.fromHost(mimetype, item);
305 } 307 }
306 308
307 } else if (message.method == 'onFirstFrameReceived') { 309 } else if (message.method == 'onFirstFrameReceived') {
308 if (remoting.clientSession) { 310 if (remoting.clientSession) {
309 remoting.clientSession.onFirstFrameReceived(); 311 remoting.clientSession.onFirstFrameReceived();
310 } 312 }
311 313
312 } else if (message.method == 'fetchPin') { 314 } else if (message.method == 'fetchPin') {
313 // The pairingSupported value in the dictionary indicates whether both 315 // The pairingSupported value in the dictionary indicates whether both
314 // client and host support pairing. If the client doesn't support pairing, 316 // client and host support pairing. If the client doesn't support pairing,
315 // then the value won't be there at all, so give it a default of false. 317 // then the value won't be there at all, so give it a default of false.
316 var pairingSupported = getBooleanAttr(message.data, 'pairingSupported', 318 var pairingSupported = base.getBooleanAttr(message.data, 'pairingSupported',
317 false); 319 false);
318 this.credentials_.getPIN(pairingSupported).then( 320 this.credentials_.getPIN(pairingSupported).then(
319 this.onPinFetched_.bind(this) 321 this.onPinFetched_.bind(this)
320 ); 322 );
321 323
322 } else if (message.method == 'fetchThirdPartyToken') { 324 } else if (message.method == 'fetchThirdPartyToken') {
323 var tokenUrl = getStringAttr(message.data, 'tokenUrl'); 325 var tokenUrl = base.getStringAttr(message.data, 'tokenUrl');
324 var hostPublicKey = getStringAttr(message.data, 'hostPublicKey'); 326 var hostPublicKey = base.getStringAttr(message.data, 'hostPublicKey');
325 var scope = getStringAttr(message.data, 'scope'); 327 var scope = base.getStringAttr(message.data, 'scope');
326 this.credentials_.getThirdPartyToken(tokenUrl, hostPublicKey, scope).then( 328 this.credentials_.getThirdPartyToken(tokenUrl, hostPublicKey, scope).then(
327 this.onThirdPartyTokenFetched_.bind(this) 329 this.onThirdPartyTokenFetched_.bind(this)
328 ); 330 );
329 } else if (message.method == 'pairingResponse') { 331 } else if (message.method == 'pairingResponse') {
330 var clientId = getStringAttr(message.data, 'clientId'); 332 var clientId = base.getStringAttr(message.data, 'clientId');
331 var sharedSecret = getStringAttr(message.data, 'sharedSecret'); 333 var sharedSecret = base.getStringAttr(message.data, 'sharedSecret');
332 this.onPairingComplete_(clientId, sharedSecret); 334 this.onPairingComplete_(clientId, sharedSecret);
333 335
334 } else if (message.method == 'unsetCursorShape') { 336 } else if (message.method == 'unsetCursorShape') {
335 this.updateMouseCursorImage_('', 0, 0); 337 this.updateMouseCursorImage_('', 0, 0);
336 338
337 } else if (message.method == 'setCursorShape') { 339 } else if (message.method == 'setCursorShape') {
338 var width = getNumberAttr(message.data, 'width'); 340 var width = base.getNumberAttr(message.data, 'width');
339 var height = getNumberAttr(message.data, 'height'); 341 var height = base.getNumberAttr(message.data, 'height');
340 var hotspotX = getNumberAttr(message.data, 'hotspotX'); 342 var hotspotX = base.getNumberAttr(message.data, 'hotspotX');
341 var hotspotY = getNumberAttr(message.data, 'hotspotY'); 343 var hotspotY = base.getNumberAttr(message.data, 'hotspotY');
342 var srcArrayBuffer = getObjectAttr(message.data, 'data'); 344 var srcArrayBuffer = base.getObjectAttr(message.data, 'data');
343 345
344 var canvas = 346 var canvas =
345 /** @type {HTMLCanvasElement} */ (document.createElement('canvas')); 347 /** @type {HTMLCanvasElement} */ (document.createElement('canvas'));
346 canvas.width = width; 348 canvas.width = width;
347 canvas.height = height; 349 canvas.height = height;
348 350
349 var context = 351 var context =
350 /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d')); 352 /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
351 var imageData = context.getImageData(0, 0, width, height); 353 var imageData = context.getImageData(0, 0, width, height);
352 base.debug.assert(srcArrayBuffer instanceof ArrayBuffer); 354 base.debug.assert(srcArrayBuffer instanceof ArrayBuffer);
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() { 786 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() {
785 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') { 787 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') {
786 return; 788 return;
787 } 789 }
788 790
789 var plugin = remoting.ClientPluginImpl.createPluginElement_(); 791 var plugin = remoting.ClientPluginImpl.createPluginElement_();
790 plugin.addEventListener( 792 plugin.addEventListener(
791 'loadend', function() { document.body.removeChild(plugin); }, false); 793 'loadend', function() { document.body.removeChild(plugin); }, false);
792 document.body.appendChild(plugin); 794 document.body.appendChild(plugin);
793 }; 795 };
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/client_plugin_host_desktop_impl.js ('k') | remoting/webapp/crd/js/gnubby_auth_handler.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698