slow_image.sjs (1801B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 // small red image 8 const IMG_BYTES = atob( 9 "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12" + 10 "P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" 11 ); 12 13 // stolen from file_blocked_script.sjs 14 function setGlobalState(data, key) { 15 let x = { 16 data, 17 QueryInterface: ChromeUtils.generateQI([]), 18 }; 19 x.wrappedJSObject = x; 20 setObjectState(key, x); 21 } 22 23 function getGlobalState(key) { 24 var data; 25 getObjectState(key, function (x) { 26 data = x && x.wrappedJSObject.data; 27 }); 28 return data; 29 } 30 31 function handleRequest(request, response) { 32 if (request.queryString == "complete") { 33 // Unblock the previous request. 34 response.setStatusLine(request.httpVersion, 200, "OK"); 35 response.setHeader("Cache-Control", "no-cache", false); 36 response.setHeader("Content-Type", "application/json", false); 37 response.write("true"); // the payload doesn't matter. 38 39 let blockedResponse = getGlobalState("a11y-image"); 40 if (blockedResponse) { 41 blockedResponse.setStatusLine(request.httpVersion, 200, "OK"); 42 blockedResponse.setHeader("Cache-Control", "no-cache", false); 43 blockedResponse.setHeader("Content-Type", "image/png", false); 44 blockedResponse.write(IMG_BYTES); 45 blockedResponse.finish(); 46 47 setGlobalState(undefined, "a11y-image"); 48 } 49 } else { 50 // Getting the image 51 response.processAsync(); 52 // Store the response in the global state 53 setGlobalState(response, "a11y-image"); 54 } 55 }