Reputation: 51
I am trying to create an Extension for Google Chrome ,in which I want to process some images.
The extension was previously created using NPAPI ,but that being phased out need to switch to another alternative, Native Messaging looked like the best suited for this job.
The native host is written in C++ and it reads from stdin a formated message sent from extension(some like {action:"name_of_action",buffer:"x0x0",length:"4"} ),parse it ,extract the buffer and do some processing with the image,after that i need to return a message to the extension.
The problem I am facing is that after a few messages(the number is not the same every time) ,the port used disconnects and in the javascript console the message is : Error when communicating with the native messaging host..
My application basicly does this:
while(true)
{
/*read until I reach a delimiter*/
while(true){
c = getchar();
buffer[i] = c;
if(i>len && memcmp(buffer+i-len+1,delimiter,len)==0)
break;
i++;
}
ProcessMessage(buffer);
}
I am sending image buffers from the extension(base64 encoded) ,decode them and process that buffer in the app.I also have tried (on windows) using UrlDownloadToFile function to download that image from C++ ,but that seems to fail ,ending up in the previous message Error when communicating with the native messaging host.Does anybody know why doesn't chrome allow downloading a file from the messaging host executable?
Upvotes: 0
Views: 1066
Reputation: 206
If you just want to do image processing in native code then you probably don't need to use Native Messaging. You can most likely use NaCl, or PNaCl, which produces OS-neutral executables that can be run safely withing Chrome.
To communicate with your NaCl module you can PostMessage too and from your extension's JavaScript code. You can even send dictionary object directly and decompose them in native code using the dictionary interface.
Native Message should only be needed when you need to access OS functionality not exposed by PPAPI, or when you need to load/run a pre-compiled code (e.g. load a windows DLL).
Upvotes: 1