Bug 1154721 - Add an "Unregister" button to about:serviceworkers, r=ehsan

This commit is contained in:
Andrea Marchesini 2015-04-15 18:11:17 +01:00
parent 2d11560001
commit 9af7bcd327
5 changed files with 56 additions and 8 deletions

View File

@ -11,13 +11,13 @@ interface nsIInterceptedChannel;
interface nsIPrincipal;
interface nsIURI;
[builtinclass, uuid(d4367ffe-e435-4195-95f8-0a51b1bbfdfb)]
[scriptable, uuid(52ee2c9d-ee87-4caf-9588-23ae77ff8798)]
interface nsIServiceWorkerUnregisterCallback : nsISupports
{
// aState is true if the unregistration succeded.
// It's false if this ServiceWorkerRegistration doesn't exist.
[noscript] void UnregisterSucceeded(in bool aState);
[noscript] void UnregisterFailed();
void unregisterSucceeded(in bool aState);
void unregisterFailed();
};
[scriptable, builtinclass, uuid(8ce0d197-5740-4ddf-aa4a-e5a63e611d03)]

View File

@ -1778,7 +1778,7 @@ private:
nsRefPtr<ServiceWorkerRegistrationInfo> registration;
if (!swm->mServiceWorkerRegistrationInfos.Get(mScope, getter_AddRefs(registration))) {
// "If registration is null, then, resolve promise with false."
return mCallback->UnregisterSucceeded(false);
return mCallback ? mCallback->UnregisterSucceeded(false) : NS_OK;
}
MOZ_ASSERT(registration);
@ -1786,7 +1786,7 @@ private:
// "Set registration's uninstalling flag."
registration->mPendingUninstall = true;
// "Resolve promise with true"
nsresult rv = mCallback->UnregisterSucceeded(true);
nsresult rv = mCallback ? mCallback->UnregisterSucceeded(true) : NS_OK;
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1824,8 +1824,10 @@ ServiceWorkerManager::Unregister(nsIPrincipal* aPrincipal,
const nsAString& aScope)
{
AssertIsOnMainThread();
MOZ_ASSERT(aPrincipal);
MOZ_ASSERT(aCallback);
if (!aPrincipal) {
return NS_ERROR_FAILURE;
}
// This is not accessible by content, and callers should always ensure scope is
// a correct URI, so this is wrapped in DEBUG

View File

@ -7,11 +7,13 @@
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
const bundle = Services.strings.createBundle(
"chrome://global/locale/aboutServiceWorkers.properties");
let gSWM;
let gSWCount = 0;
function init() {
let enabled = Services.prefs.getBoolPref("dom.serviceWorkers.enabled");
@ -99,15 +101,48 @@ function display(info) {
createItem(bundle.GetStringFromName('activeCacheName'), info.activeCacheName);
createItem(bundle.GetStringFromName('waitingCacheName'), info.waitingCacheName);
var updateButton = document.createElement("button");
let updateButton = document.createElement("button");
updateButton.appendChild(document.createTextNode(bundle.GetStringFromName('update')));
updateButton.onclick = function() {
gSWM.update(info.scope);
};
div.appendChild(updateButton);
let unregisterButton = document.createElement("button");
unregisterButton.appendChild(document.createTextNode(bundle.GetStringFromName('unregister')));
div.appendChild(unregisterButton);
let loadingMessage = document.createElement('span');
loadingMessage.appendChild(document.createTextNode(bundle.GetStringFromName('waiting')));
loadingMessage.classList.add('inactive');
div.appendChild(loadingMessage);
unregisterButton.onclick = function() {
let cb = {
unregisterSucceeded: function() {
parent.removeChild(div);
if (!--gSWCount) {
let div = document.getElementById("warning_no_serviceworkers");
div.classList.add("active");
}
},
unregisterFailed: function() {
alert(bundle.GetStringFromName('unregisterError'));
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIServiceWorkerUnregisterCallback])
};
loadingMessage.classList.remove('inactive');
gSWM.unregister(info.principal, cb, info.scope);
};
let sep = document.createElement('hr');
div.appendChild(sep);
++gSWCount;
}
window.addEventListener("DOMContentLoaded", function load() {

View File

@ -23,3 +23,10 @@ true = true
false = false
update = Update
unregister = Unregister
waiting = Waiting...
# LOCALIZATION NODE the term "Service Worker" should not translated.
unregisterError = Failed to unregister this Service Worker.

View File

@ -38,3 +38,7 @@ body {
.active {
display: block;
}
.inactive {
display: none;
}