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 ts=2 sw=2 sts=2 et: */ |
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 | const I = Components.interfaces; |
michael@0 | 8 | const C = Components.classes; |
michael@0 | 9 | |
michael@0 | 10 | const nsILocalFile = I.nsILocalFile; |
michael@0 | 11 | const nsIProperties = I.nsIProperties; |
michael@0 | 12 | const nsIFileInputStream = I.nsIFileInputStream; |
michael@0 | 13 | const nsIInputStream = I.nsIInputStream; |
michael@0 | 14 | |
michael@0 | 15 | const nsIDOMParser = I.nsIDOMParser; |
michael@0 | 16 | const nsIDOMSerializer = I.nsIDOMSerializer; |
michael@0 | 17 | const nsIDOMDocument = I.nsIDOMDocument; |
michael@0 | 18 | const nsIDOMElement = I.nsIDOMElement; |
michael@0 | 19 | const nsIDOMNode = I.nsIDOMNode; |
michael@0 | 20 | const nsIDOMCharacterData = I.nsIDOMCharacterData; |
michael@0 | 21 | const nsIDOMAttr = I.nsIDOMAttr; |
michael@0 | 22 | const nsIDOMNodeList = I.nsIDOMNodeList; |
michael@0 | 23 | const nsIDOMXULElement = I.nsIDOMXULElement; |
michael@0 | 24 | const nsIDOMProcessingInstruction = I.nsIDOMProcessingInstruction; |
michael@0 | 25 | |
michael@0 | 26 | function DOMParser() { |
michael@0 | 27 | var parser = C["@mozilla.org/xmlextras/domparser;1"].createInstance(nsIDOMParser); |
michael@0 | 28 | parser.init(); |
michael@0 | 29 | return parser; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | var __testsDirectory = null; |
michael@0 | 33 | |
michael@0 | 34 | function ParseFile(file) { |
michael@0 | 35 | if (typeof(file) == "string") { |
michael@0 | 36 | if (!__testsDirectory) { |
michael@0 | 37 | __testsDirectory = do_get_cwd(); |
michael@0 | 38 | } |
michael@0 | 39 | var fileObj = __testsDirectory.clone(); |
michael@0 | 40 | fileObj.append(file); |
michael@0 | 41 | file = fileObj; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | do_check_eq(file instanceof nsILocalFile, true); |
michael@0 | 45 | |
michael@0 | 46 | var fileStr = C["@mozilla.org/network/file-input-stream;1"] |
michael@0 | 47 | .createInstance(nsIFileInputStream); |
michael@0 | 48 | // Init for readonly reading |
michael@0 | 49 | fileStr.init(file, 0x01, 0400, nsIFileInputStream.CLOSE_ON_EOF); |
michael@0 | 50 | return ParseXML(fileStr); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | function ParseXML(data) { |
michael@0 | 54 | if (typeof(data) == "string") { |
michael@0 | 55 | return DOMParser().parseFromString(data, "application/xml"); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | do_check_eq(data instanceof nsIInputStream, true); |
michael@0 | 59 | |
michael@0 | 60 | return DOMParser().parseFromStream(data, "UTF-8", data.available(), |
michael@0 | 61 | "application/xml"); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function DOMSerializer() { |
michael@0 | 65 | return C["@mozilla.org/xmlextras/xmlserializer;1"] |
michael@0 | 66 | .createInstance(nsIDOMSerializer); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function SerializeXML(node) { |
michael@0 | 70 | return DOMSerializer().serializeToString(node); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | function roundtrip(obj) { |
michael@0 | 74 | if (typeof(obj) == "string") { |
michael@0 | 75 | return SerializeXML(ParseXML(obj)); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | do_check_eq(obj instanceof nsIDOMNode, true); |
michael@0 | 79 | return ParseXML(SerializeXML(obj)); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | function do_compare_attrs(e1, e2) { |
michael@0 | 83 | const xmlns = "http://www.w3.org/2000/xmlns/"; |
michael@0 | 84 | |
michael@0 | 85 | var a1 = e1.attributes; |
michael@0 | 86 | var a2 = e2.attributes; |
michael@0 | 87 | for (var i = 0; i < a1.length; ++i) { |
michael@0 | 88 | var att = a1.item(i); |
michael@0 | 89 | // Don't test for namespace decls, since those can just sorta be |
michael@0 | 90 | // scattered about |
michael@0 | 91 | if (att.namespaceURI != xmlns) { |
michael@0 | 92 | var att2 = a2.getNamedItemNS(att.namespaceURI, att.localName); |
michael@0 | 93 | if (!att2) { |
michael@0 | 94 | do_throw("Missing attribute with namespaceURI '" + att.namespaceURI + |
michael@0 | 95 | "' and localName '" + att.localName + "'"); |
michael@0 | 96 | } |
michael@0 | 97 | do_check_eq(att.QueryInterface(nsIDOMAttr).value, |
michael@0 | 98 | att2.QueryInterface(nsIDOMAttr).value); |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | function do_check_equiv(dom1, dom2) { |
michael@0 | 104 | do_check_eq(dom1.nodeType, dom2.nodeType); |
michael@0 | 105 | // There's no classinfo around, so we'll need to do some QIing to |
michael@0 | 106 | // make sure the right interfaces are flattened as needed. |
michael@0 | 107 | switch (dom1.nodeType) { |
michael@0 | 108 | case nsIDOMNode.PROCESSING_INSTRUCTION_NODE: |
michael@0 | 109 | do_check_eq(dom1.QueryInterface(nsIDOMProcessingInstruction).target, |
michael@0 | 110 | dom2.QueryInterface(nsIDOMProcessingInstruction).target); |
michael@0 | 111 | do_check_eq(dom1.data, dom2.data); |
michael@0 | 112 | case nsIDOMNode.TEXT_NODE: |
michael@0 | 113 | case nsIDOMNode.CDATA_SECTION_NODE: |
michael@0 | 114 | case nsIDOMNode.COMMENT_NODE: |
michael@0 | 115 | do_check_eq(dom1.QueryInterface(nsIDOMCharacterData).data, |
michael@0 | 116 | dom2.QueryInterface(nsIDOMCharacterData).data); |
michael@0 | 117 | break; |
michael@0 | 118 | case nsIDOMNode.ELEMENT_NODE: |
michael@0 | 119 | do_check_eq(dom1.namespaceURI, dom2.namespaceURI); |
michael@0 | 120 | do_check_eq(dom1.localName, dom2.localName); |
michael@0 | 121 | // Compare attrs in both directions -- do_compare_attrs does a |
michael@0 | 122 | // subset check. |
michael@0 | 123 | do_compare_attrs(dom1, dom2); |
michael@0 | 124 | do_compare_attrs(dom2, dom1); |
michael@0 | 125 | // Fall through |
michael@0 | 126 | case nsIDOMNode.DOCUMENT_NODE: |
michael@0 | 127 | do_check_eq(dom1.childNodes.length, dom2.childNodes.length); |
michael@0 | 128 | for (var i = 0; i < dom1.childNodes.length; ++i) { |
michael@0 | 129 | do_check_equiv(dom1.childNodes.item(i), dom2.childNodes.item(i)); |
michael@0 | 130 | } |
michael@0 | 131 | break; |
michael@0 | 132 | } |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | function do_check_serialize(dom) { |
michael@0 | 136 | do_check_equiv(dom, roundtrip(dom)); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | function Pipe() { |
michael@0 | 140 | var p = C["@mozilla.org/pipe;1"].createInstance(I.nsIPipe); |
michael@0 | 141 | p.init(false, false, 0, 0xffffffff, null); |
michael@0 | 142 | return p; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | function ScriptableInput(arg) { |
michael@0 | 146 | if (arg instanceof I.nsIPipe) { |
michael@0 | 147 | arg = arg.inputStream; |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | var str = C["@mozilla.org/scriptableinputstream;1"]. |
michael@0 | 151 | createInstance(I.nsIScriptableInputStream); |
michael@0 | 152 | |
michael@0 | 153 | str.init(arg); |
michael@0 | 154 | |
michael@0 | 155 | return str; |
michael@0 | 156 | } |