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.

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

mercurial