Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | var Cc = Components.classes; |
michael@0 | 2 | var Ci = Components.interfaces; |
michael@0 | 3 | var Cu = Components.utils; |
michael@0 | 4 | |
michael@0 | 5 | // From prio.h |
michael@0 | 6 | const PR_RDWR = 0x04; |
michael@0 | 7 | const PR_CREATE_FILE = 0x08; |
michael@0 | 8 | const PR_TRUNCATE = 0x20; |
michael@0 | 9 | |
michael@0 | 10 | const CUR_WORK_DIR = "CurWorkD"; |
michael@0 | 11 | |
michael@0 | 12 | Cu.import("resource://gre/modules/NetUtil.jsm"); |
michael@0 | 13 | |
michael@0 | 14 | var gBasePath = "tests/dom/apps/tests/"; |
michael@0 | 15 | var gMiniManifestTemplate = "signed_app_template.webapp"; |
michael@0 | 16 | var gAppName = "Simple App"; |
michael@0 | 17 | var gDevName = "David Clarke"; |
michael@0 | 18 | var gDevUrl = "http://dev.url"; |
michael@0 | 19 | |
michael@0 | 20 | function handleRequest(request, response) { |
michael@0 | 21 | var query = getQuery(request); |
michael@0 | 22 | |
michael@0 | 23 | response.setHeader("Access-Control-Allow-Origin", "*", false); |
michael@0 | 24 | |
michael@0 | 25 | var version = ("version" in query) ? query.version : "1"; |
michael@0 | 26 | var app = ("app" in query) ? query.app : "valid"; |
michael@0 | 27 | var prevVersion = getState("version"); |
michael@0 | 28 | |
michael@0 | 29 | if (version != prevVersion) { |
michael@0 | 30 | setState("version", version); |
michael@0 | 31 | } |
michael@0 | 32 | var packageName = app + "_app_" + version + ".zip"; |
michael@0 | 33 | setState("packageName", packageName); |
michael@0 | 34 | var packagePath = "/" + gBasePath + "signed/" + packageName; |
michael@0 | 35 | setState("packagePath", packagePath); |
michael@0 | 36 | var packageSize = readSize(packagePath); |
michael@0 | 37 | |
michael@0 | 38 | var etag = getEtag(request, version); |
michael@0 | 39 | |
michael@0 | 40 | if (etagMatches(request, etag)) { |
michael@0 | 41 | dump("Etags Match. Sending 304\n"); |
michael@0 | 42 | response.setStatusLine(request.httpVersion, "304", "Not modified"); |
michael@0 | 43 | return; |
michael@0 | 44 | } |
michael@0 | 45 | response.setHeader("Etag", etag, false); |
michael@0 | 46 | |
michael@0 | 47 | // Serve the mini-manifest corresponding to the requested app version. |
michael@0 | 48 | var template = gBasePath + gMiniManifestTemplate; |
michael@0 | 49 | |
michael@0 | 50 | response.setHeader("Content-Type", |
michael@0 | 51 | "application/x-web-app-manifest+json", false); |
michael@0 | 52 | var manifest = makeResource(template, version, packagePath, packageSize, |
michael@0 | 53 | gAppName, gDevName, gDevUrl); |
michael@0 | 54 | response.write(manifest); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function getQuery(request) { |
michael@0 | 58 | var query = {}; |
michael@0 | 59 | request.queryString.split('&').forEach(function (val) { |
michael@0 | 60 | var [name, value] = val.split('='); |
michael@0 | 61 | query[decodeURIComponent(name)] = decodeURIComponent(value); |
michael@0 | 62 | }); |
michael@0 | 63 | return query; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function getEtag(request, version) { |
michael@0 | 67 | return request.queryString.replace(/[&=]/g, '-') + '-' + version; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function etagMatches(request, etag) { |
michael@0 | 71 | return request.hasHeader("If-None-Match") && |
michael@0 | 72 | request.getHeader("If-None-Match") == etag; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | // File and resources helpers |
michael@0 | 76 | |
michael@0 | 77 | function readSize(path) { |
michael@0 | 78 | var file = Cc["@mozilla.org/file/directory_service;1"]. |
michael@0 | 79 | getService(Ci.nsIProperties).get(CUR_WORK_DIR, Ci.nsILocalFile); |
michael@0 | 80 | var split = path.split("/"); |
michael@0 | 81 | for (var i = 0; i < split.length; ++i) { |
michael@0 | 82 | file.append(split[i]); |
michael@0 | 83 | } |
michael@0 | 84 | return file.fileSize; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function readFile(path) { |
michael@0 | 88 | var file = Cc["@mozilla.org/file/directory_service;1"] |
michael@0 | 89 | .getService(Ci.nsIProperties) |
michael@0 | 90 | .get(CUR_WORK_DIR, Ci.nsILocalFile); |
michael@0 | 91 | var fstream = Cc["@mozilla.org/network/file-input-stream;1"] |
michael@0 | 92 | .createInstance(Ci.nsIFileInputStream); |
michael@0 | 93 | var split = path.split("/"); |
michael@0 | 94 | for (var i = 0; i < split.length; ++i) { |
michael@0 | 95 | file.append(split[i]); |
michael@0 | 96 | } |
michael@0 | 97 | fstream.init(file, -1, 0, 0); |
michael@0 | 98 | var data = NetUtil.readInputStreamToString(fstream, fstream.available()); |
michael@0 | 99 | fstream.close(); |
michael@0 | 100 | return data; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | function makeResource(templatePath, version, packagePath, packageSize, |
michael@0 | 104 | appName, developerName, developerUrl) { |
michael@0 | 105 | var res = readFile(templatePath). |
michael@0 | 106 | replace(/VERSIONTOKEN/g, version). |
michael@0 | 107 | replace(/PACKAGEPATHTOKEN/g, packagePath). |
michael@0 | 108 | replace(/PACKAGESIZETOKEN/g, packageSize). |
michael@0 | 109 | replace(/NAMETOKEN/g, appName); |
michael@0 | 110 | return res; |
michael@0 | 111 | } |