tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

child_channel_id.js (1437B)


      1 /**
      2 * Send HTTP requests and notify the parent about their channelId
      3 */
      4 /* global NetUtil, ChannelListener */
      5 
      6 let shouldQuit = false;
      7 
      8 function run_test() {
      9  // keep the event loop busy and the test alive until a "finish" command
     10  // is issued by parent
     11  do_timeout(100, function keepAlive() {
     12    if (!shouldQuit) {
     13      do_timeout(100, keepAlive);
     14    }
     15  });
     16 }
     17 
     18 function makeRequest(uri) {
     19  let requestChannel = NetUtil.newChannel({
     20    uri,
     21    loadUsingSystemPrincipal: true,
     22  });
     23  requestChannel.asyncOpen(new ChannelListener(checkResponse, requestChannel));
     24  requestChannel.QueryInterface(Ci.nsIHttpChannel);
     25  dump(`Child opened request: ${uri}, channelId=${requestChannel.channelId}\n`);
     26 }
     27 
     28 function checkResponse(request, buffer, requestChannel) {
     29  // notify the parent process about the original request channel
     30  requestChannel.QueryInterface(Ci.nsIHttpChannel);
     31  do_send_remote_message(`request:${requestChannel.channelId}`);
     32 
     33  // the response channel can be different (if it was redirected)
     34  let responseChannel = request.QueryInterface(Ci.nsIHttpChannel);
     35 
     36  let uri = responseChannel.URI.spec;
     37  let origUri = responseChannel.originalURI.spec;
     38  let id = responseChannel.channelId;
     39  dump(`Child got response to: ${uri} (orig=${origUri}), channelId=${id}\n`);
     40 
     41  // notify the parent process about this channel's ID
     42  do_send_remote_message(`response:${id}`);
     43 }
     44 
     45 function finish() {
     46  shouldQuit = true;
     47 }