toolkit/mozapps/extensions/content/update.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: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 // This UI is only opened from the Extension Manager when the app is upgraded.
michael@0 8
michael@0 9 "use strict";
michael@0 10
michael@0 11 const PREF_UPDATE_EXTENSIONS_ENABLED = "extensions.update.enabled";
michael@0 12 const PREF_XPINSTALL_ENABLED = "xpinstall.enabled";
michael@0 13 const PREF_EM_HOTFIX_ID = "extensions.hotfix.id";
michael@0 14
michael@0 15 // timeout (in milliseconds) to wait for response to the metadata ping
michael@0 16 const METADATA_TIMEOUT = 30000;
michael@0 17
michael@0 18 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 19 Components.utils.import("resource://gre/modules/AddonManager.jsm");
michael@0 20 Components.utils.import("resource://gre/modules/addons/AddonRepository.jsm");
michael@0 21
michael@0 22 Components.utils.import("resource://gre/modules/Log.jsm");
michael@0 23 let logger = Log.repository.getLogger("addons.update-dialog");
michael@0 24
michael@0 25 var gUpdateWizard = {
michael@0 26 // When synchronizing app compatibility info this contains all installed
michael@0 27 // add-ons. When checking for compatible versions this contains only
michael@0 28 // incompatible add-ons.
michael@0 29 addons: [],
michael@0 30 // Contains a list of add-ons that were disabled prior to the application
michael@0 31 // upgrade.
michael@0 32 inactiveAddonIDs: [],
michael@0 33 // The add-ons that we found updates available for
michael@0 34 addonsToUpdate: [],
michael@0 35 shouldSuggestAutoChecking: false,
michael@0 36 shouldAutoCheck: false,
michael@0 37 xpinstallEnabled: true,
michael@0 38 xpinstallLocked: false,
michael@0 39 // cached AddonInstall entries for add-ons we might want to update,
michael@0 40 // keyed by add-on ID
michael@0 41 addonInstalls: new Map(),
michael@0 42 shuttingDown: false,
michael@0 43 // Count the add-ons disabled by this update, enabled/disabled by
michael@0 44 // metadata checks, and upgraded.
michael@0 45 disabled: 0,
michael@0 46 metadataEnabled: 0,
michael@0 47 metadataDisabled: 0,
michael@0 48 upgraded: 0,
michael@0 49 upgradeFailed: 0,
michael@0 50 upgradeDeclined: 0,
michael@0 51
michael@0 52 init: function gUpdateWizard_init()
michael@0 53 {
michael@0 54 this.inactiveAddonIDs = window.arguments[0];
michael@0 55
michael@0 56 try {
michael@0 57 this.shouldSuggestAutoChecking =
michael@0 58 !Services.prefs.getBoolPref(PREF_UPDATE_EXTENSIONS_ENABLED);
michael@0 59 }
michael@0 60 catch (e) {
michael@0 61 }
michael@0 62
michael@0 63 try {
michael@0 64 this.xpinstallEnabled = Services.prefs.getBoolPref(PREF_XPINSTALL_ENABLED);
michael@0 65 this.xpinstallLocked = Services.prefs.prefIsLocked(PREF_XPINSTALL_ENABLED);
michael@0 66 }
michael@0 67 catch (e) {
michael@0 68 }
michael@0 69
michael@0 70 if (Services.io.offline)
michael@0 71 document.documentElement.currentPage = document.getElementById("offline");
michael@0 72 else
michael@0 73 document.documentElement.currentPage = document.getElementById("versioninfo");
michael@0 74 },
michael@0 75
michael@0 76 onWizardFinish: function gUpdateWizard_onWizardFinish ()
michael@0 77 {
michael@0 78 if (this.shouldSuggestAutoChecking)
michael@0 79 Services.prefs.setBoolPref(PREF_UPDATE_EXTENSIONS_ENABLED, this.shouldAutoCheck);
michael@0 80 },
michael@0 81
michael@0 82 _setUpButton: function gUpdateWizard_setUpButton(aButtonID, aButtonKey, aDisabled)
michael@0 83 {
michael@0 84 var strings = document.getElementById("updateStrings");
michael@0 85 var button = document.documentElement.getButton(aButtonID);
michael@0 86 if (aButtonKey) {
michael@0 87 button.label = strings.getString(aButtonKey);
michael@0 88 try {
michael@0 89 button.setAttribute("accesskey", strings.getString(aButtonKey + "Accesskey"));
michael@0 90 }
michael@0 91 catch (e) {
michael@0 92 }
michael@0 93 }
michael@0 94 button.disabled = aDisabled;
michael@0 95 },
michael@0 96
michael@0 97 setButtonLabels: function gUpdateWizard_setButtonLabels(aBackButton, aBackButtonIsDisabled,
michael@0 98 aNextButton, aNextButtonIsDisabled,
michael@0 99 aCancelButton, aCancelButtonIsDisabled)
michael@0 100 {
michael@0 101 this._setUpButton("back", aBackButton, aBackButtonIsDisabled);
michael@0 102 this._setUpButton("next", aNextButton, aNextButtonIsDisabled);
michael@0 103 this._setUpButton("cancel", aCancelButton, aCancelButtonIsDisabled);
michael@0 104 },
michael@0 105
michael@0 106 /////////////////////////////////////////////////////////////////////////////
michael@0 107 // Update Errors
michael@0 108 errorItems: [],
michael@0 109
michael@0 110 checkForErrors: function gUpdateWizard_checkForErrors(aElementIDToShow)
michael@0 111 {
michael@0 112 if (this.errorItems.length > 0)
michael@0 113 document.getElementById(aElementIDToShow).hidden = false;
michael@0 114 },
michael@0 115
michael@0 116 onWizardClose: function gUpdateWizard_onWizardClose(aEvent)
michael@0 117 {
michael@0 118 return this.onWizardCancel();
michael@0 119 },
michael@0 120
michael@0 121 onWizardCancel: function gUpdateWizard_onWizardCancel()
michael@0 122 {
michael@0 123 gUpdateWizard.shuttingDown = true;
michael@0 124 // Allow add-ons to continue downloading and installing
michael@0 125 // in the background, though some may require a later restart
michael@0 126 // Pages that are waiting for user input go into the background
michael@0 127 // on cancel
michael@0 128 if (gMismatchPage.waiting) {
michael@0 129 logger.info("Dialog closed in mismatch page");
michael@0 130 if (gUpdateWizard.addonInstalls.size > 0) {
michael@0 131 gInstallingPage.startInstalls([i for ([, i] of gUpdateWizard.addonInstalls)]);
michael@0 132 }
michael@0 133 return true;
michael@0 134 }
michael@0 135
michael@0 136 // Pages that do asynchronous things will just keep running and check
michael@0 137 // gUpdateWizard.shuttingDown to trigger background behaviour
michael@0 138 if (!gInstallingPage.installing) {
michael@0 139 logger.info("Dialog closed while waiting for updated compatibility information");
michael@0 140 }
michael@0 141 else {
michael@0 142 logger.info("Dialog closed while downloading and installing updates");
michael@0 143 }
michael@0 144 return true;
michael@0 145 }
michael@0 146 };
michael@0 147
michael@0 148 var gOfflinePage = {
michael@0 149 onPageAdvanced: function gOfflinePage_onPageAdvanced()
michael@0 150 {
michael@0 151 Services.io.offline = false;
michael@0 152 return true;
michael@0 153 },
michael@0 154
michael@0 155 toggleOffline: function gOfflinePage_toggleOffline()
michael@0 156 {
michael@0 157 var nextbtn = document.documentElement.getButton("next");
michael@0 158 nextbtn.disabled = !nextbtn.disabled;
michael@0 159 }
michael@0 160 }
michael@0 161
michael@0 162 // Addon listener to count addons enabled/disabled by metadata checks
michael@0 163 let listener = {
michael@0 164 onDisabled: function listener_onDisabled(aAddon) {
michael@0 165 logger.debug("onDisabled for ${id}", aAddon);
michael@0 166 gUpdateWizard.metadataDisabled++;
michael@0 167 },
michael@0 168 onEnabled: function listener_onEnabled(aAddon) {
michael@0 169 logger.debug("onEnabled for ${id}", aAddon);
michael@0 170 gUpdateWizard.metadataEnabled++;
michael@0 171 }
michael@0 172 };
michael@0 173
michael@0 174 var gVersionInfoPage = {
michael@0 175 _completeCount: 0,
michael@0 176 _totalCount: 0,
michael@0 177 _versionInfoDone: false,
michael@0 178 onPageShow: function gVersionInfoPage_onPageShow()
michael@0 179 {
michael@0 180 gUpdateWizard.setButtonLabels(null, true,
michael@0 181 "nextButtonText", true,
michael@0 182 "cancelButtonText", false);
michael@0 183
michael@0 184 try {
michael@0 185 var hotfixID = Services.prefs.getCharPref(PREF_EM_HOTFIX_ID);
michael@0 186 }
michael@0 187 catch (e) { }
michael@0 188
michael@0 189 // Retrieve all add-ons in order to sync their app compatibility information
michael@0 190 AddonManager.getAllAddons(function gVersionInfoPage_getAllAddons(aAddons) {
michael@0 191 if (gUpdateWizard.shuttingDown) {
michael@0 192 logger.debug("getAllAddons completed after dialog closed");
michael@0 193 }
michael@0 194
michael@0 195 gUpdateWizard.addons = [a for (a of aAddons)
michael@0 196 if (a.type != "plugin" && a.id != hotfixID)];
michael@0 197
michael@0 198 gVersionInfoPage._totalCount = gUpdateWizard.addons.length;
michael@0 199
michael@0 200 // Count the add-ons newly disabled by this application update
michael@0 201 for (let addon of gUpdateWizard.addons) {
michael@0 202 if (gUpdateWizard.inactiveAddonIDs.indexOf(addon.id) != -1) {
michael@0 203 gUpdateWizard.disabled++;
michael@0 204 }
michael@0 205 }
michael@0 206
michael@0 207 // Ensure compatibility overrides are up to date before checking for
michael@0 208 // individual addon updates.
michael@0 209 let ids = [addon.id for (addon of gUpdateWizard.addons)];
michael@0 210
michael@0 211 // Do the metadata ping, listening for any newly enabled/disabled add-ons.
michael@0 212 AddonManager.addAddonListener(listener);
michael@0 213 AddonRepository.repopulateCache(ids, function gVersionInfoPage_repopulateCache() {
michael@0 214
michael@0 215 if (gUpdateWizard.shuttingDown) {
michael@0 216 logger.debug("repopulateCache completed after dialog closed");
michael@0 217 }
michael@0 218
michael@0 219 for (let addon of gUpdateWizard.addons) {
michael@0 220 logger.debug("VersionInfo Finding updates for " + addon.id);
michael@0 221 addon.findUpdates(gVersionInfoPage, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED);
michael@0 222 }
michael@0 223 }, METADATA_TIMEOUT);
michael@0 224 });
michael@0 225 },
michael@0 226
michael@0 227 onAllUpdatesFinished: function gVersionInfoPage_onAllUpdatesFinished() {
michael@0 228 AddonManager.removeAddonListener(listener);
michael@0 229 AddonManagerPrivate.recordSimpleMeasure("appUpdate_disabled",
michael@0 230 gUpdateWizard.disabled);
michael@0 231 AddonManagerPrivate.recordSimpleMeasure("appUpdate_metadata_enabled",
michael@0 232 gUpdateWizard.metadataEnabled);
michael@0 233 AddonManagerPrivate.recordSimpleMeasure("appUpdate_metadata_disabled",
michael@0 234 gUpdateWizard.metadataDisabled);
michael@0 235 // Record 0 for these here in case we exit early; values will be replaced
michael@0 236 // later if we actually upgrade any.
michael@0 237 AddonManagerPrivate.recordSimpleMeasure("appUpdate_upgraded", 0);
michael@0 238 AddonManagerPrivate.recordSimpleMeasure("appUpdate_upgradeFailed", 0);
michael@0 239 AddonManagerPrivate.recordSimpleMeasure("appUpdate_upgradeDeclined", 0);
michael@0 240 // Filter out any add-ons that were disabled before the application was
michael@0 241 // upgraded or are already compatible
michael@0 242 logger.debug("VersionInfo updates finished: inactive " +
michael@0 243 gUpdateWizard.inactiveAddonIDs.toSource() + " found " +
michael@0 244 [addon.id + ":" + addon.appDisabled for (addon of gUpdateWizard.addons)].toSource());
michael@0 245 let filteredAddons = [];
michael@0 246 for (let a of gUpdateWizard.addons) {
michael@0 247 if (a.appDisabled && gUpdateWizard.inactiveAddonIDs.indexOf(a.id) < 0) {
michael@0 248 logger.debug("Continuing with add-on " + a.id);
michael@0 249 filteredAddons.push(a);
michael@0 250 }
michael@0 251 else if (gUpdateWizard.addonInstalls.has(a.id)) {
michael@0 252 gUpdateWizard.addonInstalls.get(a.id).cancel();
michael@0 253 gUpdateWizard.addonInstalls.delete(a.id);
michael@0 254 }
michael@0 255 }
michael@0 256 gUpdateWizard.addons = filteredAddons;
michael@0 257
michael@0 258 if (gUpdateWizard.shuttingDown) {
michael@0 259 // jump directly to updating auto-update add-ons in the background
michael@0 260 if (gUpdateWizard.addonInstalls.size > 0) {
michael@0 261 gInstallingPage.startInstalls([i for ([, i] of gUpdateWizard.addonInstalls)]);
michael@0 262 }
michael@0 263 return;
michael@0 264 }
michael@0 265
michael@0 266 if (filteredAddons.length > 0) {
michael@0 267 if (!gUpdateWizard.xpinstallEnabled && gUpdateWizard.xpinstallLocked) {
michael@0 268 document.documentElement.currentPage = document.getElementById("adminDisabled");
michael@0 269 return;
michael@0 270 }
michael@0 271 document.documentElement.currentPage = document.getElementById("mismatch");
michael@0 272 }
michael@0 273 else {
michael@0 274 logger.info("VersionInfo: No updates require further action");
michael@0 275 // VersionInfo compatibility updates resolved all compatibility problems,
michael@0 276 // close this window and continue starting the application...
michael@0 277 //XXX Bug 314754 - We need to use setTimeout to close the window due to
michael@0 278 // the EM using xmlHttpRequest when checking for updates.
michael@0 279 setTimeout(close, 0);
michael@0 280 }
michael@0 281 },
michael@0 282
michael@0 283 /////////////////////////////////////////////////////////////////////////////
michael@0 284 // UpdateListener
michael@0 285 onUpdateFinished: function gVersionInfoPage_onUpdateFinished(aAddon, status) {
michael@0 286 ++this._completeCount;
michael@0 287
michael@0 288 if (status != AddonManager.UPDATE_STATUS_NO_ERROR) {
michael@0 289 logger.debug("VersionInfo update " + this._completeCount + " of " + this._totalCount +
michael@0 290 " failed for " + aAddon.id + ": " + status);
michael@0 291 gUpdateWizard.errorItems.push(aAddon);
michael@0 292 }
michael@0 293 else {
michael@0 294 logger.debug("VersionInfo update " + this._completeCount + " of " + this._totalCount +
michael@0 295 " finished for " + aAddon.id);
michael@0 296 }
michael@0 297
michael@0 298 // If we're not in the background, just make a list of add-ons that have
michael@0 299 // updates available
michael@0 300 if (!gUpdateWizard.shuttingDown) {
michael@0 301 // If we're still in the update check window and the add-on is now active
michael@0 302 // then it won't have been disabled by startup
michael@0 303 if (aAddon.active) {
michael@0 304 AddonManagerPrivate.removeStartupChange("disabled", aAddon.id);
michael@0 305 gUpdateWizard.metadataEnabled++;
michael@0 306 }
michael@0 307
michael@0 308 // Update the status text and progress bar
michael@0 309 var updateStrings = document.getElementById("updateStrings");
michael@0 310 var statusElt = document.getElementById("versioninfo.status");
michael@0 311 var statusString = updateStrings.getFormattedString("statusPrefix", [aAddon.name]);
michael@0 312 statusElt.setAttribute("value", statusString);
michael@0 313
michael@0 314 // Update the status text and progress bar
michael@0 315 var progress = document.getElementById("versioninfo.progress");
michael@0 316 progress.mode = "normal";
michael@0 317 progress.value = Math.ceil((this._completeCount / this._totalCount) * 100);
michael@0 318 }
michael@0 319
michael@0 320 if (this._completeCount == this._totalCount)
michael@0 321 this.onAllUpdatesFinished();
michael@0 322 },
michael@0 323
michael@0 324 onUpdateAvailable: function gVersionInfoPage_onUpdateAvailable(aAddon, aInstall) {
michael@0 325 logger.debug("VersionInfo got an install for " + aAddon.id + ": " + aAddon.version);
michael@0 326 gUpdateWizard.addonInstalls.set(aAddon.id, aInstall);
michael@0 327 },
michael@0 328 };
michael@0 329
michael@0 330 var gMismatchPage = {
michael@0 331 waiting: false,
michael@0 332
michael@0 333 onPageShow: function gMismatchPage_onPageShow()
michael@0 334 {
michael@0 335 gMismatchPage.waiting = true;
michael@0 336 gUpdateWizard.setButtonLabels(null, true,
michael@0 337 "mismatchCheckNow", false,
michael@0 338 "mismatchDontCheck", false);
michael@0 339 document.documentElement.getButton("next").focus();
michael@0 340
michael@0 341 var incompatible = document.getElementById("mismatch.incompatible");
michael@0 342 for (let addon of gUpdateWizard.addons) {
michael@0 343 var listitem = document.createElement("listitem");
michael@0 344 listitem.setAttribute("label", addon.name + " " + addon.version);
michael@0 345 incompatible.appendChild(listitem);
michael@0 346 }
michael@0 347 }
michael@0 348 };
michael@0 349
michael@0 350 var gUpdatePage = {
michael@0 351 _totalCount: 0,
michael@0 352 _completeCount: 0,
michael@0 353 onPageShow: function gUpdatePage_onPageShow()
michael@0 354 {
michael@0 355 gMismatchPage.waiting = false;
michael@0 356 gUpdateWizard.setButtonLabels(null, true,
michael@0 357 "nextButtonText", true,
michael@0 358 "cancelButtonText", false);
michael@0 359 document.documentElement.getButton("next").focus();
michael@0 360
michael@0 361 gUpdateWizard.errorItems = [];
michael@0 362
michael@0 363 this._totalCount = gUpdateWizard.addons.length;
michael@0 364 for (let addon of gUpdateWizard.addons) {
michael@0 365 logger.debug("UpdatePage requesting update for " + addon.id);
michael@0 366 // Redundant call to find updates again here when we already got them
michael@0 367 // in the VersionInfo page: https://bugzilla.mozilla.org/show_bug.cgi?id=960597
michael@0 368 addon.findUpdates(this, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED);
michael@0 369 }
michael@0 370 },
michael@0 371
michael@0 372 onAllUpdatesFinished: function gUpdatePage_onAllUpdatesFinished() {
michael@0 373 if (gUpdateWizard.shuttingDown)
michael@0 374 return;
michael@0 375
michael@0 376 var nextPage = document.getElementById("noupdates");
michael@0 377 if (gUpdateWizard.addonsToUpdate.length > 0)
michael@0 378 nextPage = document.getElementById("found");
michael@0 379 document.documentElement.currentPage = nextPage;
michael@0 380 },
michael@0 381
michael@0 382 /////////////////////////////////////////////////////////////////////////////
michael@0 383 // UpdateListener
michael@0 384 onUpdateAvailable: function gUpdatePage_onUpdateAvailable(aAddon, aInstall) {
michael@0 385 logger.debug("UpdatePage got an update for " + aAddon.id + ": " + aAddon.version);
michael@0 386 gUpdateWizard.addonsToUpdate.push(aInstall);
michael@0 387 },
michael@0 388
michael@0 389 onUpdateFinished: function gUpdatePage_onUpdateFinished(aAddon, status) {
michael@0 390 if (status != AddonManager.UPDATE_STATUS_NO_ERROR)
michael@0 391 gUpdateWizard.errorItems.push(aAddon);
michael@0 392
michael@0 393 ++this._completeCount;
michael@0 394
michael@0 395 if (!gUpdateWizard.shuttingDown) {
michael@0 396 // Update the status text and progress bar
michael@0 397 var updateStrings = document.getElementById("updateStrings");
michael@0 398 var statusElt = document.getElementById("checking.status");
michael@0 399 var statusString = updateStrings.getFormattedString("statusPrefix", [aAddon.name]);
michael@0 400 statusElt.setAttribute("value", statusString);
michael@0 401
michael@0 402 var progress = document.getElementById("checking.progress");
michael@0 403 progress.value = Math.ceil((this._completeCount / this._totalCount) * 100);
michael@0 404 }
michael@0 405
michael@0 406 if (this._completeCount == this._totalCount)
michael@0 407 this.onAllUpdatesFinished()
michael@0 408 },
michael@0 409 };
michael@0 410
michael@0 411 var gFoundPage = {
michael@0 412 onPageShow: function gFoundPage_onPageShow()
michael@0 413 {
michael@0 414 gUpdateWizard.setButtonLabels(null, true,
michael@0 415 "installButtonText", false,
michael@0 416 null, false);
michael@0 417
michael@0 418 var foundUpdates = document.getElementById("found.updates");
michael@0 419 var itemCount = gUpdateWizard.addonsToUpdate.length;
michael@0 420 for (let install of gUpdateWizard.addonsToUpdate) {
michael@0 421 let listItem = foundUpdates.appendItem(install.name + " " + install.version);
michael@0 422 listItem.setAttribute("type", "checkbox");
michael@0 423 listItem.setAttribute("checked", "true");
michael@0 424 listItem.install = install;
michael@0 425 }
michael@0 426
michael@0 427 if (!gUpdateWizard.xpinstallEnabled) {
michael@0 428 document.getElementById("xpinstallDisabledAlert").hidden = false;
michael@0 429 document.getElementById("enableXPInstall").focus();
michael@0 430 document.documentElement.getButton("next").disabled = true;
michael@0 431 }
michael@0 432 else {
michael@0 433 document.documentElement.getButton("next").focus();
michael@0 434 document.documentElement.getButton("next").disabled = false;
michael@0 435 }
michael@0 436 },
michael@0 437
michael@0 438 toggleXPInstallEnable: function gFoundPage_toggleXPInstallEnable(aEvent)
michael@0 439 {
michael@0 440 var enabled = aEvent.target.checked;
michael@0 441 gUpdateWizard.xpinstallEnabled = enabled;
michael@0 442 var pref = Components.classes["@mozilla.org/preferences-service;1"]
michael@0 443 .getService(Components.interfaces.nsIPrefBranch);
michael@0 444 pref.setBoolPref(PREF_XPINSTALL_ENABLED, enabled);
michael@0 445 this.updateNextButton();
michael@0 446 },
michael@0 447
michael@0 448 updateNextButton: function gFoundPage_updateNextButton()
michael@0 449 {
michael@0 450 if (!gUpdateWizard.xpinstallEnabled) {
michael@0 451 document.documentElement.getButton("next").disabled = true;
michael@0 452 return;
michael@0 453 }
michael@0 454
michael@0 455 var oneChecked = false;
michael@0 456 var foundUpdates = document.getElementById("found.updates");
michael@0 457 var updates = foundUpdates.getElementsByTagName("listitem");
michael@0 458 for (let update of updates) {
michael@0 459 if (!update.checked)
michael@0 460 continue;
michael@0 461 oneChecked = true;
michael@0 462 break;
michael@0 463 }
michael@0 464
michael@0 465 gUpdateWizard.setButtonLabels(null, true,
michael@0 466 "installButtonText", true,
michael@0 467 null, false);
michael@0 468 document.getElementById("found").setAttribute("next", "installing");
michael@0 469 document.documentElement.getButton("next").disabled = !oneChecked;
michael@0 470 }
michael@0 471 };
michael@0 472
michael@0 473 var gInstallingPage = {
michael@0 474 _installs : [],
michael@0 475 _errors : [],
michael@0 476 _strings : null,
michael@0 477 _currentInstall : -1,
michael@0 478 _installing : false,
michael@0 479
michael@0 480 // Initialize fields we need for installing and tracking progress,
michael@0 481 // and start iterating through the installations
michael@0 482 startInstalls: function gInstallingPage_startInstalls(aInstallList) {
michael@0 483 if (!gUpdateWizard.xpinstallEnabled) {
michael@0 484 return;
michael@0 485 }
michael@0 486
michael@0 487 logger.debug("Start installs for "
michael@0 488 + [i.existingAddon.id for (i of aInstallList)].toSource());
michael@0 489 this._errors = [];
michael@0 490 this._installs = aInstallList;
michael@0 491 this._installing = true;
michael@0 492 this.startNextInstall();
michael@0 493 },
michael@0 494
michael@0 495 onPageShow: function gInstallingPage_onPageShow()
michael@0 496 {
michael@0 497 gUpdateWizard.setButtonLabels(null, true,
michael@0 498 "nextButtonText", true,
michael@0 499 null, true);
michael@0 500
michael@0 501 var foundUpdates = document.getElementById("found.updates");
michael@0 502 var updates = foundUpdates.getElementsByTagName("listitem");
michael@0 503 let toInstall = [];
michael@0 504 for (let update of updates) {
michael@0 505 if (!update.checked) {
michael@0 506 logger.info("User chose to cancel update of " + update.label);
michael@0 507 gUpdateWizard.upgradeDeclined++;
michael@0 508 update.install.cancel();
michael@0 509 continue;
michael@0 510 }
michael@0 511 toInstall.push(update.install);
michael@0 512 }
michael@0 513 this._strings = document.getElementById("updateStrings");
michael@0 514
michael@0 515 this.startInstalls(toInstall);
michael@0 516 },
michael@0 517
michael@0 518 startNextInstall: function gInstallingPage_startNextInstall() {
michael@0 519 if (this._currentInstall >= 0) {
michael@0 520 this._installs[this._currentInstall].removeListener(this);
michael@0 521 }
michael@0 522
michael@0 523 this._currentInstall++;
michael@0 524
michael@0 525 if (this._installs.length == this._currentInstall) {
michael@0 526 Services.obs.notifyObservers(null, "TEST:all-updates-done", null);
michael@0 527 AddonManagerPrivate.recordSimpleMeasure("appUpdate_upgraded",
michael@0 528 gUpdateWizard.upgraded);
michael@0 529 AddonManagerPrivate.recordSimpleMeasure("appUpdate_upgradeFailed",
michael@0 530 gUpdateWizard.upgradeFailed);
michael@0 531 AddonManagerPrivate.recordSimpleMeasure("appUpdate_upgradeDeclined",
michael@0 532 gUpdateWizard.upgradeDeclined);
michael@0 533 this._installing = false;
michael@0 534 if (gUpdateWizard.shuttingDown) {
michael@0 535 return;
michael@0 536 }
michael@0 537 var nextPage = this._errors.length > 0 ? "installerrors" : "finished";
michael@0 538 document.getElementById("installing").setAttribute("next", nextPage);
michael@0 539 document.documentElement.advance();
michael@0 540 return;
michael@0 541 }
michael@0 542
michael@0 543 let install = this._installs[this._currentInstall];
michael@0 544
michael@0 545 if (gUpdateWizard.shuttingDown && !AddonManager.shouldAutoUpdate(install.existingAddon)) {
michael@0 546 logger.debug("Don't update " + install.existingAddon.id + " in background");
michael@0 547 gUpdateWizard.upgradeDeclined++;
michael@0 548 install.cancel();
michael@0 549 this.startNextInstall();
michael@0 550 return;
michael@0 551 }
michael@0 552 install.addListener(this);
michael@0 553 install.install();
michael@0 554 },
michael@0 555
michael@0 556 /////////////////////////////////////////////////////////////////////////////
michael@0 557 // InstallListener
michael@0 558 onDownloadStarted: function gInstallingPage_onDownloadStarted(aInstall) {
michael@0 559 if (gUpdateWizard.shuttingDown) {
michael@0 560 return;
michael@0 561 }
michael@0 562 var strings = document.getElementById("updateStrings");
michael@0 563 var label = strings.getFormattedString("downloadingPrefix", [aInstall.name]);
michael@0 564 var actionItem = document.getElementById("actionItem");
michael@0 565 actionItem.value = label;
michael@0 566 },
michael@0 567
michael@0 568 onDownloadProgress: function gInstallingPage_onDownloadProgress(aInstall) {
michael@0 569 if (gUpdateWizard.shuttingDown) {
michael@0 570 return;
michael@0 571 }
michael@0 572 var downloadProgress = document.getElementById("downloadProgress");
michael@0 573 downloadProgress.value = Math.ceil(100 * aInstall.progress / aInstall.maxProgress);
michael@0 574 },
michael@0 575
michael@0 576 onDownloadEnded: function gInstallingPage_onDownloadEnded(aInstall) {
michael@0 577 },
michael@0 578
michael@0 579 onDownloadFailed: function gInstallingPage_onDownloadFailed(aInstall) {
michael@0 580 this._errors.push(aInstall);
michael@0 581
michael@0 582 gUpdateWizard.upgradeFailed++;
michael@0 583 this.startNextInstall();
michael@0 584 },
michael@0 585
michael@0 586 onInstallStarted: function gInstallingPage_onInstallStarted(aInstall) {
michael@0 587 if (gUpdateWizard.shuttingDown) {
michael@0 588 return;
michael@0 589 }
michael@0 590 var strings = document.getElementById("updateStrings");
michael@0 591 var label = strings.getFormattedString("installingPrefix", [aInstall.name]);
michael@0 592 var actionItem = document.getElementById("actionItem");
michael@0 593 actionItem.value = label;
michael@0 594 },
michael@0 595
michael@0 596 onInstallEnded: function gInstallingPage_onInstallEnded(aInstall, aAddon) {
michael@0 597 if (!gUpdateWizard.shuttingDown) {
michael@0 598 // Remember that this add-on was updated during startup
michael@0 599 AddonManagerPrivate.addStartupChange(AddonManager.STARTUP_CHANGE_CHANGED,
michael@0 600 aAddon.id);
michael@0 601 }
michael@0 602
michael@0 603 gUpdateWizard.upgraded++;
michael@0 604 this.startNextInstall();
michael@0 605 },
michael@0 606
michael@0 607 onInstallFailed: function gInstallingPage_onInstallFailed(aInstall) {
michael@0 608 this._errors.push(aInstall);
michael@0 609
michael@0 610 gUpdateWizard.upgradeFailed++;
michael@0 611 this.startNextInstall();
michael@0 612 }
michael@0 613 };
michael@0 614
michael@0 615 var gInstallErrorsPage = {
michael@0 616 onPageShow: function gInstallErrorsPage_onPageShow()
michael@0 617 {
michael@0 618 gUpdateWizard.setButtonLabels(null, true, null, true, null, true);
michael@0 619 document.documentElement.getButton("finish").focus();
michael@0 620 },
michael@0 621 };
michael@0 622
michael@0 623 // Displayed when there are incompatible add-ons and the xpinstall.enabled
michael@0 624 // pref is false and locked.
michael@0 625 var gAdminDisabledPage = {
michael@0 626 onPageShow: function gAdminDisabledPage_onPageShow()
michael@0 627 {
michael@0 628 gUpdateWizard.setButtonLabels(null, true, null, true,
michael@0 629 "cancelButtonText", true);
michael@0 630 document.documentElement.getButton("finish").focus();
michael@0 631 }
michael@0 632 };
michael@0 633
michael@0 634 // Displayed when selected add-on updates have been installed without error.
michael@0 635 // There can still be add-ons that are not compatible and don't have an update.
michael@0 636 var gFinishedPage = {
michael@0 637 onPageShow: function gFinishedPage_onPageShow()
michael@0 638 {
michael@0 639 gUpdateWizard.setButtonLabels(null, true, null, true, null, true);
michael@0 640 document.documentElement.getButton("finish").focus();
michael@0 641
michael@0 642 if (gUpdateWizard.shouldSuggestAutoChecking) {
michael@0 643 document.getElementById("finishedCheckDisabled").hidden = false;
michael@0 644 gUpdateWizard.shouldAutoCheck = true;
michael@0 645 }
michael@0 646 else
michael@0 647 document.getElementById("finishedCheckEnabled").hidden = false;
michael@0 648
michael@0 649 document.documentElement.getButton("finish").focus();
michael@0 650 }
michael@0 651 };
michael@0 652
michael@0 653 // Displayed when there are incompatible add-ons and there are no available
michael@0 654 // updates.
michael@0 655 var gNoUpdatesPage = {
michael@0 656 onPageShow: function gNoUpdatesPage_onPageLoad(aEvent)
michael@0 657 {
michael@0 658 gUpdateWizard.setButtonLabels(null, true, null, true, null, true);
michael@0 659 if (gUpdateWizard.shouldSuggestAutoChecking) {
michael@0 660 document.getElementById("noupdatesCheckDisabled").hidden = false;
michael@0 661 gUpdateWizard.shouldAutoCheck = true;
michael@0 662 }
michael@0 663 else
michael@0 664 document.getElementById("noupdatesCheckEnabled").hidden = false;
michael@0 665
michael@0 666 gUpdateWizard.checkForErrors("updateCheckErrorNotFound");
michael@0 667 document.documentElement.getButton("finish").focus();
michael@0 668 }
michael@0 669 };

mercurial