Commit b785a426 authored by jvoung@chromium.org's avatar jvoung@chromium.org

[NaCl SDK] Check that browser has support for NaCl/PNaCl/PPAPI.

Demonstrate a canonical way to detect if the browser
has support for NaCl/PNaCl in the SDK examples.

Do the check before creating the embed tag, when the page
loads. If the browser does not have support, do not create
the embed and just update the status message.

If NaCl is disabled in about:plugins, then this will show
an error.  If NaCl is not enabled in about:flags, then
this will not show an error and continue loading.  The
embed tag will then either (a) be created for CWS apps
or (b) show a puzzle piece for the open web.

For PNaCl, the page will show an error and not attempt
to create an embed tag if either NaCl is disabled
in about:plugins, or PNaCl is disabled in about:flags.

BUG=243040
NOTRY=true

Review URL: https://chromiumcodereview.appspot.com/19751003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213271 0039d316-1c4b-4281-b951-d872f2087c98
parent db9b8ccd
......@@ -14,6 +14,52 @@ var isTest = false;
// code.
var common = (function() {
function isHostToolchain(tool) {
return tool == 'win' || tool == 'linux' || tool == 'mac';
}
/**
* Return the mime type for NaCl plugin.
*
* @param {string} tool The name of the toolchain, e.g. "glibc", "newlib" etc.
* @param {bool} isRelease True if this is a release build.
* @return {string} The mime-type for the kind of NaCl plugin matching
* the given toolchain.
*/
function mimeTypeForTool(tool, isRelease) {
// For NaCl modules use application/x-nacl.
var mimetype = 'application/x-nacl';
if (isHostToolchain(tool)) {
// For non-NaCl PPAPI plugins use the x-ppapi-debug/release
// mime type.
if (isRelease)
mimetype = 'application/x-ppapi-release';
else
mimetype = 'application/x-ppapi-debug';
} else if (tool == 'pnacl') {
mimetype = 'application/x-pnacl';
}
return mimetype;
}
/**
* Check if the browser supports NaCl plugins.
*
* @param {string} tool The name of the toolchain, e.g. "glibc", "newlib" etc.
* @return {bool} True if the browser supports the type of NaCl plugin
* produced by the given toolchain.
*/
function browserSupportsNaCl(tool) {
// Assume host toolchains always work with the given browser.
// The below mime-type checking might not work with
// --register-pepper-plugins.
if (isHostToolchain(tool)) {
return true;
}
var mimetype = mimeTypeForTool(tool);
return navigator.mimeTypes[mimetype] !== undefined;
}
/**
* Create the Native Client <embed> element as a child of the DOM element
* named "listener".
......@@ -41,19 +87,7 @@ var common = (function() {
}
}
// For NaCL modules use application/x-nacl.
var mimetype = 'application/x-nacl';
var isHost = tool == 'win' || tool == 'linux' || tool == 'mac';
if (isHost) {
// For non-nacl PPAPI plugins use the x-ppapi-debug/release
// mime type.
if (path.toLowerCase().indexOf('release') != -1)
mimetype = 'application/x-ppapi-release';
else
mimetype = 'application/x-ppapi-debug';
} else if (tool == 'pnacl') {
mimetype = 'application/x-pnacl';
}
var mimetype = mimeTypeForTool(tool);
moduleEl.setAttribute('type', mimetype);
// The <EMBED> element is wrapped inside a <DIV>, which has both a 'load'
......@@ -65,6 +99,7 @@ var common = (function() {
listenerDiv.appendChild(moduleEl);
// Host plugins don't send a moduleDidLoad message. We'll fake it here.
var isHost = isHostToolchain(tool);
if (isHost) {
window.setTimeout(function() {
var evt = document.createEvent('Event');
......@@ -258,7 +293,11 @@ var common = (function() {
// status message indicating that the module is still loading. Otherwise,
// do not change the status message.
updateStatus('Page loaded.');
if (common.naclModule == null) {
var isRelease = path.toLowerCase().indexOf('release') != -1;
if (!browserSupportsNaCl(tool, isRelease)) {
updateStatus(
'Browser does not support NaCl (' + tool + '), or NaCl is disabled');
} else if (common.naclModule == null) {
updateStatus('Creating embed: ' + tool);
// We use a non-zero sized embed to give Chrome space to place the bad
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment