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: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ |
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 file, |
michael@0 | 5 | * 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 | const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
michael@0 | 10 | |
michael@0 | 11 | const CONNECTION_STATUS_DISCONNECTED = "disconnected"; |
michael@0 | 12 | const CONNECTION_STATUS_CONNECTING = "connecting"; |
michael@0 | 13 | const CONNECTION_STATUS_CONNECTED = "connected"; |
michael@0 | 14 | const CONNECTION_STATUS_DISCONNECTING = "disconnecting"; |
michael@0 | 15 | |
michael@0 | 16 | const DEBUG = false; |
michael@0 | 17 | |
michael@0 | 18 | this.EXPORTED_SYMBOLS = ["WifiP2pWorkerObserver"]; |
michael@0 | 19 | |
michael@0 | 20 | // WifiP2pWorkerObserver resides in WifiWorker to handle DOM message |
michael@0 | 21 | // by either 1) returning internally maintained information or |
michael@0 | 22 | // 2) delegating to aDomMsgResponder. It is also responsible |
michael@0 | 23 | // for observing events from WifiP2pManager and dispatch to DOM. |
michael@0 | 24 | // |
michael@0 | 25 | // @param aDomMsgResponder handles DOM messages, including |
michael@0 | 26 | // - setScanEnabled |
michael@0 | 27 | // - connect |
michael@0 | 28 | // - disconnect |
michael@0 | 29 | // - setPairingConfirmation |
michael@0 | 30 | // The instance is actually WifiP2pManager. |
michael@0 | 31 | this.WifiP2pWorkerObserver = function(aDomMsgResponder) { |
michael@0 | 32 | function debug(aMsg) { |
michael@0 | 33 | if (DEBUG) { |
michael@0 | 34 | dump('-------------- WifiP2pWorkerObserver: ' + aMsg); |
michael@0 | 35 | } |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | // Private member variables. |
michael@0 | 39 | let _localDevice; |
michael@0 | 40 | let _peerList = {}; // List of P2pDevice. |
michael@0 | 41 | let _domManagers = []; |
michael@0 | 42 | |
michael@0 | 43 | // Constructor of P2pDevice. It will be exposed to DOM. |
michael@0 | 44 | // |
michael@0 | 45 | // @param aPeer object representing a P2P device: |
michael@0 | 46 | // .name: string for the device name. |
michael@0 | 47 | // .address: Mac address. |
michael@0 | 48 | // .isGroupOwner: boolean to indicate if this device is the group owner. |
michael@0 | 49 | // .wpsCapabilities: array of string of {"pbc", "display", "keypad"}. |
michael@0 | 50 | function P2pDevice(aPeer) { |
michael@0 | 51 | this.address = aPeer.address; |
michael@0 | 52 | this.name = (aPeer.name ? aPeer.name : aPeer.address); |
michael@0 | 53 | this.isGroupOwner = aPeer.isGroupOwner; |
michael@0 | 54 | this.wpsCapabilities = aPeer.wpsCapabilities; |
michael@0 | 55 | this.connectionStatus = CONNECTION_STATUS_DISCONNECTED; |
michael@0 | 56 | |
michael@0 | 57 | // Since this object will be exposed to web, defined the exposed |
michael@0 | 58 | // properties here. |
michael@0 | 59 | this.__exposedProps__ = { |
michael@0 | 60 | address: "r", |
michael@0 | 61 | name: "r", |
michael@0 | 62 | isGroupOwner: "r", |
michael@0 | 63 | wpsCapabilities: "r", |
michael@0 | 64 | connectionStatus: "r" |
michael@0 | 65 | }; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | // Constructor of P2pGroupOwner. |
michael@0 | 69 | // |
michael@0 | 70 | // @param aGroupOwner: |
michael@0 | 71 | // .macAddress |
michael@0 | 72 | // .ipAddress |
michael@0 | 73 | // .passphrase |
michael@0 | 74 | // .ssid |
michael@0 | 75 | // .freq |
michael@0 | 76 | // .isLocal |
michael@0 | 77 | function P2pGroupOwner(aGroupOwner) { |
michael@0 | 78 | this.macAddress = aGroupOwner.macAddress; // The identifier to get further information. |
michael@0 | 79 | this.ipAddress = aGroupOwner.ipAddress; |
michael@0 | 80 | this.passphrase = aGroupOwner.passphrase; |
michael@0 | 81 | this.ssid = aGroupOwner.ssid; // e.g. DIRECT-xy. |
michael@0 | 82 | this.freq = aGroupOwner.freq; |
michael@0 | 83 | this.isLocal = aGroupOwner.isLocal; |
michael@0 | 84 | |
michael@0 | 85 | let detail = _peerList[aGroupOwner.macAddress]; |
michael@0 | 86 | if (detail) { |
michael@0 | 87 | this.name = detail.name; |
michael@0 | 88 | this.wpsCapabilities = detail.wpsCapabilities; |
michael@0 | 89 | } else if (_localDevice.address === this.macAddress) { |
michael@0 | 90 | this.name = _localDevice.name; |
michael@0 | 91 | this.wpsCapabilities = _localDevice.wpsCapabilities; |
michael@0 | 92 | } else { |
michael@0 | 93 | debug("We don't know this group owner: " + aGroupOwner.macAddress); |
michael@0 | 94 | this.name = aGroupOwner.macAddress; |
michael@0 | 95 | this.wpsCapabilities = []; |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function fireEvent(aMessage, aData) { |
michael@0 | 100 | debug('domManager: ' + JSON.stringify(_domManagers)); |
michael@0 | 101 | _domManagers.forEach(function(manager) { |
michael@0 | 102 | // Note: We should never have a dead message manager here because we |
michael@0 | 103 | // observe our child message managers shutting down below. |
michael@0 | 104 | manager.sendAsyncMessage("WifiP2pManager:" + aMessage, aData); |
michael@0 | 105 | }); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | function addDomManager(aMsg) { |
michael@0 | 109 | if (-1 === _domManagers.indexOf(aMsg.manager)) { |
michael@0 | 110 | _domManagers.push(aMsg.manager); |
michael@0 | 111 | } |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | function returnMessage(aMessage, aSuccess, aData, aMsg) { |
michael@0 | 115 | let rMsg = aMessage + ":Return:" + (aSuccess ? "OK" : "NO"); |
michael@0 | 116 | aMsg.manager.sendAsyncMessage(rMsg, |
michael@0 | 117 | { data: aData, rid: aMsg.rid, mid: aMsg.mid }); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | function handlePeerListUpdated() { |
michael@0 | 121 | fireEvent("onpeerinfoupdate", {}); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | // Return a literal object as the constructed object. |
michael@0 | 125 | return { |
michael@0 | 126 | onLocalDeviceChanged: function(aDevice) { |
michael@0 | 127 | _localDevice = aDevice; |
michael@0 | 128 | debug('Local device updated to: ' + JSON.stringify(_localDevice)); |
michael@0 | 129 | }, |
michael@0 | 130 | |
michael@0 | 131 | onEnabled: function() { |
michael@0 | 132 | _peerList = []; |
michael@0 | 133 | fireEvent("p2pUp", {}); |
michael@0 | 134 | }, |
michael@0 | 135 | |
michael@0 | 136 | onDisbaled: function() { |
michael@0 | 137 | fireEvent("p2pDown", {}); |
michael@0 | 138 | }, |
michael@0 | 139 | |
michael@0 | 140 | onPeerFound: function(aPeer) { |
michael@0 | 141 | let newFoundPeer = new P2pDevice(aPeer); |
michael@0 | 142 | let origianlPeer = _peerList[aPeer.address]; |
michael@0 | 143 | _peerList[aPeer.address] = newFoundPeer; |
michael@0 | 144 | if (origianlPeer) { |
michael@0 | 145 | newFoundPeer.connectionStatus = origianlPeer.connectionStatus; |
michael@0 | 146 | } |
michael@0 | 147 | handlePeerListUpdated(); |
michael@0 | 148 | }, |
michael@0 | 149 | |
michael@0 | 150 | onPeerLost: function(aPeer) { |
michael@0 | 151 | let lostPeer = _peerList[aPeer.address]; |
michael@0 | 152 | if (!lostPeer) { |
michael@0 | 153 | debug('Unknown peer lost: ' + aPeer.address); |
michael@0 | 154 | return; |
michael@0 | 155 | } |
michael@0 | 156 | delete _peerList[aPeer.address]; |
michael@0 | 157 | handlePeerListUpdated(); |
michael@0 | 158 | }, |
michael@0 | 159 | |
michael@0 | 160 | onConnecting: function(aPeer) { |
michael@0 | 161 | let peer = _peerList[aPeer.address]; |
michael@0 | 162 | if (!peer) { |
michael@0 | 163 | debug('Unknown peer connecting: ' + aPeer.address); |
michael@0 | 164 | peer = new P2pDevice(aPeer); |
michael@0 | 165 | _peerList[aPeer.address] = peer; |
michael@0 | 166 | handlePeerListUpdated(); |
michael@0 | 167 | } |
michael@0 | 168 | peer.connectionStatus = CONNECTION_STATUS_CONNECTING; |
michael@0 | 169 | |
michael@0 | 170 | fireEvent('onconnecting', { peer: peer }); |
michael@0 | 171 | }, |
michael@0 | 172 | |
michael@0 | 173 | onConnected: function(aGroupOwner, aPeer) { |
michael@0 | 174 | let go = new P2pGroupOwner(aGroupOwner); |
michael@0 | 175 | let peer = _peerList[aPeer.address]; |
michael@0 | 176 | if (!peer) { |
michael@0 | 177 | debug('Unknown peer connected: ' + aPeer.address); |
michael@0 | 178 | peer = new P2pDevice(aPeer); |
michael@0 | 179 | _peerList[aPeer.address] = peer; |
michael@0 | 180 | handlePeerListUpdated(); |
michael@0 | 181 | } |
michael@0 | 182 | peer.connectionStatus = CONNECTION_STATUS_CONNECTED; |
michael@0 | 183 | peer.isGroupOwner = (aPeer.address === aGroupOwner.address); |
michael@0 | 184 | |
michael@0 | 185 | fireEvent('onconnected', { groupOwner: go, peer: peer }); |
michael@0 | 186 | }, |
michael@0 | 187 | |
michael@0 | 188 | onDisconnected: function(aPeer) { |
michael@0 | 189 | let peer = _peerList[aPeer.address]; |
michael@0 | 190 | if (!peer) { |
michael@0 | 191 | debug('Unknown peer disconnected: ' + aPeer.address); |
michael@0 | 192 | return; |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | peer.connectionStatus = CONNECTION_STATUS_DISCONNECTED; |
michael@0 | 196 | fireEvent('ondisconnected', { peer: peer }); |
michael@0 | 197 | }, |
michael@0 | 198 | |
michael@0 | 199 | getObservedDOMMessages: function() { |
michael@0 | 200 | return [ |
michael@0 | 201 | "WifiP2pManager:getState", |
michael@0 | 202 | "WifiP2pManager:getPeerList", |
michael@0 | 203 | "WifiP2pManager:setScanEnabled", |
michael@0 | 204 | "WifiP2pManager:connect", |
michael@0 | 205 | "WifiP2pManager:disconnect", |
michael@0 | 206 | "WifiP2pManager:setPairingConfirmation", |
michael@0 | 207 | "WifiP2pManager:setDeviceName" |
michael@0 | 208 | ]; |
michael@0 | 209 | }, |
michael@0 | 210 | |
michael@0 | 211 | onDOMMessage: function(aMessage) { |
michael@0 | 212 | let msg = aMessage.data || {}; |
michael@0 | 213 | msg.manager = aMessage.target; |
michael@0 | 214 | |
michael@0 | 215 | if ("child-process-shutdown" === aMessage.name) { |
michael@0 | 216 | let i; |
michael@0 | 217 | if (-1 !== (i = _domManagers.indexOf(msg.manager))) { |
michael@0 | 218 | _domManagers.splice(i, 1); |
michael@0 | 219 | } |
michael@0 | 220 | return; |
michael@0 | 221 | } |
michael@0 | 222 | |
michael@0 | 223 | if (!aMessage.target.assertPermission("wifi-manage")) { |
michael@0 | 224 | return; |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | switch (aMessage.name) { |
michael@0 | 228 | case "WifiP2pManager:getState": // A new DOM manager is created. |
michael@0 | 229 | addDomManager(msg); |
michael@0 | 230 | return { peerList: _peerList, }; // Synchronous call. Simply return it. |
michael@0 | 231 | |
michael@0 | 232 | case "WifiP2pManager:setScanEnabled": |
michael@0 | 233 | { |
michael@0 | 234 | let enabled = msg.data; |
michael@0 | 235 | |
michael@0 | 236 | aDomMsgResponder.setScanEnabled(enabled, function(success) { |
michael@0 | 237 | returnMessage(aMessage.name, success, (success ? true : "ERROR"), msg); |
michael@0 | 238 | }); |
michael@0 | 239 | } |
michael@0 | 240 | break; |
michael@0 | 241 | |
michael@0 | 242 | case "WifiP2pManager:getPeerList": |
michael@0 | 243 | { |
michael@0 | 244 | // Convert the object to an array. |
michael@0 | 245 | let peerArray = []; |
michael@0 | 246 | for (let key in _peerList) { |
michael@0 | 247 | if (_peerList.hasOwnProperty(key)) { |
michael@0 | 248 | peerArray.push(_peerList[key]); |
michael@0 | 249 | } |
michael@0 | 250 | } |
michael@0 | 251 | |
michael@0 | 252 | returnMessage(aMessage.name, true, peerArray, msg); |
michael@0 | 253 | } |
michael@0 | 254 | break; |
michael@0 | 255 | |
michael@0 | 256 | case "WifiP2pManager:connect": |
michael@0 | 257 | { |
michael@0 | 258 | let peer = msg.data; |
michael@0 | 259 | |
michael@0 | 260 | let onDoConnect = function(success) { |
michael@0 | 261 | returnMessage(aMessage.name, success, (success ? true : "ERROR"), msg); |
michael@0 | 262 | }; |
michael@0 | 263 | |
michael@0 | 264 | aDomMsgResponder.connect(peer.address, peer.wpsMethod, |
michael@0 | 265 | peer.goIntent, onDoConnect); |
michael@0 | 266 | } |
michael@0 | 267 | break; |
michael@0 | 268 | |
michael@0 | 269 | case "WifiP2pManager:disconnect": |
michael@0 | 270 | { |
michael@0 | 271 | let address = msg.data; |
michael@0 | 272 | |
michael@0 | 273 | aDomMsgResponder.disconnect(address, function(success) { |
michael@0 | 274 | returnMessage(aMessage.name, success, (success ? true : "ERROR"), msg); |
michael@0 | 275 | }); |
michael@0 | 276 | } |
michael@0 | 277 | break; |
michael@0 | 278 | |
michael@0 | 279 | case "WifiP2pManager:setPairingConfirmation": |
michael@0 | 280 | { |
michael@0 | 281 | let result = msg.data; |
michael@0 | 282 | aDomMsgResponder.setPairingConfirmation(result); |
michael@0 | 283 | returnMessage(aMessage.name, true, true, msg); |
michael@0 | 284 | } |
michael@0 | 285 | break; |
michael@0 | 286 | |
michael@0 | 287 | case "WifiP2pManager:setDeviceName": |
michael@0 | 288 | { |
michael@0 | 289 | let newDeviceName = msg.data; |
michael@0 | 290 | aDomMsgResponder.setDeviceName(newDeviceName, function(success) { |
michael@0 | 291 | returnMessage(aMessage.name, success, (success ? true : "ERROR"), msg); |
michael@0 | 292 | }); |
michael@0 | 293 | } |
michael@0 | 294 | break; |
michael@0 | 295 | |
michael@0 | 296 | default: |
michael@0 | 297 | if (0 === aMessage.name.indexOf("WifiP2pManager:")) { |
michael@0 | 298 | debug("DOM WifiP2pManager message not handled: " + aMessage.name); |
michael@0 | 299 | } |
michael@0 | 300 | } // End of switch. |
michael@0 | 301 | } |
michael@0 | 302 | }; |
michael@0 | 303 | }; |