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

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

Issue 1067133002: Move ProtocolExtensionManager from SessionConnector into its own class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and Reviewer's feedback Created 5 years, 8 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_plugin.js ('k') | remoting/webapp/crd/js/client_session.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 (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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 /** @param {Event} event Message event from the plugin. */ 86 /** @param {Event} event Message event from the plugin. */
87 this.plugin_.addEventListener('message', function(event) { 87 this.plugin_.addEventListener('message', function(event) {
88 that.handleMessage_( 88 that.handleMessage_(
89 /** @type {remoting.ClientPluginMessage} */ (event.data)); 89 /** @type {remoting.ClientPluginMessage} */ (event.data));
90 }, false); 90 }, false);
91 91
92 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'native') { 92 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'native') {
93 window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500); 93 window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500);
94 } 94 }
95 95
96 /** @private */
96 this.hostDesktop_ = new remoting.ClientPlugin.HostDesktopImpl( 97 this.hostDesktop_ = new remoting.ClientPlugin.HostDesktopImpl(
97 this, this.postMessage_.bind(this)); 98 this, this.postMessage_.bind(this));
98 99
100 /** @private */
101 this.extensions_ = new remoting.ProtocolExtensionManager(
102 this.sendClientMessage.bind(this));
103
99 /** @private {remoting.CredentialsProvider} */ 104 /** @private {remoting.CredentialsProvider} */
100 this.credentials_ = null; 105 this.credentials_ = null;
101 106
102 /** @private {string} */ 107 /** @private {string} */
103 this.keyRemappings_ = ''; 108 this.keyRemappings_ = '';
104 }; 109 };
105 110
106 /** 111 /**
107 * Creates plugin element without adding it to a container. 112 * Creates plugin element without adding it to a container.
108 * 113 *
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 224
220 } else if (message.method == 'logDebugMessage') { 225 } else if (message.method == 'logDebugMessage') {
221 handler.onDebugMessage(base.getStringAttr(message.data, 'message')); 226 handler.onDebugMessage(base.getStringAttr(message.data, 'message'));
222 227
223 } else if (message.method == 'onConnectionStatus') { 228 } else if (message.method == 'onConnectionStatus') {
224 var state = remoting.ClientSession.State.fromString( 229 var state = remoting.ClientSession.State.fromString(
225 base.getStringAttr(message.data, 'state')); 230 base.getStringAttr(message.data, 'state'));
226 var error = remoting.ClientSession.ConnectionError.fromString( 231 var error = remoting.ClientSession.ConnectionError.fromString(
227 base.getStringAttr(message.data, 'error')); 232 base.getStringAttr(message.data, 'error'));
228 handler.onConnectionStatusUpdate(state, error); 233 handler.onConnectionStatusUpdate(state, error);
229 234 // TODO(kelvinp): Refactor the ClientSession.State into its own file as
235 // the plugin should not depend on ClientSession.
236 if (state === remoting.ClientSession.State.CONNECTED) {
237 this.extensions_.start();
238 }
230 } else if (message.method == 'onRouteChanged') { 239 } else if (message.method == 'onRouteChanged') {
231 var channel = base.getStringAttr(message.data, 'channel'); 240 var channel = base.getStringAttr(message.data, 'channel');
232 var connectionType = base.getStringAttr(message.data, 'connectionType'); 241 var connectionType = base.getStringAttr(message.data, 'connectionType');
233 handler.onRouteChanged(channel, connectionType); 242 handler.onRouteChanged(channel, connectionType);
234 243
235 } else if (message.method == 'onConnectionReady') { 244 } else if (message.method == 'onConnectionReady') {
236 var ready = base.getBooleanAttr(message.data, 'ready'); 245 var ready = base.getBooleanAttr(message.data, 'ready');
237 handler.onConnectionReady(ready); 246 handler.onConnectionReady(ready);
238 247
239 } else if (message.method == 'setCapabilities') { 248 } else if (message.method == 'setCapabilities') {
240 /** @type {!Array<string>} */ 249 /** @type {!Array<string>} */
241 var capabilities = tokenize( 250 var capabilities = tokenize(
242 base.getStringAttr(message.data, 'capabilities')); 251 base.getStringAttr(message.data, 'capabilities'));
243 handler.onSetCapabilities(capabilities); 252 handler.onSetCapabilities(capabilities);
244 253
245 } else if (message.method == 'extensionMessage') {
246 var extMsgType = base.getStringAttr(message.data, 'type');
247 var extMsgData = base.getStringAttr(message.data, 'data');
248 handler.onExtensionMessage(extMsgType, extMsgData);
249 } 254 }
250 } 255 }
251 256
252 if (message.method == 'hello') { 257 if (message.method == 'hello') {
253 // Resize in case we had to enlarge it to support click-to-play. 258 // Resize in case we had to enlarge it to support click-to-play.
254 this.hidePluginForClickToPlay_(); 259 this.hidePluginForClickToPlay_();
255 this.pluginApiVersion_ = base.getNumberAttr(message.data, 'apiVersion'); 260 this.pluginApiVersion_ = base.getNumberAttr(message.data, 'apiVersion');
256 this.pluginApiMinVersion_ = 261 this.pluginApiMinVersion_ =
257 base.getNumberAttr(message.data, 'apiMinVersion'); 262 base.getNumberAttr(message.data, 'apiMinVersion');
258 263
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 } 370 }
366 371
367 context.putImageData(imageData, 0, 0); 372 context.putImageData(imageData, 0, 0);
368 this.updateMouseCursorImage_(canvas.toDataURL(), hotspotX, hotspotY); 373 this.updateMouseCursorImage_(canvas.toDataURL(), hotspotX, hotspotY);
369 374
370 } else if (message.method == 'onDebugRegion') { 375 } else if (message.method == 'onDebugRegion') {
371 if (this.debugRegionHandler_) { 376 if (this.debugRegionHandler_) {
372 this.debugRegionHandler_( 377 this.debugRegionHandler_(
373 /** @type {{rects: Array<(Array<number>)>}} **/(message.data)); 378 /** @type {{rects: Array<(Array<number>)>}} **/(message.data));
374 } 379 }
380 } else if (message.method == 'extensionMessage') {
381 var extMsgType = base.getStringAttr(message.data, 'type');
382 var extMsgData = base.getStringAttr(message.data, 'data');
383 this.extensions_.onProtocolExtensionMessage(extMsgType, extMsgData);
384
375 } 385 }
376 }; 386 };
377 387
378 /** 388 /**
379 * Deletes the plugin. 389 * Deletes the plugin.
380 */ 390 */
381 remoting.ClientPluginImpl.prototype.dispose = function() { 391 remoting.ClientPluginImpl.prototype.dispose = function() {
382 if (this.plugin_) { 392 if (this.plugin_) {
383 this.plugin_.parentNode.removeChild(this.plugin_); 393 this.plugin_.parentNode.removeChild(this.plugin_);
384 this.plugin_ = null; 394 this.plugin_ = null;
385 } 395 }
396
397 base.dispose(this.extensions_);
398 this.extensions_ = null;
386 }; 399 };
387 400
388 /** 401 /**
389 * @return {HTMLEmbedElement} HTML element that corresponds to the plugin. 402 * @return {HTMLEmbedElement} HTML element that corresponds to the plugin.
390 */ 403 */
391 remoting.ClientPluginImpl.prototype.element = function() { 404 remoting.ClientPluginImpl.prototype.element = function() {
392 return this.plugin_; 405 return this.plugin_;
393 }; 406 };
394 407
395 /** 408 /**
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 this.plugin_.postMessage(JSON.stringify( 797 this.plugin_.postMessage(JSON.stringify(
785 { method: 'extensionMessage', 798 { method: 'extensionMessage',
786 data: { type: type, data: message } })); 799 data: { type: type, data: message } }));
787 800
788 }; 801 };
789 802
790 remoting.ClientPluginImpl.prototype.hostDesktop = function() { 803 remoting.ClientPluginImpl.prototype.hostDesktop = function() {
791 return this.hostDesktop_; 804 return this.hostDesktop_;
792 }; 805 };
793 806
807 remoting.ClientPluginImpl.prototype.extensions = function() {
808 return this.extensions_;
809 };
810
794 /** 811 /**
795 * If we haven't yet received a "hello" message from the plugin, change its 812 * If we haven't yet received a "hello" message from the plugin, change its
796 * size so that the user can confirm it if click-to-play is enabled, or can 813 * size so that the user can confirm it if click-to-play is enabled, or can
797 * see the "this plugin is disabled" message if it is actually disabled. 814 * see the "this plugin is disabled" message if it is actually disabled.
798 * @private 815 * @private
799 */ 816 */
800 remoting.ClientPluginImpl.prototype.showPluginForClickToPlay_ = function() { 817 remoting.ClientPluginImpl.prototype.showPluginForClickToPlay_ = function() {
801 if (!this.helloReceived_) { 818 if (!this.helloReceived_) {
802 var width = 200; 819 var width = 200;
803 var height = 200; 820 var height = 200;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() { 873 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() {
857 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') { 874 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') {
858 return; 875 return;
859 } 876 }
860 877
861 var plugin = remoting.ClientPluginImpl.createPluginElement_(); 878 var plugin = remoting.ClientPluginImpl.createPluginElement_();
862 plugin.addEventListener( 879 plugin.addEventListener(
863 'loadend', function() { document.body.removeChild(plugin); }, false); 880 'loadend', function() { document.body.removeChild(plugin); }, false);
864 document.body.appendChild(plugin); 881 document.body.appendChild(plugin);
865 }; 882 };
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/client_plugin.js ('k') | remoting/webapp/crd/js/client_session.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698