layout/generic/test/file_IconTestServer.sjs

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 const Cc = Components.classes;
     2 const Ci = Components.interfaces;
     3 const TIMEOUT_INTERVAL_MS = 100;
     5 function handleRequest(request, response) {
     7   // Allow us to asynchronously construct the response with timeouts
     8   // rather than forcing us to make the whole thing in one call. See
     9   // bug 396226.
    10   response.processAsync();
    12   // Figure out whether the client wants to load the image, or just
    13   // to tell us to finish the previous load
    14   var query = {};
    15   request.queryString.split('&').forEach(function (val) {
    16     var [name, value] = val.split('=');
    17     query[name] = unescape(value);
    18   });
    19   if (query["continue"] == "true") {
    21     // Debugging information so we can figure out the hang
    22     dump("file_IconTestServer.js DEBUG - Got continue command\n");
    24     // Get the context structure and finish the old request
    25     getObjectState("context", function(obj) {
    27       // magic or goop, depending on how you look at it
    28       savedCtx = obj.wrappedJSObject;
    30       // Write the rest of the data
    31       savedCtx.ostream.writeFrom(savedCtx.istream, savedCtx.istream.available());
    33       // Close the streams
    34       savedCtx.ostream.close();
    35       savedCtx.istream.close();
    37       // Finish off 'the old response'
    38       savedCtx.response.finish();
    39     });
    41     // Finish off 'the current response'
    42     response.finish();
    43     return;
    44   }
    46   // Debugging information so we can figure out the hang
    47   dump("file_IconTestServer.js DEBUG - Got initial request\n");
    49   // Context structure - we need to set this up properly to pass to setObjectState
    50   var ctx = {
    51     QueryInterface: function(iid) {
    52       if (iid.equals(Components.interfaces.nsISupports))
    53         return this;
    54       throw Components.results.NS_ERROR_NO_INTERFACE;
    55     }
    56   };
    57   ctx.wrappedJSObject = ctx;
    59   // Save the response
    60   ctx.response = response;
    62   // We're serving up a png
    63   response.setHeader("Content-Type", "image/png", false);
    65   // Get the output stream
    66   ctx.ostream = response.bodyOutputStream;
    68   // Ugly hack, but effective - copied from content/media/test/contentDuration1.sjs
    69   var pngFile = Components.classes["@mozilla.org/file/directory_service;1"].
    70                            getService(Components.interfaces.nsIProperties).
    71                            get("CurWorkD", Components.interfaces.nsILocalFile);
    72   var paths = "tests/layout/generic/test/file_Dolske.png";
    73   var split = paths.split("/");
    74   for(var i = 0; i < split.length; ++i) {
    75     pngFile.append(split[i]);
    76   }
    78   // Get an input stream for the png data
    79   ctx.istream = Cc["@mozilla.org/network/file-input-stream;1"].
    80                       createInstance(Components.interfaces.nsIFileInputStream);
    81   ctx.istream.init(pngFile, -1, 0, 0);
    83   // Write the first 10 bytes, which is just boilerplate/magic bytes
    84   ctx.ostream.writeFrom(ctx.istream, 10);
    86   // Save the context structure for retrieval when we get pinged
    87   setObjectState("context", ctx);
    89   // Now we play the waiting game...
    91   // Debugging information so we can figure out the hang
    92   dump("file_IconTestServer.js DEBUG - Playing the waiting game\n");
    93 }

mercurial