addon-sdk/source/lib/sdk/indexed-db.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
michael@0 5 "use strict";
michael@0 6
michael@0 7 module.metadata = {
michael@0 8 "stability": "experimental"
michael@0 9 };
michael@0 10
michael@0 11 const { Cc, Ci } = require("chrome");
michael@0 12 const { id } = require("./self");
michael@0 13
michael@0 14 // placeholder, copied from bootstrap.js
michael@0 15 let sanitizeId = function(id){
michael@0 16 let uuidRe =
michael@0 17 /^\{([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\}$/;
michael@0 18
michael@0 19 let domain = id.
michael@0 20 toLowerCase().
michael@0 21 replace(/@/g, "-at-").
michael@0 22 replace(/\./g, "-dot-").
michael@0 23 replace(uuidRe, "$1");
michael@0 24
michael@0 25 return domain
michael@0 26 };
michael@0 27
michael@0 28 const PSEUDOURI = "indexeddb://" + sanitizeId(id) // https://bugzilla.mozilla.org/show_bug.cgi?id=779197
michael@0 29
michael@0 30 // Firefox 26 and earlier releases don't support `indexedDB` in sandboxes
michael@0 31 // automatically, so we need to inject `indexedDB` to `this` scope ourselves.
michael@0 32 if (typeof(indexedDB) === "undefined") {
michael@0 33 Cc["@mozilla.org/dom/indexeddb/manager;1"].
michael@0 34 getService(Ci.nsIIndexedDatabaseManager).
michael@0 35 initWindowless(this);
michael@0 36
michael@0 37 // Firefox 14 gets this with a prefix
michael@0 38 if (typeof(indexedDB) === "undefined")
michael@0 39 this.indexedDB = mozIndexedDB;
michael@0 40 }
michael@0 41
michael@0 42 // Use XPCOM because `require("./url").URL` doesn't expose the raw uri object.
michael@0 43 let principaluri = Cc["@mozilla.org/network/io-service;1"].
michael@0 44 getService(Ci.nsIIOService).
michael@0 45 newURI(PSEUDOURI, null, null);
michael@0 46
michael@0 47 let principal = Cc["@mozilla.org/scriptsecuritymanager;1"].
michael@0 48 getService(Ci.nsIScriptSecurityManager).
michael@0 49 getCodebasePrincipal(principaluri);
michael@0 50
michael@0 51 exports.indexedDB = Object.freeze({
michael@0 52 open: indexedDB.openForPrincipal.bind(indexedDB, principal),
michael@0 53 deleteDatabase: indexedDB.deleteForPrincipal.bind(indexedDB, principal),
michael@0 54 cmp: indexedDB.cmp
michael@0 55 });
michael@0 56
michael@0 57 exports.IDBKeyRange = IDBKeyRange;
michael@0 58 exports.DOMException = Ci.nsIDOMDOMException;

mercurial