tor-browser

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

background-referrer.sjs (3179B)


      1 const BinaryOutputStream = Components.Constructor("@mozilla.org/binaryoutputstream;1", "nsIBinaryOutputStream", "setOutputStream");
      2 
      3 /*
      4 # Python used to generate the following byte array
      5 def toHex(n):
      6   if n < 16: return "0x" + hex(n)[2:].upper()
      7   return "0x" + hex(n)[2:].upper()
      8 
      9 def hexFile(name):
     10   f = open(name, "rb")
     11   try:
     12     while True:
     13       print toHex(ord(f.read(1))) + ", ",
     14   except:
     15     pass
     16 
     17 hexFile("layout/reftests/backgrounds/background-referrer-image.png")
     18 */
     19 
     20 const IMAGE_DATA =
     21   [
     22    0x89,  0x50,  0x4E,  0x47,  0x0D,  0x0A,  0x1A,  0x0A,  0x00,  0x00,  0x00,
     23    0x0D,  0x49,  0x48,  0x44,  0x52,  0x00,  0x00,  0x00,  0x64,  0x00,  0x00,
     24    0x00,  0x64,  0x08,  0x02,  0x00,  0x00,  0x00,  0xFF,  0x80,  0x02,  0x03,
     25    0x00,  0x00,  0x00,  0x01,  0x73,  0x52,  0x47,  0x42,  0x00,  0xAE,  0xCE,
     26    0x1C,  0xE9,  0x00,  0x00,  0x00,  0x9E,  0x49,  0x44,  0x41,  0x54,  0x78,
     27    0xDA,  0xED,  0xD0,  0x31,  0x01,  0x00,  0x00,  0x08,  0x03,  0xA0,  0x69,
     28    0xFF,  0xCE,  0x5A,  0xC1,  0xCF,  0x07,  0x22,  0x50,  0x99,  0x70,  0xD4,
     29    0x0A,  0x64,  0xC9,  0x92,  0x25,  0x4B,  0x96,  0x2C,  0x05,  0xB2,  0x64,
     30    0xC9,  0x92,  0x25,  0x4B,  0x96,  0x02,  0x59,  0xB2,  0x64,  0xC9,  0x92,
     31    0x25,  0x4B,  0x81,  0x2C,  0x59,  0xB2,  0x64,  0xC9,  0x92,  0xA5,  0x40,
     32    0x96,  0x2C,  0x59,  0xB2,  0x64,  0xC9,  0x52,  0x20,  0x4B,  0x96,  0x2C,
     33    0x59,  0xB2,  0x64,  0x29,  0x90,  0x25,  0x4B,  0x96,  0x2C,  0x59,  0xB2,
     34    0x14,  0xC8,  0x92,  0x25,  0x4B,  0x96,  0x2C,  0x59,  0x0A,  0x64,  0xC9,
     35    0x92,  0x25,  0x4B,  0x96,  0x2C,  0x05,  0xB2,  0x64,  0xC9,  0x92,  0x25,
     36    0x4B,  0x96,  0x02,  0x59,  0xB2,  0x64,  0xC9,  0x92,  0x25,  0x4B,  0x81,
     37    0x2C,  0x59,  0xB2,  0x64,  0xC9,  0x92,  0xA5,  0x40,  0x96,  0x2C,  0x59,
     38    0xB2,  0x64,  0xC9,  0x52,  0x20,  0x4B,  0x96,  0x2C,  0x59,  0xB2,  0x64,
     39    0x29,  0x90,  0x25,  0x4B,  0x96,  0x2C,  0x59,  0xB2,  0x14,  0xC8,  0x92,
     40    0x25,  0x4B,  0x96,  0x2C,  0x59,  0x0A,  0x64,  0xC9,  0xFA,  0xB6,  0x89,
     41    0x5F,  0x01,  0xC7,  0x24,  0x83,  0xB2,  0x0C,  0x00,  0x00,  0x00,  0x00,
     42    0x49,  0x45,  0x4E,  0x44,  0xAE,  0x42,  0x60,  0x82,
     43   ];
     44 
     45 function handleRequest(request, response)
     46 {
     47   response.setHeader("Content-Type", "text/plain", false);
     48   response.setHeader("Cache-Control", "no-cache", false);
     49 
     50   var referrer = request.hasHeader("Referer") ?
     51                    request.getHeader("Referer") : "";
     52 
     53   // Test url looks like:
     54   //   http://localhost:port/timestamp/number/background-referrer.html
     55   // Except in Android, where it looks like:
     56   //   http://A.B.C.D:port/timestamp/number/background-referrer.html
     57   // where A.B.C.D is the IP address of the box the reftest HTTP server is
     58   // running on.  And maybe that will change.  So just test for ending in
     59   // "/background-referrer.html".
     60   if (/\/background-referrer.html$/.test(referrer))
     61   {
     62     response.setHeader("Content-Type", "image/png", false);
     63 
     64     var stream = new BinaryOutputStream(response.bodyOutputStream);
     65     stream.writeByteArray(IMAGE_DATA);
     66   }
     67   else
     68   {
     69     response.setStatusLine(request.httpVersion, 404, "Not found");
     70     response.write("Accept header contained: " + accept);
     71   }
     72 }