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

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

Issue 929323003: Separate host desktop related functionality into remoting.HostDesktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Jamie's feedback Created 5 years, 10 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 30 matching lines...) Expand all
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
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 27 matching lines...) Expand all
142 * @type {number} 126 * @type {number}
143 * @private 127 * @private
144 */ 128 */
145 this.pluginApiMinVersion_ = -1; 129 this.pluginApiMinVersion_ = -1;
146 /** 130 /**
147 * @type {!Array<string>} 131 * @type {!Array<string>}
148 * @private 132 * @private
149 */ 133 */
150 this.capabilities_ = []; 134 this.capabilities_ = [];
151 /** 135 /**
136 * @type {!Array<string>}
137 * @private
138 */
139 this.hostCapabilities_ = [];
140 /**
152 * @type {boolean} 141 * @type {boolean}
153 * @private 142 * @private
154 */ 143 */
155 this.helloReceived_ = false; 144 this.helloReceived_ = false;
156 /** 145 /**
157 * @type {function(boolean)|null} 146 * @type {function(boolean)|null}
158 * @private 147 * @private
159 */ 148 */
160 this.onInitializedCallback_ = null; 149 this.onInitializedCallback_ = null;
161 /** 150 /**
(...skipping 11 matching lines...) Expand all
173 var that = this; 162 var that = this;
174 /** @param {Event} event Message event from the plugin. */ 163 /** @param {Event} event Message event from the plugin. */
175 this.plugin_.addEventListener('message', function(event) { 164 this.plugin_.addEventListener('message', function(event) {
176 that.handleMessage_( 165 that.handleMessage_(
177 /** @type {remoting.ClientPluginMessage} */ (event.data)); 166 /** @type {remoting.ClientPluginMessage} */ (event.data));
178 }, false); 167 }, false);
179 168
180 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'native') { 169 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'native') {
181 window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500); 170 window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500);
182 } 171 }
172
173 this.hostDesktop_ = new remoting.ClientPlugin.HostDesktopImpl(
174 this, this.postMessage_.bind(this));
183 }; 175 };
184 176
185 /** 177 /**
186 * Creates plugin element without adding it to a container. 178 * Creates plugin element without adding it to a container.
187 * 179 *
188 * @return {HTMLEmbedElement} Plugin element 180 * @return {HTMLEmbedElement} Plugin element
189 */ 181 */
190 remoting.ClientPluginImpl.createPluginElement_ = function() { 182 remoting.ClientPluginImpl.createPluginElement_ = function() {
191 var plugin = 183 var plugin =
192 /** @type {HTMLEmbedElement} */ (document.createElement('embed')); 184 /** @type {HTMLEmbedElement} */ (document.createElement('embed'));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 250
259 /** 251 /**
260 * @param {function(boolean):void} handler 252 * @param {function(boolean):void} handler
261 */ 253 */
262 remoting.ClientPluginImpl.prototype.setConnectionReadyHandler = 254 remoting.ClientPluginImpl.prototype.setConnectionReadyHandler =
263 function(handler) { 255 function(handler) {
264 this.onConnectionReadyHandler_ = handler; 256 this.onConnectionReadyHandler_ = handler;
265 }; 257 };
266 258
267 /** 259 /**
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 260 * @param {function(!Array<string>):void} handler
285 */ 261 */
286 remoting.ClientPluginImpl.prototype.setCapabilitiesHandler = function(handler) { 262 remoting.ClientPluginImpl.prototype.setCapabilitiesHandler = function(handler) {
287 this.onSetCapabilitiesHandler_ = handler; 263 this.onSetCapabilitiesHandler_ = handler;
288 }; 264 };
289 265
290 /** 266 /**
291 * @param {function(string):void} handler 267 * @param {function(string):void} handler
292 */ 268 */
293 remoting.ClientPluginImpl.prototype.setGnubbyAuthHandler = function(handler) { 269 remoting.ClientPluginImpl.prototype.setGnubbyAuthHandler = function(handler) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // Resize in case we had to enlarge it to support click-to-play. 343 // Resize in case we had to enlarge it to support click-to-play.
368 this.hidePluginForClickToPlay_(); 344 this.hidePluginForClickToPlay_();
369 this.pluginApiVersion_ = getNumberAttr(message.data, 'apiVersion'); 345 this.pluginApiVersion_ = getNumberAttr(message.data, 'apiVersion');
370 this.pluginApiMinVersion_ = getNumberAttr(message.data, 'apiMinVersion'); 346 this.pluginApiMinVersion_ = getNumberAttr(message.data, 'apiMinVersion');
371 347
372 if (this.pluginApiVersion_ >= 7) { 348 if (this.pluginApiVersion_ >= 7) {
373 this.pluginApiFeatures_ = 349 this.pluginApiFeatures_ =
374 tokenize(getStringAttr(message.data, 'apiFeatures')); 350 tokenize(getStringAttr(message.data, 'apiFeatures'));
375 351
376 // Negotiate capabilities. 352 // 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>} */ 353 /** @type {!Array<string>} */
386 var supportedCapabilities = []; 354 var supportedCapabilities = [];
387 if ('supportedCapabilities' in message.data) { 355 if ('supportedCapabilities' in message.data) {
388 supportedCapabilities = 356 supportedCapabilities =
389 tokenize(getStringAttr(message.data, 'supportedCapabilities')); 357 tokenize(getStringAttr(message.data, 'supportedCapabilities'));
390 } 358 }
391 // At the moment the webapp does not recognize any of 359 // At the moment the webapp does not recognize any of
392 // 'requestedCapabilities' capabilities (so they all should be disabled) 360 // 'requestedCapabilities' capabilities (so they all should be disabled)
393 // and do not care about any of 'supportedCapabilities' capabilities (so 361 // and do not care about any of 'supportedCapabilities' capabilities (so
394 // they all can be enabled). 362 // they all can be enabled).
(...skipping 23 matching lines...) Expand all
418 var error = remoting.ClientSession.ConnectionError.fromString( 386 var error = remoting.ClientSession.ConnectionError.fromString(
419 getStringAttr(message.data, 'error')); 387 getStringAttr(message.data, 'error'));
420 this.onConnectionStatusUpdateHandler_(state, error); 388 this.onConnectionStatusUpdateHandler_(state, error);
421 389
422 } else if (message.method == 'onRouteChanged') { 390 } else if (message.method == 'onRouteChanged') {
423 var channel = getStringAttr(message.data, 'channel'); 391 var channel = getStringAttr(message.data, 'channel');
424 var connectionType = getStringAttr(message.data, 'connectionType'); 392 var connectionType = getStringAttr(message.data, 'connectionType');
425 this.onRouteChangedHandler_(channel, connectionType); 393 this.onRouteChangedHandler_(channel, connectionType);
426 394
427 } else if (message.method == 'onDesktopSize') { 395 } else if (message.method == 'onDesktopSize') {
428 this.desktopWidth_ = getNumberAttr(message.data, 'width'); 396 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') { 397 } else if (message.method == 'onDesktopShape') {
435 var rects = getArrayAttr(message.data, 'rects'); 398 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') { 399 } else if (message.method == 'onPerfStats') {
446 // Return value is ignored. These calls will throw an error if the value 400 // Return value is ignored. These calls will throw an error if the value
447 // is not a number. 401 // is not a number.
448 getNumberAttr(message.data, 'videoBandwidth'); 402 getNumberAttr(message.data, 'videoBandwidth');
449 getNumberAttr(message.data, 'videoFrameRate'); 403 getNumberAttr(message.data, 'videoFrameRate');
450 getNumberAttr(message.data, 'captureLatency'); 404 getNumberAttr(message.data, 'captureLatency');
451 getNumberAttr(message.data, 'encodeLatency'); 405 getNumberAttr(message.data, 'encodeLatency');
452 getNumberAttr(message.data, 'decodeLatency'); 406 getNumberAttr(message.data, 'decodeLatency');
453 getNumberAttr(message.data, 'renderLatency'); 407 getNumberAttr(message.data, 'renderLatency');
454 getNumberAttr(message.data, 'roundtripLatency'); 408 getNumberAttr(message.data, 'roundtripLatency');
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 remoting.ClientPluginImpl.prototype.hasFeature = function(feature) { 548 remoting.ClientPluginImpl.prototype.hasFeature = function(feature) {
595 if (!this.helloReceived_) { 549 if (!this.helloReceived_) {
596 console.error( 550 console.error(
597 "hasFeature() is called before the plugin is initialized."); 551 "hasFeature() is called before the plugin is initialized.");
598 return false; 552 return false;
599 } 553 }
600 return this.pluginApiFeatures_.indexOf(feature) > -1; 554 return this.pluginApiFeatures_.indexOf(feature) > -1;
601 }; 555 };
602 556
603 /** 557 /**
558 * @param {string} capability The capability to test for.
559 * @return {boolean} True if the host supports the named capability.
560 */
561 remoting.ClientPluginImpl.prototype.hasCapability = function(capability) {
Jamie 2015/02/19 22:44:04 I don't think you need this any more.
kelvinp 2015/02/19 23:36:20 I am keeping this function as it still would be us
562 if (!this.hostCapabilities_) {
563 console.error(
564 "hasCapability() is called before the capabilities are received.");
565 return false;
566 }
567 return this.hostCapabilities_.indexOf(capability) > -1;
568 };
569
570 /**
604 * @return {boolean} True if the plugin supports the injectKeyEvent API. 571 * @return {boolean} True if the plugin supports the injectKeyEvent API.
605 */ 572 */
606 remoting.ClientPluginImpl.prototype.isInjectKeyEventSupported = function() { 573 remoting.ClientPluginImpl.prototype.isInjectKeyEventSupported = function() {
607 return this.pluginApiVersion_ >= 6; 574 return this.pluginApiVersion_ >= 6;
608 }; 575 };
609 576
610 /** 577 /**
611 * @param {string} iq Incoming IQ stanza. 578 * @param {string} iq Incoming IQ stanza.
612 */ 579 */
613 remoting.ClientPluginImpl.prototype.onIncomingIq = function(iq) { 580 remoting.ClientPluginImpl.prototype.onIncomingIq = function(iq) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 718
752 /** 719 /**
753 * Notifies the host that the client has the specified size and pixel density. 720 * Notifies the host that the client has the specified size and pixel density.
754 * 721 *
755 * @param {number} width The available client width in DIPs. 722 * @param {number} width The available client width in DIPs.
756 * @param {number} height The available client height in DIPs. 723 * @param {number} height The available client height in DIPs.
757 * @param {number} device_scale The number of device pixels per DIP. 724 * @param {number} device_scale The number of device pixels per DIP.
758 */ 725 */
759 remoting.ClientPluginImpl.prototype.notifyClientResolution = 726 remoting.ClientPluginImpl.prototype.notifyClientResolution =
760 function(width, height, device_scale) { 727 function(width, height, device_scale) {
761 if (this.hasFeature(remoting.ClientPlugin.Feature.NOTIFY_CLIENT_RESOLUTION)) { 728 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 }; 729 };
770 730
771 /** 731 /**
772 * Requests that the host pause or resume sending video updates. 732 * Requests that the host pause or resume sending video updates.
773 * 733 *
774 * @param {boolean} pause True to suspend video updates, false otherwise. 734 * @param {boolean} pause True to suspend video updates, false otherwise.
775 */ 735 */
776 remoting.ClientPluginImpl.prototype.pauseVideo = 736 remoting.ClientPluginImpl.prototype.pauseVideo =
777 function(pause) { 737 function(pause) {
778 if (this.hasFeature(remoting.ClientPlugin.Feature.VIDEO_CONTROL)) { 738 if (this.hasFeature(remoting.ClientPlugin.Feature.VIDEO_CONTROL)) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 function(type, message) { 860 function(type, message) {
901 if (!this.hasFeature(remoting.ClientPlugin.Feature.EXTENSION_MESSAGE)) { 861 if (!this.hasFeature(remoting.ClientPlugin.Feature.EXTENSION_MESSAGE)) {
902 return; 862 return;
903 } 863 }
904 this.plugin_.postMessage(JSON.stringify( 864 this.plugin_.postMessage(JSON.stringify(
905 { method: 'extensionMessage', 865 { method: 'extensionMessage',
906 data: { type: type, data: message } })); 866 data: { type: type, data: message } }));
907 867
908 }; 868 };
909 869
910 remoting.ClientPluginImpl.prototype.getDesktopWidth = function() { 870 remoting.ClientPluginImpl.prototype.hostDesktop = function() {
911 return this.desktopWidth_; 871 return this.hostDesktop_;
912 } 872 };
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 873
926 /** 874 /**
927 * If we haven't yet received a "hello" message from the plugin, change its 875 * 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 876 * 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. 877 * see the "this plugin is disabled" message if it is actually disabled.
930 * @private 878 * @private
931 */ 879 */
932 remoting.ClientPluginImpl.prototype.showPluginForClickToPlay_ = function() { 880 remoting.ClientPluginImpl.prototype.showPluginForClickToPlay_ = function() {
933 if (!this.helloReceived_) { 881 if (!this.helloReceived_) {
934 var width = 200; 882 var width = 200;
(...skipping 14 matching lines...) Expand all
949 * @private 897 * @private
950 */ 898 */
951 remoting.ClientPluginImpl.prototype.hidePluginForClickToPlay_ = function() { 899 remoting.ClientPluginImpl.prototype.hidePluginForClickToPlay_ = function() {
952 this.plugin_.style.width = ''; 900 this.plugin_.style.width = '';
953 this.plugin_.style.height = ''; 901 this.plugin_.style.height = '';
954 this.plugin_.style.top = ''; 902 this.plugin_.style.top = '';
955 this.plugin_.style.left = ''; 903 this.plugin_.style.left = '';
956 this.plugin_.style.position = ''; 904 this.plugin_.style.position = '';
957 }; 905 };
958 906
907 /**
908 * Callback passed to submodules to post a message to the plugin.
909 *
910 * @param {Object} objectLiteral
Jamie 2015/02/19 22:44:04 |objectLiteral| doesn't describe what this paramet
kelvinp 2015/02/19 23:36:20 Done.
911 * @private
912 */
913 remoting.ClientPluginImpl.prototype.postMessage_ = function(objectLiteral) {
914 if (this.plugin_ && this.plugin_.postMessage) {
915 this.plugin_.postMessage(JSON.stringify(objectLiteral));
916 }
917 };
959 918
960 /** 919 /**
961 * @constructor 920 * @constructor
962 * @implements {remoting.ClientPluginFactory} 921 * @implements {remoting.ClientPluginFactory}
963 */ 922 */
964 remoting.DefaultClientPluginFactory = function() {}; 923 remoting.DefaultClientPluginFactory = function() {};
965 924
966 /** 925 /**
967 * @param {Element} container 926 * @param {Element} container
968 * @param {function(string, string):boolean} onExtensionMessage 927 * @param {function(string, string):boolean} onExtensionMessage
969 * @param {Array<string>} requiredCapabilities 928 * @param {Array<string>} requiredCapabilities
970 * @return {remoting.ClientPlugin} 929 * @return {remoting.ClientPlugin}
971 */ 930 */
972 remoting.DefaultClientPluginFactory.prototype.createPlugin = 931 remoting.DefaultClientPluginFactory.prototype.createPlugin =
973 function(container, onExtensionMessage, requiredCapabilities) { 932 function(container, onExtensionMessage, requiredCapabilities) {
974 return new remoting.ClientPluginImpl(container, onExtensionMessage, 933 return new remoting.ClientPluginImpl(container, onExtensionMessage,
975 requiredCapabilities); 934 requiredCapabilities);
976 }; 935 };
977 936
978 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() { 937 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() {
979 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') { 938 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') {
980 return; 939 return;
981 } 940 }
982 941
983 var plugin = remoting.ClientPluginImpl.createPluginElement_(); 942 var plugin = remoting.ClientPluginImpl.createPluginElement_();
984 plugin.addEventListener( 943 plugin.addEventListener(
985 'loadend', function() { document.body.removeChild(plugin); }, false); 944 'loadend', function() { document.body.removeChild(plugin); }, false);
986 document.body.appendChild(plugin); 945 document.body.appendChild(plugin);
987 }; 946 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698