Bug 1318562 - Remove Navigator.updateManager; r=baku

This commit is contained in:
Ehsan Akhgari 2016-11-17 19:14:07 -05:00
Родитель f0f85366d9
Коммит a0a6c1cd33
17 изменённых файлов: 1 добавлений и 1828 удалений

Просмотреть файл

@ -500,9 +500,6 @@ pref("app.update.socket.maxErrors", 20);
// Enable update logging for now, to diagnose growing pains in the
// field.
pref("app.update.log", true);
// SystemUpdate API
pref("dom.system_update.active", "@mozilla.org/updates/update-prompt;1");
#else
// Explicitly disable the shutdown watchdog. It's enabled by default.
// When the updater is disabled, we want to know about shutdown hangs.
@ -939,9 +936,6 @@ pref("identity.fxaccounts.skipDeviceRegistration", true);
// Enable mapped array buffer.
pref("dom.mapped_arraybuffer.enabled", true);
// SystemUpdate API
pref("dom.system_update.enabled", true);
// UDPSocket API
pref("dom.udpsocket.enabled", true);

Просмотреть файл

@ -9,13 +9,6 @@ contract @mozilla.org/system-alerts-service;1 {fe33c107-82a4-41d6-8c64-5353267e0
component {8c719f03-afe0-4aac-91ff-6c215895d467} ContentPermissionPrompt.js
contract @mozilla.org/content-permission/prompt;1 {8c719f03-afe0-4aac-91ff-6c215895d467}
#ifdef MOZ_UPDATER
# UpdatePrompt.js
component {88b3eb21-d072-4e3b-886d-f89d8c49fe59} UpdatePrompt.js
contract @mozilla.org/updates/update-prompt;1 {88b3eb21-d072-4e3b-886d-f89d8c49fe59}
category system-update-provider MozillaProvider @mozilla.org/updates/update-prompt;1,{88b3eb21-d072-4e3b-886d-f89d8c49fe59}
#endif
#ifdef MOZ_B2G
# DirectoryProvider.js
component {9181eb7c-6f87-11e1-90b1-4f59d80dd2e5} DirectoryProvider.js

Просмотреть файл

@ -1,783 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* 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/. */
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cr = Components.results;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/AppConstants.jsm");
const VERBOSE = 1;
var log =
VERBOSE ?
function log_dump(msg) { dump("UpdatePrompt: "+ msg +"\n"); } :
function log_noop(msg) { };
const PREF_APPLY_PROMPT_TIMEOUT = "b2g.update.apply-prompt-timeout";
const PREF_APPLY_IDLE_TIMEOUT = "b2g.update.apply-idle-timeout";
const PREF_DOWNLOAD_WATCHDOG_TIMEOUT = "b2g.update.download-watchdog-timeout";
const PREF_DOWNLOAD_WATCHDOG_MAX_RETRIES = "b2g.update.download-watchdog-max-retries";
const NETWORK_ERROR_OFFLINE = 111;
const HTTP_ERROR_OFFSET = 1000;
const STATE_DOWNLOADING = 'downloading';
XPCOMUtils.defineLazyServiceGetter(Services, "aus",
"@mozilla.org/updates/update-service;1",
"nsIApplicationUpdateService");
XPCOMUtils.defineLazyServiceGetter(Services, "um",
"@mozilla.org/updates/update-manager;1",
"nsIUpdateManager");
XPCOMUtils.defineLazyServiceGetter(Services, "idle",
"@mozilla.org/widget/idleservice;1",
"nsIIdleService");
XPCOMUtils.defineLazyServiceGetter(Services, "settings",
"@mozilla.org/settingsService;1",
"nsISettingsService");
XPCOMUtils.defineLazyServiceGetter(Services, 'env',
'@mozilla.org/process/environment;1',
'nsIEnvironment');
function useSettings() {
// When we're running in the real phone, then we can use settings.
// But when we're running as part of xpcshell, there is no settings database
// and trying to use settings in this scenario causes lots of weird
// assertions at shutdown time.
if (typeof useSettings.result === "undefined") {
useSettings.result = !Services.env.get("XPCSHELL_TEST_PROFILE_DIR");
}
return useSettings.result;
}
XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
"resource://gre/modules/SystemAppProxy.jsm");
function UpdateCheckListener(updatePrompt) {
this._updatePrompt = updatePrompt;
}
UpdateCheckListener.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdateCheckListener]),
_updatePrompt: null,
onCheckComplete: function UCL_onCheckComplete(request, updates, updateCount) {
if (Services.um.activeUpdate) {
// We're actively downloading an update, that's the update the user should
// see, even if a newer update is available.
this._updatePrompt.setUpdateStatus("active-update");
this._updatePrompt.showUpdateAvailable(Services.um.activeUpdate);
return;
}
if (updateCount == 0) {
this._updatePrompt.setUpdateStatus("no-updates");
if (this._updatePrompt._systemUpdateListener) {
this._updatePrompt._systemUpdateListener.onError("no-updates");
}
return;
}
let update = Services.aus.selectUpdate(updates, updateCount);
if (!update) {
this._updatePrompt.setUpdateStatus("already-latest-version");
if (this._updatePrompt._systemUpdateListener) {
this._updatePrompt._systemUpdateListener.onError("already-latest-version");
}
return;
}
this._updatePrompt.setUpdateStatus("check-complete");
this._updatePrompt.showUpdateAvailable(update);
},
onError: function UCL_onError(request, update) {
// nsIUpdate uses a signed integer for errorCode while any platform errors
// require all 32 bits.
let errorCode = update.errorCode >>> 0;
let isNSError = (errorCode >>> 31) == 1;
let errorMsg = "check-error-";
if (errorCode == NETWORK_ERROR_OFFLINE) {
errorMsg = "retry-when-online";
this._updatePrompt.setUpdateStatus(errorMsg);
} else if (isNSError) {
errorMsg = "check-error-" + errorCode;
this._updatePrompt.setUpdateStatus(errorMsg);
} else if (errorCode > HTTP_ERROR_OFFSET) {
let httpErrorCode = errorCode - HTTP_ERROR_OFFSET;
errorMsg = "check-error-http-" + httpErrorCode;
this._updatePrompt.setUpdateStatus(errorMsg);
}
if (this._updatePrompt._systemUpdateListener) {
this._updatePrompt._systemUpdateListener.onError(errorMsg);
}
Services.aus.QueryInterface(Ci.nsIUpdateCheckListener);
Services.aus.onError(request, update);
}
};
function UpdatePrompt() {
this.wrappedJSObject = this;
this._updateCheckListener = new UpdateCheckListener(this);
}
UpdatePrompt.prototype = {
classID: Components.ID("{88b3eb21-d072-4e3b-886d-f89d8c49fe59}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdatePrompt,
Ci.nsIUpdateCheckListener,
Ci.nsIRequestObserver,
Ci.nsIProgressEventSink,
Ci.nsIObserver,
Ci.nsISystemUpdateProvider]),
_xpcom_factory: XPCOMUtils.generateSingletonFactory(UpdatePrompt),
_update: null,
_applyPromptTimer: null,
_waitingForIdle: false,
_updateCheckListner: null,
_systemUpdateListener: null,
_availableParameters: {
"deviceinfo.last_updated": null,
"gecko.updateStatus": null,
"app.update.channel": null,
"app.update.interval": null,
"app.update.url": null,
},
_pendingUpdateAvailablePackageInfo: null,
_isPendingUpdateReady: false,
_updateErrorQueue: [ ],
_receivedUpdatePromptReady: false,
// nsISystemUpdateProvider
checkForUpdate: function() {
this.forceUpdateCheck();
},
startDownload: function() {
this.downloadUpdate(this._update);
},
stopDownload: function() {
this.handleDownloadCancel();
},
applyUpdate: function() {
this.handleApplyPromptResult({result: "restart"});
},
setParameter: function(aName, aValue) {
if (!this._availableParameters.hasOwnProperty(aName)) {
return false;
}
this._availableParameters[aName] = aValue;
switch (aName) {
case "app.update.channel":
case "app.update.url":
Services.prefs.setCharPref(aName, aValue);
break;
case "app.update.interval":
Services.prefs.setIntPref(aName, parseInt(aValue, 10));
break;
}
return true;
},
getParameter: function(aName) {
if (!this._availableParameters.hasOwnProperty(aName)) {
return null;
}
return this._availableParameters[aName];
},
setListener: function(aListener) {
this._systemUpdateListener = aListener;
// If an update is available or ready, trigger the event right away at this point.
if (this._pendingUpdateAvailablePackageInfo) {
this._systemUpdateListener.onUpdateAvailable(this._pendingUpdateAvailablePackageInfo.type,
this._pendingUpdateAvailablePackageInfo.version,
this._pendingUpdateAvailablePackageInfo.description,
this._pendingUpdateAvailablePackageInfo.buildDate,
this._pendingUpdateAvailablePackageInfo.size);
// Set null when the listener is attached.
this._pendingUpdateAvailablePackageInfo = null;
}
if (this._isPendingUpdateReady) {
this._systemUpdateListener.onUpdateReady();
this._isPendingUpdateReady = false;
}
},
unsetListener: function(aListener) {
this._systemUpdateListener = null;
},
get applyPromptTimeout() {
return Services.prefs.getIntPref(PREF_APPLY_PROMPT_TIMEOUT);
},
get applyIdleTimeout() {
return Services.prefs.getIntPref(PREF_APPLY_IDLE_TIMEOUT);
},
handleContentStart: function UP_handleContentStart() {
SystemAppProxy.addEventListener("mozContentEvent", this);
},
// nsIUpdatePrompt
// FIXME/bug 737601: we should have users opt-in to downloading
// updates when on a billed pipe. Initially, opt-in for 3g, but
// that doesn't cover all cases.
checkForUpdates: function UP_checkForUpdates() { },
showUpdateAvailable: function UP_showUpdateAvailable(aUpdate) {
let packageInfo = {};
packageInfo.version = aUpdate.displayVersion;
packageInfo.description = aUpdate.statusText;
packageInfo.buildDate = aUpdate.buildID;
let patch = aUpdate.selectedPatch;
if (!patch && aUpdate.patchCount > 0) {
// For now we just check the first patch to get size information if a
// patch hasn't been selected yet.
patch = aUpdate.getPatchAt(0);
}
if (patch) {
packageInfo.size = patch.size;
packageInfo.type = patch.type;
} else {
log("Warning: no patches available in update");
}
this._pendingUpdateAvailablePackageInfo = packageInfo;
if (this._systemUpdateListener) {
this._systemUpdateListener.onUpdateAvailable(packageInfo.type,
packageInfo.version,
packageInfo.description,
packageInfo.buildDate,
packageInfo.size);
// Set null since the event is fired.
this._pendingUpdateAvailablePackageInfo = null;
}
if (!this.sendUpdateEvent("update-available", aUpdate)) {
log("Unable to prompt for available update, forcing download");
this.downloadUpdate(aUpdate);
}
},
showUpdateDownloaded: function UP_showUpdateDownloaded(aUpdate, aBackground) {
if (this._systemUpdateListener) {
this._systemUpdateListener.onUpdateReady();
} else {
this._isPendingUpdateReady = true;
}
// The update has been downloaded and staged. We send the update-downloaded
// event right away. After the user has been idle for a while, we send the
// update-prompt-restart event, increasing the chances that we can apply the
// update quietly without user intervention.
this.sendUpdateEvent("update-downloaded", aUpdate);
if (Services.idle.idleTime >= this.applyIdleTimeout) {
this.showApplyPrompt(aUpdate);
return;
}
let applyIdleTimeoutSeconds = this.applyIdleTimeout / 1000;
// We haven't been idle long enough, so register an observer
log("Update is ready to apply, registering idle timeout of " +
applyIdleTimeoutSeconds + " seconds before prompting.");
this._update = aUpdate;
this.waitForIdle();
},
storeUpdateError: function UP_storeUpdateError(aUpdate) {
log("Storing update error for later use");
this._updateErrorQueue.push(aUpdate);
},
sendStoredUpdateError: function UP_sendStoredUpdateError() {
log("Sending stored update error");
this._updateErrorQueue.forEach(aUpdate => {
this.sendUpdateEvent("update-error", aUpdate);
});
this._updateErrorQueue = [ ];
},
showUpdateError: function UP_showUpdateError(aUpdate) {
log("Update error, state: " + aUpdate.state + ", errorCode: " +
aUpdate.errorCode);
if (this._systemUpdateListener) {
this._systemUpdateListener.onError("update-error: " + aUpdate.errorCode + " " + aUpdate.statusText);
}
if (!this._receivedUpdatePromptReady) {
this.storeUpdateError(aUpdate);
} else {
this.sendUpdateEvent("update-error", aUpdate);
}
this.setUpdateStatus(aUpdate.statusText);
},
showUpdateHistory: function UP_showUpdateHistory(aParent) { },
showUpdateInstalled: function UP_showUpdateInstalled() {
this.setParameter("deviceinfo.last_updated", Date.now());
if (useSettings()) {
let lock = Services.settings.createLock();
lock.set("deviceinfo.last_updated", Date.now(), null, null);
}
},
// Custom functions
waitForIdle: function UP_waitForIdle() {
if (this._waitingForIdle) {
return;
}
this._waitingForIdle = true;
Services.idle.addIdleObserver(this, this.applyIdleTimeout / 1000);
Services.obs.addObserver(this, "quit-application", false);
},
setUpdateStatus: function UP_setUpdateStatus(aStatus) {
this.setParameter("gecko.updateStatus", aStatus);
if (useSettings()) {
log("Setting gecko.updateStatus: " + aStatus);
let lock = Services.settings.createLock();
lock.set("gecko.updateStatus", aStatus, null);
}
},
showApplyPrompt: function UP_showApplyPrompt(aUpdate) {
// Notify update package is ready to apply
if (this._systemUpdateListener) {
this._systemUpdateListener.onUpdateReady();
} else {
// Set the flag to true and fire the onUpdateReady event when the listener is attached.
this._isPendingUpdateReady = true;
}
if (!this.sendUpdateEvent("update-prompt-apply", aUpdate)) {
log("Unable to prompt, forcing restart");
this.restartProcess();
return;
}
if (AppConstants.MOZ_B2G_RIL) {
let window = Services.wm.getMostRecentWindow("navigator:browser");
let pinReq = window.navigator.mozIccManager.getCardLock("pin");
pinReq.onsuccess = function(e) {
if (e.target.result.enabled) {
// The SIM is pin locked. Don't use a fallback timer. This means that
// the user has to press Install to apply the update. If we use the
// timer, and the timer reboots the phone, then the phone will be
// unusable until the SIM is unlocked.
log("SIM is pin locked. Not starting fallback timer.");
} else {
// This means that no pin lock is enabled, so we go ahead and start
// the fallback timer.
this._applyPromptTimer = this.createTimer(this.applyPromptTimeout);
}
}.bind(this);
pinReq.onerror = function(e) {
this._applyPromptTimer = this.createTimer(this.applyPromptTimeout);
}.bind(this);
} else {
// Schedule a fallback timeout in case the UI is unable to respond or show
// a prompt for some reason.
this._applyPromptTimer = this.createTimer(this.applyPromptTimeout);
}
},
_copyProperties: ["appVersion", "buildID", "detailsURL", "displayVersion",
"errorCode", "isOSUpdate", "platformVersion",
"previousAppVersion", "state", "statusText"],
sendUpdateEvent: function UP_sendUpdateEvent(aType, aUpdate) {
let detail = {};
for (let property of this._copyProperties) {
detail[property] = aUpdate[property];
}
let patch = aUpdate.selectedPatch;
if (!patch && aUpdate.patchCount > 0) {
// For now we just check the first patch to get size information if a
// patch hasn't been selected yet.
patch = aUpdate.getPatchAt(0);
}
if (patch) {
detail.size = patch.size;
detail.updateType = patch.type;
} else {
log("Warning: no patches available in update");
}
this._update = aUpdate;
return this.sendChromeEvent(aType, detail);
},
sendChromeEvent: function UP_sendChromeEvent(aType, aDetail) {
let detail = aDetail || {};
detail.type = aType;
let sent = SystemAppProxy.dispatchEvent(detail);
if (!sent) {
log("Warning: Couldn't send update event " + aType +
": no content browser. Will send again when content becomes available.");
return false;
}
return true;
},
handleAvailableResult: function UP_handleAvailableResult(aDetail) {
// If the user doesn't choose "download", the updater will implicitly call
// showUpdateAvailable again after a certain period of time
switch (aDetail.result) {
case "download":
this.downloadUpdate(this._update);
break;
}
},
handleApplyPromptResult: function UP_handleApplyPromptResult(aDetail) {
if (this._applyPromptTimer) {
this._applyPromptTimer.cancel();
this._applyPromptTimer = null;
}
switch (aDetail.result) {
// Battery not okay, do not wait for idle to re-prompt
case "low-battery":
break;
case "wait":
// Wait until the user is idle before prompting to apply the update
this.waitForIdle();
break;
case "restart":
this.finishUpdate();
this._update = null;
break;
}
},
downloadUpdate: function UP_downloadUpdate(aUpdate) {
if (!aUpdate) {
aUpdate = Services.um.activeUpdate;
if (!aUpdate) {
log("No active update found to download");
return;
}
}
let status = Services.aus.downloadUpdate(aUpdate, true);
if (status == STATE_DOWNLOADING) {
Services.aus.addDownloadListener(this);
return;
}
// If the update has already been downloaded and applied, then
// Services.aus.downloadUpdate will return immediately and not
// call showUpdateDownloaded, so we detect this.
if (aUpdate.state == "applied" && aUpdate.errorCode == 0) {
this.showUpdateDownloaded(aUpdate, true);
return;
}
log("Error downloading update " + aUpdate.name + ": " + aUpdate.errorCode);
let errorCode = aUpdate.errorCode >>> 0;
if (errorCode == Cr.NS_ERROR_FILE_TOO_BIG) {
aUpdate.statusText = "file-too-big";
}
this.showUpdateError(aUpdate);
},
handleDownloadCancel: function UP_handleDownloadCancel() {
log("Pausing download");
Services.aus.pauseDownload();
},
finishUpdate: function UP_finishUpdate() {
if (!this._update.isOSUpdate) {
// Standard gecko+gaia updates will just need to restart the process
this.restartProcess();
return;
}
try {
Services.aus.applyOsUpdate(this._update);
}
catch (e) {
this._update.errorCode = Cr.NS_ERROR_FAILURE;
this.showUpdateError(this._update);
}
},
restartProcess: function UP_restartProcess() {
log("Update downloaded, restarting to apply it");
let callbackAfterSet = function() {
if (AppConstants.platform !== "gonk") {
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"]
.getService(Ci.nsIAppStartup);
appStartup.quit(appStartup.eForceQuit | appStartup.eRestart);
} else {
// NB: on Gonk, we rely on the system process manager to restart us.
let pmService = Cc["@mozilla.org/power/powermanagerservice;1"]
.getService(Ci.nsIPowerManagerService);
pmService.restart();
}
}
if (useSettings()) {
// Save current os version in deviceinfo.previous_os
let lock = Services.settings.createLock({
handle: callbackAfterSet,
handleAbort: function(error) {
log("Abort callback when trying to set previous_os: " + error);
callbackAfterSet();
}
});
lock.get("deviceinfo.os", {
handle: function(name, value) {
log("Set previous_os to: " + value);
lock.set("deviceinfo.previous_os", value, null, null);
}
});
}
},
forceUpdateCheck: function UP_forceUpdateCheck() {
log("Forcing update check");
let checker = Cc["@mozilla.org/updates/update-checker;1"]
.createInstance(Ci.nsIUpdateChecker);
checker.checkForUpdates(this._updateCheckListener, true);
},
handleEvent: function UP_handleEvent(evt) {
if (evt.type !== "mozContentEvent") {
return;
}
let detail = evt.detail;
if (!detail) {
return;
}
switch (detail.type) {
case "force-update-check":
this.forceUpdateCheck();
break;
case "update-available-result":
this.handleAvailableResult(detail);
// If we started the apply prompt timer, this means that we're waiting
// for the user to press Later or Install Now. In this situation we
// don't want to clear this._update, becuase handleApplyPromptResult
// needs it.
if (this._applyPromptTimer == null && !this._waitingForIdle) {
this._update = null;
}
break;
case "update-download-cancel":
this.handleDownloadCancel();
break;
case "update-prompt-apply-result":
this.handleApplyPromptResult(detail);
break;
case "update-prompt-ready":
this._receivedUpdatePromptReady = true;
this.sendStoredUpdateError();
break;
}
},
// nsIObserver
observe: function UP_observe(aSubject, aTopic, aData) {
switch (aTopic) {
case "idle":
this._waitingForIdle = false;
this.showApplyPrompt(this._update);
// Fall through
case "quit-application":
Services.idle.removeIdleObserver(this, this.applyIdleTimeout / 1000);
Services.obs.removeObserver(this, "quit-application");
break;
}
},
// nsITimerCallback
notify: function UP_notify(aTimer) {
if (aTimer == this._applyPromptTimer) {
log("Timed out waiting for result, restarting");
this._applyPromptTimer = null;
this.finishUpdate();
this._update = null;
return;
}
if (aTimer == this._watchdogTimer) {
log("Download watchdog fired");
this._watchdogTimer = null;
this._autoRestartDownload = true;
Services.aus.pauseDownload();
return;
}
},
createTimer: function UP_createTimer(aTimeoutMs) {
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(this, aTimeoutMs, timer.TYPE_ONE_SHOT);
return timer;
},
// nsIRequestObserver
_startedSent: false,
_watchdogTimer: null,
_autoRestartDownload: false,
_autoRestartCount: 0,
startWatchdogTimer: function UP_startWatchdogTimer() {
let watchdogTimeout = 120000; // 120 seconds
try {
watchdogTimeout = Services.prefs.getIntPref(PREF_DOWNLOAD_WATCHDOG_TIMEOUT);
} catch (e) {
// This means that the preference doesn't exist. watchdogTimeout will
// retain its default assigned above.
}
if (watchdogTimeout <= 0) {
// 0 implies don't bother using the watchdog timer at all.
this._watchdogTimer = null;
return;
}
if (this._watchdogTimer) {
this._watchdogTimer.cancel();
} else {
this._watchdogTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
}
this._watchdogTimer.initWithCallback(this, watchdogTimeout,
Ci.nsITimer.TYPE_ONE_SHOT);
},
stopWatchdogTimer: function UP_stopWatchdogTimer() {
if (this._watchdogTimer) {
this._watchdogTimer.cancel();
this._watchdogTimer = null;
}
},
touchWatchdogTimer: function UP_touchWatchdogTimer() {
this.startWatchdogTimer();
},
onStartRequest: function UP_onStartRequest(aRequest, aContext) {
// Wait until onProgress to send the update-download-started event, in case
// this request turns out to fail for some reason
this._startedSent = false;
this.startWatchdogTimer();
},
onStopRequest: function UP_onStopRequest(aRequest, aContext, aStatusCode) {
this.stopWatchdogTimer();
Services.aus.removeDownloadListener(this);
let paused = !Components.isSuccessCode(aStatusCode);
if (!paused) {
// The download was successful, no need to restart
this._autoRestartDownload = false;
}
if (this._autoRestartDownload) {
this._autoRestartDownload = false;
let watchdogMaxRetries = Services.prefs.getIntPref(PREF_DOWNLOAD_WATCHDOG_MAX_RETRIES);
this._autoRestartCount++;
if (this._autoRestartCount > watchdogMaxRetries) {
log("Download - retry count exceeded - error");
// We exceeded the max retries. Treat the download like an error,
// which will give the user a chance to restart manually later.
this._autoRestartCount = 0;
if (Services.um.activeUpdate) {
this.showUpdateError(Services.um.activeUpdate);
}
return;
}
log("Download - restarting download - attempt " + this._autoRestartCount);
this.downloadUpdate(null);
return;
}
this._autoRestartCount = 0;
this.sendChromeEvent("update-download-stopped", {
paused: paused
});
},
// nsIProgressEventSink
onProgress: function UP_onProgress(aRequest, aContext, aProgress,
aProgressMax) {
if (this._systemUpdateListener) {
this._systemUpdateListener.onProgress(aProgress, aProgressMax);
}
if (aProgress == aProgressMax) {
// The update.mar validation done by onStopRequest may take
// a while before the onStopRequest callback is made, so stop
// the timer now.
this.stopWatchdogTimer();
} else {
this.touchWatchdogTimer();
}
if (!this._startedSent) {
this.sendChromeEvent("update-download-started", {
total: aProgressMax
});
this._startedSent = true;
}
this.sendChromeEvent("update-download-progress", {
progress: aProgress,
total: aProgressMax
});
},
onStatus: function UP_onStatus(aRequest, aUpdate, aStatus, aStatusArg) { }
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([UpdatePrompt]);

Просмотреть файл

@ -41,11 +41,6 @@ if CONFIG['MOZ_B2G']:
'RecoveryService.js',
]
if CONFIG['MOZ_UPDATER']:
EXTRA_COMPONENTS += [
'UpdatePrompt.js',
]
EXTRA_JS_MODULES += [
'AboutServiceWorkers.jsm',
'ActivityChannel.jsm',

Просмотреть файл

@ -779,9 +779,6 @@ bin/libfreebl_32int64_3.so
#endif
@RESPATH@/components/AlertsService.js
@RESPATH@/components/ContentPermissionPrompt.js
#ifdef MOZ_UPDATER
@RESPATH@/components/UpdatePrompt.js
#endif
@RESPATH@/components/DirectoryProvider.js
@RESPATH@/components/ProcessGlobal.js
@RESPATH@/components/OMAContentHandler.js

Просмотреть файл

@ -1,2 +0,0 @@
component {e8530001-ba5b-46ab-a306-7fbeb692d0fe} SystemUpdateManager.js
contract @mozilla.org/system-update-manager;1 {e8530001-ba5b-46ab-a306-7fbeb692d0fe}

Просмотреть файл

@ -1,253 +0,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/. */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
var debug = Services.prefs.getBoolPref("dom.system_update.debug")
? (aMsg) => dump("-*- SystemUpdateManager.js : " + aMsg + "\n")
: (aMsg) => {};
const SYSTEMUPDATEPROVIDER_CID = Components.ID("{11fbea3d-fd94-459a-b8fb-557fe19e473a}");
const SYSTEMUPDATEMANAGER_CID = Components.ID("{e8530001-ba5b-46ab-a306-7fbeb692d0fe}");
const SYSTEMUPDATEMANAGER_CONTRACTID = "@mozilla.org/system-update-manager;1";
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
"@mozilla.org/childprocessmessagemanager;1",
"nsISyncMessageSender");
function SystemUpdateProvider(win, provider) {
this.initDOMRequestHelper(win, [
{name: "SystemUpdate:OnUpdateAvailable", weakRef: true},
{name: "SystemUpdate:OnProgress", weakRef: true},
{name: "SystemUpdate:OnUpdateReady", weakRef: true},
{name: "SystemUpdate:OnError", weakRef: true},
]);
this._provider = Cu.cloneInto(provider, win);
}
SystemUpdateProvider.prototype = {
__proto__: DOMRequestIpcHelper.prototype,
classID: SYSTEMUPDATEPROVIDER_CID,
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference,
Ci.nsIObserver]),
receiveMessage: function(aMsg) {
if (!aMsg || !aMsg.json) {
return;
}
let json = aMsg.json;
if (json.uuid !== this._provider.uuid) {
return;
}
debug("receive msg: " + aMsg.name);
switch (aMsg.name) {
case "SystemUpdate:OnUpdateAvailable": {
let detail = {
detail: {
packageInfo: json.packageInfo
}
};
let event = new this._window.CustomEvent("updateavailable",
Cu.cloneInto(detail, this._window));
this.__DOM_IMPL__.dispatchEvent(event);
break;
}
case "SystemUpdate:OnProgress": {
let event = new this._window.ProgressEvent("progress", {lengthComputable: true,
loaded: json.loaded,
total: json.total});
this.__DOM_IMPL__.dispatchEvent(event);
break;
}
case "SystemUpdate:OnUpdateReady": {
let event = new this._window.Event("updateready");
this.__DOM_IMPL__.dispatchEvent(event);
break;
}
case "SystemUpdate:OnError": {
let event = new this._window.ErrorEvent("error", {message: json.message});
this.__DOM_IMPL__.dispatchEvent(event);
break;
}
}
},
destroy: function() {
this.destroyDOMRequestHelper();
},
get name() {
return this._provider.name;
},
get uuid() {
return this._provider.uuid;
},
get onupdateavailable() {
return this.__DOM_IMPL__.getEventHandler("onupdateavailable");
},
set onupdateavailable(aHandler) {
this.__DOM_IMPL__.setEventHandler("onupdateavailable", aHandler);
},
get onprogress() {
return this.__DOM_IMPL__.getEventHandler("onprogress");
},
set onprogress(aHandler) {
this.__DOM_IMPL__.setEventHandler("onprogress", aHandler);
},
get onupdateready() {
return this.__DOM_IMPL__.getEventHandler("onupdateready");
},
set onupdateready(aHandler) {
this.__DOM_IMPL__.setEventHandler("onupdateready", aHandler);
},
get onerror() {
return this.__DOM_IMPL__.getEventHandler("onerror");
},
set onerror(aHandler) {
this.__DOM_IMPL__.setEventHandler("onerror", aHandler);
},
checkForUpdate: function() {
let self = this;
cpmm.sendAsyncMessage("SystemUpdate:CheckForUpdate", {
uuid: self._provider.uuid
});
},
startDownload: function() {
let self = this;
cpmm.sendAsyncMessage("SystemUpdate:StartDownload", {
uuid: self._provider.uuid
});
},
stopDownload: function() {
let self = this;
cpmm.sendAsyncMessage("SystemUpdate:StopDownload", {
uuid: self._provider.uuid
});
},
applyUpdate: function() {
let self = this;
cpmm.sendAsyncMessage("SystemUpdate:ApplyUpdate", {
uuid: self._provider.uuid
});
},
setParameter: function(aName, aValue) {
let self = this;
return cpmm.sendSyncMessage("SystemUpdate:SetParameter", {
uuid: self._provider.uuid,
name: aName,
value: aValue
})[0];
},
getParameter: function(aName) {
let self = this;
return cpmm.sendSyncMessage("SystemUpdate:GetParameter", {
uuid: self._provider.uuid,
name: aName
})[0];
},
};
function SystemUpdateManager() {}
SystemUpdateManager.prototype = {
__proto__: DOMRequestIpcHelper.prototype,
classID: SYSTEMUPDATEMANAGER_CID,
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference,
Ci.nsIObserver,
Ci.nsIDOMGlobalPropertyInitializer]),
receiveMessage: function(aMsg) {
if (!aMsg || !aMsg.json) {
return;
}
let json = aMsg.json;
let resolver = this.takePromiseResolver(json.requestId);
if (!resolver) {
return;
}
debug("receive msg: " + aMsg.name);
switch (aMsg.name) {
case "SystemUpdate:GetProviders:Result:OK": {
resolver.resolve(Cu.cloneInto(json.providers, this._window));
break;
}
case "SystemUpdate:SetActiveProvider:Result:OK":
case "SystemUpdate:GetActiveProvider:Result:OK": {
let updateProvider = new SystemUpdateProvider(this._window, json.provider);
resolver.resolve(this._window.SystemUpdateProvider._create(this._window,
updateProvider));
break;
}
case "SystemUpdate:GetProviders:Result:Error":
case "SystemUpdate:GetActiveProvider:Result:Error":
case "SystemUpdate:SetActiveProvider:Result:Error": {
resolver.reject(json.error);
break;
}
}
},
init: function(aWindow) {
this.initDOMRequestHelper(aWindow, [
{name: "SystemUpdate:GetProviders:Result:OK", weakRef: true},
{name: "SystemUpdate:GetProviders:Result:Error", weakRef: true},
{name: "SystemUpdate:GetActiveProvider:Result:OK", weakRef: true},
{name: "SystemUpdate:GetActiveProvider:Result:Error", weakRef: true},
{name: "SystemUpdate:SetActiveProvider:Result:OK", weakRef: true},
{name: "SystemUpdate:SetActiveProvider:Result:Error", weakRef: true},
]);
},
uninit: function() {
let self = this;
this.forEachPromiseResolver(function(aKey) {
self.takePromiseResolver(aKey).reject("SystemUpdateManager got destroyed");
});
},
getProviders: function() {
return this.createPromiseWithId(function(aResolverId) {
cpmm.sendAsyncMessage("SystemUpdate:GetProviders", {
requestId: aResolverId,
});
});
},
getActiveProvider: function() {
return this.createPromiseWithId(function(aResolverId) {
cpmm.sendAsyncMessage("SystemUpdate:GetActiveProvider", {
requestId: aResolverId,
});
});
},
setActiveProvider: function(aUuid) {
return this.createPromiseWithId(function(aResolverId) {
cpmm.sendAsyncMessage("SystemUpdate:SetActiveProvider", {
requestId: aResolverId,
uuid: aUuid
});
});
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SystemUpdateManager]);

Просмотреть файл

@ -1,376 +0,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/. */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
this.EXPORTED_SYMBOLS = ["SystemUpdateService"];
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
const CATEGORY_SYSTEM_UPDATE_PROVIDER = "system-update-provider";
const PROVIDER_ACTIVITY_IDLE = 0;
const PROVIDER_ACTIVITY_CHECKING = 1;
const PROVIDER_ACTIVITY_DOWNLOADING = 1 << 1;
const PROVIDER_ACTIVITY_APPLYING = 1 << 2;
var debug = Services.prefs.getBoolPref("dom.system_update.debug")
? (aMsg) => dump("-*- SystemUpdateService.jsm : " + aMsg + "\n")
: (aMsg) => {};
XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
"@mozilla.org/parentprocessmessagemanager;1",
"nsIMessageBroadcaster");
function ActiveProvider(aProvider) {
this.id = aProvider.id;
this._instance = Components.classesByID[aProvider.id].getService(Ci.nsISystemUpdateProvider);
this._instance.setListener(this);
}
ActiveProvider.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemUpdateListener]),
_activity: PROVIDER_ACTIVITY_IDLE,
destroy: function() {
if (this._instance) {
this._instance.unsetListener();
this._instance = null;
}
this.id = null;
},
checkForUpdate: function() {
this._execFuncIfNotInActivity(PROVIDER_ACTIVITY_CHECKING,
this._instance.checkForUpdate);
},
startDownload: function() {
this._execFuncIfNotInActivity(PROVIDER_ACTIVITY_DOWNLOADING,
this._instance.startDownload);
},
stopDownload: function() {
this._execFuncIfNotInActivity(PROVIDER_ACTIVITY_DOWNLOADING,
this._instance.stopDownload);
},
applyUpdate: function() {
this._execFuncIfNotInActivity(PROVIDER_ACTIVITY_APPLYING,
this._instance.applyUpdate);
},
setParameter: function(aName, aValue) {
return this._instance.setParameter(aName, aValue);
},
getParameter: function(aName) {
return this._instance.getParameter(aName);
},
// nsISystemUpdateListener
onUpdateAvailable: function(aType, aVersion, aDescription, aBuildDate, aSize) {
this._execFuncIfActiveAndInAction(PROVIDER_ACTIVITY_CHECKING, function() {
ppmm.broadcastAsyncMessage("SystemUpdate:OnUpdateAvailable", {
uuid: this.id,
packageInfo: {
type: aType,
version: aVersion,
description: aDescription,
buildDate: aBuildDate,
size: aSize,
}
});
this._unsetActivity(PROVIDER_ACTIVITY_CHECKING);
}.bind(this));
},
onProgress: function(aLoaded, aTotal) {
this._execFuncIfActiveAndInAction(PROVIDER_ACTIVITY_DOWNLOADING, function() {
ppmm.broadcastAsyncMessage("SystemUpdate:OnProgress", {
uuid: this.id,
loaded: aLoaded,
total: aTotal,
});
}.bind(this));
},
onUpdateReady: function() {
this._execFuncIfActiveAndInAction(PROVIDER_ACTIVITY_DOWNLOADING, function() {
ppmm.broadcastAsyncMessage("SystemUpdate:OnUpdateReady", {
uuid: this.id,
});
this._unsetActivity(PROVIDER_ACTIVITY_DOWNLOADING);
}.bind(this));
},
onError: function(aErrMsg) {
if (!SystemUpdateService._isActiveProviderId(this.id)) {
return;
}
ppmm.broadcastAsyncMessage("SystemUpdate:OnError", {
uuid: this.id,
message: aErrMsg,
});
this._activity = PROVIDER_ACTIVITY_IDLE;
},
isIdle: function() {
return this._activity === PROVIDER_ACTIVITY_IDLE;
},
_isInActivity: function(aActivity) {
return (this._activity & aActivity) !== PROVIDER_ACTIVITY_IDLE;
},
_setActivity: function(aActivity) {
this._activity |= aActivity;
},
_unsetActivity: function(aActivity) {
this._activity &= ~aActivity;
},
_execFuncIfNotInActivity: function(aActivity, aFunc) {
if (!this._isInActivity(aActivity)) {
this._setActivity(aActivity);
aFunc();
}
},
_execFuncIfActiveAndInAction: function(aActivity, aFunc) {
if (!SystemUpdateService._isActiveProviderId(this.id)) {
return;
}
if (this._isInActivity(aActivity)) {
aFunc();
}
},
};
this.SystemUpdateService = {
_providers: [],
_activeProvider: null,
_updateActiveProvider: function(aProvider) {
if (this._activeProvider) {
this._activeProvider.destroy();
}
this._activeProvider = new ActiveProvider(aProvider);
},
_isActiveProviderId: function(aId) {
return (this._activeProvider && this._activeProvider.id === aId);
},
init: function() {
debug("init");
let messages = ["SystemUpdate:GetProviders",
"SystemUpdate:GetActiveProvider",
"SystemUpdate:SetActiveProvider",
"SystemUpdate:CheckForUpdate",
"SystemUpdate:StartDownload",
"SystemUpdate:StopDownload",
"SystemUpdate:ApplyUpdate",
"SystemUpdate:SetParameter",
"SystemUpdate:GetParameter"];
messages.forEach((function(aMsgName) {
ppmm.addMessageListener(aMsgName, this);
}).bind(this));
// load available provider list
let catMan = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
let entries = catMan.enumerateCategory(CATEGORY_SYSTEM_UPDATE_PROVIDER);
while (entries.hasMoreElements()) {
let name = entries.getNext().QueryInterface(Ci.nsISupportsCString).data;
let [contractId, id] = catMan.getCategoryEntry(CATEGORY_SYSTEM_UPDATE_PROVIDER, name).split(",");
this._providers.push({
id: id,
name: name,
contractId: contractId
});
}
debug("available providers: " + JSON.stringify(this._providers));
// setup default active provider
let defaultActive;
try {
defaultActive = Services.prefs.getCharPref("dom.system_update.active");
} catch (e) {}
if (defaultActive) {
let defaultProvider = this._providers.find(function(aProvider) {
return aProvider.contractId === defaultActive;
});
if (defaultProvider) {
this._updateActiveProvider(defaultProvider);
}
}
},
addProvider: function(aClassId, aContractId, aName) {
debug("addProvider");
//did not allow null or empty string to add.
if(!aClassId || !aContractId || !aName) {
return;
}
let existedProvider = this._providers.find(function(provider) {
return provider.id === aClassId;
});
//skip if adding the existed provider.
if (existedProvider) {
debug("existing providers: " + JSON.stringify(existedProvider));
return;
}
//dynamically add the provider info to list.
this._providers.push({
id: aClassId,
name: aName,
contractId: aContractId
});
debug("available providers: " + JSON.stringify(this._providers));
},
getProviders: function(aData, aMm) {
debug("getProviders");
aData.providers = [];
for (let provider of this._providers) {
aData.providers.push({
name: provider.name,
uuid: provider.id
});
}
aMm.sendAsyncMessage("SystemUpdate:GetProviders:Result:OK", aData);
},
getActiveProvider: function(aData, aMm) {
debug("getActiveProvider");
let self = this;
let providerInfo = this._providers.find(function(provider) {
return self._isActiveProviderId(provider.id);
});
if (!providerInfo) {
aData.error = "NotFoundError";
aMm.sendAsyncMessage("SystemUpdate:GetActiveProvider:Result:Error", aData);
return;
}
aData.provider = {
name: providerInfo.name,
uuid: providerInfo.id
};
aMm.sendAsyncMessage("SystemUpdate:GetActiveProvider:Result:OK", aData);
},
setActiveProvider: function(aData, aMm) {
debug("setActiveProvider");
let self = this;
let selectedProvider = this._providers.find(function(provider) {
return provider.id === aData.uuid;
});
if (!selectedProvider) {
aData.error = "DataError";
aMm.sendAsyncMessage("SystemUpdate:SetActiveProvider:Result:Error", aData);
return;
}
if (!this._isActiveProviderId(selectedProvider.id)) {
// not allow changing active provider while there is an ongoing update activity
if (this.activeProvider && !this._activeProvider.isIdle()) {
aData.error = "DataError";
aMm.sendAsyncMessage("SystemUpdate:SetActiveProvider:Result:Error", aData);
return;
}
this._updateActiveProvider(selectedProvider);
Services.prefs.setCharPref("dom.system_update.active", selectedProvider.contractId);
}
aData.provider = {
name: selectedProvider.name,
uuid: selectedProvider.id
};
aMm.sendAsyncMessage("SystemUpdate:SetActiveProvider:Result:OK", aData);
},
receiveMessage: function(aMessage) {
let msg = aMessage.data || {};
let mm = aMessage.target;
switch (aMessage.name) {
case "SystemUpdate:GetProviders": {
this.getProviders(msg, mm);
break;
}
case "SystemUpdate:GetActiveProvider": {
this.getActiveProvider(msg, mm);
break;
}
case "SystemUpdate:SetActiveProvider": {
this.setActiveProvider(msg, mm);
break;
}
case "SystemUpdate:CheckForUpdate": {
if (this._isActiveProviderId(msg.uuid)) {
this._activeProvider.checkForUpdate();
}
break;
}
case "SystemUpdate:StartDownload": {
if (this._isActiveProviderId(msg.uuid)) {
this._activeProvider.startDownload();
}
break;
}
case "SystemUpdate:StopDownload": {
if (this._isActiveProviderId(msg.uuid)) {
this._activeProvider.stopDownload();
}
break;
}
case "SystemUpdate:ApplyUpdate": {
if (this._isActiveProviderId(msg.uuid)) {
this._activeProvider.applyUpdate();
}
break;
}
case "SystemUpdate:SetParameter": {
if (this._isActiveProviderId(msg.uuid)) {
return this._activeProvider.setParameter(msg.name, msg.value);
}
break;
}
case "SystemUpdate:GetParameter": {
if (this._isActiveProviderId(msg.uuid)) {
return this._activeProvider.getParameter(msg.name);
}
break;
}
}
},
};
SystemUpdateService.init();

Просмотреть файл

@ -19,7 +19,6 @@ elif toolkit in ('gtk2', 'gtk3'):
XPIDL_SOURCES += [
'nsIOSFileConstantsService.idl',
'nsISystemUpdateProvider.idl',
]
XPIDL_MODULE = 'dom_system'
@ -40,12 +39,6 @@ UNIFIED_SOURCES += [
EXTRA_COMPONENTS += [
'NetworkGeolocationProvider.js',
'NetworkGeolocationProvider.manifest',
'SystemUpdate.manifest',
'SystemUpdateManager.js',
]
EXTRA_JS_MODULES += [
'SystemUpdateService.jsm',
]
include('/ipc/chromium/chromium-config.mozbuild')

Просмотреть файл

@ -1,73 +0,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/. */
#include "nsISupports.idl"
[scriptable, uuid(775edbf5-b4a9-400c-b0ad-ea3c3a027097)]
interface nsISystemUpdateListener : nsISupports
{
/**
* callback for notifying an update package is available for download.
*/
void onUpdateAvailable(in DOMString type,
in DOMString version,
in DOMString description,
in unsigned long long buildDate,
in unsigned long long size);
/**
* callback for notifying the download progress.
*/
void onProgress(in unsigned long long loaded, in unsigned long long total);
/**
* callback for notifying an update package is ready to apply.
*/
void onUpdateReady();
/**
* callback for notifying any error while
* checking/downloading/applying an update package.
*/
void onError(in DOMString errMsg);
};
[scriptable, uuid(c9b7c166-b9cf-4396-a6de-39275e1c0a36)]
interface nsISystemUpdateProvider : nsISupports
{
void checkForUpdate();
void startDownload();
void stopDownload();
void applyUpdate();
/**
* Set the available parameter to the update provider.
* The available parameter is implementation-dependent.
* e.g. "update-url", "last-update-date", "update-status", "update-interval"
*
* @param name The number of languages.
* @param languages An array of languages.
* @return true when setting an available parameter,
* false when setting an unavailable parameter.
*/
bool setParameter(in DOMString name, in DOMString value);
/**
* Get the available parameter from the update provider.
* The available parameter is implementation-dependent.
*
* @param name The available parameter.
* @return The corresponding value to the name.
* Return null if try to get unavailable parameter.
*/
DOMString getParameter(in DOMString name);
/**
* NOTE TO IMPLEMENTORS:
* Need to consider if it is necessary to fire the pending event when
* registering the listener.
* (E.g. UpdateAvailable or UpdateReady event.)
*/
void setListener(in nsISystemUpdateListener listener);
void unsetListener();
};

Просмотреть файл

@ -1,8 +1,5 @@
[DEFAULT]
support-files =
preload-SystemUpdateManager-jsm.js
file_bug1197901.html
[test_bug1197901.html]
[test_system_update_enabled.html]
skip-if = true # Tests only ran on B2G

Просмотреть файл

@ -1,80 +0,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/. */
'use strict';
const {classes: Cc, interfaces: Ci, utils: Cu, manager: Cm} = Components;
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
const cid = '{17a84227-28f4-453d-9b80-9ae75a5682e0}';
const contractId = '@mozilla.org/test-update-provider;1';
function TestUpdateProvider() {}
TestUpdateProvider.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemUpdateProvider]),
checkForUpdate: function() {
dump('check for update');
this._listener.onUpdateAvailable('test-type', 'test-version', 'test-description', Date.now().valueOf(), 5566);
},
startDownload: function() {
dump('test start download');
this._listener.onProgress(10, 100);
},
stopDownload: function() {
dump('test stop download');
},
applyUpdate: function() {
dump('apply update');
},
setParameter: function(name, value) {
dump('set parameter');
return (name === 'dummy' && value === 'dummy-value');
},
getParameter: function(name) {
dump('get parameter');
if (name === 'dummy') {
return 'dummy-value';
}
},
setListener: function(listener) {
this._listener = listener;
},
unsetListener: function() {
this._listener = null;
},
};
var factory = {
createInstance: function(outer, iid) {
if (outer) {
throw Components.results.NS_ERROR_NO_AGGREGATION;
}
return new TestUpdateProvider().QueryInterface(iid);
},
lockFactory: function(aLock) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory])
};
Cm.nsIComponentRegistrar.registerFactory(Components.ID(cid), '', contractId, factory);
var cm = Cc['@mozilla.org/categorymanager;1'].getService(Ci.nsICategoryManager);
cm.addCategoryEntry('system-update-provider', 'DummyProvider',
contractId + ',' + cid, false, true);
Cu.import('resource://gre/modules/SystemUpdateService.jsm');
this.SystemUpdateService.addProvider('{17a84227-28f4-453d-9b80-9ae75a5682e0}',
'@mozilla.org/test-update-provider;1',
'DummyProvider');

Просмотреть файл

@ -1,175 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1037329
-->
<head>
<meta charset="utf-8">
<title>System Update API Test</title>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1037329">Test System Update API</a>
<script type="application/javascript;version=1.8">
'use strict';
SimpleTest.waitForExplicitFinish();
function setup() {
window.gUrl = SimpleTest.getTestFileURL('preload-SystemUpdateManager-jsm.js');
window.gScript = SpecialPowers.loadChromeScript(gUrl);
return Promise.resolve();
}
function testGetProviders() {
return new Promise(function(resolve, reject) {
navigator.updateManager.getProviders().then(function(providerInfos) {
info('num of providers: ' + providerInfos.length);
for (let providerInfo of providerInfos) {
info('provider info: ' + JSON.stringify(providerInfo));
}
resolve(providerInfos);
});
});
}
function testSetActiveProvider(providerInfos) {
return new Promise(function(resolve, reject) {
//Find the mock provider for our testing provider instead.
//Set the mock provider as active provider.
let targetProvider = providerInfos[0];
for(let provider of providerInfos) {
if(provider.uuid == "{17a84227-28f4-453d-9b80-9ae75a5682e0}") {
info('target provider uuid: ' + provider.uuid);
targetProvider = provider;
break;
}
}
is("{17a84227-28f4-453d-9b80-9ae75a5682e0}", targetProvider.uuid, 'get the dynamically added provider');
navigator.updateManager.setActiveProvider(targetProvider.uuid).then(function(activeProvider) {
info('active provider info: ' + JSON.stringify(activeProvider.info));
is(activeProvider.name, targetProvider.name, 'expected name of active provider');
is(activeProvider.uuid, targetProvider.uuid, 'expected uuid of active provider');
resolve({name : activeProvider.name, uuid : activeProvider.uuid});
});
});
}
function testGetActiveProvider(providerInfo) {
info('test GetActiveProvider');
return new Promise(function(resolve, reject) {
navigator.updateManager.getActiveProvider().then(function(activeProvider) {
is(activeProvider.name, providerInfo.name, 'expected name of active provider');
is(activeProvider.uuid, providerInfo.uuid, 'expected uuid of active provider');
resolve(activeProvider);
});
});
}
function testCheckForUpdate(provider) {
info('test CheckForUpdate');
return new Promise(function(resolve, reject) {
provider.addEventListener('updateavailable', function(event) {
ok(true, 'receive updateavailable event');
info('event: ' + JSON.stringify(event.detail));
resolve(provider);
});
provider.checkForUpdate();
});
}
function testStartDownload(provider) {
info('test StartDownload');
return new Promise(function(resolve, reject) {
provider.addEventListener('progress', function(event) {
ok(true, 'receive progress event');
is(event.loaded, 10, 'expected loaded');
is(event.total, 100, 'expected total');
resolve(provider);
});
provider.startDownload();
});
}
function testStopDownload(provider) {
info('test StopDownload');
return new Promise(function(resolve, reject) {
provider.stopDownload();
resolve(provider);
});
}
function testApplyUpdate(provider) {
info('test ApplyUpdate');
return new Promise(function(resolve, reject) {
provider.applyUpdate();
resolve(provider);
});
}
function testGetParameter(provider) {
info('test GetParameter');
return new Promise(function(resolve, reject) {
let dummy = provider.getParameter('dummy');
is(dummy, 'dummy-value', 'expected parameter');
resolve(provider);
});
}
function testSetParameter(provider) {
info('test SetParameter');
return new Promise(function(resolve, reject) {
provider.setParameter('dummy', 'dummy-value');
resolve();
});
}
function testSetActiveProviderError() {
info('test setActiveProvider error');
return new Promise(function(resolve, reject) {
navigator.updateManager.setActiveProvider('something not exsited').then(function(provider) {
ok(false, 'should not success');
resolve();
}, function(reason) {
info('error message: ' + reason);
ok(true, 'expected error while setActiveProvider');
resolve();
});
});
}
function runTest() {
ok(navigator.updateManager, 'should have navigator.updateManager');
setup()
.then(testGetProviders)
.then(testSetActiveProvider)
.then(testGetActiveProvider)
.then(testCheckForUpdate)
.then(testStartDownload)
.then(testStopDownload)
.then(testApplyUpdate)
.then(testGetParameter)
.then(testSetParameter)
.then(testSetActiveProviderError)
.then(function() {
info('test finished');
gScript.destroy();
SimpleTest.finish();
});
}
SpecialPowers.pushPermissions([
{type: 'system-update', allow: true, context: document},
], function() {
SpecialPowers.pushPrefEnv({
'set': [
['dom.system_update.enabled', true],
['dom.system_update.debug', true],
['dom.system_update.active', '@mozilla.org/test-update-provider;1'],
]
}, runTest);
}
);
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -1,48 +0,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/. */
dictionary SystemUpdateProviderInfo {
DOMString name = "";
DOMString uuid = "";
};
dictionary SystemUpdatePackageInfo {
DOMString type = "";
DOMString version = "";
DOMString description = "";
DOMTimeStamp buildDate = 0;
unsigned long long size = 0;
};
[JSImplementation="@mozilla.org/system-update-provider;1",
ChromeOnly,
Pref="dom.system_update.enabled"]
interface SystemUpdateProvider : EventTarget {
readonly attribute DOMString name;
readonly attribute DOMString uuid;
attribute EventHandler onupdateavailable;
attribute EventHandler onprogress;
attribute EventHandler onupdateready;
attribute EventHandler onerror;
void checkForUpdate();
void startDownload();
void stopDownload();
void applyUpdate();
boolean setParameter(DOMString name, DOMString value);
DOMString getParameter(DOMString name);
};
[NavigatorProperty="updateManager",
JSImplementation="@mozilla.org/system-update-manager;1",
ChromeOnly,
Pref="dom.system_update.enabled"]
interface SystemUpdateManager {
Promise<sequence<SystemUpdateProviderInfo>> getProviders();
Promise<SystemUpdateProvider> setActiveProvider(DOMString uuid);
Promise<SystemUpdateProvider> getActiveProvider();
};

Просмотреть файл

@ -519,7 +519,6 @@ WEBIDL_FILES = [
'SVGZoomAndPan.webidl',
'SVGZoomAndPanValues.webidl',
'SVGZoomEvent.webidl',
'SystemUpdate.webidl',
'TCPServerSocket.webidl',
'TCPServerSocketEvent.webidl',
'TCPSocket.webidl',

Просмотреть файл

@ -5232,10 +5232,6 @@ pref("dom.caches.enabled", true);
pref("camera.control.low_memory_thresholdMB", 404);
#endif
// SystemUpdate API
pref("dom.system_update.enabled", false);
pref("dom.system_update.debug", false);
// UDPSocket API
pref("dom.udpsocket.enabled", false);

Просмотреть файл

@ -10,8 +10,7 @@
#define OK 0
// Error codes that are no longer used should not be used again unless they
// aren't used in client code (e.g. nsUpdateService.js, updates.js,
// UpdatePrompt.js, etc.).
// aren't used in client code (e.g. nsUpdateService.js, updates.js, etc.).
#define MAR_ERROR_EMPTY_ACTION_LIST 1
#define LOADSOURCE_ERROR_WRONG_SIZE 2