michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const TIMEOUT_INTERVAL_MS = 100; michael@0: michael@0: function handleRequest(request, response) { michael@0: michael@0: // Allow us to asynchronously construct the response with timeouts michael@0: // rather than forcing us to make the whole thing in one call. See michael@0: // bug 396226. michael@0: response.processAsync(); michael@0: michael@0: // Figure out whether the client wants to load the image, or just michael@0: // to tell us to finish the previous load michael@0: var query = {}; michael@0: request.queryString.split('&').forEach(function (val) { michael@0: var [name, value] = val.split('='); michael@0: query[name] = unescape(value); michael@0: }); michael@0: if (query["continue"] == "true") { michael@0: michael@0: // Debugging information so we can figure out the hang michael@0: dump("file_IconTestServer.js DEBUG - Got continue command\n"); michael@0: michael@0: // Get the context structure and finish the old request michael@0: getObjectState("context", function(obj) { michael@0: michael@0: // magic or goop, depending on how you look at it michael@0: savedCtx = obj.wrappedJSObject; michael@0: michael@0: // Write the rest of the data michael@0: savedCtx.ostream.writeFrom(savedCtx.istream, savedCtx.istream.available()); michael@0: michael@0: // Close the streams michael@0: savedCtx.ostream.close(); michael@0: savedCtx.istream.close(); michael@0: michael@0: // Finish off 'the old response' michael@0: savedCtx.response.finish(); michael@0: }); michael@0: michael@0: // Finish off 'the current response' michael@0: response.finish(); michael@0: return; michael@0: } michael@0: michael@0: // Debugging information so we can figure out the hang michael@0: dump("file_IconTestServer.js DEBUG - Got initial request\n"); michael@0: michael@0: // Context structure - we need to set this up properly to pass to setObjectState michael@0: var ctx = { michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Components.interfaces.nsISupports)) michael@0: return this; michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: }; michael@0: ctx.wrappedJSObject = ctx; michael@0: michael@0: // Save the response michael@0: ctx.response = response; michael@0: michael@0: // We're serving up a png michael@0: response.setHeader("Content-Type", "image/png", false); michael@0: michael@0: // Get the output stream michael@0: ctx.ostream = response.bodyOutputStream; michael@0: michael@0: // Ugly hack, but effective - copied from content/media/test/contentDuration1.sjs michael@0: var pngFile = Components.classes["@mozilla.org/file/directory_service;1"]. michael@0: getService(Components.interfaces.nsIProperties). michael@0: get("CurWorkD", Components.interfaces.nsILocalFile); michael@0: var paths = "tests/layout/generic/test/file_Dolske.png"; michael@0: var split = paths.split("/"); michael@0: for(var i = 0; i < split.length; ++i) { michael@0: pngFile.append(split[i]); michael@0: } michael@0: michael@0: // Get an input stream for the png data michael@0: ctx.istream = Cc["@mozilla.org/network/file-input-stream;1"]. michael@0: createInstance(Components.interfaces.nsIFileInputStream); michael@0: ctx.istream.init(pngFile, -1, 0, 0); michael@0: michael@0: // Write the first 10 bytes, which is just boilerplate/magic bytes michael@0: ctx.ostream.writeFrom(ctx.istream, 10); michael@0: michael@0: // Save the context structure for retrieval when we get pinged michael@0: setObjectState("context", ctx); michael@0: michael@0: // Now we play the waiting game... michael@0: michael@0: // Debugging information so we can figure out the hang michael@0: dump("file_IconTestServer.js DEBUG - Playing the waiting game\n"); michael@0: } michael@0: