2013-09-17 12:40:27 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["PrivacyLevel"];
|
2013-09-17 12:40:27 +04:00
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2013-09-17 12:40:27 +04:00
|
|
|
|
2015-12-29 23:45:21 +03:00
|
|
|
const PREF = "browser.sessionstore.privacy_level";
|
2013-09-17 12:40:27 +04:00
|
|
|
|
|
|
|
// The following constants represent the different possible privacy levels that
|
|
|
|
// can be set by the user and that we need to consider when collecting text
|
2014-01-14 21:21:48 +04:00
|
|
|
// data, and cookies.
|
2013-09-17 12:40:27 +04:00
|
|
|
//
|
|
|
|
// Collect data from all sites (http and https).
|
2018-02-23 22:25:59 +03:00
|
|
|
// const PRIVACY_NONE = 0;
|
2013-09-17 12:40:27 +04:00
|
|
|
// Collect data from unencrypted sites (http), only.
|
|
|
|
const PRIVACY_ENCRYPTED = 1;
|
|
|
|
// Collect no data.
|
|
|
|
const PRIVACY_FULL = 2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The external API as exposed by this module.
|
|
|
|
*/
|
2015-09-15 21:19:45 +03:00
|
|
|
var PrivacyLevel = Object.freeze({
|
2016-06-01 15:48:15 +03:00
|
|
|
/**
|
|
|
|
* Returns whether the current privacy level allows saving data for the given
|
|
|
|
* |url|.
|
|
|
|
*
|
|
|
|
* @param url The URL we want to save data for.
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-02-01 01:05:31 +03:00
|
|
|
check(url) {
|
2017-03-30 14:57:42 +03:00
|
|
|
return PrivacyLevel.canSave(url.startsWith("https:"));
|
2016-06-01 15:48:15 +03:00
|
|
|
},
|
|
|
|
|
2013-09-17 12:40:27 +04:00
|
|
|
/**
|
|
|
|
* Checks whether we're allowed to save data for a specific site.
|
|
|
|
*
|
2017-03-30 14:57:42 +03:00
|
|
|
* @param isHttps A boolean that tells whether the site uses TLS.
|
2013-09-17 12:40:27 +04:00
|
|
|
* @return {bool} Whether we can save data for the specified site.
|
|
|
|
*/
|
2017-03-30 14:57:42 +03:00
|
|
|
canSave(isHttps) {
|
2015-12-29 23:45:21 +03:00
|
|
|
let level = Services.prefs.getIntPref(PREF);
|
2013-09-17 12:40:27 +04:00
|
|
|
|
|
|
|
// Never save any data when full privacy is requested.
|
|
|
|
if (level == PRIVACY_FULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't save data for encrypted sites when requested.
|
|
|
|
if (isHttps && level == PRIVACY_ENCRYPTED) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2013-09-17 12:40:27 +04:00
|
|
|
});
|