SiteSettingsBackupResource.sys.mjs (2341B)
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 XPCOMUtils.defineLazyPreferenceGetter( 11 lazy, 12 "isSanitizeOnShutdownEnabled", 13 "privacy.sanitize.sanitizeOnShutdown", 14 false 15 ); 16 17 XPCOMUtils.defineLazyPreferenceGetter( 18 lazy, 19 "isSiteSettingsClearedOnShutdown", 20 "privacy.clearOnShutdown.siteSettings", 21 false 22 ); 23 24 XPCOMUtils.defineLazyPreferenceGetter( 25 lazy, 26 "isSiteSettingsClearedOnShutdown2", 27 "privacy.clearOnShutdown_v2.siteSettings", 28 false 29 ); 30 31 XPCOMUtils.defineLazyPreferenceGetter( 32 lazy, 33 "useOldClearHistoryDialog", 34 "privacy.sanitize.useOldClearHistoryDialog", 35 false 36 ); 37 38 /** 39 * Class representing the backup and restore of a user's site settings 40 */ 41 export class SiteSettingsBackupResource extends BackupResource { 42 static get key() { 43 return "site_settings"; 44 } 45 46 static get requiresEncryption() { 47 return false; 48 } 49 50 static get priority() { 51 return 1; 52 } 53 54 static get canBackupResource() { 55 if (!lazy.isSanitizeOnShutdownEnabled) { 56 return true; 57 } 58 59 if (lazy.useOldClearHistoryDialog) { 60 return !lazy.isSiteSettingsClearedOnShutdown; 61 } 62 return !lazy.isSiteSettingsClearedOnShutdown2; 63 } 64 65 async backup( 66 stagingPath, 67 profilePath = PathUtils.profileDir, 68 _isEncrypting = false 69 ) { 70 const sqliteDatabases = ["permissions.sqlite", "content-prefs.sqlite"]; 71 await BackupResource.copySqliteDatabases( 72 profilePath, 73 stagingPath, 74 sqliteDatabases 75 ); 76 return null; 77 } 78 79 async recover(_manifestEntry, recoveryPath, destProfilePath) { 80 /** 81 * pass the file path to postRecovery() so that we can import all bookmarks into the new 82 * profile once it's been launched and restored. 83 */ 84 const simpleCopyFiles = ["permissions.sqlite", "content-prefs.sqlite"]; 85 await BackupResource.copyFiles( 86 recoveryPath, 87 destProfilePath, 88 simpleCopyFiles 89 ); 90 91 return null; 92 } 93 94 async measure(_profilePath = PathUtils.profileDir) { 95 // Unsure how to measure this!! 96 } 97 }