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 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 /** @type {remoting.ClientPluginImpl} */ | 84 /** @type {remoting.ClientPluginImpl} */ |
85 var that = this; | 85 var that = this; |
86 this.plugin_.addEventListener('message', | 86 this.plugin_.addEventListener('message', |
87 /** @param {Event} event Message event from the plugin. */ | 87 /** @param {Event} event Message event from the plugin. */ |
88 function(event) { | 88 function(event) { |
89 that.handleMessage_( | 89 that.handleMessage_( |
90 /** @type {remoting.ClientPluginMessage} */ (event.data)); | 90 /** @type {remoting.ClientPluginMessage} */ (event.data)); |
91 }, false); | 91 }, false); |
92 | 92 |
93 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'native') { | |
94 window.setTimeout(this.showPluginForClickToPlay_.bind(this), 500); | |
95 } | |
96 | |
97 /** @private */ | 93 /** @private */ |
98 this.hostDesktop_ = new remoting.ClientPlugin.HostDesktopImpl( | 94 this.hostDesktop_ = new remoting.ClientPlugin.HostDesktopImpl( |
99 this, this.postMessage_.bind(this)); | 95 this, this.postMessage_.bind(this)); |
100 | 96 |
101 /** @private */ | 97 /** @private */ |
102 this.extensions_ = new remoting.ProtocolExtensionManager( | 98 this.extensions_ = new remoting.ProtocolExtensionManager( |
103 this.sendClientMessage_.bind(this)); | 99 this.sendClientMessage_.bind(this)); |
104 | 100 |
105 /** @private {remoting.CredentialsProvider} */ | 101 /** @private {remoting.CredentialsProvider} */ |
106 this.credentials_ = null; | 102 this.credentials_ = null; |
107 | 103 |
108 /** @private {!Object} */ | 104 /** @private {!Object} */ |
109 this.keyRemappings_ = {}; | 105 this.keyRemappings_ = {}; |
110 }; | 106 }; |
111 | 107 |
112 /** | 108 /** |
113 * Creates plugin element without adding it to a container. | 109 * Creates plugin element without adding it to a container. |
114 * | 110 * |
115 * @return {HTMLEmbedElement} Plugin element | 111 * @return {HTMLEmbedElement} Plugin element |
116 */ | 112 */ |
117 remoting.ClientPluginImpl.createPluginElement_ = function() { | 113 remoting.ClientPluginImpl.createPluginElement_ = function() { |
118 var plugin = | 114 var plugin = |
119 /** @type {HTMLEmbedElement} */ (document.createElement('embed')); | 115 /** @type {HTMLEmbedElement} */ (document.createElement('embed')); |
120 if (remoting.settings.CLIENT_PLUGIN_TYPE == 'pnacl') { | 116 plugin.src = 'remoting_client_pnacl.nmf'; |
121 plugin.src = 'remoting_client_pnacl.nmf'; | 117 plugin.type = 'application/x-pnacl'; |
122 plugin.type = 'application/x-pnacl'; | |
123 } else if (remoting.settings.CLIENT_PLUGIN_TYPE == 'nacl') { | |
124 plugin.src = 'remoting_client_nacl.nmf'; | |
125 plugin.type = 'application/x-nacl'; | |
126 } else { | |
127 plugin.src = 'about://none'; | |
128 plugin.type = 'application/vnd.chromium.remoting-viewer'; | |
129 } | |
130 plugin.width = '0'; | 118 plugin.width = '0'; |
131 plugin.height = '0'; | 119 plugin.height = '0'; |
132 plugin.tabIndex = 0; // Required, otherwise focus() doesn't work. | 120 plugin.tabIndex = 0; // Required, otherwise focus() doesn't work. |
133 return plugin; | 121 return plugin; |
134 } | 122 } |
135 | 123 |
136 /** | 124 /** |
137 * Chromoting session API version (for this javascript). | 125 * Chromoting session API version (for this javascript). |
138 * This is compared with the plugin API version to verify that they are | 126 * This is compared with the plugin API version to verify that they are |
139 * compatible. | 127 * compatible. |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 | 815 |
828 remoting.ClientPluginImpl.prototype.hostDesktop = function() { | 816 remoting.ClientPluginImpl.prototype.hostDesktop = function() { |
829 return this.hostDesktop_; | 817 return this.hostDesktop_; |
830 }; | 818 }; |
831 | 819 |
832 remoting.ClientPluginImpl.prototype.extensions = function() { | 820 remoting.ClientPluginImpl.prototype.extensions = function() { |
833 return this.extensions_; | 821 return this.extensions_; |
834 }; | 822 }; |
835 | 823 |
836 /** | 824 /** |
837 * If we haven't yet received a "hello" message from the plugin, change its | |
838 * size so that the user can confirm it if click-to-play is enabled, or can | |
839 * see the "this plugin is disabled" message if it is actually disabled. | |
840 * @private | |
841 */ | |
842 remoting.ClientPluginImpl.prototype.showPluginForClickToPlay_ = function() { | |
843 if (!this.helloReceived_) { | |
844 var width = 200; | |
845 var height = 200; | |
846 this.plugin_.style.width = width + 'px'; | |
847 this.plugin_.style.height = height + 'px'; | |
848 // Center the plugin just underneath the "Connnecting..." dialog. | |
849 var dialog = document.getElementById('client-dialog'); | |
850 var dialogRect = dialog.getBoundingClientRect(); | |
851 this.plugin_.style.top = (dialogRect.bottom + 16) + 'px'; | |
852 this.plugin_.style.left = (window.innerWidth - width) / 2 + 'px'; | |
853 this.plugin_.style.position = 'fixed'; | |
854 } | |
855 }; | |
856 | |
857 /** | |
858 * Undo the CSS rules needed to make the plugin clickable for click-to-play. | 825 * Undo the CSS rules needed to make the plugin clickable for click-to-play. |
859 * @private | 826 * @private |
860 */ | 827 */ |
861 remoting.ClientPluginImpl.prototype.hidePluginForClickToPlay_ = function() { | 828 remoting.ClientPluginImpl.prototype.hidePluginForClickToPlay_ = function() { |
862 this.plugin_.style.width = ''; | 829 this.plugin_.style.width = ''; |
863 this.plugin_.style.height = ''; | 830 this.plugin_.style.height = ''; |
864 this.plugin_.style.top = ''; | 831 this.plugin_.style.top = ''; |
865 this.plugin_.style.left = ''; | 832 this.plugin_.style.left = ''; |
866 this.plugin_.style.position = ''; | 833 this.plugin_.style.position = ''; |
867 }; | 834 }; |
(...skipping 21 matching lines...) Expand all Loading... |
889 * @param {Array<string>} requiredCapabilities | 856 * @param {Array<string>} requiredCapabilities |
890 * @return {remoting.ClientPlugin} | 857 * @return {remoting.ClientPlugin} |
891 */ | 858 */ |
892 remoting.DefaultClientPluginFactory.prototype.createPlugin = | 859 remoting.DefaultClientPluginFactory.prototype.createPlugin = |
893 function(container, requiredCapabilities) { | 860 function(container, requiredCapabilities) { |
894 return new remoting.ClientPluginImpl(container, | 861 return new remoting.ClientPluginImpl(container, |
895 requiredCapabilities); | 862 requiredCapabilities); |
896 }; | 863 }; |
897 | 864 |
898 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() { | 865 remoting.DefaultClientPluginFactory.prototype.preloadPlugin = function() { |
899 if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') { | |
900 return; | |
901 } | |
902 | |
903 var plugin = remoting.ClientPluginImpl.createPluginElement_(); | 866 var plugin = remoting.ClientPluginImpl.createPluginElement_(); |
904 plugin.addEventListener( | 867 plugin.addEventListener( |
905 'loadend', function() { document.body.removeChild(plugin); }, false); | 868 'loadend', function() { document.body.removeChild(plugin); }, false); |
906 document.body.appendChild(plugin); | 869 document.body.appendChild(plugin); |
907 }; | 870 }; |
OLD | NEW |