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: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * Date: 07 February 2001 |
michael@0 | 8 | * |
michael@0 | 9 | * Functionality common to Array testing - |
michael@0 | 10 | */ |
michael@0 | 11 | //----------------------------------------------------------------------------- |
michael@0 | 12 | |
michael@0 | 13 | |
michael@0 | 14 | var CHAR_LBRACKET = '['; |
michael@0 | 15 | var CHAR_RBRACKET = ']'; |
michael@0 | 16 | var CHAR_QT_DBL = '"'; |
michael@0 | 17 | var CHAR_QT = "'"; |
michael@0 | 18 | var CHAR_NL = '\n'; |
michael@0 | 19 | var CHAR_COMMA = ','; |
michael@0 | 20 | var CHAR_SPACE = ' '; |
michael@0 | 21 | var TYPE_STRING = typeof 'abc'; |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | /* |
michael@0 | 25 | * If available, arr.toSource() gives more detail than arr.toString() |
michael@0 | 26 | * |
michael@0 | 27 | * var arr = Array(1,2,'3'); |
michael@0 | 28 | * |
michael@0 | 29 | * arr.toSource() |
michael@0 | 30 | * [1, 2, "3"] |
michael@0 | 31 | * |
michael@0 | 32 | * arr.toString() |
michael@0 | 33 | * 1,2,3 |
michael@0 | 34 | * |
michael@0 | 35 | * But toSource() doesn't exist in Rhino, so use our own imitation, below - |
michael@0 | 36 | * |
michael@0 | 37 | */ |
michael@0 | 38 | function formatArray(arr) |
michael@0 | 39 | { |
michael@0 | 40 | try |
michael@0 | 41 | { |
michael@0 | 42 | return arr.toSource(); |
michael@0 | 43 | } |
michael@0 | 44 | catch(e) |
michael@0 | 45 | { |
michael@0 | 46 | return toSource(arr); |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | |
michael@0 | 51 | |
michael@0 | 52 | /* |
michael@0 | 53 | * Imitate SpiderMonkey's arr.toSource() method: |
michael@0 | 54 | * |
michael@0 | 55 | * a) Double-quote each array element that is of string type |
michael@0 | 56 | * b) Represent |undefined| and |null| by empty strings |
michael@0 | 57 | * c) Delimit elements by a comma + single space |
michael@0 | 58 | * d) Do not add delimiter at the end UNLESS the last element is |undefined| |
michael@0 | 59 | * e) Add square brackets to the beginning and end of the string |
michael@0 | 60 | */ |
michael@0 | 61 | function toSource(arr) |
michael@0 | 62 | { |
michael@0 | 63 | var delim = CHAR_COMMA + CHAR_SPACE; |
michael@0 | 64 | var elt = ''; |
michael@0 | 65 | var ret = ''; |
michael@0 | 66 | var len = arr.length; |
michael@0 | 67 | |
michael@0 | 68 | for (i=0; i<len; i++) |
michael@0 | 69 | { |
michael@0 | 70 | elt = arr[i]; |
michael@0 | 71 | |
michael@0 | 72 | switch(true) |
michael@0 | 73 | { |
michael@0 | 74 | case (typeof elt === TYPE_STRING) : |
michael@0 | 75 | ret += doubleQuote(elt); |
michael@0 | 76 | break; |
michael@0 | 77 | |
michael@0 | 78 | case (elt === undefined || elt === null) : |
michael@0 | 79 | break; // add nothing but the delimiter, below - |
michael@0 | 80 | |
michael@0 | 81 | default: |
michael@0 | 82 | ret += elt.toString(); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | if ((i < len-1) || (elt === undefined)) |
michael@0 | 86 | ret += delim; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | return CHAR_LBRACKET + ret + CHAR_RBRACKET; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | |
michael@0 | 93 | function doubleQuote(text) |
michael@0 | 94 | { |
michael@0 | 95 | return CHAR_QT_DBL + text + CHAR_QT_DBL; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | |
michael@0 | 99 | function singleQuote(text) |
michael@0 | 100 | { |
michael@0 | 101 | return CHAR_QT + text + CHAR_QT; |
michael@0 | 102 | } |
michael@0 | 103 |