diff options
author | garykac@chromium.org <garykac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-05 16:08:42 +0000 |
---|---|---|
committer | garykac@chromium.org <garykac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-05 16:08:42 +0000 |
commit | 9824c4a3c726381011a4bde95274950bef0ecf98 (patch) | |
tree | cc705cd868995a37812d69ed8bb5ad68ec5797da /remoting | |
parent | badf5acbd419d31eaddeb4480c5df1d57111755e (diff) | |
download | chromium_src-9824c4a3c726381011a4bde95274950bef0ecf98.zip chromium_src-9824c4a3c726381011a4bde95274950bef0ecf98.tar.gz chromium_src-9824c4a3c726381011a4bde95274950bef0ecf98.tar.bz2 |
Add support for extension messages to Chromoting's ClientPlugin.
BUG=
R=jamiewalch@chromium.org
Review URL: https://codereview.chromium.org/154853002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249014 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/webapp/client_plugin.js | 13 | ||||
-rw-r--r-- | remoting/webapp/client_screen.js | 37 | ||||
-rw-r--r-- | remoting/webapp/client_session.js | 16 | ||||
-rw-r--r-- | remoting/webapp/session_connector.js | 15 |
4 files changed, 60 insertions, 21 deletions
diff --git a/remoting/webapp/client_plugin.js b/remoting/webapp/client_plugin.js index cc621f2..7ef05c7 100644 --- a/remoting/webapp/client_plugin.js +++ b/remoting/webapp/client_plugin.js @@ -18,10 +18,14 @@ var remoting = remoting || {}; /** * @param {remoting.ViewerPlugin} plugin The plugin embed element. + * @param {function(string, string):boolean} onExtensionMessage The handler for + * protocol extension messages. Returns true if a message is recognized; + * false otherwise. * @constructor */ -remoting.ClientPlugin = function(plugin) { +remoting.ClientPlugin = function(plugin, onExtensionMessage) { this.plugin = plugin; + this.onExtensionMessage_ = onExtensionMessage; this.desktopWidth = 0; this.desktopHeight = 0; @@ -342,8 +346,11 @@ remoting.ClientPlugin.prototype.handleMessage_ = function(messageStr) { console.log('Got echo reply: ' + message.data['data']); break; default: - console.log('Unexpected message received: ' + - message.data['type'] + ': ' + message.data['data']); + if (!this.onExtensionMessage_(message.data['type'], + message.data['data'])) { + console.log('Unexpected message received: ' + + message.data['type'] + ': ' + message.data['data']); + } } } }; diff --git a/remoting/webapp/client_screen.js b/remoting/webapp/client_screen.js index bee7a928..b870e8a 100644 --- a/remoting/webapp/client_screen.js +++ b/remoting/webapp/client_screen.js @@ -28,12 +28,7 @@ remoting.clientSession = null; * Initiate an IT2Me connection. */ remoting.connectIT2Me = function() { - if (!remoting.connector) { - remoting.connector = new remoting.SessionConnector( - document.getElementById('client-plugin-container'), - remoting.onConnected, - showConnectError_); - } + remoting.ensureSessionConnector_(); var accessCode = document.getElementById('access-code-entry').value; remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); remoting.connector.connectIT2Me(accessCode); @@ -246,12 +241,7 @@ remoting.connectMe2Me = function(hostId) { * @return {void} Nothing. */ remoting.connectMe2MeHostVersionAcknowledged_ = function(host) { - if (!remoting.connector) { - remoting.connector = new remoting.SessionConnector( - document.getElementById('client-plugin-container'), - remoting.onConnected, - showConnectError_); - } + remoting.ensureSessionConnector_(); remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); /** @@ -386,3 +376,26 @@ remoting.onConnected = function(clientSession) { clientSession.requestPairing(clientName, onPairingComplete); } }; + +/** + * Extension message handler. + * + * @param {string} type The type of the extension message. + * @param {string} data The payload of the extension message. + * @return {boolean} Return true if the extension message was recognized. + */ +remoting.onExtensionMessage = function(type, data) { + return false; +}; + +/** + * Create a session connector if one doesn't already exist. + */ +remoting.ensureSessionConnector_ = function() { + if (!remoting.connector) { + remoting.connector = new remoting.SessionConnector( + document.getElementById('client-plugin-container'), + remoting.onConnected, + showConnectError_, remoting.onExtensionMessage); + } +}; diff --git a/remoting/webapp/client_session.js b/remoting/webapp/client_session.js index 2d3e88d..021446a 100644 --- a/remoting/webapp/client_session.js +++ b/remoting/webapp/client_session.js @@ -307,10 +307,14 @@ remoting.ClientSession.prototype.hasCapability_ = function(capability) { /** * @param {Element} container The element to add the plugin to. * @param {string} id Id to use for the plugin element . + * @param {function(string, string):boolean} onExtensionMessage The handler for + * protocol extension messages. Returns true if a message is recognized; + * false otherwise. * @return {remoting.ClientPlugin} Create plugin object for the locally * installed plugin. */ -remoting.ClientSession.prototype.createClientPlugin_ = function(container, id) { +remoting.ClientSession.prototype.createClientPlugin_ = + function(container, id, onExtensionMessage) { var plugin = /** @type {remoting.ViewerPlugin} */ document.createElement('embed'); @@ -322,7 +326,7 @@ remoting.ClientSession.prototype.createClientPlugin_ = function(container, id) { plugin.tabIndex = 0; // Required, otherwise focus() doesn't work. container.appendChild(plugin); - return new remoting.ClientPlugin(plugin); + return new remoting.ClientPlugin(plugin, onExtensionMessage); }; /** @@ -350,10 +354,14 @@ remoting.ClientSession.prototype.pluginLostFocus_ = function() { * Adds <embed> element to |container| and readies the sesion object. * * @param {Element} container The element to add the plugin to. + * @param {function(string, string):boolean} onExtensionMessage The handler for + * protocol extension messages. Returns true if a message is recognized; + * false otherwise. */ remoting.ClientSession.prototype.createPluginAndConnect = - function(container) { - this.plugin_ = this.createClientPlugin_(container, this.PLUGIN_ID); + function(container, onExtensionMessage) { + this.plugin_ = this.createClientPlugin_(container, this.PLUGIN_ID, + onExtensionMessage); remoting.HostSettings.load(this.hostId_, this.onHostSettingsLoaded_.bind(this)); }; diff --git a/remoting/webapp/session_connector.js b/remoting/webapp/session_connector.js index 077b292..3c507d4 100644 --- a/remoting/webapp/session_connector.js +++ b/remoting/webapp/session_connector.js @@ -16,9 +16,13 @@ var remoting = remoting || {}; * @param {Element} pluginParent The node under which to add the client plugin. * @param {function(remoting.ClientSession):void} onOk Callback on success. * @param {function(remoting.Error):void} onError Callback on error. + * @param {function(string, string):boolean} onExtensionMessage The handler for + * protocol extension messages. Returns true if a message is recognized; + * false otherwise. * @constructor */ -remoting.SessionConnector = function(pluginParent, onOk, onError) { +remoting.SessionConnector = function(pluginParent, onOk, onError, + onExtensionMessage) { /** * @type {Element} * @private @@ -38,6 +42,12 @@ remoting.SessionConnector = function(pluginParent, onOk, onError) { this.onError_ = onError; /** + * @type {function(string, string):boolean} + * @private + */ + this.onExtensionMessage_ = onExtensionMessage; + + /** * @type {string} * @private */ @@ -384,7 +394,8 @@ remoting.SessionConnector.prototype.createSession_ = function() { this.connectionMode_, this.clientPairingId_, this.clientPairedSecret_); this.clientSession_.logHostOfflineErrors(!this.refreshHostJidIfOffline_); this.clientSession_.setOnStateChange(this.onStateChange_.bind(this)); - this.clientSession_.createPluginAndConnect(this.pluginParent_); + this.clientSession_.createPluginAndConnect(this.pluginParent_, + this.onExtensionMessage_); }; /** |