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

Side by Side Diff: remoting/webapp/client_session.js

Issue 552403004: Interfaceify ClientPlugin in preparation for mocking it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed interfaces. Created 6 years, 3 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 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 * TODO(jamiewalch): crbug.com/252796: Remove this once crbug.com/240772 is 227 * TODO(jamiewalch): crbug.com/252796: Remove this once crbug.com/240772 is
228 * fixed. 228 * fixed.
229 */ 229 */
230 remoting.ClientSession.prototype.updateScrollbarVisibility = function() { 230 remoting.ClientSession.prototype.updateScrollbarVisibility = function() {
231 var needsVerticalScroll = false; 231 var needsVerticalScroll = false;
232 var needsHorizontalScroll = false; 232 var needsHorizontalScroll = false;
233 if (!this.shrinkToFit_) { 233 if (!this.shrinkToFit_) {
234 // Determine whether or not horizontal or vertical scrollbars are 234 // Determine whether or not horizontal or vertical scrollbars are
235 // required, taking into account their width. 235 // required, taking into account their width.
236 var clientArea = this.getClientArea_(); 236 var clientArea = this.getClientArea_();
237 needsVerticalScroll = clientArea.height < this.plugin_.desktopHeight; 237 needsVerticalScroll = clientArea.height < this.plugin_.getDesktopHeight();
238 needsHorizontalScroll = clientArea.width < this.plugin_.desktopWidth; 238 needsHorizontalScroll = clientArea.width < this.plugin_.getDesktopWidth();
239 var kScrollBarWidth = 16; 239 var kScrollBarWidth = 16;
240 if (needsHorizontalScroll && !needsVerticalScroll) { 240 if (needsHorizontalScroll && !needsVerticalScroll) {
241 needsVerticalScroll = 241 needsVerticalScroll =
242 clientArea.height - kScrollBarWidth < this.plugin_.desktopHeight; 242 clientArea.height - kScrollBarWidth < this.plugin_.getDesktopHeight();
243 } else if (!needsHorizontalScroll && needsVerticalScroll) { 243 } else if (!needsHorizontalScroll && needsVerticalScroll) {
244 needsHorizontalScroll = 244 needsHorizontalScroll =
245 clientArea.width - kScrollBarWidth < this.plugin_.desktopWidth; 245 clientArea.width - kScrollBarWidth < this.plugin_.getDesktopWidth();
246 } 246 }
247 } 247 }
248 248
249 var scroller = document.getElementById('scroller'); 249 var scroller = document.getElementById('scroller');
250 if (needsHorizontalScroll) { 250 if (needsHorizontalScroll) {
251 scroller.classList.remove('no-horizontal-scroll'); 251 scroller.classList.remove('no-horizontal-scroll');
252 } else { 252 } else {
253 scroller.classList.add('no-horizontal-scroll'); 253 scroller.classList.add('no-horizontal-scroll');
254 } 254 }
255 if (needsVerticalScroll) { 255 if (needsVerticalScroll) {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 440
441 /** 441 /**
442 * Adds <embed> element to |container| and readies the sesion object. 442 * Adds <embed> element to |container| and readies the sesion object.
443 * 443 *
444 * @param {function(string, string):boolean} onExtensionMessage The handler for 444 * @param {function(string, string):boolean} onExtensionMessage The handler for
445 * protocol extension messages. Returns true if a message is recognized; 445 * protocol extension messages. Returns true if a message is recognized;
446 * false otherwise. 446 * false otherwise.
447 */ 447 */
448 remoting.ClientSession.prototype.createPluginAndConnect = 448 remoting.ClientSession.prototype.createPluginAndConnect =
449 function(onExtensionMessage) { 449 function(onExtensionMessage) {
450 this.plugin_ = new remoting.ClientPlugin( 450 this.plugin_ = remoting.ClientPlugin.factory.createPlugin(
451 this.container_.querySelector('.client-plugin-container'), 451 this.container_.querySelector('.client-plugin-container'),
452 onExtensionMessage); 452 onExtensionMessage);
453 remoting.HostSettings.load(this.hostId_, 453 remoting.HostSettings.load(this.hostId_,
454 this.onHostSettingsLoaded_.bind(this)); 454 this.onHostSettingsLoaded_.bind(this));
455 }; 455 };
456 456
457 /** 457 /**
458 * @param {Object.<string>} options The current options for the host, or {} 458 * @param {Object.<string>} options The current options for the host, or {}
459 * if this client has no saved settings for the host. 459 * if this client has no saved settings for the host.
460 * @private 460 * @private
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 this.plugin_.element().addEventListener( 493 this.plugin_.element().addEventListener(
494 'blur', this.callPluginLostFocus_, false); 494 'blur', this.callPluginLostFocus_, false);
495 this.plugin_.element().focus(); 495 this.plugin_.element().focus();
496 }; 496 };
497 497
498 /** 498 /**
499 * @param {remoting.Error} error 499 * @param {remoting.Error} error
500 */ 500 */
501 remoting.ClientSession.prototype.resetWithError_ = function(error) { 501 remoting.ClientSession.prototype.resetWithError_ = function(error) {
502 this.signalStrategy_.setIncomingStanzaCallback(null); 502 this.signalStrategy_.setIncomingStanzaCallback(null);
503 this.plugin_.cleanup(); 503 this.plugin_.dispose();
504 this.plugin_ = null; 504 this.plugin_ = null;
505 this.error_ = error; 505 this.error_ = error;
506 this.setState_(remoting.ClientSession.State.FAILED); 506 this.setState_(remoting.ClientSession.State.FAILED);
507 } 507 }
508 508
509 /** 509 /**
510 * @param {boolean} initialized 510 * @param {boolean} initialized
511 */ 511 */
512 remoting.ClientSession.prototype.onPluginInitialized_ = function(initialized) { 512 remoting.ClientSession.prototype.onPluginInitialized_ = function(initialized) {
513 if (!initialized) { 513 if (!initialized) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 this.video_.style.width = '0px'; 550 this.video_.style.width = '0px';
551 this.video_.style.height = '0px'; 551 this.video_.style.height = '0px';
552 552
553 var renderer = new remoting.MediaSourceRenderer(this.video_); 553 var renderer = new remoting.MediaSourceRenderer(this.video_);
554 this.plugin_.enableMediaSourceRendering(renderer); 554 this.plugin_.enableMediaSourceRendering(renderer);
555 this.container_.classList.add('mediasource-rendering'); 555 this.container_.classList.add('mediasource-rendering');
556 } else { 556 } else {
557 this.container_.classList.remove('mediasource-rendering'); 557 this.container_.classList.remove('mediasource-rendering');
558 } 558 }
559 559
560 /** @param {string} msg The IQ stanza to send. */ 560 this.plugin_.setOnOutgoingIqHandler(this.sendIq_.bind(this));
561 this.plugin_.onOutgoingIqHandler = this.sendIq_.bind(this); 561 this.plugin_.setOnDebugMessageHandler(
562 /** @param {string} msg The message to log. */ 562 /** @param {string} msg */
563 this.plugin_.onDebugMessageHandler = function(msg) { 563 function(msg) {
564 console.log('plugin: ' + msg.trimRight()); 564 console.log('plugin: ' + msg.trimRight());
565 }; 565 });
566 566
567 this.plugin_.onConnectionStatusUpdateHandler = 567 this.plugin_.setConnectionStatusUpdateHandler(
568 this.onConnectionStatusUpdate_.bind(this); 568 this.onConnectionStatusUpdate_.bind(this));
569 this.plugin_.onConnectionReadyHandler = this.onConnectionReady_.bind(this); 569 this.plugin_.setConnectionReadyHandler(this.onConnectionReady_.bind(this));
570 this.plugin_.onDesktopSizeUpdateHandler = 570 this.plugin_.setDesktopSizeUpdateHandler(
571 this.onDesktopSizeChanged_.bind(this); 571 this.onDesktopSizeChanged_.bind(this));
572 this.plugin_.onSetCapabilitiesHandler = this.onSetCapabilities_.bind(this); 572 this.plugin_.setCapabilitiesHandler(this.onSetCapabilities_.bind(this));
573 this.plugin_.onGnubbyAuthHandler = this.processGnubbyAuthMessage_.bind(this); 573 this.plugin_.setGnubbyAuthHandler(
574 this.plugin_.updateMouseCursorImage = this.updateMouseCursorImage_.bind(this); 574 this.processGnubbyAuthMessage_.bind(this));
575 this.plugin_.onCastExtensionHandler = 575 this.plugin_.setMouseCursorHandler(this.updateMouseCursorImage_.bind(this));
576 this.processCastExtensionMessage_.bind(this); 576 this.plugin_.setCastExtensionHandler(
577 this.processCastExtensionMessage_.bind(this));
577 this.initiateConnection_(); 578 this.initiateConnection_();
578 }; 579 };
579 580
580 /** 581 /**
581 * Deletes the <embed> element from the container, without sending a 582 * Deletes the <embed> element from the container, without sending a
582 * session_terminate request. This is to be called when the session was 583 * session_terminate request. This is to be called when the session was
583 * disconnected by the Host. 584 * disconnected by the Host.
584 * 585 *
585 * @return {void} Nothing. 586 * @return {void} Nothing.
586 */ 587 */
587 remoting.ClientSession.prototype.removePlugin = function() { 588 remoting.ClientSession.prototype.removePlugin = function() {
588 if (this.plugin_) { 589 if (this.plugin_) {
589 this.plugin_.element().removeEventListener( 590 this.plugin_.element().removeEventListener(
590 'focus', this.callPluginGotFocus_, false); 591 'focus', this.callPluginGotFocus_, false);
591 this.plugin_.element().removeEventListener( 592 this.plugin_.element().removeEventListener(
592 'blur', this.callPluginLostFocus_, false); 593 'blur', this.callPluginLostFocus_, false);
593 this.plugin_.cleanup(); 594 this.plugin_.dispose();
594 this.plugin_ = null; 595 this.plugin_ = null;
595 } 596 }
596 597
597 // Delete event handlers that aren't relevent when not connected. 598 // Delete event handlers that aren't relevent when not connected.
598 this.fullScreenButton_.removeEventListener( 599 this.fullScreenButton_.removeEventListener(
599 'click', this.callToggleFullScreen_, false); 600 'click', this.callToggleFullScreen_, false);
600 601
601 // Leave full-screen mode, and stop listening for related events. 602 // Leave full-screen mode, and stop listening for related events.
602 var listener = this.callOnFullScreenChanged_; 603 var listener = this.callOnFullScreenChanged_;
603 remoting.fullscreen.activate( 604 remoting.fullscreen.activate(
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 remoting.ClientSession.prototype.getSharedSecret_ = function(callback) { 911 remoting.ClientSession.prototype.getSharedSecret_ = function(callback) {
911 /** @type remoting.ClientSession */ 912 /** @type remoting.ClientSession */
912 var that = this; 913 var that = this;
913 if (this.plugin_.hasFeature(remoting.ClientPlugin.Feature.THIRD_PARTY_AUTH)) { 914 if (this.plugin_.hasFeature(remoting.ClientPlugin.Feature.THIRD_PARTY_AUTH)) {
914 /** @type{function(string, string, string): void} */ 915 /** @type{function(string, string, string): void} */
915 var fetchThirdPartyToken = function(tokenUrl, hostPublicKey, scope) { 916 var fetchThirdPartyToken = function(tokenUrl, hostPublicKey, scope) {
916 that.fetchThirdPartyToken_( 917 that.fetchThirdPartyToken_(
917 tokenUrl, hostPublicKey, scope, 918 tokenUrl, hostPublicKey, scope,
918 that.plugin_.onThirdPartyTokenFetched.bind(that.plugin_)); 919 that.plugin_.onThirdPartyTokenFetched.bind(that.plugin_));
919 }; 920 };
920 this.plugin_.fetchThirdPartyTokenHandler = fetchThirdPartyToken; 921 this.plugin_.setFetchThirdPartyTokenHandler(fetchThirdPartyToken);
921 } 922 }
922 if (this.accessCode_) { 923 if (this.accessCode_) {
923 // Shared secret was already supplied before connecting (It2Me case). 924 // Shared secret was already supplied before connecting (It2Me case).
924 callback(this.accessCode_); 925 callback(this.accessCode_);
925 } else if (this.plugin_.hasFeature( 926 } else if (this.plugin_.hasFeature(
926 remoting.ClientPlugin.Feature.ASYNC_PIN)) { 927 remoting.ClientPlugin.Feature.ASYNC_PIN)) {
927 // Plugin supports asynchronously asking for the PIN. 928 // Plugin supports asynchronously asking for the PIN.
928 this.plugin_.useAsyncPinDialog(); 929 this.plugin_.useAsyncPinDialog();
929 /** @param {boolean} pairingSupported */ 930 /** @param {boolean} pairingSupported */
930 var fetchPin = function(pairingSupported) { 931 var fetchPin = function(pairingSupported) {
931 that.fetchPin_(pairingSupported, 932 that.fetchPin_(pairingSupported,
932 that.plugin_.onPinFetched.bind(that.plugin_)); 933 that.plugin_.onPinFetched.bind(that.plugin_));
933 }; 934 };
934 this.plugin_.fetchPinHandler = fetchPin; 935 this.plugin_.setFetchPinHandler(fetchPin);
935 callback(''); 936 callback('');
936 } else { 937 } else {
937 // Clients that don't support asking for a PIN asynchronously also don't 938 // Clients that don't support asking for a PIN asynchronously also don't
938 // support pairing, so request the PIN now without offering to remember it. 939 // support pairing, so request the PIN now without offering to remember it.
939 this.fetchPin_(false, callback); 940 this.fetchPin_(false, callback);
940 } 941 }
941 }; 942 };
942 943
943 /** 944 /**
944 * Callback that the plugin invokes to indicate that the connection 945 * Callback that the plugin invokes to indicate that the connection
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 1141
1141 /** 1142 /**
1142 * This is a callback that gets called when the plugin notifies us of a change 1143 * This is a callback that gets called when the plugin notifies us of a change
1143 * in the size of the remote desktop. 1144 * in the size of the remote desktop.
1144 * 1145 *
1145 * @private 1146 * @private
1146 * @return {void} Nothing. 1147 * @return {void} Nothing.
1147 */ 1148 */
1148 remoting.ClientSession.prototype.onDesktopSizeChanged_ = function() { 1149 remoting.ClientSession.prototype.onDesktopSizeChanged_ = function() {
1149 console.log('desktop size changed: ' + 1150 console.log('desktop size changed: ' +
1150 this.plugin_.desktopWidth + 'x' + 1151 this.plugin_.getDesktopWidth() + 'x' +
1151 this.plugin_.desktopHeight +' @ ' + 1152 this.plugin_.getDesktopHeight() +' @ ' +
1152 this.plugin_.desktopXDpi + 'x' + 1153 this.plugin_.getDesktopXDpi() + 'x' +
1153 this.plugin_.desktopYDpi + ' DPI'); 1154 this.plugin_.getDesktopYDpi() + ' DPI');
1154 this.updateDimensions(); 1155 this.updateDimensions();
1155 this.updateScrollbarVisibility(); 1156 this.updateScrollbarVisibility();
1156 }; 1157 };
1157 1158
1158 /** 1159 /**
1159 * Refreshes the plugin's dimensions, taking into account the sizes of the 1160 * Refreshes the plugin's dimensions, taking into account the sizes of the
1160 * remote desktop and client window, and the current scale-to-fit setting. 1161 * remote desktop and client window, and the current scale-to-fit setting.
1161 * 1162 *
1162 * @return {void} Nothing. 1163 * @return {void} Nothing.
1163 */ 1164 */
1164 remoting.ClientSession.prototype.updateDimensions = function() { 1165 remoting.ClientSession.prototype.updateDimensions = function() {
1165 if (this.plugin_.desktopWidth == 0 || 1166 if (this.plugin_.getDesktopWidth() == 0 ||
1166 this.plugin_.desktopHeight == 0) { 1167 this.plugin_.getDesktopHeight() == 0) {
1167 return; 1168 return;
1168 } 1169 }
1169 1170
1170 var clientArea = this.getClientArea_(); 1171 var clientArea = this.getClientArea_();
1171 var desktopWidth = this.plugin_.desktopWidth; 1172 var desktopWidth = this.plugin_.getDesktopWidth();
1172 var desktopHeight = this.plugin_.desktopHeight; 1173 var desktopHeight = this.plugin_.getDesktopHeight();
1173 1174
1174 // When configured to display a host at its original size, we aim to display 1175 // When configured to display a host at its original size, we aim to display
1175 // it as close to its physical size as possible, without losing data: 1176 // it as close to its physical size as possible, without losing data:
1176 // - If client and host have matching DPI, render the host pixel-for-pixel. 1177 // - If client and host have matching DPI, render the host pixel-for-pixel.
1177 // - If the host has higher DPI then still render pixel-for-pixel. 1178 // - If the host has higher DPI then still render pixel-for-pixel.
1178 // - If the host has lower DPI then let Chrome up-scale it to natural size. 1179 // - If the host has lower DPI then let Chrome up-scale it to natural size.
1179 1180
1180 // We specify the plugin dimensions in Density-Independent Pixels, so to 1181 // We specify the plugin dimensions in Density-Independent Pixels, so to
1181 // render pixel-for-pixel we need to down-scale the host dimensions by the 1182 // render pixel-for-pixel we need to down-scale the host dimensions by the
1182 // devicePixelRatio of the client. To match the host pixel density, we choose 1183 // devicePixelRatio of the client. To match the host pixel density, we choose
1183 // an initial scale factor based on the client devicePixelRatio and host DPI. 1184 // an initial scale factor based on the client devicePixelRatio and host DPI.
1184 1185
1185 // Determine the effective device pixel ratio of the host, based on DPI. 1186 // Determine the effective device pixel ratio of the host, based on DPI.
1186 var hostPixelRatioX = Math.ceil(this.plugin_.desktopXDpi / 96); 1187 var hostPixelRatioX = Math.ceil(this.plugin_.getDesktopXDpi() / 96);
1187 var hostPixelRatioY = Math.ceil(this.plugin_.desktopYDpi / 96); 1188 var hostPixelRatioY = Math.ceil(this.plugin_.getDesktopYDpi() / 96);
1188 var hostPixelRatio = Math.min(hostPixelRatioX, hostPixelRatioY); 1189 var hostPixelRatio = Math.min(hostPixelRatioX, hostPixelRatioY);
1189 1190
1190 // Down-scale by the smaller of the client and host ratios. 1191 // Down-scale by the smaller of the client and host ratios.
1191 var scale = 1.0 / Math.min(window.devicePixelRatio, hostPixelRatio); 1192 var scale = 1.0 / Math.min(window.devicePixelRatio, hostPixelRatio);
1192 1193
1193 if (this.shrinkToFit_) { 1194 if (this.shrinkToFit_) {
1194 // Reduce the scale, if necessary, to fit the whole desktop in the window. 1195 // Reduce the scale, if necessary, to fit the whole desktop in the window.
1195 var scaleFitWidth = Math.min(scale, 1.0 * clientArea.width / desktopWidth); 1196 var scaleFitWidth = Math.min(scale, 1.0 * clientArea.width / desktopWidth);
1196 var scaleFitHeight = 1197 var scaleFitHeight =
1197 Math.min(scale, 1.0 * clientArea.height / desktopHeight); 1198 Math.min(scale, 1.0 * clientArea.height / desktopHeight);
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1609 * @param {string} data Contents of the extension message. 1610 * @param {string} data Contents of the extension message.
1610 * @return {boolean} True if the message was recognized, false otherwise. 1611 * @return {boolean} True if the message was recognized, false otherwise.
1611 */ 1612 */
1612 remoting.ClientSession.prototype.handleExtensionMessage = 1613 remoting.ClientSession.prototype.handleExtensionMessage =
1613 function(type, data) { 1614 function(type, data) {
1614 if (this.videoFrameRecorder_) { 1615 if (this.videoFrameRecorder_) {
1615 return this.videoFrameRecorder_.handleMessage(type, data); 1616 return this.videoFrameRecorder_.handleMessage(type, data);
1616 } 1617 }
1617 return false; 1618 return false;
1618 } 1619 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698