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 | /* -*- tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ |
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 | "use strict"; |
michael@0 | 8 | |
michael@0 | 9 | /** |
michael@0 | 10 | * Methods shared between RootActor and BrowserTabActor. |
michael@0 | 11 | */ |
michael@0 | 12 | |
michael@0 | 13 | /** |
michael@0 | 14 | * Populate |this._extraActors| as specified by |aFactories|, reusing whatever |
michael@0 | 15 | * actors are already there. Add all actors in the final extra actors table to |
michael@0 | 16 | * |aPool|. |
michael@0 | 17 | * |
michael@0 | 18 | * The root actor and the tab actor use this to instantiate actors that other |
michael@0 | 19 | * parts of the browser have specified with DebuggerServer.addTabActor antd |
michael@0 | 20 | * DebuggerServer.addGlobalActor. |
michael@0 | 21 | * |
michael@0 | 22 | * @param aFactories |
michael@0 | 23 | * An object whose own property names are the names of properties to add to |
michael@0 | 24 | * some reply packet (say, a tab actor grip or the "listTabs" response |
michael@0 | 25 | * form), and whose own property values are actor constructor functions, as |
michael@0 | 26 | * documented for addTabActor and addGlobalActor. |
michael@0 | 27 | * |
michael@0 | 28 | * @param this |
michael@0 | 29 | * The BrowserRootActor or BrowserTabActor with which the new actors will |
michael@0 | 30 | * be associated. It should support whatever API the |aFactories| |
michael@0 | 31 | * constructor functions might be interested in, as it is passed to them. |
michael@0 | 32 | * For the sake of CommonCreateExtraActors itself, it should have at least |
michael@0 | 33 | * the following properties: |
michael@0 | 34 | * |
michael@0 | 35 | * - _extraActors |
michael@0 | 36 | * An object whose own property names are factory table (and packet) |
michael@0 | 37 | * property names, and whose values are no-argument actor constructors, |
michael@0 | 38 | * of the sort that one can add to an ActorPool. |
michael@0 | 39 | * |
michael@0 | 40 | * - conn |
michael@0 | 41 | * The DebuggerServerConnection in which the new actors will participate. |
michael@0 | 42 | * |
michael@0 | 43 | * - actorID |
michael@0 | 44 | * The actor's name, for use as the new actors' parentID. |
michael@0 | 45 | */ |
michael@0 | 46 | exports.createExtraActors = function createExtraActors(aFactories, aPool) { |
michael@0 | 47 | // Walk over global actors added by extensions. |
michael@0 | 48 | for (let name in aFactories) { |
michael@0 | 49 | let actor = this._extraActors[name]; |
michael@0 | 50 | if (!actor) { |
michael@0 | 51 | actor = aFactories[name].bind(null, this.conn, this); |
michael@0 | 52 | actor.prototype = aFactories[name].prototype; |
michael@0 | 53 | actor.parentID = this.actorID; |
michael@0 | 54 | this._extraActors[name] = actor; |
michael@0 | 55 | } |
michael@0 | 56 | aPool.addActor(actor); |
michael@0 | 57 | } |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | /** |
michael@0 | 61 | * Append the extra actors in |this._extraActors|, constructed by a prior call |
michael@0 | 62 | * to CommonCreateExtraActors, to |aObject|. |
michael@0 | 63 | * |
michael@0 | 64 | * @param aObject |
michael@0 | 65 | * The object to which the extra actors should be added, under the |
michael@0 | 66 | * property names given in the |aFactories| table passed to |
michael@0 | 67 | * CommonCreateExtraActors. |
michael@0 | 68 | * |
michael@0 | 69 | * @param this |
michael@0 | 70 | * The BrowserRootActor or BrowserTabActor whose |_extraActors| table we |
michael@0 | 71 | * should use; see above. |
michael@0 | 72 | */ |
michael@0 | 73 | exports.appendExtraActors = function appendExtraActors(aObject) { |
michael@0 | 74 | for (let name in this._extraActors) { |
michael@0 | 75 | let actor = this._extraActors[name]; |
michael@0 | 76 | aObject[name] = actor.actorID; |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * Construct an ActorPool. |
michael@0 | 82 | * |
michael@0 | 83 | * ActorPools are actorID -> actor mapping and storage. These are |
michael@0 | 84 | * used to accumulate and quickly dispose of groups of actors that |
michael@0 | 85 | * share a lifetime. |
michael@0 | 86 | */ |
michael@0 | 87 | function ActorPool(aConnection) |
michael@0 | 88 | { |
michael@0 | 89 | this.conn = aConnection; |
michael@0 | 90 | this._cleanups = {}; |
michael@0 | 91 | this._actors = {}; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | ActorPool.prototype = { |
michael@0 | 95 | /** |
michael@0 | 96 | * Add an actor to the actor pool. If the actor doesn't have an ID, |
michael@0 | 97 | * allocate one from the connection. |
michael@0 | 98 | * |
michael@0 | 99 | * @param aActor object |
michael@0 | 100 | * The actor implementation. If the object has a |
michael@0 | 101 | * 'disconnect' property, it will be called when the actor |
michael@0 | 102 | * pool is cleaned up. |
michael@0 | 103 | */ |
michael@0 | 104 | addActor: function AP_addActor(aActor) { |
michael@0 | 105 | aActor.conn = this.conn; |
michael@0 | 106 | if (!aActor.actorID) { |
michael@0 | 107 | let prefix = aActor.actorPrefix; |
michael@0 | 108 | if (typeof aActor == "function") { |
michael@0 | 109 | // typeName is a convention used with protocol.js-based actors |
michael@0 | 110 | prefix = aActor.prototype.actorPrefix || aActor.prototype.typeName; |
michael@0 | 111 | } |
michael@0 | 112 | aActor.actorID = this.conn.allocID(prefix || undefined); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | if (aActor.registeredPool) { |
michael@0 | 116 | aActor.registeredPool.removeActor(aActor); |
michael@0 | 117 | } |
michael@0 | 118 | aActor.registeredPool = this; |
michael@0 | 119 | |
michael@0 | 120 | this._actors[aActor.actorID] = aActor; |
michael@0 | 121 | if (aActor.disconnect) { |
michael@0 | 122 | this._cleanups[aActor.actorID] = aActor; |
michael@0 | 123 | } |
michael@0 | 124 | }, |
michael@0 | 125 | |
michael@0 | 126 | get: function AP_get(aActorID) { |
michael@0 | 127 | return this._actors[aActorID]; |
michael@0 | 128 | }, |
michael@0 | 129 | |
michael@0 | 130 | has: function AP_has(aActorID) { |
michael@0 | 131 | return aActorID in this._actors; |
michael@0 | 132 | }, |
michael@0 | 133 | |
michael@0 | 134 | /** |
michael@0 | 135 | * Returns true if the pool is empty. |
michael@0 | 136 | */ |
michael@0 | 137 | isEmpty: function AP_isEmpty() { |
michael@0 | 138 | return Object.keys(this._actors).length == 0; |
michael@0 | 139 | }, |
michael@0 | 140 | |
michael@0 | 141 | /** |
michael@0 | 142 | * Remove an actor from the actor pool. |
michael@0 | 143 | */ |
michael@0 | 144 | removeActor: function AP_remove(aActor) { |
michael@0 | 145 | delete this._actors[aActor.actorID]; |
michael@0 | 146 | delete this._cleanups[aActor.actorID]; |
michael@0 | 147 | }, |
michael@0 | 148 | |
michael@0 | 149 | /** |
michael@0 | 150 | * Match the api expected by the protocol library. |
michael@0 | 151 | */ |
michael@0 | 152 | unmanage: function(aActor) { |
michael@0 | 153 | return this.removeActor(aActor); |
michael@0 | 154 | }, |
michael@0 | 155 | |
michael@0 | 156 | /** |
michael@0 | 157 | * Run all actor cleanups. |
michael@0 | 158 | */ |
michael@0 | 159 | cleanup: function AP_cleanup() { |
michael@0 | 160 | for each (let actor in this._cleanups) { |
michael@0 | 161 | actor.disconnect(); |
michael@0 | 162 | } |
michael@0 | 163 | this._cleanups = {}; |
michael@0 | 164 | } |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | exports.ActorPool = ActorPool; |
michael@0 | 168 |