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 | /* This code is mostly copied from chrome/test/unit/head_crtestutils.js */ |
michael@0 | 2 | |
michael@0 | 3 | const NS_CHROME_MANIFESTS_FILE_LIST = "ChromeML"; |
michael@0 | 4 | const XUL_CACHE_PREF = "nglayout.debug.disable_xul_cache"; |
michael@0 | 5 | |
michael@0 | 6 | const Cc = Components.classes; |
michael@0 | 7 | const Ci = Components.interfaces; |
michael@0 | 8 | const Cr = Components.results; |
michael@0 | 9 | |
michael@0 | 10 | let gDirSvc = Cc["@mozilla.org/file/directory_service;1"]. |
michael@0 | 11 | getService(Ci.nsIDirectoryService).QueryInterface(Ci.nsIProperties); |
michael@0 | 12 | let gChromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]. |
michael@0 | 13 | getService(Ci.nsIXULChromeRegistry); |
michael@0 | 14 | let gPrefs = Cc["@mozilla.org/preferences-service;1"]. |
michael@0 | 15 | getService(Ci.nsIPrefBranch); |
michael@0 | 16 | |
michael@0 | 17 | // Create the temporary file in the profile, instead of in TmpD, because |
michael@0 | 18 | // we know the mochitest harness kills off the profile when it's done. |
michael@0 | 19 | function copyToTemporaryFile(f) |
michael@0 | 20 | { |
michael@0 | 21 | let tmpd = gDirSvc.get("ProfD", Ci.nsIFile); |
michael@0 | 22 | tmpf = tmpd.clone(); |
michael@0 | 23 | tmpf.append("temp.manifest"); |
michael@0 | 24 | tmpf.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600); |
michael@0 | 25 | tmpf.remove(false); |
michael@0 | 26 | f.copyTo(tmpd, tmpf.leafName); |
michael@0 | 27 | return tmpf; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function dirIter(directory) |
michael@0 | 31 | { |
michael@0 | 32 | var ioSvc = Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 33 | getService(Ci.nsIIOService); |
michael@0 | 34 | var testsDir = ioSvc.newURI(directory, null, null) |
michael@0 | 35 | .QueryInterface(Ci.nsIFileURL).file; |
michael@0 | 36 | |
michael@0 | 37 | let en = testsDir.directoryEntries; |
michael@0 | 38 | while (en.hasMoreElements()) { |
michael@0 | 39 | let file = en.getNext(); |
michael@0 | 40 | yield file.QueryInterface(Ci.nsIFile); |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function getParent(path) { |
michael@0 | 45 | let lastSlash = path.lastIndexOf("/"); |
michael@0 | 46 | if (lastSlash == -1) { |
michael@0 | 47 | lastSlash = path.lastIndexOf("\\"); |
michael@0 | 48 | if (lastSlash == -1) { |
michael@0 | 49 | return ""; |
michael@0 | 50 | } |
michael@0 | 51 | return '/' + path.substring(0, lastSlash).replace(/\\/g, '/'); |
michael@0 | 52 | } |
michael@0 | 53 | return path.substring(0, lastSlash); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function copyDirToTempProfile(path, subdirname) { |
michael@0 | 57 | |
michael@0 | 58 | if (subdirname === undefined) { |
michael@0 | 59 | subdirname = "mochikit-tmp"; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | let tmpdir = gDirSvc.get("ProfD", Ci.nsIFile); |
michael@0 | 63 | tmpdir.append(subdirname); |
michael@0 | 64 | tmpdir.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777); |
michael@0 | 65 | |
michael@0 | 66 | let rootDir = getParent(path); |
michael@0 | 67 | if (rootDir == "") { |
michael@0 | 68 | return tmpdir; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | // The SimpleTest directory is hidden |
michael@0 | 72 | var files = [file for (file in dirIter('file://' +rootDir))]; |
michael@0 | 73 | for (f in files) { |
michael@0 | 74 | files[f].copyTo(tmpdir, ""); |
michael@0 | 75 | } |
michael@0 | 76 | return tmpdir; |
michael@0 | 77 | |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | function convertChromeURI(chromeURI) |
michael@0 | 81 | { |
michael@0 | 82 | let uri = Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 83 | getService(Ci.nsIIOService).newURI(chromeURI, null, null); |
michael@0 | 84 | return gChromeReg.convertChromeURL(uri); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function chromeURIToFile(chromeURI) |
michael@0 | 88 | { |
michael@0 | 89 | var jar = getJar(chromeURI); |
michael@0 | 90 | if (jar) { |
michael@0 | 91 | var tmpDir = extractJarToTmp(jar); |
michael@0 | 92 | let parts = chromeURI.split('/'); |
michael@0 | 93 | if (parts[parts.length - 1] != '') { |
michael@0 | 94 | tmpDir.append(parts[parts.length - 1]); |
michael@0 | 95 | } |
michael@0 | 96 | return tmpDir; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | return convertChromeURI(chromeURI). |
michael@0 | 100 | QueryInterface(Ci.nsIFileURL).file; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | // Register a chrome manifest temporarily and return a function which un-does |
michael@0 | 104 | // the registrarion when no longer needed. |
michael@0 | 105 | function createManifestTemporarily(tempDir, manifestText) |
michael@0 | 106 | { |
michael@0 | 107 | gPrefs.setBoolPref(XUL_CACHE_PREF, true); |
michael@0 | 108 | |
michael@0 | 109 | tempDir.append("temp.manifest"); |
michael@0 | 110 | |
michael@0 | 111 | let foStream = Cc["@mozilla.org/network/file-output-stream;1"] |
michael@0 | 112 | .createInstance(Ci.nsIFileOutputStream); |
michael@0 | 113 | foStream.init(tempDir, |
michael@0 | 114 | 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate |
michael@0 | 115 | foStream.write(manifestText, manifestText.length); |
michael@0 | 116 | foStream.close(); |
michael@0 | 117 | let tempfile = copyToTemporaryFile(tempDir); |
michael@0 | 118 | |
michael@0 | 119 | Components.manager.QueryInterface(Ci.nsIComponentRegistrar). |
michael@0 | 120 | autoRegister(tempfile); |
michael@0 | 121 | |
michael@0 | 122 | gChromeReg.refreshSkins(); |
michael@0 | 123 | |
michael@0 | 124 | return function() { |
michael@0 | 125 | tempfile.fileSize = 0; // truncate the manifest |
michael@0 | 126 | gChromeReg.checkForNewChrome(); |
michael@0 | 127 | gChromeReg.refreshSkins(); |
michael@0 | 128 | gPrefs.clearUserPref(XUL_CACHE_PREF); |
michael@0 | 129 | } |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | // Register a chrome manifest temporarily and return a function which un-does |
michael@0 | 133 | // the registrarion when no longer needed. |
michael@0 | 134 | function registerManifestTemporarily(manifestURI) |
michael@0 | 135 | { |
michael@0 | 136 | gPrefs.setBoolPref(XUL_CACHE_PREF, true); |
michael@0 | 137 | |
michael@0 | 138 | let file = chromeURIToFile(manifestURI); |
michael@0 | 139 | |
michael@0 | 140 | let tempfile = copyToTemporaryFile(file); |
michael@0 | 141 | Components.manager.QueryInterface(Ci.nsIComponentRegistrar). |
michael@0 | 142 | autoRegister(tempfile); |
michael@0 | 143 | |
michael@0 | 144 | gChromeReg.refreshSkins(); |
michael@0 | 145 | |
michael@0 | 146 | return function() { |
michael@0 | 147 | tempfile.fileSize = 0; // truncate the manifest |
michael@0 | 148 | gChromeReg.checkForNewChrome(); |
michael@0 | 149 | gChromeReg.refreshSkins(); |
michael@0 | 150 | gPrefs.clearUserPref(XUL_CACHE_PREF); |
michael@0 | 151 | } |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | function registerManifestPermanently(manifestURI) |
michael@0 | 155 | { |
michael@0 | 156 | var chromepath = chromeURIToFile(manifestURI); |
michael@0 | 157 | |
michael@0 | 158 | Components.manager.QueryInterface(Ci.nsIComponentRegistrar). |
michael@0 | 159 | autoRegister(chromepath); |
michael@0 | 160 | return chromepath; |
michael@0 | 161 | } |