toolkit/components/thumbnails/test/thumbnails_background.sjs

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // The timer never fires if it's not declared and set to this variable outside
     5 // handleRequest, as if it's getting GC'ed when handleRequest's scope goes away.
     6 // Shouldn't the timer thread hold a strong reference to it?
     7 var timer;
     9 function handleRequest(req, resp) {
    10   resp.processAsync();
    11   resp.setHeader("Cache-Control", "no-cache, no-store", false);
    12   resp.setHeader("Content-Type", "text/html;charset=utf-8", false);
    14   let opts = {};
    15   try {
    16     opts = JSON.parse(decodeURIComponent(req.queryString));
    17   }
    18   catch (err) {}
    20   if (opts.setRedCookie)
    21     resp.setHeader("Set-Cookie", "red", false);
    23   if (opts.setGreenCookie)
    24     resp.setHeader("Set-Cookie", "green", false);
    26   if (req.hasHeader("Cookie") &&
    27       req.getHeader("Cookie").split(";").indexOf("red") >= 0) {
    28     resp.write('<html style="background: #f00;"></html>');
    29     resp.finish();
    30     return;
    31   }
    33   if (req.hasHeader("Cookie") &&
    34       req.getHeader("Cookie").split(";").indexOf("green") >= 0) {
    35     resp.write('<html style="background: #0f0;"></html>');
    36     resp.finish();
    37     return;
    38   }
    40   if (opts.redirect) {
    41     resp.setHeader("Location", opts.redirect);
    42     resp.setStatusLine(null, 303, null);
    43     resp.finish();
    44     return;
    45   }
    47   if (opts.wait) {
    48     resp.write("Waiting " + opts.wait + " ms... ");
    49     timer = Components.classes["@mozilla.org/timer;1"].
    50             createInstance(Components.interfaces.nsITimer);
    51     timer.init(function ding() {
    52       resp.write("OK!");
    53       resp.finish();
    54     }, opts.wait, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
    55     return;
    56   }
    58   resp.write("<pre>" + JSON.stringify(opts, undefined, 2) + "</pre>");
    59   resp.finish();
    60 }

mercurial