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