Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | function handleRequest(request, response) |
michael@0 | 2 | { |
michael@0 | 3 | var file = Components.classes["@mozilla.org/file/directory_service;1"] |
michael@0 | 4 | .getService(Components.interfaces.nsIProperties) |
michael@0 | 5 | .get("CurWorkD", Components.interfaces.nsIFile); |
michael@0 | 6 | |
michael@0 | 7 | file.append("tests"); |
michael@0 | 8 | file.append("image"); |
michael@0 | 9 | file.append("test"); |
michael@0 | 10 | file.append("mochitest"); |
michael@0 | 11 | |
michael@0 | 12 | if (request.getHeader("Accept") == "image/png,image/*;q=0.8,*/*;q=0.5") { |
michael@0 | 13 | file.append('blue.png'); |
michael@0 | 14 | } else { |
michael@0 | 15 | file.append('red.png'); |
michael@0 | 16 | } |
michael@0 | 17 | response.setStatusLine(request.httpVersion, 200, "OK"); |
michael@0 | 18 | response.setHeader("Content-Type", "image/png", false); |
michael@0 | 19 | response.setHeader("Cache-Control", "no-cache", false); |
michael@0 | 20 | |
michael@0 | 21 | var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1'] |
michael@0 | 22 | .createInstance(Components.interfaces.nsIFileInputStream); |
michael@0 | 23 | fileStream.init(file, 1, 0, false); |
michael@0 | 24 | var binaryStream = Components.classes['@mozilla.org/binaryinputstream;1'] |
michael@0 | 25 | .createInstance(Components.interfaces.nsIBinaryInputStream); |
michael@0 | 26 | binaryStream.setInputStream(fileStream); |
michael@0 | 27 | |
michael@0 | 28 | response.bodyOutputStream.writeFrom(binaryStream, binaryStream.available()); |
michael@0 | 29 | |
michael@0 | 30 | binaryStream.close(); |
michael@0 | 31 | fileStream.close(); |
michael@0 | 32 | } |