addon-sdk/source/lib/sdk/ui/button/contract.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2 * License, v. 2.0. If a copy of the MPL was not distributed with this
     3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     4 'use strict';
     6 const { contract } = require('../../util/contract');
     7 const { isLocalURL } = require('../../url');
     8 const { isNil, isObject, isString } = require('../../lang/type');
     9 const { required, either, string, boolean, object } = require('../../deprecated/api-utils');
    10 const { merge } = require('../../util/object');
    11 const { freeze } = Object;
    13 function isIconSet(icons) {
    14   return Object.keys(icons).
    15     every(size => String(size >>> 0) === size && isLocalURL(icons[size]))
    16 }
    18 let iconSet = {
    19   is: either(object, string),
    20   map: v => isObject(v) ? freeze(merge({}, v)) : v,
    21   ok: v => (isString(v) && isLocalURL(v)) || (isObject(v) && isIconSet(v)),
    22   msg: 'The option "icon" must be a local URL or an object with ' +
    23     'numeric keys / local URL values pair.'
    24 }
    26 let id = {
    27   is: string,
    28   ok: v => /^[a-z-_][a-z0-9-_]*$/i.test(v),
    29   msg: 'The option "id" must be a valid alphanumeric id (hyphens and ' +
    30         'underscores are allowed).'
    31 };
    33 let label = {
    34   is: string,
    35   ok: v => isNil(v) || v.trim().length > 0,
    36   msg: 'The option "label" must be a non empty string'
    37 }
    39 let stateContract = contract({
    40   label: label,
    41   icon: iconSet,
    42   disabled: boolean
    43 });
    45 exports.stateContract = stateContract;
    47 let buttonContract = contract(merge({}, stateContract.rules, {
    48   id: required(id),
    49   label: required(label),
    50   icon: required(iconSet)
    51 }));
    53 exports.buttonContract = buttonContract;
    55 exports.toggleStateContract = contract(merge({
    56   checked: boolean
    57 }, stateContract.rules));
    59 exports.toggleButtonContract = contract(merge({
    60   checked: boolean
    61 }, buttonContract.rules));

mercurial