Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Unified Diff: native_client_sdk/src/examples/common.js

Issue 19751003: [NaCl SDK] Check that browser has support for NaCl/PNaCl/PPAPI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: indicate it could be disabled Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/examples/common.js
diff --git a/native_client_sdk/src/examples/common.js b/native_client_sdk/src/examples/common.js
index 1562924d03e435e064e83c983ec40b63b1a09d82..8e044e4098beebe1cf8a617dc673af440c5e6865 100644
--- a/native_client_sdk/src/examples/common.js
+++ b/native_client_sdk/src/examples/common.js
@@ -14,6 +14,42 @@ 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} is_release True if this is a release build.
binji 2013/07/23 18:29:32 add @return doc
jvoung (off chromium) 2013/07/23 19:57:45 Done.
+ */
+ function mimeTypeForTool(tool, is_release) {
+ // 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 (is_release)
+ mimetype = 'application/x-ppapi-release';
+ else
+ mimetype = 'application/x-ppapi-debug';
+ } else if (tool == 'pnacl') {
+ mimetype = 'application/x-pnacl';
+ }
+ return mimetype;
+ }
+
+ /**
+ * Return true if the browser supports NaCl plugins.
+ *
+ * @param {string} tool The name of the toolchain, e.g. "glibc", "newlib" etc.
binji 2013/07/23 18:29:32 add @return doc
jvoung (off chromium) 2013/07/23 19:57:45 Done.
+ */
+ function browserSupportsNaCl(tool) {
+ 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 +77,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 +89,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 +283,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 is_release = path.toLowerCase().indexOf('release') != -1;
binji 2013/07/23 18:29:32 nit: isRelease
jvoung (off chromium) 2013/07/23 19:57:45 Done. Same code style for parameter names (above)
binji 2013/07/23 20:01:52 Yes, camelCase for all names in JavaScript.
+ if (!browserSupportsNaCl(tool, is_release)) {
+ 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698