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 | // Code that is shared between clients and workers. |
michael@0 | 6 | this.EXPORTED_SYMBOLS = ["AbstractPort"]; |
michael@0 | 7 | |
michael@0 | 8 | this.AbstractPort = function AbstractPort(portid) { |
michael@0 | 9 | this._portid = portid; |
michael@0 | 10 | this._handler = undefined; |
michael@0 | 11 | this._closed = false; |
michael@0 | 12 | // pending messages sent to this port before it has a message handler. |
michael@0 | 13 | this._pendingMessagesIncoming = []; |
michael@0 | 14 | }; |
michael@0 | 15 | |
michael@0 | 16 | AbstractPort.prototype = { |
michael@0 | 17 | _portType: null, // set by a subclass. |
michael@0 | 18 | // abstract methods to be overridden. |
michael@0 | 19 | _dopost: function fw_AbstractPort_dopost(data) { |
michael@0 | 20 | throw new Error("not implemented"); |
michael@0 | 21 | }, |
michael@0 | 22 | _onerror: function fw_AbstractPort_onerror(err) { |
michael@0 | 23 | throw new Error("not implemented"); |
michael@0 | 24 | }, |
michael@0 | 25 | |
michael@0 | 26 | // and concrete methods shared by client and workers. |
michael@0 | 27 | toString: function fw_AbstractPort_toString() { |
michael@0 | 28 | return "MessagePort(portType='" + this._portType + "', portId=" |
michael@0 | 29 | + this._portid + (this._closed ? ", closed=true" : "") + ")"; |
michael@0 | 30 | }, |
michael@0 | 31 | _JSONParse: function fw_AbstractPort_JSONParse(data) JSON.parse(data), |
michael@0 | 32 | |
michael@0 | 33 | _postControlMessage: function fw_AbstractPort_postControlMessage(topic, data) { |
michael@0 | 34 | let postData = { |
michael@0 | 35 | portTopic: topic, |
michael@0 | 36 | portId: this._portid, |
michael@0 | 37 | portFromType: this._portType, |
michael@0 | 38 | data: data |
michael@0 | 39 | }; |
michael@0 | 40 | this._dopost(postData); |
michael@0 | 41 | }, |
michael@0 | 42 | |
michael@0 | 43 | _onmessage: function fw_AbstractPort_onmessage(data) { |
michael@0 | 44 | // See comments in postMessage below - we work around a cloning |
michael@0 | 45 | // issue by using JSON for these messages. |
michael@0 | 46 | // Further, we allow the workers to override exactly how the JSON parsing |
michael@0 | 47 | // is done - we try and do such parsing in the client window so things |
michael@0 | 48 | // like prototype overrides on Array work as expected. |
michael@0 | 49 | if (!this._handler) { |
michael@0 | 50 | this._pendingMessagesIncoming.push(data); |
michael@0 | 51 | } else { |
michael@0 | 52 | data = this._JSONParse(data); |
michael@0 | 53 | try { |
michael@0 | 54 | this._handler({ |
michael@0 | 55 | data: data, |
michael@0 | 56 | __exposedProps__: { |
michael@0 | 57 | data: 'r' |
michael@0 | 58 | } |
michael@0 | 59 | }); |
michael@0 | 60 | } catch (ex) { |
michael@0 | 61 | this._onerror(ex); |
michael@0 | 62 | } |
michael@0 | 63 | } |
michael@0 | 64 | }, |
michael@0 | 65 | |
michael@0 | 66 | set onmessage(handler) { // property setter for onmessage |
michael@0 | 67 | this._handler = handler; |
michael@0 | 68 | while (this._pendingMessagesIncoming.length) { |
michael@0 | 69 | this._onmessage(this._pendingMessagesIncoming.shift()); |
michael@0 | 70 | } |
michael@0 | 71 | }, |
michael@0 | 72 | get onmessage() { |
michael@0 | 73 | return this._handler; |
michael@0 | 74 | }, |
michael@0 | 75 | |
michael@0 | 76 | /** |
michael@0 | 77 | * postMessage |
michael@0 | 78 | * |
michael@0 | 79 | * Send data to the onmessage handler on the other end of the port. The |
michael@0 | 80 | * data object should have a topic property. |
michael@0 | 81 | * |
michael@0 | 82 | * @param {jsobj} data |
michael@0 | 83 | */ |
michael@0 | 84 | postMessage: function fw_AbstractPort_postMessage(data) { |
michael@0 | 85 | if (this._closed) { |
michael@0 | 86 | throw new Error("port is closed"); |
michael@0 | 87 | } |
michael@0 | 88 | // There seems to be an issue with passing objects directly and letting |
michael@0 | 89 | // the structured clone thing work - we sometimes get: |
michael@0 | 90 | // [Exception... "The object could not be cloned." code: "25" nsresult: "0x80530019 (DataCloneError)"] |
michael@0 | 91 | // The best guess is that this happens when funky things have been added to the prototypes. |
michael@0 | 92 | // It doesn't happen for our "control" messages, only in messages from |
michael@0 | 93 | // content - so we explicitly use JSON on these messages as that avoids |
michael@0 | 94 | // the problem. |
michael@0 | 95 | this._postControlMessage("port-message", JSON.stringify(data)); |
michael@0 | 96 | }, |
michael@0 | 97 | |
michael@0 | 98 | close: function fw_AbstractPort_close() { |
michael@0 | 99 | if (this._closed) { |
michael@0 | 100 | return; // already closed. |
michael@0 | 101 | } |
michael@0 | 102 | this._postControlMessage("port-close"); |
michael@0 | 103 | // and clean myself up. |
michael@0 | 104 | this._handler = null; |
michael@0 | 105 | this._pendingMessagesIncoming = []; |
michael@0 | 106 | this._closed = true; |
michael@0 | 107 | } |
michael@0 | 108 | }; |