michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: this.EXPORTED_SYMBOLS = ["LoadContextInfo"]; michael@0: michael@0: const Ci = Components.interfaces; michael@0: const Cc = Components.classes; michael@0: const Cr = Components.results; michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: this.LoadContextInfo = {}; michael@0: michael@0: _LoadContextInfo.prototype = { michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsILoadContextInfo, Ci.nsISupports]), michael@0: get isPrivate() { return this._isPrivate }, michael@0: get isAnonymous() { return this._isAnonymous }, michael@0: get isInBrowserElement() { return this._isInBrowserElement }, michael@0: get appId() { return this._appId } michael@0: } michael@0: michael@0: function _LoadContextInfo(_private, _anonymous, _appId, _inBrowser) { michael@0: this._isPrivate = _private || false; michael@0: this._isAnonymous = _anonymous || false; michael@0: this._appId = _appId || 0; michael@0: this._isInBrowserElement = _inBrowser || false; michael@0: } michael@0: michael@0: // LoadContextInfo.default michael@0: michael@0: // Non-private, non-anonymous, no app ID, not in browser michael@0: XPCOMUtils.defineLazyGetter(LoadContextInfo, "default", function () { michael@0: return new _LoadContextInfo(false, false, 0, false); michael@0: }); michael@0: michael@0: // LoadContextInfo.private michael@0: michael@0: // Private, non-anonymous, no app ID, not in browser michael@0: XPCOMUtils.defineLazyGetter(LoadContextInfo, "private", function () { michael@0: return new _LoadContextInfo(true, false, 0, false); michael@0: }); michael@0: michael@0: // LoadContextInfo.anonymous michael@0: michael@0: // Non-private, anonymous, no app ID, not in browser michael@0: XPCOMUtils.defineLazyGetter(LoadContextInfo, "anonymous", function () { michael@0: return new _LoadContextInfo(false, true, 0, false); michael@0: }); michael@0: michael@0: // Fully customizable michael@0: LoadContextInfo.custom = function(_private, _anonymous, _appId, _inBrowser) { michael@0: return new _LoadContextInfo(_private, _anonymous, _appId, _inBrowser); michael@0: } michael@0: michael@0: // Copies info from provided nsILoadContext michael@0: LoadContextInfo.fromLoadContext = function(_loadContext, _anonymous) { michael@0: return new _LoadContextInfo(_loadContext.isPrivate, michael@0: _anonymous, michael@0: _loadContext.appId, michael@0: _loadContext.isInBrowserElement); michael@0: }