2

"NaCl is currently only turned on by default for applications/extensions from the Chrome Webstore, or unpacked extensions for development purposes." - the Internet

Yet I can't seem to be able to use NaCl from an unpacked extension. (I did not try the Web Store.)

I have a really simple test extension which has the following in its background.js:

function clicked() {
    var testNaclElement = document.createElement("embed");
    testNaclElement.setAttribute("type","application/x-nacl");
    testNaclElement.setAttribute("width",0);
    testNaclElement.setAttribute("height",0);
    document.body.appendChild(testNaclElement);
    alert(testNaclElement.postMessage?true:false);
    document.body.removeChild(testNaclElement);
}

chrome.browserAction.onClicked.addListener(updateIcon);
updateIcon();

This extension reports true when the NaCl is enabled in chrome://flags, but when NaCl is disabled in chrome://flags (which is the default) it reports false.

I expected it to report true.

What am I missing?

Update:

It seems that inventing my own detection code not such a good idea after all. If I create and install an unpacked chrome webapp that points to url X, then NaCl will work on that page, but this detection code will still report false, while the very same code reports true when on a normal webpage with NaCl enabled in chrome://flags.

BUT if create an extension (not a chrome webapp) that uses NaCl in an iFrame which points to url X, then NaCl will not work in it.

BUT if I create a webapp that points to url X and an extension that uses url X in an iFrame, then both will work if installed at the same time.

Update2: If I actually include the nmf and nexe in the extension, then it works.

Update3: nexe needn't be included in the extension.

Xan
  • 74,770
  • 16
  • 179
  • 206
Tarnay Kálmán
  • 6,907
  • 5
  • 46
  • 57

2 Answers2

0

a better way to detect if a NaCl module is loaded is to use progress events. see https://developers.google.com/native-client/pepper16/devguide/coding/progress-events for the enumeration of events and an example.

about the url X -- i don't think events propagate pass iframes if the iframe's URL and the container's URL domains differ -- and any enabling of NaCl in the web store or unpacked extensions corresponds to an URL (possibly with a special proto-spec; i don't know the details), so that might explain the various combinations that you're seeing. it probably also depend on how you specified the URL set in the webapp manifest.

the code's testNaclElement lack a src= attribute/value pair. it's been a while since i looked at the NaCl plugin's code, but that might also cause problems.

Bennet Yee
  • 506
  • 2
  • 6
0

Chrome requires nmf location to belong to extension. Empty nmf attribute doesn't have this property.

Ha.
  • 3,454
  • 21
  • 24
  • 1
    The code responsibe for deciding is in http://src.chromium.org/viewvc/chrome/trunk/src/chrome/renderer/chrome_content_renderer_client.cc in the following functions: IsNaClAllowed CreatePlugin – Tarnay Kálmán Mar 03 '12 at 02:59
  • 1
    It seems from the code that the decision is based on the URL of the nmf file (which kinda explains why my detection only works without the src tag when NaCl is enabled by the flag) – Tarnay Kálmán Mar 03 '12 at 03:15
  • I updated the answer in order to not confuse readers with the wrong one. – Ha. Mar 03 '12 at 04:36