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: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | const Ci = Components.interfaces; |
michael@0 | 8 | const Cc = Components.classes; |
michael@0 | 9 | const Cr = Components.results; |
michael@0 | 10 | const Cu = Components.utils; |
michael@0 | 11 | |
michael@0 | 12 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 13 | |
michael@0 | 14 | // Import common head. |
michael@0 | 15 | let (commonFile = do_get_file("../head_common.js", false)) { |
michael@0 | 16 | let uri = Services.io.newFileURI(commonFile); |
michael@0 | 17 | Services.scriptloader.loadSubScript(uri.spec, this); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | // Put any other stuff relative to this test folder below. |
michael@0 | 21 | |
michael@0 | 22 | |
michael@0 | 23 | // Simulates an expiration at shutdown. |
michael@0 | 24 | function shutdownExpiration() |
michael@0 | 25 | { |
michael@0 | 26 | let expire = Cc["@mozilla.org/places/expiration;1"].getService(Ci.nsIObserver); |
michael@0 | 27 | expire.observe(null, "places-will-close-connection", null); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | |
michael@0 | 31 | /** |
michael@0 | 32 | * Causes expiration component to start, otherwise it would wait for the first |
michael@0 | 33 | * history notification. |
michael@0 | 34 | */ |
michael@0 | 35 | function force_expiration_start() { |
michael@0 | 36 | Cc["@mozilla.org/places/expiration;1"].getService(Ci.nsISupports); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | |
michael@0 | 40 | /** |
michael@0 | 41 | * Forces an expiration run. |
michael@0 | 42 | * |
michael@0 | 43 | * @param [optional] aLimit |
michael@0 | 44 | * Limit for the expiration. Pass -1 for unlimited. |
michael@0 | 45 | * Any other non-positive value will just expire orphans. |
michael@0 | 46 | * |
michael@0 | 47 | * @return {Promise} |
michael@0 | 48 | * @resolves When expiration finishes. |
michael@0 | 49 | * @rejects Never. |
michael@0 | 50 | */ |
michael@0 | 51 | function promiseForceExpirationStep(aLimit) { |
michael@0 | 52 | let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED); |
michael@0 | 53 | let expire = Cc["@mozilla.org/places/expiration;1"].getService(Ci.nsIObserver); |
michael@0 | 54 | expire.observe(null, "places-debug-start-expiration", aLimit); |
michael@0 | 55 | return promise; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | |
michael@0 | 59 | /** |
michael@0 | 60 | * Expiration preferences helpers. |
michael@0 | 61 | */ |
michael@0 | 62 | |
michael@0 | 63 | function setInterval(aNewInterval) { |
michael@0 | 64 | Services.prefs.setIntPref("places.history.expiration.interval_seconds", aNewInterval); |
michael@0 | 65 | } |
michael@0 | 66 | function getInterval() { |
michael@0 | 67 | return Services.prefs.getIntPref("places.history.expiration.interval_seconds"); |
michael@0 | 68 | } |
michael@0 | 69 | function clearInterval() { |
michael@0 | 70 | try { |
michael@0 | 71 | Services.prefs.clearUserPref("places.history.expiration.interval_seconds"); |
michael@0 | 72 | } |
michael@0 | 73 | catch(ex) {} |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | |
michael@0 | 77 | function setMaxPages(aNewMaxPages) { |
michael@0 | 78 | Services.prefs.setIntPref("places.history.expiration.max_pages", aNewMaxPages); |
michael@0 | 79 | } |
michael@0 | 80 | function getMaxPages() { |
michael@0 | 81 | return Services.prefs.getIntPref("places.history.expiration.max_pages"); |
michael@0 | 82 | } |
michael@0 | 83 | function clearMaxPages() { |
michael@0 | 84 | try { |
michael@0 | 85 | Services.prefs.clearUserPref("places.history.expiration.max_pages"); |
michael@0 | 86 | } |
michael@0 | 87 | catch(ex) {} |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | |
michael@0 | 91 | function setHistoryEnabled(aHistoryEnabled) { |
michael@0 | 92 | Services.prefs.setBoolPref("places.history.enabled", aHistoryEnabled); |
michael@0 | 93 | } |
michael@0 | 94 | function getHistoryEnabled() { |
michael@0 | 95 | return Services.prefs.getBoolPref("places.history.enabled"); |
michael@0 | 96 | } |
michael@0 | 97 | function clearHistoryEnabled() { |
michael@0 | 98 | try { |
michael@0 | 99 | Services.prefs.clearUserPref("places.history.enabled"); |
michael@0 | 100 | } |
michael@0 | 101 | catch(ex) {} |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | /** |
michael@0 | 105 | * Returns a PRTime in the past usable to add expirable visits. |
michael@0 | 106 | * |
michael@0 | 107 | * @note Expiration ignores any visit added in the last 7 days, but it's |
michael@0 | 108 | * better be safe against DST issues, by going back one day more. |
michael@0 | 109 | */ |
michael@0 | 110 | function getExpirablePRTime() { |
michael@0 | 111 | let dateObj = new Date(); |
michael@0 | 112 | // Normalize to midnight |
michael@0 | 113 | dateObj.setHours(0); |
michael@0 | 114 | dateObj.setMinutes(0); |
michael@0 | 115 | dateObj.setSeconds(0); |
michael@0 | 116 | dateObj.setMilliseconds(0); |
michael@0 | 117 | dateObj = new Date(dateObj.getTime() - 8 * 86400000); |
michael@0 | 118 | return dateObj.getTime() * 1000; |
michael@0 | 119 | } |