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 | 'use strict'; |
michael@0 | 5 | |
michael@0 | 6 | const { contract } = require('../../util/contract'); |
michael@0 | 7 | const { isLocalURL } = require('../../url'); |
michael@0 | 8 | const { isNil, isObject, isString } = require('../../lang/type'); |
michael@0 | 9 | const { required, either, string, boolean, object } = require('../../deprecated/api-utils'); |
michael@0 | 10 | const { merge } = require('../../util/object'); |
michael@0 | 11 | const { freeze } = Object; |
michael@0 | 12 | |
michael@0 | 13 | function isIconSet(icons) { |
michael@0 | 14 | return Object.keys(icons). |
michael@0 | 15 | every(size => String(size >>> 0) === size && isLocalURL(icons[size])) |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | let iconSet = { |
michael@0 | 19 | is: either(object, string), |
michael@0 | 20 | map: v => isObject(v) ? freeze(merge({}, v)) : v, |
michael@0 | 21 | ok: v => (isString(v) && isLocalURL(v)) || (isObject(v) && isIconSet(v)), |
michael@0 | 22 | msg: 'The option "icon" must be a local URL or an object with ' + |
michael@0 | 23 | 'numeric keys / local URL values pair.' |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | let id = { |
michael@0 | 27 | is: string, |
michael@0 | 28 | ok: v => /^[a-z-_][a-z0-9-_]*$/i.test(v), |
michael@0 | 29 | msg: 'The option "id" must be a valid alphanumeric id (hyphens and ' + |
michael@0 | 30 | 'underscores are allowed).' |
michael@0 | 31 | }; |
michael@0 | 32 | |
michael@0 | 33 | let label = { |
michael@0 | 34 | is: string, |
michael@0 | 35 | ok: v => isNil(v) || v.trim().length > 0, |
michael@0 | 36 | msg: 'The option "label" must be a non empty string' |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | let stateContract = contract({ |
michael@0 | 40 | label: label, |
michael@0 | 41 | icon: iconSet, |
michael@0 | 42 | disabled: boolean |
michael@0 | 43 | }); |
michael@0 | 44 | |
michael@0 | 45 | exports.stateContract = stateContract; |
michael@0 | 46 | |
michael@0 | 47 | let buttonContract = contract(merge({}, stateContract.rules, { |
michael@0 | 48 | id: required(id), |
michael@0 | 49 | label: required(label), |
michael@0 | 50 | icon: required(iconSet) |
michael@0 | 51 | })); |
michael@0 | 52 | |
michael@0 | 53 | exports.buttonContract = buttonContract; |
michael@0 | 54 | |
michael@0 | 55 | exports.toggleStateContract = contract(merge({ |
michael@0 | 56 | checked: boolean |
michael@0 | 57 | }, stateContract.rules)); |
michael@0 | 58 | |
michael@0 | 59 | exports.toggleButtonContract = contract(merge({ |
michael@0 | 60 | checked: boolean |
michael@0 | 61 | }, buttonContract.rules)); |
michael@0 | 62 |