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 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | const { Cc, Ci, Cu } = require("chrome"); |
michael@0 | 8 | const TargetFactory = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools.TargetFactory; |
michael@0 | 9 | const gcli = require("gcli/index"); |
michael@0 | 10 | |
michael@0 | 11 | loader.lazyImporter(this, "gDevTools", "resource:///modules/devtools/gDevTools.jsm"); |
michael@0 | 12 | |
michael@0 | 13 | loader.lazyGetter(this, "Debugger", () => { |
michael@0 | 14 | let global = Cu.getGlobalForObject({}); |
michael@0 | 15 | let JsDebugger = Cu.import("resource://gre/modules/jsdebugger.jsm", {}); |
michael@0 | 16 | JsDebugger.addDebuggerToGlobal(global); |
michael@0 | 17 | return global.Debugger; |
michael@0 | 18 | }); |
michael@0 | 19 | |
michael@0 | 20 | let debuggers = []; |
michael@0 | 21 | let chromeDebuggers = []; |
michael@0 | 22 | let sandboxes = []; |
michael@0 | 23 | |
michael@0 | 24 | exports.items = [ |
michael@0 | 25 | { |
michael@0 | 26 | name: "calllog", |
michael@0 | 27 | description: gcli.lookup("calllogDesc") |
michael@0 | 28 | }, |
michael@0 | 29 | { |
michael@0 | 30 | name: "calllog start", |
michael@0 | 31 | description: gcli.lookup("calllogStartDesc"), |
michael@0 | 32 | |
michael@0 | 33 | exec: function(args, context) { |
michael@0 | 34 | let contentWindow = context.environment.window; |
michael@0 | 35 | |
michael@0 | 36 | let dbg = new Debugger(contentWindow); |
michael@0 | 37 | dbg.onEnterFrame = function(frame) { |
michael@0 | 38 | // BUG 773652 - Make the output from the GCLI calllog command nicer |
michael@0 | 39 | contentWindow.console.log("Method call: " + this.callDescription(frame)); |
michael@0 | 40 | }.bind(this); |
michael@0 | 41 | |
michael@0 | 42 | debuggers.push(dbg); |
michael@0 | 43 | |
michael@0 | 44 | let gBrowser = context.environment.chromeDocument.defaultView.gBrowser; |
michael@0 | 45 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 46 | gDevTools.showToolbox(target, "webconsole"); |
michael@0 | 47 | |
michael@0 | 48 | return gcli.lookup("calllogStartReply"); |
michael@0 | 49 | }, |
michael@0 | 50 | |
michael@0 | 51 | callDescription: function(frame) { |
michael@0 | 52 | let name = "<anonymous>"; |
michael@0 | 53 | if (frame.callee.name) { |
michael@0 | 54 | name = frame.callee.name; |
michael@0 | 55 | } |
michael@0 | 56 | else { |
michael@0 | 57 | let desc = frame.callee.getOwnPropertyDescriptor("displayName"); |
michael@0 | 58 | if (desc && desc.value && typeof desc.value == "string") { |
michael@0 | 59 | name = desc.value; |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | let args = frame.arguments.map(this.valueToString).join(", "); |
michael@0 | 64 | return name + "(" + args + ")"; |
michael@0 | 65 | }, |
michael@0 | 66 | |
michael@0 | 67 | valueToString: function(value) { |
michael@0 | 68 | if (typeof value !== "object" || value === null) { |
michael@0 | 69 | return uneval(value); |
michael@0 | 70 | } |
michael@0 | 71 | return "[object " + value.class + "]"; |
michael@0 | 72 | } |
michael@0 | 73 | }, |
michael@0 | 74 | { |
michael@0 | 75 | name: "calllog stop", |
michael@0 | 76 | description: gcli.lookup("calllogStopDesc"), |
michael@0 | 77 | |
michael@0 | 78 | exec: function(args, context) { |
michael@0 | 79 | let numDebuggers = debuggers.length; |
michael@0 | 80 | if (numDebuggers == 0) { |
michael@0 | 81 | return gcli.lookup("calllogStopNoLogging"); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | for (let dbg of debuggers) { |
michael@0 | 85 | dbg.onEnterFrame = undefined; |
michael@0 | 86 | } |
michael@0 | 87 | debuggers = []; |
michael@0 | 88 | |
michael@0 | 89 | return gcli.lookupFormat("calllogStopReply", [ numDebuggers ]); |
michael@0 | 90 | } |
michael@0 | 91 | }, |
michael@0 | 92 | { |
michael@0 | 93 | name: "calllog chromestart", |
michael@0 | 94 | description: gcli.lookup("calllogChromeStartDesc"), |
michael@0 | 95 | get hidden() gcli.hiddenByChromePref(), |
michael@0 | 96 | params: [ |
michael@0 | 97 | { |
michael@0 | 98 | name: "sourceType", |
michael@0 | 99 | type: { |
michael@0 | 100 | name: "selection", |
michael@0 | 101 | data: ["content-variable", "chrome-variable", "jsm", "javascript"] |
michael@0 | 102 | } |
michael@0 | 103 | }, |
michael@0 | 104 | { |
michael@0 | 105 | name: "source", |
michael@0 | 106 | type: "string", |
michael@0 | 107 | description: gcli.lookup("calllogChromeSourceTypeDesc"), |
michael@0 | 108 | manual: gcli.lookup("calllogChromeSourceTypeManual"), |
michael@0 | 109 | } |
michael@0 | 110 | ], |
michael@0 | 111 | exec: function(args, context) { |
michael@0 | 112 | let globalObj; |
michael@0 | 113 | let contentWindow = context.environment.window; |
michael@0 | 114 | |
michael@0 | 115 | if (args.sourceType == "jsm") { |
michael@0 | 116 | try { |
michael@0 | 117 | globalObj = Cu.import(args.source); |
michael@0 | 118 | } |
michael@0 | 119 | catch (e) { |
michael@0 | 120 | return gcli.lookup("callLogChromeInvalidJSM"); |
michael@0 | 121 | } |
michael@0 | 122 | } else if (args.sourceType == "content-variable") { |
michael@0 | 123 | if (args.source in contentWindow) { |
michael@0 | 124 | globalObj = Cu.getGlobalForObject(contentWindow[args.source]); |
michael@0 | 125 | } else { |
michael@0 | 126 | throw new Error(gcli.lookup("callLogChromeVarNotFoundContent")); |
michael@0 | 127 | } |
michael@0 | 128 | } else if (args.sourceType == "chrome-variable") { |
michael@0 | 129 | let chromeWin = context.environment.chromeDocument.defaultView; |
michael@0 | 130 | if (args.source in chromeWin) { |
michael@0 | 131 | globalObj = Cu.getGlobalForObject(chromeWin[args.source]); |
michael@0 | 132 | } else { |
michael@0 | 133 | return gcli.lookup("callLogChromeVarNotFoundChrome"); |
michael@0 | 134 | } |
michael@0 | 135 | } else { |
michael@0 | 136 | let chromeWin = context.environment.chromeDocument.defaultView; |
michael@0 | 137 | let sandbox = new Cu.Sandbox(chromeWin, |
michael@0 | 138 | { |
michael@0 | 139 | sandboxPrototype: chromeWin, |
michael@0 | 140 | wantXrays: false, |
michael@0 | 141 | sandboxName: "gcli-cmd-calllog-chrome" |
michael@0 | 142 | }); |
michael@0 | 143 | let returnVal; |
michael@0 | 144 | try { |
michael@0 | 145 | returnVal = Cu.evalInSandbox(args.source, sandbox, "ECMAv5"); |
michael@0 | 146 | sandboxes.push(sandbox); |
michael@0 | 147 | } catch(e) { |
michael@0 | 148 | // We need to save the message before cleaning up else e contains a dead |
michael@0 | 149 | // object. |
michael@0 | 150 | let msg = gcli.lookup("callLogChromeEvalException") + ": " + e; |
michael@0 | 151 | Cu.nukeSandbox(sandbox); |
michael@0 | 152 | return msg; |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | if (typeof returnVal == "undefined") { |
michael@0 | 156 | return gcli.lookup("callLogChromeEvalNeedsObject"); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | globalObj = Cu.getGlobalForObject(returnVal); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | let dbg = new Debugger(globalObj); |
michael@0 | 163 | chromeDebuggers.push(dbg); |
michael@0 | 164 | |
michael@0 | 165 | dbg.onEnterFrame = function(frame) { |
michael@0 | 166 | // BUG 773652 - Make the output from the GCLI calllog command nicer |
michael@0 | 167 | contentWindow.console.log(gcli.lookup("callLogChromeMethodCall") + |
michael@0 | 168 | ": " + this.callDescription(frame)); |
michael@0 | 169 | }.bind(this); |
michael@0 | 170 | |
michael@0 | 171 | let gBrowser = context.environment.chromeDocument.defaultView.gBrowser; |
michael@0 | 172 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 173 | gDevTools.showToolbox(target, "webconsole"); |
michael@0 | 174 | |
michael@0 | 175 | return gcli.lookup("calllogChromeStartReply"); |
michael@0 | 176 | }, |
michael@0 | 177 | |
michael@0 | 178 | valueToString: function(value) { |
michael@0 | 179 | if (typeof value !== "object" || value === null) |
michael@0 | 180 | return uneval(value); |
michael@0 | 181 | return "[object " + value.class + "]"; |
michael@0 | 182 | }, |
michael@0 | 183 | |
michael@0 | 184 | callDescription: function(frame) { |
michael@0 | 185 | let name = frame.callee.name || gcli.lookup("callLogChromeAnonFunction"); |
michael@0 | 186 | let args = frame.arguments.map(this.valueToString).join(", "); |
michael@0 | 187 | return name + "(" + args + ")"; |
michael@0 | 188 | } |
michael@0 | 189 | }, |
michael@0 | 190 | { |
michael@0 | 191 | name: "calllog chromestop", |
michael@0 | 192 | description: gcli.lookup("calllogChromeStopDesc"), |
michael@0 | 193 | get hidden() gcli.hiddenByChromePref(), |
michael@0 | 194 | exec: function(args, context) { |
michael@0 | 195 | let numDebuggers = chromeDebuggers.length; |
michael@0 | 196 | if (numDebuggers == 0) { |
michael@0 | 197 | return gcli.lookup("calllogChromeStopNoLogging"); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | for (let dbg of chromeDebuggers) { |
michael@0 | 201 | dbg.onEnterFrame = undefined; |
michael@0 | 202 | dbg.enabled = false; |
michael@0 | 203 | } |
michael@0 | 204 | for (let sandbox of sandboxes) { |
michael@0 | 205 | Cu.nukeSandbox(sandbox); |
michael@0 | 206 | } |
michael@0 | 207 | chromeDebuggers = []; |
michael@0 | 208 | sandboxes = []; |
michael@0 | 209 | |
michael@0 | 210 | return gcli.lookupFormat("calllogChromeStopReply", [ numDebuggers ]); |
michael@0 | 211 | } |
michael@0 | 212 | } |
michael@0 | 213 | ]; |