Chromium Code Reviews| 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 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 |
| 11 * client plugins versions when it is necessary. | 11 * client plugins versions when it is necessary. |
| 12 */ | 12 */ |
| 13 | 13 |
| 14 'use strict'; | 14 'use strict'; |
| 15 | 15 |
| 16 /** @suppress {duplicate} */ | 16 /** @suppress {duplicate} */ |
| 17 var remoting = remoting || {}; | 17 var remoting = remoting || {}; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * @param {Element} container The container for the embed element. | 20 * @param {Element} container The container for the embed element. |
| 21 * @param {function(string, string):boolean} onExtensionMessage The handler for | 21 * @param {function(string, string):boolean} onExtensionMessage The handler for |
| 22 * protocol extension messages. Returns true if a message is recognized; | 22 * protocol extension messages. Returns true if a message is recognized; |
| 23 * false otherwise. | 23 * false otherwise. |
| 24 * @constructor | 24 * @constructor |
| 25 */ | 25 */ |
| 26 remoting.ClientPlugin = function(container, onExtensionMessage) { | 26 remoting.ClientPlugin = function(container, onExtensionMessage) { |
| 27 this.plugin_ = /** @type {remoting.ViewerPlugin} */ | 27 this.plugin_ = remoting.ClientPlugin.createPluginElement_(); |
| 28 document.createElement('embed'); | |
| 29 | |
| 30 this.plugin_.id = 'session-client-plugin'; | 28 this.plugin_.id = 'session-client-plugin'; |
| 31 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'pnacl') { | |
| 32 this.plugin_.src = 'remoting_client_pnacl.nmf'; | |
| 33 this.plugin_.type = 'application/x-pnacl'; | |
| 34 } else if (remoting.settings.CLIENT_PLUGIN_TYPE == 'nacl') { | |
| 35 this.plugin_.src = 'remoting_client_nacl.nmf'; | |
| 36 this.plugin_.type = 'application/x-nacl'; | |
| 37 } else { | |
| 38 this.plugin_.src = 'about://none'; | |
| 39 this.plugin_.type = 'application/vnd.chromium.remoting-viewer'; | |
| 40 } | |
| 41 | |
| 42 this.plugin_.width = 0; | |
| 43 this.plugin_.height = 0; | |
| 44 this.plugin_.tabIndex = 0; // Required, otherwise focus() doesn't work. | |
| 45 container.appendChild(this.plugin_); | 29 container.appendChild(this.plugin_); |
| 46 | 30 |
| 47 this.onExtensionMessage_ = onExtensionMessage; | 31 this.onExtensionMessage_ = onExtensionMessage; |
| 48 | 32 |
| 49 this.desktopWidth = 0; | 33 this.desktopWidth = 0; |
| 50 this.desktopHeight = 0; | 34 this.desktopHeight = 0; |
| 51 this.desktopXDpi = 96; | 35 this.desktopXDpi = 96; |
| 52 this.desktopYDpi = 96; | 36 this.desktopYDpi = 96; |
| 53 | 37 |
| 54 /** @param {string} iq The Iq stanza received from the host. */ | 38 /** @param {string} iq The Iq stanza received from the host. */ |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 this.plugin_.addEventListener('message', function(event) { | 93 this.plugin_.addEventListener('message', function(event) { |
| 110 that.handleMessage_(event.data); | 94 that.handleMessage_(event.data); |
| 111 }, false); | 95 }, false); |
| 112 | 96 |
| 113 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'native') { | 97 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'native') { |
| 114 window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500); | 98 window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500); |
| 115 } | 99 } |
| 116 }; | 100 }; |
| 117 | 101 |
| 118 /** | 102 /** |
| 103 * Creates plugin element without adding it to a container. | |
| 104 * | |
| 105 * @return {remoting.ViewerPlugin} Plugin element | |
| 106 */ | |
| 107 remoting.ClientPlugin.createPluginElement_ = function() { | |
| 108 var plugin = /** @type {remoting.ViewerPlugin} */ | |
| 109 document.createElement('embed'); | |
| 110 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'pnacl') { | |
| 111 plugin.src = 'remoting_client_pnacl.nmf'; | |
| 112 plugin.type = 'application/x-pnacl'; | |
| 113 } else if (remoting.settings.CLIENT_PLUGIN_TYPE == 'nacl') { | |
| 114 plugin.src = 'remoting_client_nacl.nmf'; | |
| 115 plugin.type = 'application/x-nacl'; | |
| 116 } else { | |
| 117 plugin.src = 'about://none'; | |
| 118 plugin.type = 'application/vnd.chromium.remoting-viewer'; | |
| 119 } | |
| 120 plugin.width = 0; | |
| 121 plugin.height = 0; | |
| 122 plugin.tabIndex = 0; // Required, otherwise focus() doesn't work. | |
| 123 return plugin; | |
| 124 } | |
| 125 | |
| 126 /** | |
| 127 * Preloads the plugin to make instantiation faster when the user tries | |
| 128 * to connect. | |
| 129 */ | |
| 130 remoting.ClientPlugin.preload = function() { | |
| 131 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') | |
| 132 return; | |
| 133 | |
| 134 document.body.appendChild(remoting.ClientPlugin.createPluginElement_()); | |
|
Wez
2014/08/12 22:03:31
Do we need to make sure the plugin is hidden?
Jamie
2014/08/12 22:35:58
We'll end up with 2 plugins; is that okay? It migh
Jamie
2014/08/12 22:35:58
It mustn't have the hidden attribute set, or Chrom
Sergey Ulanov
2014/08/15 01:00:17
Yes, the plugin handles multiple instances just fi
| |
| 135 } | |
| 136 | |
| 137 /** | |
| 119 * Set of features for which hasFeature() can be used to test. | 138 * Set of features for which hasFeature() can be used to test. |
| 120 * | 139 * |
| 121 * @enum {string} | 140 * @enum {string} |
| 122 */ | 141 */ |
| 123 remoting.ClientPlugin.Feature = { | 142 remoting.ClientPlugin.Feature = { |
| 124 INJECT_KEY_EVENT: 'injectKeyEvent', | 143 INJECT_KEY_EVENT: 'injectKeyEvent', |
| 125 NOTIFY_CLIENT_RESOLUTION: 'notifyClientResolution', | 144 NOTIFY_CLIENT_RESOLUTION: 'notifyClientResolution', |
| 126 ASYNC_PIN: 'asyncPin', | 145 ASYNC_PIN: 'asyncPin', |
| 127 PAUSE_VIDEO: 'pauseVideo', | 146 PAUSE_VIDEO: 'pauseVideo', |
| 128 PAUSE_AUDIO: 'pauseAudio', | 147 PAUSE_AUDIO: 'pauseAudio', |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 * Undo the CSS rules needed to make the plugin clickable for click-to-play. | 800 * Undo the CSS rules needed to make the plugin clickable for click-to-play. |
| 782 * @private | 801 * @private |
| 783 */ | 802 */ |
| 784 remoting.ClientPlugin.prototype.hidePluginForClickToPlay_ = function() { | 803 remoting.ClientPlugin.prototype.hidePluginForClickToPlay_ = function() { |
| 785 this.plugin_.style.width = ''; | 804 this.plugin_.style.width = ''; |
| 786 this.plugin_.style.height = ''; | 805 this.plugin_.style.height = ''; |
| 787 this.plugin_.style.top = ''; | 806 this.plugin_.style.top = ''; |
| 788 this.plugin_.style.left = ''; | 807 this.plugin_.style.left = ''; |
| 789 this.plugin_.style.position = ''; | 808 this.plugin_.style.position = ''; |
| 790 }; | 809 }; |
| OLD | NEW |