Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Native Messaging not closed when chrome closed

I've made chrome host for passing native messages between my extension and my process, my process starts when chrome starts but not closed when i close chrome, should i add parameter to the manifest of the host or should i add my process handling to close the process when the chrome closed ?

thanks.

like image 931
shacharsa Avatar asked Jan 13 '14 08:01

shacharsa


1 Answers

You don't offer a lot of details but I can answer some of your questions: - no need to add a "parameter" to the manifest; there is no such parameter - no need to detect, from your process, when Chrome closes

Chrome starts your native messaging host whenever you send a message to it or, if you're using long lived connection, when you open the connection. The application should close when the STDIN stream closes (simply put, you can't read anymore from stdin).

For a single threaded app, the flow looks like this: 1. Read request from stdin 2. process request 3. write response to stdout; Repeat 1-3 as long as you can read from stdin; if you can't read from stdin, break the loop and exit.

    std::string req;
while(!(req=read_request()).empty())
{
       //process request and send response
}

read_request is up to you to implement: the first 4 BYTES of the request contain the message length so read those 4 first then read len bytes that contain the actual JSON request. If you can't read anything (empty), then the while loop will break and you exit the app.

like image 166
bkdc Avatar answered Oct 19 '22 05:10

bkdc