|
1 const Cc = Components.classes; |
|
2 const Ci = Components.interfaces; |
|
3 const TIMEOUT_INTERVAL_MS = 100; |
|
4 |
|
5 function handleRequest(request, response) { |
|
6 |
|
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(); |
|
11 |
|
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") { |
|
20 |
|
21 // Debugging information so we can figure out the hang |
|
22 dump("file_IconTestServer.js DEBUG - Got continue command\n"); |
|
23 |
|
24 // Get the context structure and finish the old request |
|
25 getObjectState("context", function(obj) { |
|
26 |
|
27 // magic or goop, depending on how you look at it |
|
28 savedCtx = obj.wrappedJSObject; |
|
29 |
|
30 // Write the rest of the data |
|
31 savedCtx.ostream.writeFrom(savedCtx.istream, savedCtx.istream.available()); |
|
32 |
|
33 // Close the streams |
|
34 savedCtx.ostream.close(); |
|
35 savedCtx.istream.close(); |
|
36 |
|
37 // Finish off 'the old response' |
|
38 savedCtx.response.finish(); |
|
39 }); |
|
40 |
|
41 // Finish off 'the current response' |
|
42 response.finish(); |
|
43 return; |
|
44 } |
|
45 |
|
46 // Debugging information so we can figure out the hang |
|
47 dump("file_IconTestServer.js DEBUG - Got initial request\n"); |
|
48 |
|
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; |
|
58 |
|
59 // Save the response |
|
60 ctx.response = response; |
|
61 |
|
62 // We're serving up a png |
|
63 response.setHeader("Content-Type", "image/png", false); |
|
64 |
|
65 // Get the output stream |
|
66 ctx.ostream = response.bodyOutputStream; |
|
67 |
|
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 } |
|
77 |
|
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); |
|
82 |
|
83 // Write the first 10 bytes, which is just boilerplate/magic bytes |
|
84 ctx.ostream.writeFrom(ctx.istream, 10); |
|
85 |
|
86 // Save the context structure for retrieval when we get pinged |
|
87 setObjectState("context", ctx); |
|
88 |
|
89 // Now we play the waiting game... |
|
90 |
|
91 // Debugging information so we can figure out the hang |
|
92 dump("file_IconTestServer.js DEBUG - Playing the waiting game\n"); |
|
93 } |
|
94 |