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 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | const { classes: Cc, interfaces: Ci, utils: Cu } = Components; |
michael@0 | 5 | |
michael@0 | 6 | Cu.import("resource://gre/modules/osfile.jsm"); |
michael@0 | 7 | Cu.import("resource://gre/modules/Task.jsm"); |
michael@0 | 8 | Cu.import("resource://gre/modules/Promise.jsm"); |
michael@0 | 9 | |
michael@0 | 10 | const LINUX = navigator.platform.startsWith("Linux"); |
michael@0 | 11 | const MAC = navigator.platform.startsWith("Mac"); |
michael@0 | 12 | const WIN = navigator.platform.startsWith("Win"); |
michael@0 | 13 | const MAC_106 = navigator.userAgent.contains("Mac OS X 10.6"); |
michael@0 | 14 | |
michael@0 | 15 | function checkFiles(files) { |
michael@0 | 16 | return Task.spawn(function*() { |
michael@0 | 17 | for (let file of files) { |
michael@0 | 18 | if (!(yield OS.File.exists(file))) { |
michael@0 | 19 | info("File doesn't exist: " + file); |
michael@0 | 20 | return false; |
michael@0 | 21 | } |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | return true; |
michael@0 | 25 | }); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function checkDateHigherThan(files, date) { |
michael@0 | 29 | return Task.spawn(function*() { |
michael@0 | 30 | for (let file of files) { |
michael@0 | 31 | if (!(yield OS.File.exists(file))) { |
michael@0 | 32 | info("File doesn't exist: " + file); |
michael@0 | 33 | return false; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | let stat = yield OS.File.stat(file); |
michael@0 | 37 | if (!(stat.lastModificationDate > date)) { |
michael@0 | 38 | info("File not newer: " + file); |
michael@0 | 39 | return false; |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | return true; |
michael@0 | 44 | }); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function wait(time) { |
michael@0 | 48 | let deferred = Promise.defer(); |
michael@0 | 49 | |
michael@0 | 50 | setTimeout(function() { |
michael@0 | 51 | deferred.resolve(); |
michael@0 | 52 | }, time); |
michael@0 | 53 | |
michael@0 | 54 | return deferred.promise; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | // Helper to create a nsIFile from a set of path components |
michael@0 | 58 | function getFile() { |
michael@0 | 59 | let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); |
michael@0 | 60 | file.initWithPath(OS.Path.join.apply(OS.Path, arguments)); |
michael@0 | 61 | return file; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function setDryRunPref() { |
michael@0 | 65 | let old_dry_run; |
michael@0 | 66 | try { |
michael@0 | 67 | old_dry_run = Services.prefs.getBoolPref("browser.mozApps.installer.dry_run"); |
michael@0 | 68 | } catch (ex) {} |
michael@0 | 69 | |
michael@0 | 70 | Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false); |
michael@0 | 71 | |
michael@0 | 72 | SimpleTest.registerCleanupFunction(function() { |
michael@0 | 73 | if (old_dry_run === undefined) { |
michael@0 | 74 | Services.prefs.clearUserPref("browser.mozApps.installer.dry_run"); |
michael@0 | 75 | } else { |
michael@0 | 76 | Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", old_dry_run); |
michael@0 | 77 | } |
michael@0 | 78 | }); |
michael@0 | 79 | } |