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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 * | 135 * |
136 * @type {boolean} @private | 136 * @type {boolean} @private |
137 */ | 137 */ |
138 this.logHostOfflineErrors_ = true; | 138 this.logHostOfflineErrors_ = true; |
139 | 139 |
140 /** @private */ | 140 /** @private */ |
141 this.callPluginLostFocus_ = this.pluginLostFocus_.bind(this); | 141 this.callPluginLostFocus_ = this.pluginLostFocus_.bind(this); |
142 /** @private */ | 142 /** @private */ |
143 this.callPluginGotFocus_ = this.pluginGotFocus_.bind(this); | 143 this.callPluginGotFocus_ = this.pluginGotFocus_.bind(this); |
144 /** @private */ | 144 /** @private */ |
145 this.callToggleFullScreen_ = remoting.fullscreen.toggle.bind( | |
146 remoting.fullscreen); | |
147 /** @private */ | |
148 this.callOnFullScreenChanged_ = this.onFullScreenChanged_.bind(this) | 145 this.callOnFullScreenChanged_ = this.onFullScreenChanged_.bind(this) |
149 | 146 |
150 /** @private */ | |
151 this.screenOptionsMenu_ = new remoting.MenuButton( | |
152 document.getElementById('screen-options-menu'), | |
153 this.onShowOptionsMenu_.bind(this)); | |
154 /** @private */ | |
155 this.sendKeysMenu_ = new remoting.MenuButton( | |
156 document.getElementById('send-keys-menu') | |
157 ); | |
158 | |
159 /** @type {HTMLMediaElement} @private */ | 147 /** @type {HTMLMediaElement} @private */ |
160 this.video_ = null; | 148 this.video_ = null; |
161 | 149 |
162 /** @type {Element} @private */ | 150 /** @type {Element} @private */ |
163 this.mouseCursorOverlay_ = | 151 this.mouseCursorOverlay_ = |
164 this.container_.querySelector('.mouse-cursor-overlay'); | 152 this.container_.querySelector('.mouse-cursor-overlay'); |
165 | 153 |
166 /** @type {Element} */ | 154 /** @type {Element} */ |
167 var img = this.mouseCursorOverlay_; | 155 var img = this.mouseCursorOverlay_; |
168 /** @param {Event} event @private */ | 156 /** @param {Event} event @private */ |
169 this.updateMouseCursorPosition_ = function(event) { | 157 this.updateMouseCursorPosition_ = function(event) { |
170 img.style.top = event.y + 'px'; | 158 img.style.top = event.y + 'px'; |
171 img.style.left = event.x + 'px'; | 159 img.style.left = event.x + 'px'; |
172 }; | 160 }; |
173 | 161 |
174 /** @type {HTMLElement} @private */ | |
175 this.resizeToClientButton_ = | |
176 document.getElementById('screen-resize-to-client'); | |
177 /** @type {HTMLElement} @private */ | |
178 this.shrinkToFitButton_ = document.getElementById('screen-shrink-to-fit'); | |
179 /** @type {HTMLElement} @private */ | |
180 this.fullScreenButton_ = document.getElementById('toggle-full-screen'); | |
181 | |
182 /** @type {remoting.GnubbyAuthHandler} @private */ | 162 /** @type {remoting.GnubbyAuthHandler} @private */ |
183 this.gnubbyAuthHandler_ = null; | 163 this.gnubbyAuthHandler_ = null; |
184 | 164 |
185 /** @type {remoting.CastExtensionHandler} @private */ | 165 /** @type {remoting.CastExtensionHandler} @private */ |
186 this.castExtensionHandler_ = null; | 166 this.castExtensionHandler_ = null; |
187 | 167 |
188 /** @type {remoting.VideoFrameRecorder} @private */ | 168 /** @type {remoting.VideoFrameRecorder} @private */ |
189 this.videoFrameRecorder_ = null; | 169 this.videoFrameRecorder_ = null; |
190 | 170 |
191 if (this.mode_ == remoting.ClientSession.Mode.IT2ME) { | |
192 // Resize-to-client is not supported for IT2Me hosts. | |
193 this.resizeToClientButton_.hidden = true; | |
194 } else { | |
195 this.resizeToClientButton_.hidden = false; | |
196 } | |
197 | |
198 this.fullScreenButton_.addEventListener( | |
199 'click', this.callToggleFullScreen_, false); | |
200 | |
201 this.defineEvents(Object.keys(remoting.ClientSession.Events)); | 171 this.defineEvents(Object.keys(remoting.ClientSession.Events)); |
202 }; | 172 }; |
203 | 173 |
204 base.extend(remoting.ClientSession, base.EventSource); | 174 base.extend(remoting.ClientSession, base.EventSource); |
205 | 175 |
206 /** @enum {string} */ | 176 /** @enum {string} */ |
207 remoting.ClientSession.Events = { | 177 remoting.ClientSession.Events = { |
208 stateChanged: 'stateChanged', | 178 stateChanged: 'stateChanged', |
209 videoChannelStateChanged: 'videoChannelStateChanged', | 179 videoChannelStateChanged: 'videoChannelStateChanged', |
210 bumpScrollStarted: 'bumpScrollStarted', | 180 bumpScrollStarted: 'bumpScrollStarted', |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 remoting.ClientSession.prototype.removePlugin = function() { | 558 remoting.ClientSession.prototype.removePlugin = function() { |
589 if (this.plugin_) { | 559 if (this.plugin_) { |
590 this.plugin_.element().removeEventListener( | 560 this.plugin_.element().removeEventListener( |
591 'focus', this.callPluginGotFocus_, false); | 561 'focus', this.callPluginGotFocus_, false); |
592 this.plugin_.element().removeEventListener( | 562 this.plugin_.element().removeEventListener( |
593 'blur', this.callPluginLostFocus_, false); | 563 'blur', this.callPluginLostFocus_, false); |
594 this.plugin_.dispose(); | 564 this.plugin_.dispose(); |
595 this.plugin_ = null; | 565 this.plugin_ = null; |
596 } | 566 } |
597 | 567 |
598 // Delete event handlers that aren't relevent when not connected. | |
599 this.fullScreenButton_.removeEventListener( | |
600 'click', this.callToggleFullScreen_, false); | |
601 | |
602 // Leave full-screen mode, and stop listening for related events. | 568 // Leave full-screen mode, and stop listening for related events. |
603 var listener = this.callOnFullScreenChanged_; | 569 var listener = this.callOnFullScreenChanged_; |
604 remoting.fullscreen.activate( | 570 remoting.fullscreen.activate( |
605 false, | 571 false, |
606 function() { | 572 function() { |
607 remoting.fullscreen.removeListener(listener); | 573 remoting.fullscreen.removeListener(listener); |
608 }); | 574 }); |
609 if (remoting.windowFrame) { | 575 if (remoting.windowFrame) { |
610 remoting.windowFrame.setClientSession(null); | 576 remoting.windowFrame.setClientSession(null); |
611 } else { | 577 } else { |
612 remoting.toolbar.setClientSession(null); | 578 remoting.toolbar.setClientSession(null); |
613 } | 579 } |
| 580 remoting.optionsMenu.setClientSession(null); |
614 document.body.classList.remove('connected'); | 581 document.body.classList.remove('connected'); |
615 | 582 |
616 // Remove mediasource-rendering class from the container - this will also | 583 // Remove mediasource-rendering class from the container - this will also |
617 // hide the <video> element. | 584 // hide the <video> element. |
618 this.container_.classList.remove('mediasource-rendering'); | 585 this.container_.classList.remove('mediasource-rendering'); |
619 | 586 |
620 this.container_.removeEventListener('mousemove', | 587 this.container_.removeEventListener('mousemove', |
621 this.updateMouseCursorPosition_, | 588 this.updateMouseCursorPosition_, |
622 true); | 589 true); |
623 }; | 590 }; |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 clientArea.height, | 927 clientArea.height, |
961 window.devicePixelRatio); | 928 window.devicePixelRatio); |
962 } | 929 } |
963 // Activate full-screen related UX. | 930 // Activate full-screen related UX. |
964 remoting.fullscreen.addListener(this.callOnFullScreenChanged_); | 931 remoting.fullscreen.addListener(this.callOnFullScreenChanged_); |
965 if (remoting.windowFrame) { | 932 if (remoting.windowFrame) { |
966 remoting.windowFrame.setClientSession(this); | 933 remoting.windowFrame.setClientSession(this); |
967 } else { | 934 } else { |
968 remoting.toolbar.setClientSession(this); | 935 remoting.toolbar.setClientSession(this); |
969 } | 936 } |
| 937 remoting.optionsMenu.setClientSession(this); |
970 document.body.classList.add('connected'); | 938 document.body.classList.add('connected'); |
971 | 939 |
972 this.container_.addEventListener('mousemove', | 940 this.container_.addEventListener('mousemove', |
973 this.updateMouseCursorPosition_, | 941 this.updateMouseCursorPosition_, |
974 true); | 942 true); |
975 | 943 |
976 } else if (status == remoting.ClientSession.State.FAILED) { | 944 } else if (status == remoting.ClientSession.State.FAILED) { |
977 switch (error) { | 945 switch (error) { |
978 case remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE: | 946 case remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE: |
979 this.error_ = remoting.Error.HOST_IS_OFFLINE; | 947 this.error_ = remoting.Error.HOST_IS_OFFLINE; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 var htmlNode = /** @type {HTMLElement} */ (document.documentElement); | 1266 var htmlNode = /** @type {HTMLElement} */ (document.documentElement); |
1299 this.enableBumpScroll_(fullscreen); | 1267 this.enableBumpScroll_(fullscreen); |
1300 if (fullscreen) { | 1268 if (fullscreen) { |
1301 htmlNode.classList.add('full-screen'); | 1269 htmlNode.classList.add('full-screen'); |
1302 } else { | 1270 } else { |
1303 htmlNode.classList.remove('full-screen'); | 1271 htmlNode.classList.remove('full-screen'); |
1304 } | 1272 } |
1305 }; | 1273 }; |
1306 | 1274 |
1307 /** | 1275 /** |
1308 * Updates the options menu to reflect the current scale-to-fit and full-screen | |
1309 * settings. | |
1310 * @return {void} Nothing. | |
1311 * @private | |
1312 */ | |
1313 remoting.ClientSession.prototype.onShowOptionsMenu_ = function() { | |
1314 remoting.MenuButton.select(this.resizeToClientButton_, this.resizeToClient_); | |
1315 remoting.MenuButton.select(this.shrinkToFitButton_, this.shrinkToFit_); | |
1316 remoting.MenuButton.select(this.fullScreenButton_, | |
1317 remoting.fullscreen.isActive()); | |
1318 }; | |
1319 | |
1320 /** | |
1321 * Scroll the client plugin by the specified amount, keeping it visible. | 1276 * Scroll the client plugin by the specified amount, keeping it visible. |
1322 * Note that this is only used in content full-screen mode (not windowed or | 1277 * Note that this is only used in content full-screen mode (not windowed or |
1323 * browser full-screen modes), where window.scrollBy and the scrollTop and | 1278 * browser full-screen modes), where window.scrollBy and the scrollTop and |
1324 * scrollLeft properties don't work. | 1279 * scrollLeft properties don't work. |
1325 * @param {number} dx The amount by which to scroll horizontally. Positive to | 1280 * @param {number} dx The amount by which to scroll horizontally. Positive to |
1326 * scroll right; negative to scroll left. | 1281 * scroll right; negative to scroll left. |
1327 * @param {number} dy The amount by which to scroll vertically. Positive to | 1282 * @param {number} dy The amount by which to scroll vertically. Positive to |
1328 * scroll down; negative to scroll up. | 1283 * scroll down; negative to scroll up. |
1329 * @return {boolean} True if the requested scroll had no effect because both | 1284 * @return {boolean} True if the requested scroll had no effect because both |
1330 * vertical and horizontal edges of the screen have been reached. | 1285 * vertical and horizontal edges of the screen have been reached. |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 * @param {string} data Contents of the extension message. | 1565 * @param {string} data Contents of the extension message. |
1611 * @return {boolean} True if the message was recognized, false otherwise. | 1566 * @return {boolean} True if the message was recognized, false otherwise. |
1612 */ | 1567 */ |
1613 remoting.ClientSession.prototype.handleExtensionMessage = | 1568 remoting.ClientSession.prototype.handleExtensionMessage = |
1614 function(type, data) { | 1569 function(type, data) { |
1615 if (this.videoFrameRecorder_) { | 1570 if (this.videoFrameRecorder_) { |
1616 return this.videoFrameRecorder_.handleMessage(type, data); | 1571 return this.videoFrameRecorder_.handleMessage(type, data); |
1617 } | 1572 } |
1618 return false; | 1573 return false; |
1619 } | 1574 } |
OLD | NEW |