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); | |
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) { | |
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 send always send | |
Jamie
2013/04/15 22:14:11
s/to send/to/
alexeypa (please no reviews)
2013/04/15 23:18:53
Done.
| |
151 // the client's dimensions. | |
152 this.capabilities_.push('alwaysResizeToClient'); | |
Jamie
2013/04/15 22:14:11
Use ALWAYS_RESIZE_TO_CLIENT variable to avoid dupl
alexeypa (please no reviews)
2013/04/15 23:18:53
Done.
| |
153 } | |
154 | |
111 if (this.pluginApiVersion_ >= 7) { | 155 if (this.pluginApiVersion_ >= 7) { |
112 if (typeof message.data['apiFeatures'] != 'string') { | 156 if (typeof message.data['apiFeatures'] != 'string') { |
113 console.error('Received invalid hello message: ' + messageStr); | 157 console.error('Received invalid hello message: ' + messageStr); |
114 return; | 158 return; |
115 } | 159 } |
116 this.pluginApiFeatures_ = | 160 this.pluginApiFeatures_ = |
117 /** @type {Array.<string>} */ message.data['apiFeatures'].split(' '); | 161 /** @type {Array.<string>} */ tokenize(message.data['apiFeatures']); |
118 } else if (this.pluginApiVersion_ >= 6) { | 162 } else if (this.pluginApiVersion_ >= 6) { |
119 this.pluginApiFeatures_ = ['highQualityScaling', 'injectKeyEvent']; | 163 this.pluginApiFeatures_ = ['highQualityScaling', 'injectKeyEvent']; |
120 } else { | 164 } else { |
121 this.pluginApiFeatures_ = ['highQualityScaling']; | 165 this.pluginApiFeatures_ = ['highQualityScaling']; |
122 } | 166 } |
123 this.pluginApiMinVersion_ = | 167 this.pluginApiMinVersion_ = |
124 /** @type {number} */ message.data['apiMinVersion']; | 168 /** @type {number} */ message.data['apiMinVersion']; |
125 this.helloReceived_ = true; | 169 this.helloReceived_ = true; |
126 if (this.onInitializedCallback_ != null) { | 170 if (this.onInitializedCallback_ != null) { |
127 this.onInitializedCallback_(true); | 171 this.onInitializedCallback_(true); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 } | 245 } |
202 } else if (message.method == 'onConnectionReady') { | 246 } else if (message.method == 'onConnectionReady') { |
203 if (typeof message.data['ready'] != 'boolean') { | 247 if (typeof message.data['ready'] != 'boolean') { |
204 console.error('Received incorrect onConnectionReady message.'); | 248 console.error('Received incorrect onConnectionReady message.'); |
205 return; | 249 return; |
206 } | 250 } |
207 var ready = /** @type {boolean} */ message.data['ready']; | 251 var ready = /** @type {boolean} */ message.data['ready']; |
208 this.onConnectionReadyHandler(ready); | 252 this.onConnectionReadyHandler(ready); |
209 } else if (message.method == 'fetchPin') { | 253 } else if (message.method == 'fetchPin') { |
210 this.fetchPinHandler(); | 254 this.fetchPinHandler(); |
255 } else if (message.method == 'setCapabilities') { | |
256 if (typeof message.data['capabilities'] != 'string') { | |
257 console.error('Received incorrect setCapabilities message.'); | |
258 return; | |
259 } | |
260 | |
261 /** @type {!Array.<string>} */ | |
262 var capabilities = tokenize(message.data['capabilities']); | |
263 this.onSetCapabilitiesHandler(capabilities); | |
211 } | 264 } |
212 }; | 265 }; |
213 | 266 |
214 /** | 267 /** |
215 * Deletes the plugin. | 268 * Deletes the plugin. |
216 */ | 269 */ |
217 remoting.ClientPluginAsync.prototype.cleanup = function() { | 270 remoting.ClientPluginAsync.prototype.cleanup = function() { |
218 this.plugin.parentNode.removeChild(this.plugin); | 271 this.plugin.parentNode.removeChild(this.plugin); |
219 }; | 272 }; |
220 | 273 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 remoting.ClientPluginAsync.prototype.connect = function( | 352 remoting.ClientPluginAsync.prototype.connect = function( |
300 hostJid, hostPublicKey, localJid, sharedSecret, | 353 hostJid, hostPublicKey, localJid, sharedSecret, |
301 authenticationMethods, authenticationTag) { | 354 authenticationMethods, authenticationTag) { |
302 this.plugin.postMessage(JSON.stringify( | 355 this.plugin.postMessage(JSON.stringify( |
303 { method: 'connect', data: { | 356 { method: 'connect', data: { |
304 hostJid: hostJid, | 357 hostJid: hostJid, |
305 hostPublicKey: hostPublicKey, | 358 hostPublicKey: hostPublicKey, |
306 localJid: localJid, | 359 localJid: localJid, |
307 sharedSecret: sharedSecret, | 360 sharedSecret: sharedSecret, |
308 authenticationMethods: authenticationMethods, | 361 authenticationMethods: authenticationMethods, |
309 authenticationTag: authenticationTag | 362 authenticationTag: authenticationTag, |
363 capabilities: this.capabilities_ | |
310 } | 364 } |
311 })); | 365 })); |
312 }; | 366 }; |
313 | 367 |
314 /** | 368 /** |
315 * Release all currently pressed keys. | 369 * Release all currently pressed keys. |
316 */ | 370 */ |
317 remoting.ClientPluginAsync.prototype.releaseAllKeys = function() { | 371 remoting.ClientPluginAsync.prototype.releaseAllKeys = function() { |
318 this.plugin.postMessage(JSON.stringify( | 372 this.plugin.postMessage(JSON.stringify( |
319 { method: 'releaseAllKeys', data: {} })); | 373 { method: 'releaseAllKeys', data: {} })); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 this.plugin.width = width; | 530 this.plugin.width = width; |
477 this.plugin.height = height; | 531 this.plugin.height = height; |
478 // Center the plugin just underneath the "Connnecting..." dialog. | 532 // Center the plugin just underneath the "Connnecting..." dialog. |
479 var parentNode = this.plugin.parentNode; | 533 var parentNode = this.plugin.parentNode; |
480 var dialog = document.getElementById('client-dialog'); | 534 var dialog = document.getElementById('client-dialog'); |
481 var dialogRect = dialog.getBoundingClientRect(); | 535 var dialogRect = dialog.getBoundingClientRect(); |
482 parentNode.style.top = (dialogRect.bottom + 16) + 'px'; | 536 parentNode.style.top = (dialogRect.bottom + 16) + 'px'; |
483 parentNode.style.left = (window.innerWidth - width) / 2 + 'px'; | 537 parentNode.style.left = (window.innerWidth - width) / 2 + 'px'; |
484 } | 538 } |
485 }; | 539 }; |
OLD | NEW |