Chrome Native Messaging not closed when chrome closed
Asked Answered
I

2

10

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.

Intermix answered 13/1, 2014 at 8:42 Comment(1)
What language are you using? Would you mind posting some code?Pachysandra
P
7

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.

Pachysandra answered 23/1, 2014 at 16:42 Comment(0)
T
0

Building upon bkdc's answer;

if you are using C library function - getchar(), this should work;

unsigned int c = getchar();
if (c == 0xFFFFFFFF){//this means native app finished its work
        return 0;
}
Transom answered 7/9, 2015 at 8:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.