addon-sdk/source/lib/sdk/private-browsing.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 'use strict';
michael@0 5
michael@0 6 module.metadata = {
michael@0 7 "stability": "stable"
michael@0 8 };
michael@0 9
michael@0 10 const { Ci } = require('chrome');
michael@0 11 const { setMode, getMode, on: onStateChange, isPermanentPrivateBrowsing } = require('./private-browsing/utils');
michael@0 12 const { isWindowPrivate } = require('./window/utils');
michael@0 13 const { emit, on, once, off } = require('./event/core');
michael@0 14 const { when: unload } = require('./system/unload');
michael@0 15 const { deprecateUsage, deprecateFunction, deprecateEvent } = require('./util/deprecate');
michael@0 16 const { getOwnerWindow } = require('./private-browsing/window/utils');
michael@0 17
michael@0 18 onStateChange('start', function onStart() {
michael@0 19 emit(exports, 'start');
michael@0 20 });
michael@0 21
michael@0 22 onStateChange('stop', function onStop() {
michael@0 23 emit(exports, 'stop');
michael@0 24 });
michael@0 25
michael@0 26 Object.defineProperty(exports, "isActive", {
michael@0 27 get: deprecateFunction(getMode, 'require("private-browsing").isActive is deprecated.')
michael@0 28 });
michael@0 29
michael@0 30 exports.activate = function activate() setMode(true);
michael@0 31 exports.deactivate = function deactivate() setMode(false);
michael@0 32
michael@0 33 exports.on = deprecateEvents(on.bind(null, exports));
michael@0 34 exports.once = deprecateEvents(once.bind(null, exports));
michael@0 35 exports.removeListener = deprecateEvents(function removeListener(type, listener) {
michael@0 36 // Note: We can't just bind `off` as we do it for other methods cause skipping
michael@0 37 // a listener argument will remove all listeners for the given event type
michael@0 38 // causing misbehavior. This way we make sure all arguments are passed.
michael@0 39 off(exports, type, listener);
michael@0 40 });
michael@0 41
michael@0 42 exports.isPrivate = function(thing) {
michael@0 43 // if thing is defined, and we can find a window for it
michael@0 44 // then check if the window is private
michael@0 45 if (!!thing) {
michael@0 46 // if the thing is a window, and the window is private
michael@0 47 // then return true
michael@0 48 if (isWindowPrivate(thing)) {
michael@0 49 return true;
michael@0 50 }
michael@0 51
michael@0 52 // does the thing have an associated tab?
michael@0 53 // page-mod instances do..
michael@0 54 if (thing.tab) {
michael@0 55 let tabWindow = getOwnerWindow(thing.tab);
michael@0 56 if (tabWindow) {
michael@0 57 let isThingPrivate = isWindowPrivate(tabWindow);
michael@0 58 if (isThingPrivate)
michael@0 59 return isThingPrivate;
michael@0 60 }
michael@0 61 }
michael@0 62
michael@0 63 // can we find an associated window?
michael@0 64 let window = getOwnerWindow(thing);
michael@0 65 if (window)
michael@0 66 return isWindowPrivate(window);
michael@0 67
michael@0 68 try {
michael@0 69 let { isChannelPrivate } = thing.QueryInterface(Ci.nsIPrivateBrowsingChannel);
michael@0 70 if (isChannelPrivate)
michael@0 71 return true;
michael@0 72 } catch(e) {}
michael@0 73 }
michael@0 74
michael@0 75 // check if the post pwpb, global pb service is enabled.
michael@0 76 if (isPermanentPrivateBrowsing())
michael@0 77 return true;
michael@0 78
michael@0 79 // if we get here, and global private browsing
michael@0 80 // is available, and it is true, then return
michael@0 81 // true otherwise false is returned here
michael@0 82 return getMode();
michael@0 83 };
michael@0 84
michael@0 85 function deprecateEvents(func) deprecateEvent(
michael@0 86 func,
michael@0 87 'The require("sdk/private-browsing") module\'s "start" and "stop" events ' +
michael@0 88 'are deprecated.',
michael@0 89 ['start', 'stop']
michael@0 90 );
michael@0 91
michael@0 92 // Make sure listeners are cleaned up.
michael@0 93 unload(function() off(exports));

mercurial