Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding NaCl in an Chrome Extension

My question is quite simple, I tried to create a chrome extension that calls a NaCl module. My button and different files seem to be ok, and my quite simple code in C++ returns a PostMessage hello World. But, when I try it, it doesn't work. Are there specific things that I haven't done for including a NaCl module in a Chrome extension? I must say that I'm a little bit losing hope.

Here is my "background.html":

<body>
  <script src="background.js"></script>
  <div id="listener">
    <embed name="nacl_module"
      id="nacl_correction"
      src="nacl_correction.nmf"
      type="application/x-nacl" />
  </div>
  <script >
   document.getElementById('listener').addEventListener('load', moduleDidLoad, true);
  </script>
</body>

Here is my "background.js" :

var NaclCorrectionModule = null;  // Global application object.

function moduleDidLoad() {
    NaclCorrectionModule = document.getElementById('nacl_correction');
    //alert( NaclCorrectionModule);
    if (NaclCorrectionModule == null) {
        alert('Out');    
    }
    else {
        alert (NaclCorrectionModule);       
    }
    NaclCorrectionModule.addEventListener('message', handleMessage, false);
} 
function handleMessage(message_event) {
   alert(message_event.data);
}
chrome.browserAction.onClicked.addListener(moduleDidLoad);

And, at last, my "Manifest.json" :

{
  "name": "Correction de Cordial sous Chrome",
  "version": "1.0",
  "background_page" :"background.html",
  "description": "Intégration d'une extension Cordial pour la correction sous Chrome",
  "permissions": [
     "tabs", "http://*/*"
  ],
  "browser_action": {
  "default_icon": "corriger_big.png",  // Icône de l'extension
  "default_title": "Correction de Cordial"  // Titre affiche sur le bouton        
  }
}

If anybody has any ideas, I would be thankful.

like image 683
Nicolalalas Avatar asked Apr 26 '12 14:04

Nicolalalas


People also ask

What is NaCl chromium?

Native Client (NaCl) is a secure sandbox for running untrusted native machine code in the Chrome browser. NaCl programs have special restrictions on the generated code, which are implemented by the compiler toolchain and statically verified at runtime by the trusted NaCl loader.


1 Answers

After a little seeking, I've found that I forgot something. In my background.js, I didn't send any message to NaCl, so it can't work.

I only needed to add 1 line:

NaclCorrectionModule.postMessage('');

Thank you for reading my question, and I hope this can help somebody!!

like image 76
Nicolalalas Avatar answered Oct 07 '22 15:10

Nicolalalas