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

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

Issue 981083002: [Chromoting] Move ownership of ClientPlugin into SessionConnector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 5 years, 9 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
« no previous file with comments | « remoting/webapp/crd/js/client_session.js ('k') | remoting/webapp/crd/js/session_connector.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 user-facing aspects of the client session. 7 * Class handling user-facing aspects of the client session.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
11 11
12 /** @suppress {duplicate} */ 12 /** @suppress {duplicate} */
13 var remoting = remoting || {}; 13 var remoting = remoting || {};
14 14
15 /** 15 /**
16 * True to enable mouse lock. 16 * True to enable mouse lock.
17 * This is currently disabled because the current client plugin does not 17 * This is currently disabled because the current client plugin does not
18 * properly handle mouse lock and delegated large cursors at the same time. 18 * properly handle mouse lock and delegated large cursors at the same time.
19 * This should be re-enabled (by removing this flag) once a version of 19 * This should be re-enabled (by removing this flag) once a version of
20 * the plugin that supports both has reached Chrome Stable channel. 20 * the plugin that supports both has reached Chrome Stable channel.
21 * (crbug.com/429322). 21 * (crbug.com/429322).
22 * 22 *
23 * @type {boolean} 23 * @type {boolean}
24 */ 24 */
25 remoting.enableMouseLock = false; 25 remoting.enableMouseLock = false;
26 26
27 /** 27 /**
28 * @param {remoting.ClientPlugin} plugin
28 * @param {remoting.ClientSession} session 29 * @param {remoting.ClientSession} session
29 * @param {HTMLElement} container 30 * @param {HTMLElement} container
30 * @param {remoting.Host} host 31 * @param {remoting.Host} host
31 * @param {remoting.DesktopConnectedView.Mode} mode The mode of this connection. 32 * @param {remoting.DesktopConnectedView.Mode} mode The mode of this connection.
32 * @param {string} defaultRemapKeys The default set of remap keys, to use 33 * @param {string} defaultRemapKeys The default set of remap keys, to use
33 * when the client doesn't define any. 34 * when the client doesn't define any.
34 * @param {function(remoting.Error, remoting.ClientPlugin): void} onInitialized
35 * @constructor 35 * @constructor
36 * @extends {base.EventSourceImpl} 36 * @extends {base.EventSourceImpl}
37 */ 37 */
38 remoting.DesktopConnectedView = function(session, container, host, mode, 38 remoting.DesktopConnectedView = function(plugin, session, container, host, mode,
39 defaultRemapKeys, onInitialized) { 39 defaultRemapKeys) {
40 this.session_ = session; 40 this.session_ = session;
41 41
42 /** @private {HTMLElement} */ 42 /** @private {HTMLElement} */
43 this.container_ = container; 43 this.container_ = container;
44 44
45 /** @private {remoting.ClientPlugin} */ 45 /** @private {remoting.ClientPlugin} */
46 this.plugin_ = null; 46 this.plugin_ = plugin;
47 47
48 /** @private */ 48 /** @private */
49 this.host_ = host; 49 this.host_ = host;
50 50
51 /** @private */ 51 /** @private */
52 this.mode_ = mode; 52 this.mode_ = mode;
53 53
54 /** @private {string} */ 54 /** @private {string} */
55 this.defaultRemapKeys_ = defaultRemapKeys; 55 this.defaultRemapKeys_ = defaultRemapKeys;
56 56
57 /**
58 * Called when the UI is finished initializing.
59 * @type {function(remoting.Error, remoting.ClientPlugin):void}
60 */
61 this.onInitialized_ = onInitialized;
62
63 /** @private */ 57 /** @private */
64 this.callPluginLostFocus_ = this.pluginLostFocus_.bind(this); 58 this.callPluginLostFocus_ = this.pluginLostFocus_.bind(this);
65 /** @private */ 59 /** @private */
66 this.callPluginGotFocus_ = this.pluginGotFocus_.bind(this); 60 this.callPluginGotFocus_ = this.pluginGotFocus_.bind(this);
67 /** @private {Element} */ 61 /** @private {Element} */
68 this.debugRegionContainer_ = 62 this.debugRegionContainer_ =
69 this.container_.querySelector('.debug-region-container'); 63 this.container_.querySelector('.debug-region-container');
70 64
71 /** @private {Element} */ 65 /** @private {Element} */
72 this.mouseCursorOverlay_ = 66 this.mouseCursorOverlay_ =
(...skipping 11 matching lines...) Expand all
84 this.updateMouseCursorPosition_ = function(event) { 78 this.updateMouseCursorPosition_ = function(event) {
85 img.style.top = event.offsetY + 'px'; 79 img.style.top = event.offsetY + 'px';
86 img.style.left = event.offsetX + 'px'; 80 img.style.left = event.offsetX + 'px';
87 }; 81 };
88 82
89 /** @private {remoting.VideoFrameRecorder} */ 83 /** @private {remoting.VideoFrameRecorder} */
90 this.videoFrameRecorder_ = null; 84 this.videoFrameRecorder_ = null;
91 85
92 /** private {base.Disposable} */ 86 /** private {base.Disposable} */
93 this.eventHooks_ = null; 87 this.eventHooks_ = null;
88
89 this.setupPlugin_();
94 }; 90 };
95 91
96 // The mode of this session. 92 // The mode of this session.
97 /** @enum {number} */ 93 /** @enum {number} */
98 remoting.DesktopConnectedView.Mode = { 94 remoting.DesktopConnectedView.Mode = {
99 IT2ME: 0, 95 IT2ME: 0,
100 ME2ME: 1, 96 ME2ME: 1,
101 APP_REMOTING: 2 97 APP_REMOTING: 2
102 }; 98 };
103 99
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 */ 145 */
150 remoting.DesktopConnectedView.prototype.getPluginContainer_ = function() { 146 remoting.DesktopConnectedView.prototype.getPluginContainer_ = function() {
151 return this.container_.querySelector('.client-plugin-container'); 147 return this.container_.querySelector('.client-plugin-container');
152 }; 148 };
153 149
154 /** @return {remoting.DesktopViewport} */ 150 /** @return {remoting.DesktopViewport} */
155 remoting.DesktopConnectedView.prototype.getViewportForTesting = function() { 151 remoting.DesktopConnectedView.prototype.getViewportForTesting = function() {
156 return this.viewport_; 152 return this.viewport_;
157 }; 153 };
158 154
159 /** 155 /** @private */
160 * Adds <embed> element to the UI container and readies the session object. 156 remoting.DesktopConnectedView.prototype.setupPlugin_ = function() {
161 *
162 * @param {function(string, string):boolean} onExtensionMessage The handler for
163 * protocol extension messages. Returns true if a message is recognized;
164 * false otherwise.
165 * @param {Array<string>} requiredCapabilities A list of capabilities
166 * required by this application.
167 */
168 remoting.DesktopConnectedView.prototype.createPluginAndConnect =
169 function(onExtensionMessage, requiredCapabilities) {
170 this.plugin_ = remoting.ClientPlugin.factory.createPlugin(
171 this.getPluginContainer_(),
172 onExtensionMessage, requiredCapabilities);
173 var that = this;
174 this.host_.options.load().then(function(){
175 that.plugin_.initialize(that.onPluginInitialized_.bind(that));
176 });
177 };
178
179 /**
180 * @param {boolean} initialized
181 */
182 remoting.DesktopConnectedView.prototype.onPluginInitialized_ = function(
183 initialized) {
184 if (!initialized) {
185 console.error('ERROR: remoting plugin not loaded');
186 this.onInitialized_(remoting.Error.MISSING_PLUGIN, this.plugin_);
187 return;
188 }
189
190 if (!this.plugin_.isSupportedVersion()) {
191 this.onInitialized_(remoting.Error.BAD_PLUGIN_VERSION, this.plugin_);
192 return;
193 }
194
195 // Show the Send Keys menu only if the plugin has the injectKeyEvent feature, 157 // Show the Send Keys menu only if the plugin has the injectKeyEvent feature,
196 // and the Ctrl-Alt-Del button only in Me2Me mode. 158 // and the Ctrl-Alt-Del button only in Me2Me mode.
197 if (!this.plugin_.hasFeature( 159 if (!this.plugin_.hasFeature(
198 remoting.ClientPlugin.Feature.INJECT_KEY_EVENT)) { 160 remoting.ClientPlugin.Feature.INJECT_KEY_EVENT)) {
199 var sendKeysElement = document.getElementById('send-keys-menu'); 161 var sendKeysElement = document.getElementById('send-keys-menu');
200 sendKeysElement.hidden = true; 162 sendKeysElement.hidden = true;
201 } else if (this.mode_ != remoting.DesktopConnectedView.Mode.ME2ME && 163 } else if (this.mode_ != remoting.DesktopConnectedView.Mode.ME2ME &&
202 this.mode_ != remoting.DesktopConnectedView.Mode.APP_REMOTING) { 164 this.mode_ != remoting.DesktopConnectedView.Mode.APP_REMOTING) {
203 var sendCadElement = document.getElementById('send-ctrl-alt-del'); 165 var sendCadElement = document.getElementById('send-ctrl-alt-del');
204 sendCadElement.hidden = true; 166 sendCadElement.hidden = true;
205 } 167 }
206 168
207 // Apply customized key remappings if the plugin supports remapKeys. 169 // Apply customized key remappings if the plugin supports remapKeys.
208 if (this.plugin_.hasFeature(remoting.ClientPlugin.Feature.REMAP_KEY)) { 170 if (this.plugin_.hasFeature(remoting.ClientPlugin.Feature.REMAP_KEY)) {
209 this.applyRemapKeys_(true); 171 this.applyRemapKeys_(true);
210 } 172 }
211 173
212 // TODO(wez): Only allow mouse lock if the app has the pointerLock permission. 174 // TODO(wez): Only allow mouse lock if the app has the pointerLock permission.
213 // Enable automatic mouse-lock. 175 // Enable automatic mouse-lock.
214 if (remoting.enableMouseLock && 176 if (remoting.enableMouseLock &&
215 this.plugin_.hasFeature(remoting.ClientPlugin.Feature.ALLOW_MOUSE_LOCK)) { 177 this.plugin_.hasFeature(remoting.ClientPlugin.Feature.ALLOW_MOUSE_LOCK)) {
216 this.plugin_.allowMouseLock(); 178 this.plugin_.allowMouseLock();
217 } 179 }
218 180
219 this.plugin_.setMouseCursorHandler(this.updateMouseCursorImage_.bind(this)); 181 this.plugin_.setMouseCursorHandler(this.updateMouseCursorImage_.bind(this));
220
221 this.onInitialized_(remoting.Error.NONE, this.plugin_);
222 }; 182 };
223 183
224 /** 184 /**
225 * This is a callback that gets called when the window is resized. 185 * This is a callback that gets called when the window is resized.
226 * 186 *
227 * @return {void} Nothing. 187 * @return {void} Nothing.
228 * @private. 188 * @private.
229 */ 189 */
230 remoting.DesktopConnectedView.prototype.onResize_ = function() { 190 remoting.DesktopConnectedView.prototype.onResize_ = function() {
231 if (this.viewport_) { 191 if (this.viewport_) {
(...skipping 29 matching lines...) Expand all
261 * disconnected by the Host. 221 * disconnected by the Host.
262 * 222 *
263 * @return {void} Nothing. 223 * @return {void} Nothing.
264 */ 224 */
265 remoting.DesktopConnectedView.prototype.removePlugin = function() { 225 remoting.DesktopConnectedView.prototype.removePlugin = function() {
266 if (this.plugin_) { 226 if (this.plugin_) {
267 this.plugin_.element().removeEventListener( 227 this.plugin_.element().removeEventListener(
268 'focus', this.callPluginGotFocus_, false); 228 'focus', this.callPluginGotFocus_, false);
269 this.plugin_.element().removeEventListener( 229 this.plugin_.element().removeEventListener(
270 'blur', this.callPluginLostFocus_, false); 230 'blur', this.callPluginLostFocus_, false);
271 this.plugin_.dispose();
272 this.plugin_ = null; 231 this.plugin_ = null;
273 } 232 }
274 233
275 this.updateClientSessionUi_(null); 234 this.updateClientSessionUi_(null);
276 }; 235 };
277 236
278 /** 237 /**
279 * @param {remoting.ClientSession} clientSession The active session, or null if 238 * @param {remoting.ClientSession} clientSession The active session, or null if
280 * there is no connection. 239 * there is no connection.
281 */ 240 */
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 var rect = document.createElement('div'); 556 var rect = document.createElement('div');
598 rect.classList.add('debug-region-rect'); 557 rect.classList.add('debug-region-rect');
599 rect.style.left = rects[i][0] + 'px'; 558 rect.style.left = rects[i][0] + 'px';
600 rect.style.top = rects[i][1] +'px'; 559 rect.style.top = rects[i][1] +'px';
601 rect.style.width = rects[i][2] +'px'; 560 rect.style.width = rects[i][2] +'px';
602 rect.style.height = rects[i][3] + 'px'; 561 rect.style.height = rects[i][3] + 'px';
603 this.debugRegionContainer_.appendChild(rect); 562 this.debugRegionContainer_.appendChild(rect);
604 } 563 }
605 } 564 }
606 }; 565 };
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/client_session.js ('k') | remoting/webapp/crd/js/session_connector.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698