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

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: 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
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
garykac 2015/04/07 22:14:16 Or have an onConnected, onDisconnected,... message
kelvinp 2015/04/08 00:26:02 Even if we break onConnectionStatus into OnConnect
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') { 254 } else if (message.method == 'extensionMessage') {
246 var extMsgType = base.getStringAttr(message.data, 'type'); 255 var extMsgType = base.getStringAttr(message.data, 'type');
247 var extMsgData = base.getStringAttr(message.data, 'data'); 256 var extMsgData = base.getStringAttr(message.data, 'data');
248 handler.onExtensionMessage(extMsgType, extMsgData); 257 this.extensions_.onProtocolExtensionMessage(extMsgType, extMsgData);
garykac 2015/04/07 22:14:16 Since this no longer requires a connectionEventHan
kelvinp 2015/04/08 00:26:02 Done.
249 } 258 }
250 } 259 }
251 260
252 if (message.method == 'hello') { 261 if (message.method == 'hello') {
253 // Resize in case we had to enlarge it to support click-to-play. 262 // Resize in case we had to enlarge it to support click-to-play.
254 this.hidePluginForClickToPlay_(); 263 this.hidePluginForClickToPlay_();
255 this.pluginApiVersion_ = base.getNumberAttr(message.data, 'apiVersion'); 264 this.pluginApiVersion_ = base.getNumberAttr(message.data, 'apiVersion');
256 this.pluginApiMinVersion_ = 265 this.pluginApiMinVersion_ =
257 base.getNumberAttr(message.data, 'apiMinVersion'); 266 base.getNumberAttr(message.data, 'apiMinVersion');
258 267
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 }; 385 };
377 386
378 /** 387 /**
379 * Deletes the plugin. 388 * Deletes the plugin.
380 */ 389 */
381 remoting.ClientPluginImpl.prototype.dispose = function() { 390 remoting.ClientPluginImpl.prototype.dispose = function() {
382 if (this.plugin_) { 391 if (this.plugin_) {
383 this.plugin_.parentNode.removeChild(this.plugin_); 392 this.plugin_.parentNode.removeChild(this.plugin_);
384 this.plugin_ = null; 393 this.plugin_ = null;
385 } 394 }
395
396 base.dispose(this.extensions_);
397 this.extensions_ = null;
386 }; 398 };
387 399
388 /** 400 /**
389 * @return {HTMLEmbedElement} HTML element that corresponds to the plugin. 401 * @return {HTMLEmbedElement} HTML element that corresponds to the plugin.
390 */ 402 */
391 remoting.ClientPluginImpl.prototype.element = function() { 403 remoting.ClientPluginImpl.prototype.element = function() {
392 return this.plugin_; 404 return this.plugin_;
393 }; 405 };
394 406
395 /** 407 /**
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 this.plugin_.postMessage(JSON.stringify( 796 this.plugin_.postMessage(JSON.stringify(
785 { method: 'extensionMessage', 797 { method: 'extensionMessage',
786 data: { type: type, data: message } })); 798 data: { type: type, data: message } }));
787 799
788 }; 800 };
789 801
790 remoting.ClientPluginImpl.prototype.hostDesktop = function() { 802 remoting.ClientPluginImpl.prototype.hostDesktop = function() {
791 return this.hostDesktop_; 803 return this.hostDesktop_;
792 }; 804 };
793 805
806 remoting.ClientPluginImpl.prototype.extensions = function() {
807 return this.extensions_;
808 };
809
794 /** 810 /**
795 * If we haven't yet received a "hello" message from the plugin, change its 811 * 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 812 * 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. 813 * see the "this plugin is disabled" message if it is actually disabled.
798 * @private 814 * @private
799 */ 815 */
800 remoting.ClientPluginImpl.prototype.showPluginForClickToPlay_ = function() { 816 remoting.ClientPluginImpl.prototype.showPluginForClickToPlay_ = function() {
801 if (!this.helloReceived_) { 817 if (!this.helloReceived_) {
802 var width = 200; 818 var width = 200;
803 var height = 200; 819 var height = 200;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() { 872 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() {
857 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') { 873 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') {
858 return; 874 return;
859 } 875 }
860 876
861 var plugin = remoting.ClientPluginImpl.createPluginElement_(); 877 var plugin = remoting.ClientPluginImpl.createPluginElement_();
862 plugin.addEventListener( 878 plugin.addEventListener(
863 'loadend', function() { document.body.removeChild(plugin); }, false); 879 'loadend', function() { document.body.removeChild(plugin); }, false);
864 document.body.appendChild(plugin); 880 document.body.appendChild(plugin);
865 }; 881 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698