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 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | |
michael@0 | 4 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 5 | Components.utils.import("resource://gre/modules/NetUtil.jsm"); |
michael@0 | 6 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 7 | Components.utils.import("resource://gre/modules/FileUtils.jsm"); |
michael@0 | 8 | Components.utils.import("resource://gre/modules/Promise.jsm"); |
michael@0 | 9 | Components.utils.import("resource://testing-common/AppInfo.jsm"); |
michael@0 | 10 | |
michael@0 | 11 | const BROWSER_SEARCH_PREF = "browser.search."; |
michael@0 | 12 | const NS_APP_SEARCH_DIR = "SrchPlugns"; |
michael@0 | 13 | |
michael@0 | 14 | const MODE_RDONLY = FileUtils.MODE_RDONLY; |
michael@0 | 15 | const MODE_WRONLY = FileUtils.MODE_WRONLY; |
michael@0 | 16 | const MODE_CREATE = FileUtils.MODE_CREATE; |
michael@0 | 17 | const MODE_TRUNCATE = FileUtils.MODE_TRUNCATE; |
michael@0 | 18 | |
michael@0 | 19 | // Need to create and register a profile folder. |
michael@0 | 20 | var gProfD = do_get_profile(); |
michael@0 | 21 | |
michael@0 | 22 | function dumpn(text) |
michael@0 | 23 | { |
michael@0 | 24 | dump("search test: " + text + "\n"); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * Clean the profile of any metadata files left from a previous run. |
michael@0 | 29 | */ |
michael@0 | 30 | function removeMetadata() |
michael@0 | 31 | { |
michael@0 | 32 | let file = gProfD.clone(); |
michael@0 | 33 | file.append("search-metadata.json"); |
michael@0 | 34 | if (file.exists()) { |
michael@0 | 35 | file.remove(false); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | file = gProfD.clone(); |
michael@0 | 39 | file.append("search.sqlite"); |
michael@0 | 40 | if (file.exists()) { |
michael@0 | 41 | file.remove(false); |
michael@0 | 42 | } |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function removeCacheFile() |
michael@0 | 46 | { |
michael@0 | 47 | let file = gProfD.clone(); |
michael@0 | 48 | file.append("search.json"); |
michael@0 | 49 | if (file.exists()) { |
michael@0 | 50 | file.remove(false); |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | /** |
michael@0 | 55 | * Clean the profile of any cache file left from a previous run. |
michael@0 | 56 | */ |
michael@0 | 57 | function removeCache() |
michael@0 | 58 | { |
michael@0 | 59 | let file = gProfD.clone(); |
michael@0 | 60 | file.append("search.json"); |
michael@0 | 61 | if (file.exists()) { |
michael@0 | 62 | file.remove(false); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | /** |
michael@0 | 68 | * Run some callback once metadata has been committed to disk. |
michael@0 | 69 | */ |
michael@0 | 70 | function afterCommit(callback) |
michael@0 | 71 | { |
michael@0 | 72 | let obs = function(result, topic, verb) { |
michael@0 | 73 | if (verb == "write-metadata-to-disk-complete") { |
michael@0 | 74 | Services.obs.removeObserver(obs, topic); |
michael@0 | 75 | callback(result); |
michael@0 | 76 | } else { |
michael@0 | 77 | dump("TOPIC: " + topic+ "\n"); |
michael@0 | 78 | } |
michael@0 | 79 | } |
michael@0 | 80 | Services.obs.addObserver(obs, "browser-search-service", false); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | /** |
michael@0 | 84 | * Run some callback once cache has been built. |
michael@0 | 85 | */ |
michael@0 | 86 | function afterCache(callback) |
michael@0 | 87 | { |
michael@0 | 88 | let obs = function(result, topic, verb) { |
michael@0 | 89 | do_print("afterCache: " + verb); |
michael@0 | 90 | if (verb == "write-cache-to-disk-complete") { |
michael@0 | 91 | Services.obs.removeObserver(obs, topic); |
michael@0 | 92 | callback(result); |
michael@0 | 93 | } else { |
michael@0 | 94 | dump("TOPIC: " + topic+ "\n"); |
michael@0 | 95 | } |
michael@0 | 96 | } |
michael@0 | 97 | Services.obs.addObserver(obs, "browser-search-service", false); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | function parseJsonFromStream(aInputStream) { |
michael@0 | 101 | const json = Cc["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON); |
michael@0 | 102 | const data = json.decodeFromStream(aInputStream, aInputStream.available()); |
michael@0 | 103 | return data; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | /** |
michael@0 | 107 | * Read a JSON file and return the JS object |
michael@0 | 108 | */ |
michael@0 | 109 | function readJSONFile(aFile) { |
michael@0 | 110 | let stream = Cc["@mozilla.org/network/file-input-stream;1"]. |
michael@0 | 111 | createInstance(Ci.nsIFileInputStream); |
michael@0 | 112 | try { |
michael@0 | 113 | stream.init(aFile, MODE_RDONLY, FileUtils.PERMS_FILE, 0); |
michael@0 | 114 | return parseJsonFromStream(stream, stream.available()); |
michael@0 | 115 | } catch(ex) { |
michael@0 | 116 | dumpn("readJSONFile: Error reading JSON file: " + ex); |
michael@0 | 117 | } finally { |
michael@0 | 118 | stream.close(); |
michael@0 | 119 | } |
michael@0 | 120 | return false; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | /** |
michael@0 | 124 | * Recursively compare two objects and check that every property of expectedObj has the same value |
michael@0 | 125 | * on actualObj. |
michael@0 | 126 | */ |
michael@0 | 127 | function isSubObjectOf(expectedObj, actualObj) { |
michael@0 | 128 | for (let prop in expectedObj) { |
michael@0 | 129 | if (expectedObj[prop] instanceof Object) { |
michael@0 | 130 | do_check_eq(expectedObj[prop].length, actualObj[prop].length); |
michael@0 | 131 | isSubObjectOf(expectedObj[prop], actualObj[prop]); |
michael@0 | 132 | } else { |
michael@0 | 133 | do_check_eq(expectedObj[prop], actualObj[prop]); |
michael@0 | 134 | } |
michael@0 | 135 | } |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | // Expand the amount of information available in error logs |
michael@0 | 139 | Services.prefs.setBoolPref("browser.search.log", true); |
michael@0 | 140 |