Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 file, |
michael@0 | 3 | * 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 | this.EXPORTED_SYMBOLS = ["PrivacyLevel"]; |
michael@0 | 8 | |
michael@0 | 9 | const Cu = Components.utils; |
michael@0 | 10 | |
michael@0 | 11 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 12 | |
michael@0 | 13 | const PREF_NORMAL = "browser.sessionstore.privacy_level"; |
michael@0 | 14 | const PREF_DEFERRED = "browser.sessionstore.privacy_level_deferred"; |
michael@0 | 15 | |
michael@0 | 16 | // The following constants represent the different possible privacy levels that |
michael@0 | 17 | // can be set by the user and that we need to consider when collecting text |
michael@0 | 18 | // data, and cookies. |
michael@0 | 19 | // |
michael@0 | 20 | // Collect data from all sites (http and https). |
michael@0 | 21 | const PRIVACY_NONE = 0; |
michael@0 | 22 | // Collect data from unencrypted sites (http), only. |
michael@0 | 23 | const PRIVACY_ENCRYPTED = 1; |
michael@0 | 24 | // Collect no data. |
michael@0 | 25 | const PRIVACY_FULL = 2; |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * Returns whether we will resume the session automatically on next startup. |
michael@0 | 29 | */ |
michael@0 | 30 | function willResumeAutomatically() { |
michael@0 | 31 | return Services.prefs.getIntPref("browser.startup.page") == 3 || |
michael@0 | 32 | Services.prefs.getBoolPref("browser.sessionstore.resume_session_once"); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | /** |
michael@0 | 36 | * Determines the current privacy level as set by the user. |
michael@0 | 37 | * |
michael@0 | 38 | * @param isPinned |
michael@0 | 39 | * Whether to return the privacy level for pinned tabs. |
michael@0 | 40 | * @return {int} The privacy level as read from the user's preferences. |
michael@0 | 41 | */ |
michael@0 | 42 | function getCurrentLevel(isPinned) { |
michael@0 | 43 | let pref = PREF_NORMAL; |
michael@0 | 44 | |
michael@0 | 45 | // If we're in the process of quitting and we're not autoresuming the session |
michael@0 | 46 | // then we will use the deferred privacy level for non-pinned tabs. |
michael@0 | 47 | if (!isPinned && Services.startup.shuttingDown && !willResumeAutomatically()) { |
michael@0 | 48 | pref = PREF_DEFERRED; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | return Services.prefs.getIntPref(pref); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | /** |
michael@0 | 55 | * The external API as exposed by this module. |
michael@0 | 56 | */ |
michael@0 | 57 | let PrivacyLevel = Object.freeze({ |
michael@0 | 58 | /** |
michael@0 | 59 | * Checks whether we're allowed to save data for a specific site. |
michael@0 | 60 | * |
michael@0 | 61 | * @param {isHttps: boolean, isPinned: boolean} |
michael@0 | 62 | * An object that must have two properties: 'isHttps' and 'isPinned'. |
michael@0 | 63 | * 'isHttps' tells whether the site us secure communication (HTTPS). |
michael@0 | 64 | * 'isPinned' tells whether the site is loaded in a pinned tab. |
michael@0 | 65 | * @return {bool} Whether we can save data for the specified site. |
michael@0 | 66 | */ |
michael@0 | 67 | canSave: function ({isHttps, isPinned}) { |
michael@0 | 68 | let level = getCurrentLevel(isPinned); |
michael@0 | 69 | |
michael@0 | 70 | // Never save any data when full privacy is requested. |
michael@0 | 71 | if (level == PRIVACY_FULL) { |
michael@0 | 72 | return false; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | // Don't save data for encrypted sites when requested. |
michael@0 | 76 | if (isHttps && level == PRIVACY_ENCRYPTED) { |
michael@0 | 77 | return false; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | return true; |
michael@0 | 81 | } |
michael@0 | 82 | }); |