1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/modules/LoadContextInfo.jsm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,62 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +this.EXPORTED_SYMBOLS = ["LoadContextInfo"]; 1.9 + 1.10 +const Ci = Components.interfaces; 1.11 +const Cc = Components.classes; 1.12 +const Cr = Components.results; 1.13 + 1.14 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.15 + 1.16 +this.LoadContextInfo = {}; 1.17 + 1.18 +_LoadContextInfo.prototype = { 1.19 + QueryInterface: XPCOMUtils.generateQI([Ci.nsILoadContextInfo, Ci.nsISupports]), 1.20 + get isPrivate() { return this._isPrivate }, 1.21 + get isAnonymous() { return this._isAnonymous }, 1.22 + get isInBrowserElement() { return this._isInBrowserElement }, 1.23 + get appId() { return this._appId } 1.24 +} 1.25 + 1.26 +function _LoadContextInfo(_private, _anonymous, _appId, _inBrowser) { 1.27 + this._isPrivate = _private || false; 1.28 + this._isAnonymous = _anonymous || false; 1.29 + this._appId = _appId || 0; 1.30 + this._isInBrowserElement = _inBrowser || false; 1.31 +} 1.32 + 1.33 +// LoadContextInfo.default 1.34 + 1.35 +// Non-private, non-anonymous, no app ID, not in browser 1.36 +XPCOMUtils.defineLazyGetter(LoadContextInfo, "default", function () { 1.37 + return new _LoadContextInfo(false, false, 0, false); 1.38 +}); 1.39 + 1.40 +// LoadContextInfo.private 1.41 + 1.42 +// Private, non-anonymous, no app ID, not in browser 1.43 +XPCOMUtils.defineLazyGetter(LoadContextInfo, "private", function () { 1.44 + return new _LoadContextInfo(true, false, 0, false); 1.45 +}); 1.46 + 1.47 +// LoadContextInfo.anonymous 1.48 + 1.49 +// Non-private, anonymous, no app ID, not in browser 1.50 +XPCOMUtils.defineLazyGetter(LoadContextInfo, "anonymous", function () { 1.51 + return new _LoadContextInfo(false, true, 0, false); 1.52 +}); 1.53 + 1.54 +// Fully customizable 1.55 +LoadContextInfo.custom = function(_private, _anonymous, _appId, _inBrowser) { 1.56 + return new _LoadContextInfo(_private, _anonymous, _appId, _inBrowser); 1.57 +} 1.58 + 1.59 +// Copies info from provided nsILoadContext 1.60 +LoadContextInfo.fromLoadContext = function(_loadContext, _anonymous) { 1.61 + return new _LoadContextInfo(_loadContext.isPrivate, 1.62 + _anonymous, 1.63 + _loadContext.appId, 1.64 + _loadContext.isInBrowserElement); 1.65 +}