tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FormHistoryBackupResource.sys.mjs (2511B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      4 
      5 import { BackupResource } from "resource:///modules/backup/BackupResource.sys.mjs";
      6 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
      7 
      8 const lazy = {};
      9 
     10 ChromeUtils.defineESModuleGetters(lazy, {
     11  PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
     12 });
     13 
     14 XPCOMUtils.defineLazyPreferenceGetter(
     15  lazy,
     16  "isBrowsingHistoryEnabled",
     17  "places.history.enabled",
     18  true
     19 );
     20 
     21 XPCOMUtils.defineLazyPreferenceGetter(
     22  lazy,
     23  "isSanitizeOnShutdownEnabled",
     24  "privacy.sanitize.sanitizeOnShutdown",
     25  false
     26 );
     27 
     28 XPCOMUtils.defineLazyPreferenceGetter(
     29  lazy,
     30  "isFormDataClearedOnShutdown",
     31  "privacy.clearOnShutdown.formdata",
     32  false
     33 );
     34 
     35 XPCOMUtils.defineLazyPreferenceGetter(
     36  lazy,
     37  "isFormDataClearedOnShutdown2",
     38  "privacy.clearOnShutdown_v2.formdata",
     39  false
     40 );
     41 
     42 XPCOMUtils.defineLazyPreferenceGetter(
     43  lazy,
     44  "useOldClearHistoryDialog",
     45  "privacy.sanitize.useOldClearHistoryDialog",
     46  false
     47 );
     48 
     49 /**
     50 * Class representing Form history database within a user profile.
     51 */
     52 export class FormHistoryBackupResource extends BackupResource {
     53  static get key() {
     54    return "formhistory";
     55  }
     56 
     57  static get requiresEncryption() {
     58    return false;
     59  }
     60 
     61  static get canBackupResource() {
     62    if (
     63      lazy.PrivateBrowsingUtils.permanentPrivateBrowsing ||
     64      !lazy.isBrowsingHistoryEnabled
     65    ) {
     66      return false;
     67    }
     68 
     69    if (!lazy.isSanitizeOnShutdownEnabled) {
     70      return true;
     71    }
     72 
     73    if (lazy.useOldClearHistoryDialog) {
     74      return !lazy.isFormDataClearedOnShutdown;
     75    }
     76    return !lazy.isFormDataClearedOnShutdown2;
     77  }
     78 
     79  async backup(
     80    stagingPath,
     81    profilePath = PathUtils.profileDir,
     82    _isEncrypting = false
     83  ) {
     84    await BackupResource.copySqliteDatabases(profilePath, stagingPath, [
     85      "formhistory.sqlite",
     86    ]);
     87 
     88    return null;
     89  }
     90 
     91  async recover(_manifestEntry, recoveryPath, destProfilePath) {
     92    await BackupResource.copyFiles(recoveryPath, destProfilePath, [
     93      "formhistory.sqlite",
     94    ]);
     95 
     96    return null;
     97  }
     98 
     99  async measure(profilePath = PathUtils.profileDir) {
    100    let formHistoryDBPath = PathUtils.join(profilePath, "formhistory.sqlite");
    101    let formHistorySize = await BackupResource.getFileSize(formHistoryDBPath);
    102 
    103    Glean.browserBackup.formHistorySize.set(formHistorySize);
    104  }
    105 }