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 Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | "use strict"; |
michael@0 | 5 | |
michael@0 | 6 | module.metadata = { |
michael@0 | 7 | "stability": "deprecated" |
michael@0 | 8 | }; |
michael@0 | 9 | |
michael@0 | 10 | const { Cc, Ci, Cu, components } = require("chrome"); |
michael@0 | 11 | const { when: unload } = require("../system/unload") |
michael@0 | 12 | |
michael@0 | 13 | var trackedObjects = {}; |
michael@0 | 14 | const Compacter = { |
michael@0 | 15 | notify: function() { |
michael@0 | 16 | var newTrackedObjects = {}; |
michael@0 | 17 | |
michael@0 | 18 | for (let name in trackedObjects) { |
michael@0 | 19 | let oldBin = trackedObjects[name]; |
michael@0 | 20 | let newBin = []; |
michael@0 | 21 | let strongRefs = []; |
michael@0 | 22 | |
michael@0 | 23 | for (let i = 0, l = oldBin.length; i < l; i++) { |
michael@0 | 24 | let strongRef = oldBin[i].weakref.get(); |
michael@0 | 25 | |
michael@0 | 26 | if (strongRef && strongRefs.indexOf(strongRef) == -1) { |
michael@0 | 27 | strongRefs.push(strongRef); |
michael@0 | 28 | newBin.push(oldBin[i]); |
michael@0 | 29 | } |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | if (newBin.length) |
michael@0 | 33 | newTrackedObjects[name] = newBin; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | trackedObjects = newTrackedObjects; |
michael@0 | 37 | } |
michael@0 | 38 | }; |
michael@0 | 39 | |
michael@0 | 40 | var timer = Cc["@mozilla.org/timer;1"] |
michael@0 | 41 | .createInstance(Ci.nsITimer); |
michael@0 | 42 | timer.initWithCallback(Compacter, |
michael@0 | 43 | 5000, |
michael@0 | 44 | Ci.nsITimer.TYPE_REPEATING_SLACK); |
michael@0 | 45 | |
michael@0 | 46 | function track(object, bin, stackFrameNumber) { |
michael@0 | 47 | var frame = components.stack.caller; |
michael@0 | 48 | var weakref = Cu.getWeakReference(object); |
michael@0 | 49 | |
michael@0 | 50 | if (!bin && 'constructor' in object) |
michael@0 | 51 | bin = object.constructor.name; |
michael@0 | 52 | if (bin == "Object") |
michael@0 | 53 | bin = frame.name; |
michael@0 | 54 | if (!bin) |
michael@0 | 55 | bin = "generic"; |
michael@0 | 56 | if (!(bin in trackedObjects)) |
michael@0 | 57 | trackedObjects[bin] = []; |
michael@0 | 58 | |
michael@0 | 59 | if (stackFrameNumber > 0) |
michael@0 | 60 | for (var i = 0; i < stackFrameNumber; i++) |
michael@0 | 61 | frame = frame.caller; |
michael@0 | 62 | |
michael@0 | 63 | trackedObjects[bin].push({weakref: weakref, |
michael@0 | 64 | created: new Date(), |
michael@0 | 65 | filename: frame.filename, |
michael@0 | 66 | lineNo: frame.lineNumber, |
michael@0 | 67 | bin: bin}); |
michael@0 | 68 | } |
michael@0 | 69 | exports.track = track; |
michael@0 | 70 | |
michael@0 | 71 | var getBins = exports.getBins = function getBins() { |
michael@0 | 72 | var names = []; |
michael@0 | 73 | for (let name in trackedObjects) |
michael@0 | 74 | names.push(name); |
michael@0 | 75 | return names; |
michael@0 | 76 | }; |
michael@0 | 77 | |
michael@0 | 78 | function getObjects(bin) { |
michael@0 | 79 | var results = []; |
michael@0 | 80 | |
michael@0 | 81 | function getLiveObjectsInBin(bin) { |
michael@0 | 82 | for (let i = 0, l = bin.length; i < l; i++) { |
michael@0 | 83 | let object = bin[i].weakref.get(); |
michael@0 | 84 | |
michael@0 | 85 | if (object) { |
michael@0 | 86 | results.push(bin[i]); |
michael@0 | 87 | } |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | if (bin) { |
michael@0 | 92 | if (bin in trackedObjects) |
michael@0 | 93 | getLiveObjectsInBin(trackedObjects[bin]); |
michael@0 | 94 | } |
michael@0 | 95 | else { |
michael@0 | 96 | for (let name in trackedObjects) |
michael@0 | 97 | getLiveObjectsInBin(trackedObjects[name]); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | return results; |
michael@0 | 101 | } |
michael@0 | 102 | exports.getObjects = getObjects; |
michael@0 | 103 | |
michael@0 | 104 | function gc() { |
michael@0 | 105 | // Components.utils.forceGC() doesn't currently perform |
michael@0 | 106 | // cycle collection, which means that e.g. DOM elements |
michael@0 | 107 | // won't be collected by it. Fortunately, there are |
michael@0 | 108 | // other ways... |
michael@0 | 109 | var test_utils = Cc["@mozilla.org/appshell/appShellService;1"] |
michael@0 | 110 | .getService(Ci.nsIAppShellService) |
michael@0 | 111 | .hiddenDOMWindow |
michael@0 | 112 | .QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 113 | .getInterface(Ci.nsIDOMWindowUtils); |
michael@0 | 114 | test_utils.garbageCollect(); |
michael@0 | 115 | // Clean metadata for dead objects |
michael@0 | 116 | Compacter.notify(); |
michael@0 | 117 | // Not sure why, but sometimes it appears that we don't get |
michael@0 | 118 | // them all with just one CC, so let's do it again. |
michael@0 | 119 | test_utils.garbageCollect(); |
michael@0 | 120 | }; |
michael@0 | 121 | exports.gc = gc; |
michael@0 | 122 | |
michael@0 | 123 | unload(_ => { |
michael@0 | 124 | trackedObjects = {}; |
michael@0 | 125 | if (timer) { |
michael@0 | 126 | timer.cancel(); |
michael@0 | 127 | timer = null; |
michael@0 | 128 | } |
michael@0 | 129 | }); |