The extension just retrieves the URL of the active tab and sends it to the native app. It succeeds in all the other websites including sub-pages of youtube where a video is playing. The same problem happens in both- firefox and chrome.
The following is the code for chrome
chrome.tabs.query({currentWindow:true,active:true},onGot);
function onGot(tabs){
tab=tabs[0].url;
port.postMessage(tab);
console.log(tab);
console.log("Response sent!");
}
In the native app, I am reading the size first and then the message. The following is the code for reading the size.
int num = 0;
unsigned char c;
log("Listening for data Attempt1");
for (int i = 1;i <= 4;i++)
{
log("Waiting for chararcter");
c = cin.get();
int s = (i - 1) * 8 - 1;
if (s < 0) s = 0;
num = num | (((int)c) << s);
log("Read Character from extension");
log(int(c));
}
log("Output Size:");
log(num);
if (num <0 || num>1999) *//EDIT*
return "NULL";
This is my logfile when I try to return the URL to my native application when on "https://www.youtube.com/"
Listening for data Attempt1
Waiting for chararcter
Read Character from extension
255
Waiting for chararcter
Read Character from extension
255
Waiting for chararcter
Read Character from extension
255
Waiting for chararcter
Read Character from extension
255
Output Size:
2147483647
0xFFFFFFFF is end of file. Which means the standard input stream is closed. This happens only with youtube.com.
From std::cin
's type std::istream
documentation, one can read:
int_type get();
Reads one character and returns it if available. Otherwise, returns
Traits::eof()
and sets failbit and eofbit.
If you want to modify your code as little as possible, check c
against Traits::eof()
:
c = cin.get();
if (c == decltype(std::cin)::traits_type::eof()) {
break;
}
An improvement would however be to treat the reading from std::cin
and the data manipulation in two different part of the code (two functions?) and then use std::transform
for instance to chain them.
User contributions licensed under CC BY-SA 3.0