diff options
Diffstat (limited to 'toolkit/mozapps/update/content')
-rw-r--r-- | toolkit/mozapps/update/content/history.js | 96 | ||||
-rw-r--r-- | toolkit/mozapps/update/content/history.xhtml | 44 | ||||
-rw-r--r-- | toolkit/mozapps/update/content/updateElevation.js | 138 | ||||
-rw-r--r-- | toolkit/mozapps/update/content/updateElevation.xhtml | 80 |
4 files changed, 358 insertions, 0 deletions
diff --git a/toolkit/mozapps/update/content/history.js b/toolkit/mozapps/update/content/history.js new file mode 100644 index 0000000000..51de669af3 --- /dev/null +++ b/toolkit/mozapps/update/content/history.js @@ -0,0 +1,96 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* 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/. */ + +var gUpdateHistory = { + _view: null, + + /** + * Initialize the User Interface + */ + onLoad() { + this._view = document.getElementById("historyItems"); + + var um = Cc["@mozilla.org/updates/update-manager;1"].getService( + Ci.nsIUpdateManager + ); + var uc = um.getUpdateCount(); + if (uc) { + while (this._view.hasChildNodes()) { + this._view.firstChild.remove(); + } + + for (var i = 0; i < uc; ++i) { + var update = um.getUpdateAt(i); + + if (!update || !update.name) { + continue; + } + + // Don't display updates that are downloading since they don't have + // valid statusText for the UI (bug 485493). + if (!update.statusText) { + continue; + } + + var element = document.createXULElement("richlistitem"); + element.className = "update"; + + const topLine = document.createXULElement("hbox"); + const nameLabel = document.createXULElement("label"); + nameLabel.className = "update-name"; + document.l10n.setAttributes(nameLabel, "update-full-build-name", { + name: update.name, + buildID: update.buildID, + }); + topLine.appendChild(nameLabel); + + if (update.detailsURL) { + const detailsLink = document.createXULElement("label", { + is: "text-link", + }); + detailsLink.href = update.detailsURL; + document.l10n.setAttributes(detailsLink, "update-details"); + topLine.appendChild(detailsLink); + } + + const installedOnLabel = document.createXULElement("label"); + installedOnLabel.className = "update-installedOn-label"; + document.l10n.setAttributes(installedOnLabel, "update-installed-on", { + date: this._formatDate(update.installDate), + }); + + const statusLabel = document.createXULElement("label"); + statusLabel.className = "update-status-label"; + document.l10n.setAttributes(statusLabel, "update-status", { + status: update.statusText, + }); + + element.append(topLine, installedOnLabel, statusLabel); + this._view.appendChild(element); + } + } + var cancelbutton = document.getElementById("history").getButton("cancel"); + cancelbutton.focus(); + }, + + /** + * Formats a date into human readable form + * @param seconds + * A date in seconds since 1970 epoch + * @returns A human readable date string + */ + _formatDate(seconds) { + var date = new Date(seconds); + const dtOptions = { + year: "numeric", + month: "long", + day: "numeric", + hour: "numeric", + minute: "numeric", + second: "numeric", + }; + return date.toLocaleString(undefined, dtOptions); + }, +}; diff --git a/toolkit/mozapps/update/content/history.xhtml b/toolkit/mozapps/update/content/history.xhtml new file mode 100644 index 0000000000..9930ed9ce1 --- /dev/null +++ b/toolkit/mozapps/update/content/history.xhtml @@ -0,0 +1,44 @@ +<?xml version="1.0"?> + +<!-- 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/. --> + +<!DOCTYPE window> + +<window + windowtype="Update:History" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + xmlns:html="http://www.w3.org/1999/xhtml" + style="min-width: 35em" + data-l10n-id="close-button-label" + data-l10n-attrs="title" + onload="gUpdateHistory.onLoad();" +> + <dialog + id="history" + buttons="cancel" + defaultButton="cancel" + data-l10n-id="close-button-label" + data-l10n-attrs="buttonlabelcancel" + > + <linkset> + <html:link rel="stylesheet" href="chrome://global/skin/global.css" /> + <html:link + rel="stylesheet" + href="chrome://mozapps/skin/update/updates.css" + /> + + <html:link rel="localization" href="toolkit/updates/history.ftl" /> + </linkset> + + <script src="chrome://mozapps/content/update/history.js" /> + + <label data-l10n-id="history-intro"></label> + <separator class="thin" /> + <richlistbox id="historyItems"> + <label data-l10n-id="no-updates-label"></label> + </richlistbox> + <separator class="thin" /> + </dialog> +</window> diff --git a/toolkit/mozapps/update/content/updateElevation.js b/toolkit/mozapps/update/content/updateElevation.js new file mode 100644 index 0000000000..251a4b5618 --- /dev/null +++ b/toolkit/mozapps/update/content/updateElevation.js @@ -0,0 +1,138 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- + * + * 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/. */ + +/* This is temporary until bug 1521632 is fixed */ + +"use strict"; + +/* import-globals-from /toolkit/content/contentAreaUtils.js */ + +const gUpdateElevationDialog = { + openUpdateURL(event) { + if (event.button == 0) { + openURL(event.target.getAttribute("url")); + } + }, + getAUSString(key, strings) { + if (strings) { + return this.strings.getFormattedString(key, strings); + } + return this.strings.getString(key); + }, + _setButton(button, string) { + var label = this.getAUSString(string); + if (label.includes("%S")) { + label = label.replace(/%S/, this.brandName); + } + button.label = label; + button.setAttribute("accesskey", this.getAUSString(string + ".accesskey")); + }, + onLoad() { + this.strings = document.getElementById("updateStrings"); + this.brandName = document + .getElementById("brandStrings") + .getString("brandShortName"); + + let um = Cc["@mozilla.org/updates/update-manager;1"].getService( + Ci.nsIUpdateManager + ); + let update = um.readyUpdate; + let updateFinishedName = document.getElementById("updateFinishedName"); + updateFinishedName.value = update.name; + + let link = document.getElementById("detailsLinkLabel"); + if (update.detailsURL) { + link.setAttribute("url", update.detailsURL); + // The details link is stealing focus so it is disabled by default and + // should only be enabled after onPageShow has been called. + link.disabled = false; + } else { + link.hidden = true; + } + + let manualLinkLabel = document.getElementById("manualLinkLabel"); + let manualURL = Services.urlFormatter.formatURLPref( + "app.update.url.manual" + ); + manualLinkLabel.value = manualURL; + manualLinkLabel.setAttribute("url", manualURL); + + let button = document.getElementById("elevateExtra2"); + this._setButton(button, "restartLaterButton"); + button = document.getElementById("elevateExtra1"); + this._setButton(button, "noThanksButton"); + button = document.getElementById("elevateAccept"); + this._setButton(button, "restartNowButton"); + button.focus(); + }, + onRestartLater() { + window.close(); + }, + onNoThanks() { + Services.obs.notifyObservers(null, "update-canceled"); + let um = Cc["@mozilla.org/updates/update-manager;1"].getService( + Ci.nsIUpdateManager + ); + let update = um.readyUpdate; + um.cleanupReadyUpdate(); + // Since the user has clicked "No Thanks", we should not prompt them to update to + // this version again unless they manually select "Check for Updates..." + // which will clear app.update.elevate.never preference. + let aus = Cc["@mozilla.org/updates/update-service;1"].getService( + Ci.nsIApplicationUpdateService + ); + if (aus.elevationRequired && update) { + Services.prefs.setCharPref("app.update.elevate.never", update.appVersion); + } + window.close(); + }, + onRestartNow() { + // disable the "finish" (Restart) and "extra1" (Later) buttons + // because the Software Update wizard is still up at the point, + // and will remain up until we return and we close the + // window with a |window.close()| in wizard.xml + // (it was the firing the "wizardfinish" event that got us here.) + // This prevents the user from switching back + // to the Software Update dialog and clicking "Restart" or "Later" + // when dealing with the "confirm close" prompts. + // See bug #350299 for more details. + document.getElementById("elevateExtra2").disabled = true; + document.getElementById("elevateExtra1").disabled = true; + document.getElementById("elevateAccept").disabled = true; + + // This dialog was shown because elevation was required so there is no need + // to check if elevation is required again. + let um = Cc["@mozilla.org/updates/update-manager;1"].getService( + Ci.nsIUpdateManager + ); + um.elevationOptedIn(); + + // Notify all windows that an application quit has been requested. + let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance( + Ci.nsISupportsPRBool + ); + Services.obs.notifyObservers( + cancelQuit, + "quit-application-requested", + "restart" + ); + + // Something aborted the quit process. + if (cancelQuit.data) { + return; + } + + // If already in safe mode restart in safe mode (bug 327119) + if (Services.appinfo.inSafeMode) { + Services.env.set("MOZ_SAFE_MODE_RESTART", "1"); + } + + // Restart the application + Services.startup.quit( + Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart + ); + }, +}; diff --git a/toolkit/mozapps/update/content/updateElevation.xhtml b/toolkit/mozapps/update/content/updateElevation.xhtml new file mode 100644 index 0000000000..0504feeb42 --- /dev/null +++ b/toolkit/mozapps/update/content/updateElevation.xhtml @@ -0,0 +1,80 @@ +<?xml version="1.0"?> + +<!-- 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/. --> + +<!-- This is temporary until bug 1521632 is fixed --> + +<window windowtype="Update:Elevation" + type="child" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + xmlns:html="http://www.w3.org/1999/xhtml" + data-l10n-id="elevation-update-wizard" + data-l10n-attrs="title" + style="width: auto; height: auto" + onload="gUpdateElevationDialog.onLoad();"> +<dialog id="updates" + buttons="extra2,extra1,accept"> + + <script src="chrome://global/content/contentAreaUtils.js"/> + <script src="chrome://global/content/globalOverlay.js"/> + <script src="chrome://global/content/editMenuOverlay.js"/> + <script src="chrome://mozapps/content/update/updateElevation.js"/> + +<linkset> + <html:link rel="stylesheet" href="chrome://global/skin/global.css" /> + <html:link rel="stylesheet" href="chrome://mozapps/skin/update/updates.css" /> + + <html:link rel="localization" href="branding/brand.ftl"/> + <html:link rel="localization" href="toolkit/updates/elevation.ftl"/> +</linkset> + +#if defined(XP_MACOSX) && MOZ_BUILD_APP == browser +#include ../../../../browser/base/content/macWindow.inc.xhtml +#endif + + <stringbundleset id="updateSet"> + <stringbundle id="brandStrings" src="chrome://branding/locale/brand.properties"/> + <stringbundle id="updateStrings" src="chrome://mozapps/locale/update/updates.properties"/> + </stringbundleset> + + <vbox id="elevationBox"> + <hbox class="update-header" flex="1"> + <vbox class="update-header-box-1"> + <vbox class="update-header-box-text"> + <label class="update-header-label" data-l10n-id="elevation-finished-page"/> + </vbox> + </vbox> + </hbox> + <vbox class="update-content" flex="1"> + <label data-l10n-id="elevation-finished-background-page"/> + <separator/> + <hbox align="center"> + <label data-l10n-id="elevation-finished-background"/> + <label id="updateFinishedName" flex="1" crop="end" value=""/> + <label id="detailsLinkLabel" disabled="true" is="text-link" + data-l10n-id="elevation-details-link-label" + onclick="gUpdateElevationDialog.openUpdateURL(event);"/> + </hbox> + <spacer flex="1"/> + <label id="finishedBackgroundMoreElevated" data-l10n-id="elevation-more-elevated"/> + <label data-l10n-id="elevation-error-manual"/> + <hbox> + <label id="manualLinkLabel" is="text-link" value="" + onclick="gUpdateElevationDialog.openUpdateURL(event);"/> + </hbox> + </vbox> + </vbox> + <separator class="groove update-buttons-separator"/> + <hbox id="update-button-box" pack="end"> + <button id="elevateExtra2" dlgtype="extra2" label="" class="dialog-button" + oncommand="gUpdateElevationDialog.onRestartLater();" /> + <button id="elevateExtra1" dlgtype="extra1" label="" class="dialog-button" + oncommand="gUpdateElevationDialog.onNoThanks();" /> + <spacer flex="1"/> + <button id="elevateAccept" dlgtype="accept" label="" class="dialog-button" + oncommand="gUpdateElevationDialog.onRestartNow();" default="true"/> + </hbox> +</dialog> +</window> |