Sat, 03 Jan 2015 20:18:00 +0100
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": "unstable" |
michael@0 | 8 | }; |
michael@0 | 9 | |
michael@0 | 10 | const { Cc, Ci, Cu } = require('chrome'); |
michael@0 | 11 | const { defer } = require('../lang/functional'); |
michael@0 | 12 | const { emit, on, once, off } = require('../event/core'); |
michael@0 | 13 | const { when: unload } = require('../system/unload'); |
michael@0 | 14 | const events = require('../system/events'); |
michael@0 | 15 | const { deprecateFunction } = require('../util/deprecate'); |
michael@0 | 16 | const { isOneOf, is, satisfiesVersion, version } = require('../system/xul-app'); |
michael@0 | 17 | const { isWindowPrivate } = require('../window/utils'); |
michael@0 | 18 | const { isPrivateBrowsingSupported } = require('../self'); |
michael@0 | 19 | |
michael@0 | 20 | let deferredEmit = defer(emit); |
michael@0 | 21 | let pbService; |
michael@0 | 22 | let PrivateBrowsingUtils; |
michael@0 | 23 | |
michael@0 | 24 | // Private browsing is only supported in Fx |
michael@0 | 25 | if (isOneOf(['Firefox', 'Fennec'])) { |
michael@0 | 26 | // get the nsIPrivateBrowsingService if it exists |
michael@0 | 27 | try { |
michael@0 | 28 | pbService = Cc["@mozilla.org/privatebrowsing;1"]. |
michael@0 | 29 | getService(Ci.nsIPrivateBrowsingService); |
michael@0 | 30 | |
michael@0 | 31 | // a dummy service exists for the moment (Fx20 atleast), but will be removed eventually |
michael@0 | 32 | // ie: the service will exist, but it won't do anything and the global private browing |
michael@0 | 33 | // feature is not really active. See Bug 818800 and Bug 826037 |
michael@0 | 34 | if (!('privateBrowsingEnabled' in pbService)) |
michael@0 | 35 | pbService = undefined; |
michael@0 | 36 | } |
michael@0 | 37 | catch(e) { /* Private Browsing Service has been removed (Bug 818800) */ } |
michael@0 | 38 | |
michael@0 | 39 | try { |
michael@0 | 40 | PrivateBrowsingUtils = Cu.import('resource://gre/modules/PrivateBrowsingUtils.jsm', {}).PrivateBrowsingUtils; |
michael@0 | 41 | } |
michael@0 | 42 | catch(e) { /* if this file DNE then an error will be thrown */ } |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | // checks that global private browsing is implemented |
michael@0 | 46 | let isGlobalPBSupported = exports.isGlobalPBSupported = !!pbService && is('Firefox'); |
michael@0 | 47 | |
michael@0 | 48 | // checks that per-window private browsing is implemented |
michael@0 | 49 | let isWindowPBSupported = exports.isWindowPBSupported = |
michael@0 | 50 | !pbService && !!PrivateBrowsingUtils && is('Firefox'); |
michael@0 | 51 | |
michael@0 | 52 | // checks that per-tab private browsing is implemented |
michael@0 | 53 | let isTabPBSupported = exports.isTabPBSupported = |
michael@0 | 54 | !pbService && !!PrivateBrowsingUtils && is('Fennec') && satisfiesVersion(version, '>=20.0*'); |
michael@0 | 55 | |
michael@0 | 56 | exports.isPermanentPrivateBrowsing = function() { |
michael@0 | 57 | return !!(PrivateBrowsingUtils && PrivateBrowsingUtils.permanentPrivateBrowsing); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function ignoreWindow(window) { |
michael@0 | 61 | return !isPrivateBrowsingSupported && isWindowPrivate(window) && !isGlobalPBSupported; |
michael@0 | 62 | } |
michael@0 | 63 | exports.ignoreWindow = ignoreWindow; |
michael@0 | 64 | |
michael@0 | 65 | function onChange() { |
michael@0 | 66 | // Emit event with in next turn of event loop. |
michael@0 | 67 | deferredEmit(exports, pbService.privateBrowsingEnabled ? 'start' : 'stop'); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | // Currently, only Firefox implements the private browsing service. |
michael@0 | 71 | if (isGlobalPBSupported) { |
michael@0 | 72 | // set up an observer for private browsing switches. |
michael@0 | 73 | events.on('private-browsing-transition-complete', onChange); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | // We toggle private browsing mode asynchronously in order to work around |
michael@0 | 77 | // bug 659629. Since private browsing transitions are asynchronous |
michael@0 | 78 | // anyway, this doesn't significantly change the behavior of the API. |
michael@0 | 79 | let setMode = defer(function setMode(value) { |
michael@0 | 80 | value = !!value; // Cast to boolean. |
michael@0 | 81 | |
michael@0 | 82 | // default |
michael@0 | 83 | return pbService && (pbService.privateBrowsingEnabled = value); |
michael@0 | 84 | }); |
michael@0 | 85 | exports.setMode = deprecateFunction( |
michael@0 | 86 | setMode, |
michael@0 | 87 | 'require("sdk/private-browsing").activate and ' + |
michael@0 | 88 | 'require("sdk/private-browsing").deactivate ' + |
michael@0 | 89 | 'are deprecated.' |
michael@0 | 90 | ); |
michael@0 | 91 | |
michael@0 | 92 | let getMode = function getMode(chromeWin) { |
michael@0 | 93 | if (isWindowPrivate(chromeWin)) |
michael@0 | 94 | return true; |
michael@0 | 95 | |
michael@0 | 96 | // default |
michael@0 | 97 | return pbService ? pbService.privateBrowsingEnabled : false; |
michael@0 | 98 | }; |
michael@0 | 99 | exports.getMode = getMode; |
michael@0 | 100 | |
michael@0 | 101 | exports.on = on.bind(null, exports); |
michael@0 | 102 | |
michael@0 | 103 | // Make sure listeners are cleaned up. |
michael@0 | 104 | unload(function() off(exports)); |