2015-04-10 11:50:06 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
"use strict";
|
2015-04-10 11:50:06 +03:00
|
|
|
|
2015-10-07 15:03:21 +03:00
|
|
|
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
2015-04-10 11:50:06 +03:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2017-01-17 18:48:17 +03:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2015-04-10 11:50:06 +03:00
|
|
|
|
|
|
|
const bundle = Services.strings.createBundle(
|
|
|
|
"chrome://global/locale/aboutServiceWorkers.properties");
|
|
|
|
|
2015-04-27 17:47:24 +03:00
|
|
|
const brandBundle = Services.strings.createBundle(
|
|
|
|
"chrome://branding/locale/brand.properties");
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var gSWM;
|
|
|
|
var gSWCount = 0;
|
2015-04-15 04:21:08 +03:00
|
|
|
|
2015-04-10 11:50:06 +03:00
|
|
|
function init() {
|
|
|
|
let enabled = Services.prefs.getBoolPref("dom.serviceWorkers.enabled");
|
|
|
|
if (!enabled) {
|
|
|
|
let div = document.getElementById("warning_not_enabled");
|
|
|
|
div.classList.add("active");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-15 04:21:08 +03:00
|
|
|
gSWM = Cc["@mozilla.org/serviceworkers/manager;1"]
|
|
|
|
.getService(Ci.nsIServiceWorkerManager);
|
|
|
|
if (!gSWM) {
|
2015-04-10 11:50:06 +03:00
|
|
|
dump("AboutServiceWorkers: Failed to get the ServiceWorkerManager service!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-15 04:21:08 +03:00
|
|
|
let data = gSWM.getAllRegistrations();
|
2015-04-10 11:50:06 +03:00
|
|
|
if (!data) {
|
|
|
|
dump("AboutServiceWorkers: Failed to retrieve the registrations.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let length = data.length;
|
|
|
|
if (!length) {
|
|
|
|
let div = document.getElementById("warning_no_serviceworkers");
|
|
|
|
div.classList.add("active");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-08 23:41:48 +03:00
|
|
|
let ps = undefined;
|
2015-07-29 19:12:51 +03:00
|
|
|
try {
|
2015-12-08 23:41:48 +03:00
|
|
|
ps = Cc["@mozilla.org/push/Service;1"]
|
|
|
|
.getService(Ci.nsIPushService);
|
2016-08-04 10:28:58 +03:00
|
|
|
} catch (e) {
|
2015-12-08 23:41:48 +03:00
|
|
|
dump("Could not acquire PushService\n");
|
2015-07-29 19:12:51 +03:00
|
|
|
}
|
|
|
|
|
2015-04-10 11:50:06 +03:00
|
|
|
for (let i = 0; i < length; ++i) {
|
2015-11-02 17:04:41 +03:00
|
|
|
let info = data.queryElementAt(i, Ci.nsIServiceWorkerRegistrationInfo);
|
2015-04-10 11:50:06 +03:00
|
|
|
if (!info) {
|
2015-11-02 17:04:41 +03:00
|
|
|
dump("AboutServiceWorkers: Invalid nsIServiceWorkerRegistrationInfo interface.\n");
|
2015-04-10 11:50:06 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-12-08 23:41:48 +03:00
|
|
|
display(info, ps);
|
2015-04-10 11:50:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 23:41:48 +03:00
|
|
|
function display(info, pushService) {
|
2015-04-10 11:50:06 +03:00
|
|
|
let parent = document.getElementById("serviceworkers");
|
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
let div = document.createElement("div");
|
2015-04-10 11:50:06 +03:00
|
|
|
parent.appendChild(div);
|
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
let title = document.createElement("h2");
|
|
|
|
let titleStr = bundle.formatStringFromName("title", [info.principal.origin], 1);
|
2015-04-10 11:50:06 +03:00
|
|
|
title.appendChild(document.createTextNode(titleStr));
|
|
|
|
div.appendChild(title);
|
|
|
|
|
|
|
|
if (info.principal.appId) {
|
2017-01-17 18:48:17 +03:00
|
|
|
let b2gtitle = document.createElement("h3");
|
|
|
|
let trueFalse = bundle.GetStringFromName(info.principal.isInIsolatedMozBrowserElement ? "true" : "false");
|
2015-04-27 17:47:24 +03:00
|
|
|
|
|
|
|
let b2gtitleStr =
|
2017-01-17 18:48:17 +03:00
|
|
|
bundle.formatStringFromName("b2gtitle", [ brandBundle.getString("brandShortName"),
|
2015-04-27 17:47:24 +03:00
|
|
|
info.principal.appId,
|
|
|
|
trueFalse], 2);
|
2015-04-10 11:50:06 +03:00
|
|
|
b2gtitle.appendChild(document.createTextNode(b2gtitleStr));
|
|
|
|
div.appendChild(b2gtitle);
|
|
|
|
}
|
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
let list = document.createElement("ul");
|
2015-04-10 11:50:06 +03:00
|
|
|
div.appendChild(list);
|
|
|
|
|
2015-04-15 04:08:33 +03:00
|
|
|
function createItem(title, value, makeLink) {
|
2017-01-17 18:48:17 +03:00
|
|
|
let item = document.createElement("li");
|
2015-04-10 11:50:06 +03:00
|
|
|
list.appendChild(item);
|
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
let bold = document.createElement("strong");
|
2015-04-10 11:50:06 +03:00
|
|
|
bold.appendChild(document.createTextNode(title + " "));
|
|
|
|
item.appendChild(bold);
|
|
|
|
|
2015-04-27 17:44:45 +03:00
|
|
|
let textNode = document.createTextNode(value);
|
|
|
|
|
2015-04-15 04:08:33 +03:00
|
|
|
if (makeLink) {
|
|
|
|
let link = document.createElement("a");
|
|
|
|
link.href = value;
|
|
|
|
link.target = "_blank";
|
2015-04-27 17:44:45 +03:00
|
|
|
link.appendChild(textNode);
|
2015-04-15 04:08:33 +03:00
|
|
|
item.appendChild(link);
|
|
|
|
} else {
|
2015-04-27 17:44:45 +03:00
|
|
|
item.appendChild(textNode);
|
2015-04-15 04:08:33 +03:00
|
|
|
}
|
2015-04-27 17:44:45 +03:00
|
|
|
|
|
|
|
return textNode;
|
2015-04-10 11:50:06 +03:00
|
|
|
}
|
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
createItem(bundle.GetStringFromName("scope"), info.scope);
|
|
|
|
createItem(bundle.GetStringFromName("scriptSpec"), info.scriptSpec, true);
|
2015-11-05 09:15:49 +03:00
|
|
|
let currentWorkerURL = info.activeWorker ? info.activeWorker.scriptSpec : "";
|
2017-01-17 18:48:17 +03:00
|
|
|
createItem(bundle.GetStringFromName("currentWorkerURL"), currentWorkerURL, true);
|
2015-11-05 09:15:49 +03:00
|
|
|
let activeCacheName = info.activeWorker ? info.activeWorker.cacheName : "";
|
2017-01-17 18:48:17 +03:00
|
|
|
createItem(bundle.GetStringFromName("activeCacheName"), activeCacheName);
|
2015-11-05 09:15:49 +03:00
|
|
|
let waitingCacheName = info.waitingWorker ? info.waitingWorker.cacheName : "";
|
2017-01-17 18:48:17 +03:00
|
|
|
createItem(bundle.GetStringFromName("waitingCacheName"), waitingCacheName);
|
2015-04-10 11:50:06 +03:00
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
let pushItem = createItem(bundle.GetStringFromName("pushEndpoint"), bundle.GetStringFromName("waiting"));
|
2015-12-08 23:41:48 +03:00
|
|
|
if (pushService) {
|
2015-12-23 07:11:50 +03:00
|
|
|
pushService.getSubscription(info.scope, info.principal, (status, pushRecord) => {
|
2015-12-08 23:41:48 +03:00
|
|
|
if (Components.isSuccessCode(status)) {
|
2015-07-29 19:12:51 +03:00
|
|
|
pushItem.data = JSON.stringify(pushRecord);
|
2015-12-08 23:41:48 +03:00
|
|
|
} else {
|
2015-07-29 19:12:51 +03:00
|
|
|
dump("about:serviceworkers - retrieving push registration failed\n");
|
2015-12-08 23:41:48 +03:00
|
|
|
}
|
|
|
|
});
|
2015-07-29 19:12:51 +03:00
|
|
|
}
|
2015-04-21 21:10:51 +03:00
|
|
|
|
2015-04-15 20:11:17 +03:00
|
|
|
let updateButton = document.createElement("button");
|
2017-01-17 18:48:17 +03:00
|
|
|
updateButton.appendChild(document.createTextNode(bundle.GetStringFromName("update")));
|
2015-04-15 04:21:08 +03:00
|
|
|
updateButton.onclick = function() {
|
2015-06-04 21:51:57 +03:00
|
|
|
gSWM.propagateSoftUpdate(info.principal.originAttributes, info.scope);
|
2015-04-15 04:21:08 +03:00
|
|
|
};
|
|
|
|
div.appendChild(updateButton);
|
|
|
|
|
2015-04-15 20:11:17 +03:00
|
|
|
let unregisterButton = document.createElement("button");
|
2017-01-17 18:48:17 +03:00
|
|
|
unregisterButton.appendChild(document.createTextNode(bundle.GetStringFromName("unregister")));
|
2015-04-15 20:11:17 +03:00
|
|
|
div.appendChild(unregisterButton);
|
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
let loadingMessage = document.createElement("span");
|
|
|
|
loadingMessage.appendChild(document.createTextNode(bundle.GetStringFromName("waiting")));
|
|
|
|
loadingMessage.classList.add("inactive");
|
2015-04-15 20:11:17 +03:00
|
|
|
div.appendChild(loadingMessage);
|
|
|
|
|
|
|
|
unregisterButton.onclick = function() {
|
|
|
|
let cb = {
|
2016-12-30 02:34:54 +03:00
|
|
|
unregisterSucceeded() {
|
2015-04-15 20:11:17 +03:00
|
|
|
parent.removeChild(div);
|
|
|
|
|
|
|
|
if (!--gSWCount) {
|
|
|
|
let div = document.getElementById("warning_no_serviceworkers");
|
|
|
|
div.classList.add("active");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
unregisterFailed() {
|
2017-01-17 18:48:17 +03:00
|
|
|
alert(bundle.GetStringFromName("unregisterError"));
|
2015-04-15 20:11:17 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIServiceWorkerUnregisterCallback])
|
|
|
|
};
|
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
loadingMessage.classList.remove("inactive");
|
2015-06-04 21:51:57 +03:00
|
|
|
gSWM.propagateUnregister(info.principal, cb, info.scope);
|
2015-04-15 20:11:17 +03:00
|
|
|
};
|
|
|
|
|
2017-01-17 18:48:17 +03:00
|
|
|
let sep = document.createElement("hr");
|
2015-04-10 11:50:06 +03:00
|
|
|
div.appendChild(sep);
|
2015-04-15 20:11:17 +03:00
|
|
|
|
|
|
|
++gSWCount;
|
2015-04-10 11:50:06 +03:00
|
|
|
}
|
|
|
|
|
2017-01-25 09:01:52 +03:00
|
|
|
window.addEventListener("DOMContentLoaded", function() {
|
2015-04-10 11:50:06 +03:00
|
|
|
init();
|
2017-01-25 09:01:52 +03:00
|
|
|
}, {once: true});
|