Adding NaCl in an Chrome Extension

谁说我不能喝 提交于 2020-01-12 04:32:06

问题


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.


回答1:


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!!



来源:https://stackoverflow.com/questions/10335284/adding-nacl-in-an-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!