toolkit/identity/IdentityUtils.jsm

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 /* -*- Mode: js2; js2-basic-offset: 2; indent-tabs-mode: nil; -*- */
     2 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 // functions common to Identity.jsm and MinimalIdentity.jsm
     9 "use strict";
    11 this.EXPORTED_SYMBOLS = [
    12   "checkDeprecated",
    13   "checkRenamed",
    14   "getRandomId",
    15   "objectCopy",
    16   "makeMessageObject",
    17 ];
    19 const Cu = Components.utils;
    21 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    23 XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
    24                                    "@mozilla.org/uuid-generator;1",
    25                                    "nsIUUIDGenerator");
    27 XPCOMUtils.defineLazyModuleGetter(this, "Logger",
    28                                   "resource://gre/modules/identity/LogUtils.jsm");
    30 function log(...aMessageArgs) {
    31   Logger.log.apply(Logger, ["Identity"].concat(aMessageArgs));
    32 }
    34 function defined(item) {
    35   return typeof item !== 'undefined';
    36 }
    38 var checkDeprecated = this.checkDeprecated = function checkDeprecated(aOptions, aField) {
    39   if (defined(aOptions[aField])) {
    40     log("WARNING: field is deprecated:", aField);
    41     return true;
    42   }
    43   return false;
    44 };
    46 this.checkRenamed = function checkRenamed(aOptions, aOldName, aNewName) {
    47   if (defined(aOptions[aOldName]) &&
    48       defined(aOptions[aNewName])) {
    49     let err = "You cannot provide both " + aOldName + " and " + aNewName;
    50     Logger.reportError(err);
    51     throw new Error(err);
    52   }
    54   if (checkDeprecated(aOptions, aOldName)) {
    55     aOptions[aNewName] = aOptions[aOldName];
    56     delete(aOptions[aOldName]);
    57   }
    58 };
    60 this.getRandomId = function getRandomId() {
    61   return uuidgen.generateUUID().toString();
    62 };
    64 /*
    65  * copy source object into target, excluding private properties
    66  * (those whose names begin with an underscore)
    67  */
    68 this.objectCopy = function objectCopy(source, target){
    69   let desc;
    70   Object.getOwnPropertyNames(source).forEach(function(name) {
    71     if (name[0] !== '_') {
    72       desc = Object.getOwnPropertyDescriptor(source, name);
    73       Object.defineProperty(target, name, desc);
    74     }
    75   });
    76 };
    78 this.makeMessageObject = function makeMessageObject(aRpCaller) {
    79   let options = {};
    81   options.id = aRpCaller.id;
    82   options.origin = aRpCaller.origin;
    84   // Backwards compatibility with Persona beta:
    85   // loggedInUser can be undefined, null, or a string
    86   options.loggedInUser = aRpCaller.loggedInUser;
    88   // Special flag for internal calls for Persona in b2g
    89   options._internal = aRpCaller._internal;
    91   Object.keys(aRpCaller).forEach(function(option) {
    92     // Duplicate the callerobject, scrubbing out functions and other
    93     // internal variables (like _mm, the message manager object)
    94     if (!Object.hasOwnProperty(this, option)
    95         && option[0] !== '_'
    96         && typeof aRpCaller[option] !== 'function') {
    97       options[option] = aRpCaller[option];
    98     }
    99   });
   101   // check validity of message structure
   102   if ((typeof options.id === 'undefined') ||
   103       (typeof options.origin === 'undefined')) {
   104     let err = "id and origin required in relying-party message: " + JSON.stringify(options);
   105     reportError(err);
   106     throw new Error(err);
   107   }
   109   return options;
   110 }

mercurial