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