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 30 matching lines...) Expand all Loading... |
41 this.plugin_.id = 'session-client-plugin'; | 41 this.plugin_.id = 'session-client-plugin'; |
42 container.appendChild(this.plugin_); | 42 container.appendChild(this.plugin_); |
43 | 43 |
44 this.onExtensionMessage_ = onExtensionMessage; | 44 this.onExtensionMessage_ = onExtensionMessage; |
45 /** | 45 /** |
46 * @type {Array<string>} | 46 * @type {Array<string>} |
47 * @private | 47 * @private |
48 */ | 48 */ |
49 this.requiredCapabilities_ = requiredCapabilities; | 49 this.requiredCapabilities_ = requiredCapabilities; |
50 | 50 |
51 /** @private */ | |
52 this.desktopWidth_ = 0; | |
53 /** @private */ | |
54 this.desktopHeight_ = 0; | |
55 /** @private */ | |
56 this.desktopXDpi_ = 96; | |
57 /** @private */ | |
58 this.desktopYDpi_ = 96; | |
59 | |
60 /** | 51 /** |
61 * @param {string} iq The Iq stanza received from the host. | 52 * @param {string} iq The Iq stanza received from the host. |
62 * @private | 53 * @private |
63 */ | 54 */ |
64 this.onOutgoingIqHandler_ = function (iq) {}; | 55 this.onOutgoingIqHandler_ = function (iq) {}; |
65 /** | 56 /** |
66 * @param {string} message Log message. | 57 * @param {string} message Log message. |
67 * @private | 58 * @private |
68 */ | 59 */ |
69 this.onDebugMessageHandler_ = function (message) {}; | 60 this.onDebugMessageHandler_ = function (message) {}; |
(...skipping 18 matching lines...) Expand all Loading... |
88 this.onConnectionReadyHandler_ = function(ready) {}; | 79 this.onConnectionReadyHandler_ = function(ready) {}; |
89 | 80 |
90 /** | 81 /** |
91 * @param {string} tokenUrl Token-request URL, received from the host. | 82 * @param {string} tokenUrl Token-request URL, received from the host. |
92 * @param {string} hostPublicKey Public key for the host. | 83 * @param {string} hostPublicKey Public key for the host. |
93 * @param {string} scope OAuth scope to request the token for. | 84 * @param {string} scope OAuth scope to request the token for. |
94 * @private | 85 * @private |
95 */ | 86 */ |
96 this.fetchThirdPartyTokenHandler_ = function( | 87 this.fetchThirdPartyTokenHandler_ = function( |
97 tokenUrl, hostPublicKey, scope) {}; | 88 tokenUrl, hostPublicKey, scope) {}; |
98 /** @private */ | |
99 this.onDesktopSizeUpdateHandler_ = function () {}; | |
100 /** | |
101 * @param {Array<Array<number>>} rects | |
102 * @private | |
103 */ | |
104 this.onDesktopShapeUpdateHandler_ = function (rects) {}; | |
105 /** | 89 /** |
106 * @param {!Array<string>} capabilities The negotiated capabilities. | 90 * @param {!Array<string>} capabilities The negotiated capabilities. |
107 * @private | 91 * @private |
108 */ | 92 */ |
109 this.onSetCapabilitiesHandler_ = function (capabilities) {}; | 93 this.onSetCapabilitiesHandler_ = function (capabilities) {}; |
110 /** @private */ | 94 /** @private */ |
111 this.fetchPinHandler_ = function (supportsPairing) {}; | 95 this.fetchPinHandler_ = function (supportsPairing) {}; |
112 /** | 96 /** |
113 * @param {string} data Remote gnubbyd data. | 97 * @param {string} data Remote gnubbyd data. |
114 * @private | 98 * @private |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 var that = this; | 157 var that = this; |
174 /** @param {Event} event Message event from the plugin. */ | 158 /** @param {Event} event Message event from the plugin. */ |
175 this.plugin_.addEventListener('message', function(event) { | 159 this.plugin_.addEventListener('message', function(event) { |
176 that.handleMessage_( | 160 that.handleMessage_( |
177 /** @type {remoting.ClientPluginMessage} */ (event.data)); | 161 /** @type {remoting.ClientPluginMessage} */ (event.data)); |
178 }, false); | 162 }, false); |
179 | 163 |
180 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'native') { | 164 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'native') { |
181 window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500); | 165 window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500); |
182 } | 166 } |
| 167 |
| 168 this.hostDesktop_ = new remoting.ClientPlugin.HostDesktopImpl( |
| 169 this, this.postMessage_.bind(this)); |
183 }; | 170 }; |
184 | 171 |
185 /** | 172 /** |
186 * Creates plugin element without adding it to a container. | 173 * Creates plugin element without adding it to a container. |
187 * | 174 * |
188 * @return {HTMLEmbedElement} Plugin element | 175 * @return {HTMLEmbedElement} Plugin element |
189 */ | 176 */ |
190 remoting.ClientPluginImpl.createPluginElement_ = function() { | 177 remoting.ClientPluginImpl.createPluginElement_ = function() { |
191 var plugin = | 178 var plugin = |
192 /** @type {HTMLEmbedElement} */ (document.createElement('embed')); | 179 /** @type {HTMLEmbedElement} */ (document.createElement('embed')); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 245 |
259 /** | 246 /** |
260 * @param {function(boolean):void} handler | 247 * @param {function(boolean):void} handler |
261 */ | 248 */ |
262 remoting.ClientPluginImpl.prototype.setConnectionReadyHandler = | 249 remoting.ClientPluginImpl.prototype.setConnectionReadyHandler = |
263 function(handler) { | 250 function(handler) { |
264 this.onConnectionReadyHandler_ = handler; | 251 this.onConnectionReadyHandler_ = handler; |
265 }; | 252 }; |
266 | 253 |
267 /** | 254 /** |
268 * @param {function():void} handler | |
269 */ | |
270 remoting.ClientPluginImpl.prototype.setDesktopSizeUpdateHandler = | |
271 function(handler) { | |
272 this.onDesktopSizeUpdateHandler_ = handler; | |
273 }; | |
274 | |
275 /** | |
276 * @param {function(Array<Array<number>>):void} handler | |
277 */ | |
278 remoting.ClientPluginImpl.prototype.setDesktopShapeUpdateHandler = | |
279 function(handler) { | |
280 this.onDesktopShapeUpdateHandler_ = handler; | |
281 }; | |
282 | |
283 /** | |
284 * @param {function(!Array<string>):void} handler | 255 * @param {function(!Array<string>):void} handler |
285 */ | 256 */ |
286 remoting.ClientPluginImpl.prototype.setCapabilitiesHandler = function(handler) { | 257 remoting.ClientPluginImpl.prototype.setCapabilitiesHandler = function(handler) { |
287 this.onSetCapabilitiesHandler_ = handler; | 258 this.onSetCapabilitiesHandler_ = handler; |
288 }; | 259 }; |
289 | 260 |
290 /** | 261 /** |
291 * @param {function(string):void} handler | 262 * @param {function(string):void} handler |
292 */ | 263 */ |
293 remoting.ClientPluginImpl.prototype.setGnubbyAuthHandler = function(handler) { | 264 remoting.ClientPluginImpl.prototype.setGnubbyAuthHandler = function(handler) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // Resize in case we had to enlarge it to support click-to-play. | 338 // Resize in case we had to enlarge it to support click-to-play. |
368 this.hidePluginForClickToPlay_(); | 339 this.hidePluginForClickToPlay_(); |
369 this.pluginApiVersion_ = getNumberAttr(message.data, 'apiVersion'); | 340 this.pluginApiVersion_ = getNumberAttr(message.data, 'apiVersion'); |
370 this.pluginApiMinVersion_ = getNumberAttr(message.data, 'apiMinVersion'); | 341 this.pluginApiMinVersion_ = getNumberAttr(message.data, 'apiMinVersion'); |
371 | 342 |
372 if (this.pluginApiVersion_ >= 7) { | 343 if (this.pluginApiVersion_ >= 7) { |
373 this.pluginApiFeatures_ = | 344 this.pluginApiFeatures_ = |
374 tokenize(getStringAttr(message.data, 'apiFeatures')); | 345 tokenize(getStringAttr(message.data, 'apiFeatures')); |
375 | 346 |
376 // Negotiate capabilities. | 347 // Negotiate capabilities. |
377 | |
378 /** @type {!Array<string>} */ | |
379 var requestedCapabilities = []; | |
380 if ('requestedCapabilities' in message.data) { | |
381 requestedCapabilities = | |
382 tokenize(getStringAttr(message.data, 'requestedCapabilities')); | |
383 } | |
384 | |
385 /** @type {!Array<string>} */ | 348 /** @type {!Array<string>} */ |
386 var supportedCapabilities = []; | 349 var supportedCapabilities = []; |
387 if ('supportedCapabilities' in message.data) { | 350 if ('supportedCapabilities' in message.data) { |
388 supportedCapabilities = | 351 supportedCapabilities = |
389 tokenize(getStringAttr(message.data, 'supportedCapabilities')); | 352 tokenize(getStringAttr(message.data, 'supportedCapabilities')); |
390 } | 353 } |
391 // At the moment the webapp does not recognize any of | 354 // At the moment the webapp does not recognize any of |
392 // 'requestedCapabilities' capabilities (so they all should be disabled) | 355 // 'requestedCapabilities' capabilities (so they all should be disabled) |
393 // and do not care about any of 'supportedCapabilities' capabilities (so | 356 // and do not care about any of 'supportedCapabilities' capabilities (so |
394 // they all can be enabled). | 357 // they all can be enabled). |
(...skipping 23 matching lines...) Expand all Loading... |
418 var error = remoting.ClientSession.ConnectionError.fromString( | 381 var error = remoting.ClientSession.ConnectionError.fromString( |
419 getStringAttr(message.data, 'error')); | 382 getStringAttr(message.data, 'error')); |
420 this.onConnectionStatusUpdateHandler_(state, error); | 383 this.onConnectionStatusUpdateHandler_(state, error); |
421 | 384 |
422 } else if (message.method == 'onRouteChanged') { | 385 } else if (message.method == 'onRouteChanged') { |
423 var channel = getStringAttr(message.data, 'channel'); | 386 var channel = getStringAttr(message.data, 'channel'); |
424 var connectionType = getStringAttr(message.data, 'connectionType'); | 387 var connectionType = getStringAttr(message.data, 'connectionType'); |
425 this.onRouteChangedHandler_(channel, connectionType); | 388 this.onRouteChangedHandler_(channel, connectionType); |
426 | 389 |
427 } else if (message.method == 'onDesktopSize') { | 390 } else if (message.method == 'onDesktopSize') { |
428 this.desktopWidth_ = getNumberAttr(message.data, 'width'); | 391 this.hostDesktop_.onSizeUpdated(message); |
429 this.desktopHeight_ = getNumberAttr(message.data, 'height'); | |
430 this.desktopXDpi_ = getNumberAttr(message.data, 'x_dpi', 96); | |
431 this.desktopYDpi_ = getNumberAttr(message.data, 'y_dpi', 96); | |
432 this.onDesktopSizeUpdateHandler_(); | |
433 | |
434 } else if (message.method == 'onDesktopShape') { | 392 } else if (message.method == 'onDesktopShape') { |
435 var rects = getArrayAttr(message.data, 'rects'); | 393 this.hostDesktop_.onShapeUpdated(message); |
436 for (var i = 0; i < rects.length; ++i) { | |
437 /** @type {Array<number>} */ | |
438 var rect = rects[i]; | |
439 if (typeof rect != 'object' || rect.length != 4) { | |
440 throw 'Received invalid onDesktopShape message'; | |
441 } | |
442 } | |
443 this.onDesktopShapeUpdateHandler_(rects); | |
444 | |
445 } else if (message.method == 'onPerfStats') { | 394 } else if (message.method == 'onPerfStats') { |
446 // Return value is ignored. These calls will throw an error if the value | 395 // Return value is ignored. These calls will throw an error if the value |
447 // is not a number. | 396 // is not a number. |
448 getNumberAttr(message.data, 'videoBandwidth'); | 397 getNumberAttr(message.data, 'videoBandwidth'); |
449 getNumberAttr(message.data, 'videoFrameRate'); | 398 getNumberAttr(message.data, 'videoFrameRate'); |
450 getNumberAttr(message.data, 'captureLatency'); | 399 getNumberAttr(message.data, 'captureLatency'); |
451 getNumberAttr(message.data, 'encodeLatency'); | 400 getNumberAttr(message.data, 'encodeLatency'); |
452 getNumberAttr(message.data, 'decodeLatency'); | 401 getNumberAttr(message.data, 'decodeLatency'); |
453 getNumberAttr(message.data, 'renderLatency'); | 402 getNumberAttr(message.data, 'renderLatency'); |
454 getNumberAttr(message.data, 'roundtripLatency'); | 403 getNumberAttr(message.data, 'roundtripLatency'); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 | 700 |
752 /** | 701 /** |
753 * Notifies the host that the client has the specified size and pixel density. | 702 * Notifies the host that the client has the specified size and pixel density. |
754 * | 703 * |
755 * @param {number} width The available client width in DIPs. | 704 * @param {number} width The available client width in DIPs. |
756 * @param {number} height The available client height in DIPs. | 705 * @param {number} height The available client height in DIPs. |
757 * @param {number} device_scale The number of device pixels per DIP. | 706 * @param {number} device_scale The number of device pixels per DIP. |
758 */ | 707 */ |
759 remoting.ClientPluginImpl.prototype.notifyClientResolution = | 708 remoting.ClientPluginImpl.prototype.notifyClientResolution = |
760 function(width, height, device_scale) { | 709 function(width, height, device_scale) { |
761 if (this.hasFeature(remoting.ClientPlugin.Feature.NOTIFY_CLIENT_RESOLUTION)) { | 710 this.hostDesktop_.resize(width, height, device_scale); |
762 var dpi = Math.floor(device_scale * 96); | |
763 this.plugin_.postMessage(JSON.stringify( | |
764 { method: 'notifyClientResolution', | |
765 data: { width: Math.floor(width * device_scale), | |
766 height: Math.floor(height * device_scale), | |
767 x_dpi: dpi, y_dpi: dpi }})); | |
768 } | |
769 }; | 711 }; |
770 | 712 |
771 /** | 713 /** |
772 * Requests that the host pause or resume sending video updates. | 714 * Requests that the host pause or resume sending video updates. |
773 * | 715 * |
774 * @param {boolean} pause True to suspend video updates, false otherwise. | 716 * @param {boolean} pause True to suspend video updates, false otherwise. |
775 */ | 717 */ |
776 remoting.ClientPluginImpl.prototype.pauseVideo = | 718 remoting.ClientPluginImpl.prototype.pauseVideo = |
777 function(pause) { | 719 function(pause) { |
778 if (this.hasFeature(remoting.ClientPlugin.Feature.VIDEO_CONTROL)) { | 720 if (this.hasFeature(remoting.ClientPlugin.Feature.VIDEO_CONTROL)) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 function(type, message) { | 842 function(type, message) { |
901 if (!this.hasFeature(remoting.ClientPlugin.Feature.EXTENSION_MESSAGE)) { | 843 if (!this.hasFeature(remoting.ClientPlugin.Feature.EXTENSION_MESSAGE)) { |
902 return; | 844 return; |
903 } | 845 } |
904 this.plugin_.postMessage(JSON.stringify( | 846 this.plugin_.postMessage(JSON.stringify( |
905 { method: 'extensionMessage', | 847 { method: 'extensionMessage', |
906 data: { type: type, data: message } })); | 848 data: { type: type, data: message } })); |
907 | 849 |
908 }; | 850 }; |
909 | 851 |
910 remoting.ClientPluginImpl.prototype.getDesktopWidth = function() { | 852 remoting.ClientPluginImpl.prototype.hostDesktop = function() { |
911 return this.desktopWidth_; | 853 return this.hostDesktop_; |
912 } | 854 }; |
913 | |
914 remoting.ClientPluginImpl.prototype.getDesktopHeight = function() { | |
915 return this.desktopHeight_; | |
916 } | |
917 | |
918 remoting.ClientPluginImpl.prototype.getDesktopXDpi = function() { | |
919 return this.desktopXDpi_; | |
920 } | |
921 | |
922 remoting.ClientPluginImpl.prototype.getDesktopYDpi = function() { | |
923 return this.desktopYDpi_; | |
924 } | |
925 | 855 |
926 /** | 856 /** |
927 * If we haven't yet received a "hello" message from the plugin, change its | 857 * If we haven't yet received a "hello" message from the plugin, change its |
928 * size so that the user can confirm it if click-to-play is enabled, or can | 858 * size so that the user can confirm it if click-to-play is enabled, or can |
929 * see the "this plugin is disabled" message if it is actually disabled. | 859 * see the "this plugin is disabled" message if it is actually disabled. |
930 * @private | 860 * @private |
931 */ | 861 */ |
932 remoting.ClientPluginImpl.prototype.showPluginForClickToPlay_ = function() { | 862 remoting.ClientPluginImpl.prototype.showPluginForClickToPlay_ = function() { |
933 if (!this.helloReceived_) { | 863 if (!this.helloReceived_) { |
934 var width = 200; | 864 var width = 200; |
(...skipping 14 matching lines...) Expand all Loading... |
949 * @private | 879 * @private |
950 */ | 880 */ |
951 remoting.ClientPluginImpl.prototype.hidePluginForClickToPlay_ = function() { | 881 remoting.ClientPluginImpl.prototype.hidePluginForClickToPlay_ = function() { |
952 this.plugin_.style.width = ''; | 882 this.plugin_.style.width = ''; |
953 this.plugin_.style.height = ''; | 883 this.plugin_.style.height = ''; |
954 this.plugin_.style.top = ''; | 884 this.plugin_.style.top = ''; |
955 this.plugin_.style.left = ''; | 885 this.plugin_.style.left = ''; |
956 this.plugin_.style.position = ''; | 886 this.plugin_.style.position = ''; |
957 }; | 887 }; |
958 | 888 |
| 889 /** |
| 890 * Callback passed to submodules to post a message to the plugin. |
| 891 * |
| 892 * @param {Object} message |
| 893 * @private |
| 894 */ |
| 895 remoting.ClientPluginImpl.prototype.postMessage_ = function(message) { |
| 896 if (this.plugin_ && this.plugin_.postMessage) { |
| 897 this.plugin_.postMessage(JSON.stringify(message)); |
| 898 } |
| 899 }; |
959 | 900 |
960 /** | 901 /** |
961 * @constructor | 902 * @constructor |
962 * @implements {remoting.ClientPluginFactory} | 903 * @implements {remoting.ClientPluginFactory} |
963 */ | 904 */ |
964 remoting.DefaultClientPluginFactory = function() {}; | 905 remoting.DefaultClientPluginFactory = function() {}; |
965 | 906 |
966 /** | 907 /** |
967 * @param {Element} container | 908 * @param {Element} container |
968 * @param {function(string, string):boolean} onExtensionMessage | 909 * @param {function(string, string):boolean} onExtensionMessage |
969 * @param {Array<string>} requiredCapabilities | 910 * @param {Array<string>} requiredCapabilities |
970 * @return {remoting.ClientPlugin} | 911 * @return {remoting.ClientPlugin} |
971 */ | 912 */ |
972 remoting.DefaultClientPluginFactory.prototype.createPlugin = | 913 remoting.DefaultClientPluginFactory.prototype.createPlugin = |
973 function(container, onExtensionMessage, requiredCapabilities) { | 914 function(container, onExtensionMessage, requiredCapabilities) { |
974 return new remoting.ClientPluginImpl(container, onExtensionMessage, | 915 return new remoting.ClientPluginImpl(container, onExtensionMessage, |
975 requiredCapabilities); | 916 requiredCapabilities); |
976 }; | 917 }; |
977 | 918 |
978 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() { | 919 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() { |
979 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') { | 920 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') { |
980 return; | 921 return; |
981 } | 922 } |
982 | 923 |
983 var plugin = remoting.ClientPluginImpl.createPluginElement_(); | 924 var plugin = remoting.ClientPluginImpl.createPluginElement_(); |
984 plugin.addEventListener( | 925 plugin.addEventListener( |
985 'loadend', function() { document.body.removeChild(plugin); }, false); | 926 'loadend', function() { document.body.removeChild(plugin); }, false); |
986 document.body.appendChild(plugin); | 927 document.body.appendChild(plugin); |
987 }; | 928 }; |
OLD | NEW |