toolkit/mozapps/update/nsUpdateServiceStub.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 const Ci = Components.interfaces;
michael@0 7 const Cc = Components.classes;
michael@0 8 const Cu = Components.utils;
michael@0 9
michael@0 10 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 11 Cu.import("resource://gre/modules/FileUtils.jsm");
michael@0 12 Cu.import("resource://gre/modules/Services.jsm");
michael@0 13
michael@0 14 const DIR_UPDATES = "updates";
michael@0 15 const FILE_UPDATES_DB = "updates.xml";
michael@0 16 const FILE_UPDATE_ACTIVE = "active-update.xml";
michael@0 17 const FILE_LAST_LOG = "last-update.log";
michael@0 18 const FILE_BACKUP_LOG = "backup-update.log";
michael@0 19 const FILE_UPDATE_STATUS = "update.status";
michael@0 20
michael@0 21 const KEY_UPDROOT = "UpdRootD";
michael@0 22
michael@0 23 #ifdef XP_WIN
michael@0 24
michael@0 25 const PREF_APP_UPDATE_MIGRATE_APP_DIR = "app.update.migrated.updateDir";
michael@0 26
michael@0 27
michael@0 28 function getTaskbarIDHash(rootKey, exePath, appInfoName) {
michael@0 29 let registry = Cc["@mozilla.org/windows-registry-key;1"].
michael@0 30 createInstance(Ci.nsIWindowsRegKey);
michael@0 31 try {
michael@0 32 registry.open(rootKey, "Software\\Mozilla\\" + appInfoName + "\\TaskBarIDs",
michael@0 33 Ci.nsIWindowsRegKey.ACCESS_READ);
michael@0 34 if (registry.hasValue(exePath)) {
michael@0 35 return registry.readStringValue(exePath);
michael@0 36 }
michael@0 37 } catch (ex) {
michael@0 38 } finally {
michael@0 39 registry.close();
michael@0 40 }
michael@0 41 return undefined;
michael@0 42 };
michael@0 43
michael@0 44 /*
michael@0 45 * Migrates old update directory files to the new update directory
michael@0 46 * which is based on a hash of the installation.
michael@0 47 */
michael@0 48 function migrateOldUpdateDir() {
michael@0 49 // Get the old udpate root leaf dir. It is based on the sub directory of
michael@0 50 // program files, or if the exe path is not inside program files, the appname.
michael@0 51 var appinfo = Components.classes["@mozilla.org/xre/app-info;1"].
michael@0 52 getService(Components.interfaces.nsIXULAppInfo).
michael@0 53 QueryInterface(Components.interfaces.nsIXULRuntime);
michael@0 54 var updateLeafName;
michael@0 55 var programFiles = FileUtils.getFile("ProgF", []);
michael@0 56 var exeFile = FileUtils.getFile("XREExeF", []);
michael@0 57 if (exeFile.path.substring(0, programFiles.path.length).toLowerCase() ==
michael@0 58 programFiles.path.toLowerCase()) {
michael@0 59 updateLeafName = exeFile.parent.leafName;
michael@0 60 } else {
michael@0 61 updateLeafName = appinfo.name;
michael@0 62 }
michael@0 63
michael@0 64 // Get the old update root dir
michael@0 65 var oldUpdateRoot;
michael@0 66 if (appinfo.vendor) {
michael@0 67 oldUpdateRoot = FileUtils.getDir("LocalAppData", [appinfo.vendor,
michael@0 68 appinfo.name,
michael@0 69 updateLeafName], false);
michael@0 70 } else {
michael@0 71 oldUpdateRoot = FileUtils.getDir("LocalAppData", [appinfo.name,
michael@0 72 updateLeafName], false);
michael@0 73 }
michael@0 74
michael@0 75 // Obtain the new update root
michael@0 76 var newUpdateRoot = FileUtils.getDir("UpdRootD", [], true);
michael@0 77
michael@0 78 // If there is no taskbar ID then we want to retry this migration
michael@0 79 // at a later time if the application gets a taskbar ID.
michael@0 80 var taskbarID = getTaskbarIDHash(Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
michael@0 81 exeFile.parent.path, appinfo.name);
michael@0 82 if (!taskbarID) {
michael@0 83 taskbarID = getTaskbarIDHash(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
michael@0 84 exeFile.parent.path, appinfo.name);
michael@0 85 if (!taskbarID) {
michael@0 86 return;
michael@0 87 }
michael@0 88 }
michael@0 89
michael@0 90 Services.prefs.setBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR, true);
michael@0 91
michael@0 92 // Sanity checks only to ensure we don't delete something we don't mean to.
michael@0 93 if (oldUpdateRoot.path.toLowerCase() == newUpdateRoot.path.toLowerCase() ||
michael@0 94 updateLeafName.length == 0) {
michael@0 95 return;
michael@0 96 }
michael@0 97
michael@0 98 // If the old update root doesn't exist then we have already migrated
michael@0 99 // or else there is no work to do.
michael@0 100 if (!oldUpdateRoot.exists()) {
michael@0 101 return;
michael@0 102 }
michael@0 103
michael@0 104 // Get an array of all of the files we want to migrate.
michael@0 105 // We do this so we don't copy anything extra.
michael@0 106 var filesToMigrate = [FILE_UPDATES_DB, FILE_UPDATE_ACTIVE,
michael@0 107 ["updates", FILE_LAST_LOG], ["updates", FILE_BACKUP_LOG],
michael@0 108 ["updates", "0", FILE_UPDATE_STATUS]];
michael@0 109
michael@0 110 // Move each of those files to the new directory
michael@0 111 filesToMigrate.forEach(relPath => {
michael@0 112 let oldFile = oldUpdateRoot.clone();
michael@0 113 let newFile = newUpdateRoot.clone();
michael@0 114 if (relPath instanceof Array) {
michael@0 115 relPath.forEach(relPathPart => {
michael@0 116 oldFile.append(relPathPart);
michael@0 117 newFile.append(relPathPart);
michael@0 118 });
michael@0 119 } else {
michael@0 120 oldFile.append(relPath);
michael@0 121 newFile.append(relPath);
michael@0 122 }
michael@0 123
michael@0 124 try {
michael@0 125 if (!newFile.exists()) {
michael@0 126 oldFile.moveTo(newFile.parent, newFile.leafName);
michael@0 127 }
michael@0 128 } catch (e) {
michael@0 129 Components.utils.reportError(e);
michael@0 130 }
michael@0 131 });
michael@0 132
michael@0 133 oldUpdateRoot.remove(true);
michael@0 134 }
michael@0 135 #endif
michael@0 136
michael@0 137 /**
michael@0 138 * Gets the specified directory at the specified hierarchy under the update root
michael@0 139 * directory without creating it if it doesn't exist.
michael@0 140 * @param pathArray
michael@0 141 * An array of path components to locate beneath the directory
michael@0 142 * specified by |key|
michael@0 143 * @return nsIFile object for the location specified.
michael@0 144 */
michael@0 145 function getUpdateDirNoCreate(pathArray) {
michael@0 146 return FileUtils.getDir(KEY_UPDROOT, pathArray, false);
michael@0 147 }
michael@0 148
michael@0 149 function UpdateServiceStub() {
michael@0 150 #ifdef XP_WIN
michael@0 151 // Don't attempt this migration more than once for perf reasons
michael@0 152 var migrated = 0;
michael@0 153 try {
michael@0 154 migrated = Services.prefs.getBoolPref(PREF_APP_UPDATE_MIGRATE_APP_DIR);
michael@0 155 } catch (e) {
michael@0 156 }
michael@0 157
michael@0 158 if (!migrated) {
michael@0 159 try {
michael@0 160 migrateOldUpdateDir();
michael@0 161 } catch (e) {
michael@0 162 Components.utils.reportError(e);
michael@0 163 }
michael@0 164 }
michael@0 165 #endif
michael@0 166
michael@0 167 let statusFile = getUpdateDirNoCreate([DIR_UPDATES, "0"]);
michael@0 168 statusFile.append(FILE_UPDATE_STATUS);
michael@0 169 // If the update.status file exists then initiate post update processing.
michael@0 170 if (statusFile.exists()) {
michael@0 171 let aus = Components.classes["@mozilla.org/updates/update-service;1"].
michael@0 172 getService(Ci.nsIApplicationUpdateService).
michael@0 173 QueryInterface(Ci.nsIObserver);
michael@0 174 aus.observe(null, "post-update-processing", "");
michael@0 175 }
michael@0 176 }
michael@0 177 UpdateServiceStub.prototype = {
michael@0 178 observe: function(){},
michael@0 179 classID: Components.ID("{e43b0010-04ba-4da6-b523-1f92580bc150}"),
michael@0 180 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver])
michael@0 181 };
michael@0 182
michael@0 183 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([UpdateServiceStub]);

mercurial