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 handling creation and teardown of a remoting client session. | 7 * Class handling creation and teardown of a remoting client session. |
8 * | 8 * |
9 * The ClientSession class controls lifetime of the client plugin | 9 * The ClientSession class controls lifetime of the client plugin |
10 * object and provides the plugin with the functionality it needs to | 10 * object and provides the plugin with the functionality it needs to |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 this.clientJid = ''; | 54 this.clientJid = ''; |
55 this.sessionId = ''; | 55 this.sessionId = ''; |
56 /** @type {remoting.ClientPlugin} */ | 56 /** @type {remoting.ClientPlugin} */ |
57 this.plugin = null; | 57 this.plugin = null; |
58 this.scaleToFit = false; | 58 this.scaleToFit = false; |
59 this.logToServer = new remoting.LogToServer(); | 59 this.logToServer = new remoting.LogToServer(); |
60 this.onStateChange = onStateChange; | 60 this.onStateChange = onStateChange; |
61 /** @type {remoting.ClientSession} */ | 61 /** @type {remoting.ClientSession} */ |
62 var that = this; | 62 var that = this; |
63 /** @type {function():void} @private */ | 63 /** @type {function():void} @private */ |
64 this.refocusPlugin_ = function() { that.plugin.element().focus(); }; | 64 this.callPluginLostFocus_ = function() { that.pluginLostFocus_(); }; |
| 65 /** @type {function():void} @private */ |
| 66 this.callPluginGotFocus_ = function() { that.pluginGotFocus_(); }; |
65 }; | 67 }; |
66 | 68 |
67 // Note that the positive values in both of these enums are copied directly | 69 // Note that the positive values in both of these enums are copied directly |
68 // from chromoting_scriptable_object.h and must be kept in sync. The negative | 70 // from chromoting_scriptable_object.h and must be kept in sync. The negative |
69 // values represent states transitions that occur within the web-app that have | 71 // values represent states transitions that occur within the web-app that have |
70 // no corresponding plugin state transition. | 72 // no corresponding plugin state transition. |
71 /** @enum {number} */ | 73 /** @enum {number} */ |
72 remoting.ClientSession.State = { | 74 remoting.ClientSession.State = { |
73 CREATED: -3, | 75 CREATED: -3, |
74 BAD_PLUGIN_VERSION: -2, | 76 BAD_PLUGIN_VERSION: -2, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 189 |
188 /** | 190 /** |
189 * Callback function called when the plugin element gets focus. | 191 * Callback function called when the plugin element gets focus. |
190 */ | 192 */ |
191 remoting.ClientSession.prototype.pluginGotFocus_ = function() { | 193 remoting.ClientSession.prototype.pluginGotFocus_ = function() { |
192 // It would be cleaner to send a paste command to the plugin element, | 194 // It would be cleaner to send a paste command to the plugin element, |
193 // but that's not supported. | 195 // but that's not supported. |
194 /** @type {function(string): void } */ | 196 /** @type {function(string): void } */ |
195 document.execCommand; | 197 document.execCommand; |
196 document.execCommand("paste"); | 198 document.execCommand("paste"); |
197 } | 199 }; |
| 200 |
| 201 /** |
| 202 * Callback function called when the plugin element loses focus. |
| 203 */ |
| 204 remoting.ClientSession.prototype.pluginLostFocus_ = function() { |
| 205 if (this.plugin) { |
| 206 // Release all keys to prevent them becoming 'stuck down' on the host. |
| 207 this.plugin.releaseAllKeys(); |
| 208 if (this.plugin.element()) { |
| 209 // Focus should stay on the element, not (for example) the toolbar. |
| 210 this.plugin.element().focus(); |
| 211 } |
| 212 } |
| 213 }; |
198 | 214 |
199 /** | 215 /** |
200 * Adds <embed> element to |container| and readies the sesion object. | 216 * Adds <embed> element to |container| and readies the sesion object. |
201 * | 217 * |
202 * @param {Element} container The element to add the plugin to. | 218 * @param {Element} container The element to add the plugin to. |
203 * @param {string} oauth2AccessToken A valid OAuth2 access token. | 219 * @param {string} oauth2AccessToken A valid OAuth2 access token. |
204 */ | 220 */ |
205 remoting.ClientSession.prototype.createPluginAndConnect = | 221 remoting.ClientSession.prototype.createPluginAndConnect = |
206 function(container, oauth2AccessToken) { | 222 function(container, oauth2AccessToken) { |
207 this.plugin = this.createClientPlugin_(container, this.PLUGIN_ID); | 223 this.plugin = this.createClientPlugin_(container, this.PLUGIN_ID); |
208 | 224 |
209 this.plugin.element().focus(); | 225 this.plugin.element().focus(); |
210 this.plugin.element().addEventListener('blur', this.refocusPlugin_, false); | |
211 | 226 |
212 /** @type {remoting.ClientSession} */ | 227 /** @type {remoting.ClientSession} */ |
213 var that = this; | 228 var that = this; |
214 /** @param {boolean} result */ | 229 /** @param {boolean} result */ |
215 this.plugin.initialize(function(result) { | 230 this.plugin.initialize(function(result) { |
216 that.onPluginInitialized_(oauth2AccessToken, result); | 231 that.onPluginInitialized_(oauth2AccessToken, result); |
217 }); | 232 }); |
218 this.plugin.element().addEventListener( | 233 this.plugin.element().addEventListener( |
219 'focus', function() { that.pluginGotFocus_() }, false); | 234 'focus', this.callPluginGotFocus_, false); |
| 235 this.plugin.element().addEventListener( |
| 236 'blur', this.callPluginLostFocus_, false); |
220 }; | 237 }; |
221 | 238 |
222 /** | 239 /** |
223 * @param {string} oauth2AccessToken | 240 * @param {string} oauth2AccessToken |
224 * @param {boolean} initialized | 241 * @param {boolean} initialized |
225 */ | 242 */ |
226 remoting.ClientSession.prototype.onPluginInitialized_ = | 243 remoting.ClientSession.prototype.onPluginInitialized_ = |
227 function(oauth2AccessToken, initialized) { | 244 function(oauth2AccessToken, initialized) { |
228 if (!initialized) { | 245 if (!initialized) { |
229 console.error('ERROR: remoting plugin not loaded'); | 246 console.error('ERROR: remoting plugin not loaded'); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 /** | 286 /** |
270 * Deletes the <embed> element from the container, without sending a | 287 * Deletes the <embed> element from the container, without sending a |
271 * session_terminate request. This is to be called when the session was | 288 * session_terminate request. This is to be called when the session was |
272 * disconnected by the Host. | 289 * disconnected by the Host. |
273 * | 290 * |
274 * @return {void} Nothing. | 291 * @return {void} Nothing. |
275 */ | 292 */ |
276 remoting.ClientSession.prototype.removePlugin = function() { | 293 remoting.ClientSession.prototype.removePlugin = function() { |
277 if (this.plugin) { | 294 if (this.plugin) { |
278 this.plugin.element().removeEventListener( | 295 this.plugin.element().removeEventListener( |
279 'blur', this.refocusPlugin_, false); | 296 'focus', this.callPluginGotFocus_, false); |
| 297 this.plugin.element().removeEventListener( |
| 298 'blur', this.callPluginLostFocus_, false); |
280 this.plugin.cleanup(); | 299 this.plugin.cleanup(); |
281 this.plugin = null; | 300 this.plugin = null; |
282 } | 301 } |
283 }; | 302 }; |
284 | 303 |
285 /** | 304 /** |
286 * Deletes the <embed> element from the container and disconnects. | 305 * Deletes the <embed> element from the container and disconnects. |
287 * | 306 * |
288 * @return {void} Nothing. | 307 * @return {void} Nothing. |
289 */ | 308 */ |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 }; | 531 }; |
513 | 532 |
514 /** | 533 /** |
515 * Logs statistics. | 534 * Logs statistics. |
516 * | 535 * |
517 * @param {remoting.ClientSession.PerfStats} stats | 536 * @param {remoting.ClientSession.PerfStats} stats |
518 */ | 537 */ |
519 remoting.ClientSession.prototype.logStatistics = function(stats) { | 538 remoting.ClientSession.prototype.logStatistics = function(stats) { |
520 this.logToServer.logStatistics(stats, this.mode); | 539 this.logToServer.logStatistics(stats, this.mode); |
521 }; | 540 }; |
OLD | NEW |