Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 23 matching lines...) Expand all Loading... | |
| 34 /** @param {string} message Log message. */ | 34 /** @param {string} message Log message. */ |
| 35 this.onDebugMessageHandler = function (message) {}; | 35 this.onDebugMessageHandler = function (message) {}; |
| 36 /** | 36 /** |
| 37 * @param {number} state The connection state. | 37 * @param {number} state The connection state. |
| 38 * @param {number} error The error code, if any. | 38 * @param {number} error The error code, if any. |
| 39 */ | 39 */ |
| 40 this.onConnectionStatusUpdateHandler = function(state, error) {}; | 40 this.onConnectionStatusUpdateHandler = function(state, error) {}; |
| 41 /** @param {boolean} ready Connection ready state. */ | 41 /** @param {boolean} ready Connection ready state. */ |
| 42 this.onConnectionReadyHandler = function(ready) {}; | 42 this.onConnectionReadyHandler = function(ready) {}; |
| 43 this.onDesktopSizeUpdateHandler = function () {}; | 43 this.onDesktopSizeUpdateHandler = function () {}; |
| 44 /** @param {!Array.<string>} capabilities The negotiated capabilities. */ | |
| 45 this.onSetCapabilitiesHandler = function (capabilities) {}; | |
| 44 this.fetchPinHandler = function () {}; | 46 this.fetchPinHandler = function () {}; |
| 45 | 47 |
| 46 /** @type {number} */ | 48 /** @type {number} */ |
| 47 this.pluginApiVersion_ = -1; | 49 this.pluginApiVersion_ = -1; |
| 48 /** @type {Array.<string>} */ | 50 /** @type {Array.<string>} */ |
| 49 this.pluginApiFeatures_ = []; | 51 this.pluginApiFeatures_ = []; |
| 50 /** @type {number} */ | 52 /** @type {number} */ |
| 51 this.pluginApiMinVersion_ = -1; | 53 this.pluginApiMinVersion_ = -1; |
| 54 /** @type {!Array.<string>} */ | |
| 55 this.capabilities_ = []; | |
| 52 /** @type {boolean} */ | 56 /** @type {boolean} */ |
| 53 this.helloReceived_ = false; | 57 this.helloReceived_ = false; |
| 54 /** @type {function(boolean)|null} */ | 58 /** @type {function(boolean)|null} */ |
| 55 this.onInitializedCallback_ = null; | 59 this.onInitializedCallback_ = null; |
| 56 | 60 |
| 57 /** @type {remoting.ClientSession.PerfStats} */ | 61 /** @type {remoting.ClientSession.PerfStats} */ |
| 58 this.perfStats_ = new remoting.ClientSession.PerfStats(); | 62 this.perfStats_ = new remoting.ClientSession.PerfStats(); |
| 59 | 63 |
| 60 /** @type {remoting.ClientPluginAsync} */ | 64 /** @type {remoting.ClientPluginAsync} */ |
| 61 var that = this; | 65 var that = this; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 91 */ | 95 */ |
| 92 remoting.ClientPluginAsync.prototype.handleMessage_ = function(messageStr) { | 96 remoting.ClientPluginAsync.prototype.handleMessage_ = function(messageStr) { |
| 93 var message = /** @type {{method:string, data:Object.<string,string>}} */ | 97 var message = /** @type {{method:string, data:Object.<string,string>}} */ |
| 94 jsonParseSafe(messageStr); | 98 jsonParseSafe(messageStr); |
| 95 | 99 |
| 96 if (!message || !('method' in message) || !('data' in message)) { | 100 if (!message || !('method' in message) || !('data' in message)) { |
| 97 console.error('Received invalid message from the plugin: ' + messageStr); | 101 console.error('Received invalid message from the plugin: ' + messageStr); |
| 98 return; | 102 return; |
| 99 } | 103 } |
| 100 | 104 |
| 105 /** | |
| 106 * Splits a string into a list of words delimited by spaces. | |
| 107 * @param {string} str String that should be split. | |
| 108 * @return {!Array.<string>} List of words. | |
| 109 */ | |
| 110 var tokenize = function(str) { | |
| 111 /** @type {Array.<string>} */ | |
| 112 var tokens = str.match(/\S+/g); | |
|
Sergey Ulanov
2013/04/16 08:38:53
would it be better to use .split(" ") here? at lea
alexeypa (please no reviews)
2013/04/16 22:06:11
Nope. "".split(" ") returns [""] while we want [].
| |
| 113 return tokens ? tokens : []; | |
| 114 }; | |
| 115 | |
| 101 if (message.method == 'hello') { | 116 if (message.method == 'hello') { |
| 102 // Reset the size in case we had to enlarge it to support click-to-play. | 117 // Reset the size in case we had to enlarge it to support click-to-play. |
| 103 this.plugin.width = 0; | 118 this.plugin.width = 0; |
| 104 this.plugin.height = 0; | 119 this.plugin.height = 0; |
| 105 if (typeof message.data['apiVersion'] != 'number' || | 120 if (typeof message.data['apiVersion'] != 'number' || |
| 106 typeof message.data['apiMinVersion'] != 'number') { | 121 typeof message.data['apiMinVersion'] != 'number') { |
| 107 console.error('Received invalid hello message: ' + messageStr); | 122 console.error('Received invalid hello message: ' + messageStr); |
| 108 return; | 123 return; |
| 109 } | 124 } |
| 110 this.pluginApiVersion_ = /** @type {number} */ message.data['apiVersion']; | 125 this.pluginApiVersion_ = /** @type {number} */ message.data['apiVersion']; |
| 126 | |
| 127 // Negotiate capabilities. | |
| 128 if (this.pluginApiVersion_ >= 8) { | |
|
Sergey Ulanov
2013/04/16 08:38:53
For new versions we normally use apiFeatures prope
alexeypa (please no reviews)
2013/04/16 22:06:11
Done.
| |
| 129 if (typeof message.data['requestedCapabilities'] != 'string' || | |
| 130 typeof message.data['supportedCapabilities'] != 'string') { | |
| 131 console.error('Received invalid hello message: ' + messageStr); | |
| 132 return; | |
| 133 } | |
| 134 | |
| 135 /** @type {!Array.<string>} */ | |
| 136 var requestedCapabilities = | |
| 137 tokenize(message.data['requestedCapabilities']); | |
| 138 | |
| 139 /** @type {!Array.<string>} */ | |
| 140 var supportedCapabilities = | |
| 141 tokenize(message.data['supportedCapabilities']); | |
| 142 | |
| 143 // At the moment the webapp does not recognize any of | |
| 144 // 'requestedCapabilities' capabilities (so they all should be disabled) | |
| 145 // and do not care about any of 'supportedCapabilities' capabilities (so | |
| 146 // they all can be enabled). | |
| 147 if (supportedCapabilities) | |
| 148 this.capabilities_ = supportedCapabilities; | |
| 149 | |
| 150 // Let the host know that the webapp can be requested to always send | |
| 151 // the client's dimensions. | |
| 152 this.capabilities_.push( | |
| 153 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION); | |
| 154 } | |
| 155 | |
| 111 if (this.pluginApiVersion_ >= 7) { | 156 if (this.pluginApiVersion_ >= 7) { |
| 112 if (typeof message.data['apiFeatures'] != 'string') { | 157 if (typeof message.data['apiFeatures'] != 'string') { |
| 113 console.error('Received invalid hello message: ' + messageStr); | 158 console.error('Received invalid hello message: ' + messageStr); |
| 114 return; | 159 return; |
| 115 } | 160 } |
| 116 this.pluginApiFeatures_ = | 161 this.pluginApiFeatures_ = |
| 117 /** @type {Array.<string>} */ message.data['apiFeatures'].split(' '); | 162 /** @type {Array.<string>} */ tokenize(message.data['apiFeatures']); |
| 118 } else if (this.pluginApiVersion_ >= 6) { | 163 } else if (this.pluginApiVersion_ >= 6) { |
| 119 this.pluginApiFeatures_ = ['highQualityScaling', 'injectKeyEvent']; | 164 this.pluginApiFeatures_ = ['highQualityScaling', 'injectKeyEvent']; |
| 120 } else { | 165 } else { |
| 121 this.pluginApiFeatures_ = ['highQualityScaling']; | 166 this.pluginApiFeatures_ = ['highQualityScaling']; |
| 122 } | 167 } |
| 123 this.pluginApiMinVersion_ = | 168 this.pluginApiMinVersion_ = |
| 124 /** @type {number} */ message.data['apiMinVersion']; | 169 /** @type {number} */ message.data['apiMinVersion']; |
| 125 this.helloReceived_ = true; | 170 this.helloReceived_ = true; |
| 126 if (this.onInitializedCallback_ != null) { | 171 if (this.onInitializedCallback_ != null) { |
| 127 this.onInitializedCallback_(true); | 172 this.onInitializedCallback_(true); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 } | 246 } |
| 202 } else if (message.method == 'onConnectionReady') { | 247 } else if (message.method == 'onConnectionReady') { |
| 203 if (typeof message.data['ready'] != 'boolean') { | 248 if (typeof message.data['ready'] != 'boolean') { |
| 204 console.error('Received incorrect onConnectionReady message.'); | 249 console.error('Received incorrect onConnectionReady message.'); |
| 205 return; | 250 return; |
| 206 } | 251 } |
| 207 var ready = /** @type {boolean} */ message.data['ready']; | 252 var ready = /** @type {boolean} */ message.data['ready']; |
| 208 this.onConnectionReadyHandler(ready); | 253 this.onConnectionReadyHandler(ready); |
| 209 } else if (message.method == 'fetchPin') { | 254 } else if (message.method == 'fetchPin') { |
| 210 this.fetchPinHandler(); | 255 this.fetchPinHandler(); |
| 256 } else if (message.method == 'setCapabilities') { | |
| 257 if (typeof message.data['capabilities'] != 'string') { | |
| 258 console.error('Received incorrect setCapabilities message.'); | |
| 259 return; | |
| 260 } | |
| 261 | |
| 262 /** @type {!Array.<string>} */ | |
| 263 var capabilities = tokenize(message.data['capabilities']); | |
| 264 this.onSetCapabilitiesHandler(capabilities); | |
| 211 } | 265 } |
| 212 }; | 266 }; |
| 213 | 267 |
| 214 /** | 268 /** |
| 215 * Deletes the plugin. | 269 * Deletes the plugin. |
| 216 */ | 270 */ |
| 217 remoting.ClientPluginAsync.prototype.cleanup = function() { | 271 remoting.ClientPluginAsync.prototype.cleanup = function() { |
| 218 this.plugin.parentNode.removeChild(this.plugin); | 272 this.plugin.parentNode.removeChild(this.plugin); |
| 219 }; | 273 }; |
| 220 | 274 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 remoting.ClientPluginAsync.prototype.connect = function( | 353 remoting.ClientPluginAsync.prototype.connect = function( |
| 300 hostJid, hostPublicKey, localJid, sharedSecret, | 354 hostJid, hostPublicKey, localJid, sharedSecret, |
| 301 authenticationMethods, authenticationTag) { | 355 authenticationMethods, authenticationTag) { |
| 302 this.plugin.postMessage(JSON.stringify( | 356 this.plugin.postMessage(JSON.stringify( |
| 303 { method: 'connect', data: { | 357 { method: 'connect', data: { |
| 304 hostJid: hostJid, | 358 hostJid: hostJid, |
| 305 hostPublicKey: hostPublicKey, | 359 hostPublicKey: hostPublicKey, |
| 306 localJid: localJid, | 360 localJid: localJid, |
| 307 sharedSecret: sharedSecret, | 361 sharedSecret: sharedSecret, |
| 308 authenticationMethods: authenticationMethods, | 362 authenticationMethods: authenticationMethods, |
| 309 authenticationTag: authenticationTag | 363 authenticationTag: authenticationTag, |
| 364 capabilities: this.capabilities_ | |
| 310 } | 365 } |
| 311 })); | 366 })); |
| 312 }; | 367 }; |
| 313 | 368 |
| 314 /** | 369 /** |
| 315 * Release all currently pressed keys. | 370 * Release all currently pressed keys. |
| 316 */ | 371 */ |
| 317 remoting.ClientPluginAsync.prototype.releaseAllKeys = function() { | 372 remoting.ClientPluginAsync.prototype.releaseAllKeys = function() { |
| 318 this.plugin.postMessage(JSON.stringify( | 373 this.plugin.postMessage(JSON.stringify( |
| 319 { method: 'releaseAllKeys', data: {} })); | 374 { method: 'releaseAllKeys', data: {} })); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 this.plugin.width = width; | 531 this.plugin.width = width; |
| 477 this.plugin.height = height; | 532 this.plugin.height = height; |
| 478 // Center the plugin just underneath the "Connnecting..." dialog. | 533 // Center the plugin just underneath the "Connnecting..." dialog. |
| 479 var parentNode = this.plugin.parentNode; | 534 var parentNode = this.plugin.parentNode; |
| 480 var dialog = document.getElementById('client-dialog'); | 535 var dialog = document.getElementById('client-dialog'); |
| 481 var dialogRect = dialog.getBoundingClientRect(); | 536 var dialogRect = dialog.getBoundingClientRect(); |
| 482 parentNode.style.top = (dialogRect.bottom + 16) + 'px'; | 537 parentNode.style.top = (dialogRect.bottom + 16) + 'px'; |
| 483 parentNode.style.left = (window.innerWidth - width) / 2 + 'px'; | 538 parentNode.style.left = (window.innerWidth - width) / 2 + 'px'; |
| 484 } | 539 } |
| 485 }; | 540 }; |
| OLD | NEW |