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

Commit

Permalink
Preload PNaCl plugin when the webapp is started.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sergeyu@chromium.org committed Aug 15, 2014
1 parent 533bd19 commit b68026d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
57 changes: 40 additions & 17 deletions remoting/webapp/client_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,8 @@ var remoting = remoting || {};
* @constructor
*/
remoting.ClientPlugin = function(container, onExtensionMessage) {
this.plugin_ = /** @type {remoting.ViewerPlugin} */
document.createElement('embed');

this.plugin_ = remoting.ClientPlugin.createPluginElement_();
this.plugin_.id = 'session-client-plugin';
if (remoting.settings.CLIENT_PLUGIN_TYPE == 'pnacl') {
this.plugin_.src = 'remoting_client_pnacl.nmf';
this.plugin_.type = 'application/x-pnacl';
} else if (remoting.settings.CLIENT_PLUGIN_TYPE == 'nacl') {
this.plugin_.src = 'remoting_client_nacl.nmf';
this.plugin_.type = 'application/x-nacl';
} else {
this.plugin_.src = 'about://none';
this.plugin_.type = 'application/vnd.chromium.remoting-viewer';
}

this.plugin_.width = 0;
this.plugin_.height = 0;
this.plugin_.tabIndex = 0; // Required, otherwise focus() doesn't work.
container.appendChild(this.plugin_);

this.onExtensionMessage_ = onExtensionMessage;
Expand Down Expand Up @@ -115,6 +99,45 @@ remoting.ClientPlugin = function(container, onExtensionMessage) {
}
};

/**
* Creates plugin element without adding it to a container.
*
* @return {remoting.ViewerPlugin} Plugin element
*/
remoting.ClientPlugin.createPluginElement_ = function() {
var plugin = /** @type {remoting.ViewerPlugin} */
document.createElement('embed');
if (remoting.settings.CLIENT_PLUGIN_TYPE == 'pnacl') {
plugin.src = 'remoting_client_pnacl.nmf';
plugin.type = 'application/x-pnacl';
} else if (remoting.settings.CLIENT_PLUGIN_TYPE == 'nacl') {
plugin.src = 'remoting_client_nacl.nmf';
plugin.type = 'application/x-nacl';
} else {
plugin.src = 'about://none';
plugin.type = 'application/vnd.chromium.remoting-viewer';
}
plugin.width = 0;
plugin.height = 0;
plugin.tabIndex = 0; // Required, otherwise focus() doesn't work.
return plugin;
}

/**
* Preloads the plugin to make instantiation faster when the user tries
* to connect.
*/
remoting.ClientPlugin.preload = function() {
if (remoting.settings.CLIENT_PLUGIN_TYPE != 'pnacl') {
return;
}

var plugin = remoting.ClientPlugin.createPluginElement_();
plugin.addEventListener(
'loadend', function() { document.body.removeChild(plugin); }, false);
document.body.appendChild(plugin);
}

/**
* Set of features for which hasFeature() can be used to test.
*
Expand Down
2 changes: 2 additions & 0 deletions remoting/webapp/remoting.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ remoting.init = function() {
uiModeChanged: 'uiModeChanged'
};
remoting.testEvents.defineEvents(base.values(remoting.testEvents.Names));

remoting.ClientPlugin.preload();
};

/**
Expand Down

0 comments on commit b68026d

Please sign in to comment.