Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit b68026d

Browse files
Preload PNaCl plugin when the webapp is started.
Preloading the plugin starts NaCl translator, which saves time when the user tries to connect. Review URL: https://codereview.chromium.org/467903002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290040 0039d316-1c4b-4281-b951-d872f2087c98
1 parent 533bd19 commit b68026d

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

remoting/webapp/client_plugin.js

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,8 @@ var remoting = remoting || {};
2424
* @constructor
2525
*/
2626
remoting.ClientPlugin = function(container, onExtensionMessage) {
27-
this.plugin_ = /** @type {remoting.ViewerPlugin} */
28-
document.createElement('embed');
29-
27+
this.plugin_ = remoting.ClientPlugin.createPluginElement_();
3028
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.
4529
container.appendChild(this.plugin_);
4630

4731
this.onExtensionMessage_ = onExtensionMessage;
@@ -115,6 +99,45 @@ remoting.ClientPlugin = function(container, onExtensionMessage) {
11599
}
116100
};
117101

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+
135+
var plugin = remoting.ClientPlugin.createPluginElement_();
136+
plugin.addEventListener(
137+
'loadend', function() { document.body.removeChild(plugin); }, false);
138+
document.body.appendChild(plugin);
139+
}
140+
118141
/**
119142
* Set of features for which hasFeature() can be used to test.
120143
*

remoting/webapp/remoting.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ remoting.init = function() {
207207
uiModeChanged: 'uiModeChanged'
208208
};
209209
remoting.testEvents.defineEvents(base.values(remoting.testEvents.Names));
210+
211+
remoting.ClientPlugin.preload();
210212
};
211213

212214
/**

0 commit comments

Comments
 (0)