addon-sdk/source/lib/sdk/passwords.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.

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 module.metadata = {
michael@0 7 "stability": "stable"
michael@0 8 };
michael@0 9
michael@0 10 const { search, remove, store } = require("./passwords/utils");
michael@0 11 const { defer, delay } = require("./lang/functional");
michael@0 12
michael@0 13 /**
michael@0 14 * Utility function that returns `onComplete` and `onError` callbacks form the
michael@0 15 * given `options` objects. Also properties are removed from the passed
michael@0 16 * `options` objects.
michael@0 17 * @param {Object} options
michael@0 18 * Object that is passed to the exported functions of this module.
michael@0 19 * @returns {Function[]}
michael@0 20 * Array with two elements `onComplete` and `onError` functions.
michael@0 21 */
michael@0 22 function getCallbacks(options) {
michael@0 23 let value = [
michael@0 24 'onComplete' in options ? options.onComplete : null,
michael@0 25 'onError' in options ? defer(options.onError) : console.exception
michael@0 26 ];
michael@0 27
michael@0 28 delete options.onComplete;
michael@0 29 delete options.onError;
michael@0 30
michael@0 31 return value;
michael@0 32 };
michael@0 33
michael@0 34 /**
michael@0 35 * Creates a wrapper function that tries to call `onComplete` with a return
michael@0 36 * value of the wrapped function or falls back to `onError` if wrapped function
michael@0 37 * throws an exception.
michael@0 38 */
michael@0 39 function createWrapperMethod(wrapped) {
michael@0 40 return function (options) {
michael@0 41 let [ onComplete, onError ] = getCallbacks(options);
michael@0 42 try {
michael@0 43 let value = wrapped(options);
michael@0 44 if (onComplete) {
michael@0 45 delay(function() {
michael@0 46 try {
michael@0 47 onComplete(value);
michael@0 48 } catch (exception) {
michael@0 49 onError(exception);
michael@0 50 }
michael@0 51 });
michael@0 52 }
michael@0 53 } catch (exception) {
michael@0 54 onError(exception);
michael@0 55 }
michael@0 56 };
michael@0 57 }
michael@0 58
michael@0 59 exports.search = createWrapperMethod(search);
michael@0 60 exports.store = createWrapperMethod(store);
michael@0 61 exports.remove = createWrapperMethod(remove);

mercurial