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/. */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
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");
|
2015-04-15 20:11: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");
|
|
|
|
|
|
|
|
let div = document.createElement('div');
|
|
|
|
parent.appendChild(div);
|
|
|
|
|
|
|
|
let title = document.createElement('h2');
|
|
|
|
let titleStr = bundle.formatStringFromName('title', [info.principal.origin], 1);
|
|
|
|
title.appendChild(document.createTextNode(titleStr));
|
|
|
|
div.appendChild(title);
|
|
|
|
|
|
|
|
if (info.principal.appId) {
|
|
|
|
let b2gtitle = document.createElement('h3');
|
2016-02-05 04:42:44 +03:00
|
|
|
let trueFalse = bundle.GetStringFromName(info.principal.isInIsolatedMozBrowserElement ? 'true' : 'false');
|
2015-04-27 17:47:24 +03:00
|
|
|
|
|
|
|
let b2gtitleStr =
|
|
|
|
bundle.formatStringFromName('b2gtitle', [ brandBundle.getString("brandShortName"),
|
|
|
|
info.principal.appId,
|
|
|
|
trueFalse], 2);
|
2015-04-10 11:50:06 +03:00
|
|
|
b2gtitle.appendChild(document.createTextNode(b2gtitleStr));
|
|
|
|
div.appendChild(b2gtitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
let list = document.createElement('ul');
|
|
|
|
div.appendChild(list);
|
|
|
|
|
2015-04-15 04:08:33 +03:00
|
|
|
function createItem(title, value, makeLink) {
|
2015-04-10 11:50:06 +03:00
|
|
|
let item = document.createElement('li');
|
|
|
|
list.appendChild(item);
|
|
|
|
|
|
|
|
let bold = document.createElement('strong');
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
createItem(bundle.GetStringFromName('scope'), info.scope);
|
2015-04-15 04:08:33 +03:00
|
|
|
createItem(bundle.GetStringFromName('scriptSpec'), info.scriptSpec, true);
|
2015-11-05 09:15:49 +03:00
|
|
|
let currentWorkerURL = info.activeWorker ? info.activeWorker.scriptSpec : "";
|
|
|
|
createItem(bundle.GetStringFromName('currentWorkerURL'), currentWorkerURL, true);
|
|
|
|
let activeCacheName = info.activeWorker ? info.activeWorker.cacheName : "";
|
2015-11-10 19:06:15 +03:00
|
|
|
createItem(bundle.GetStringFromName('activeCacheName'), activeCacheName);
|
2015-11-05 09:15:49 +03:00
|
|
|
let waitingCacheName = info.waitingWorker ? info.waitingWorker.cacheName : "";
|
2015-11-10 19:06:15 +03:00
|
|
|
createItem(bundle.GetStringFromName('waitingCacheName'), waitingCacheName);
|
2015-04-10 11:50:06 +03:00
|
|
|
|
2015-04-27 17:44:45 +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");
|
2015-04-15 04:21:08 +03:00
|
|
|
updateButton.appendChild(document.createTextNode(bundle.GetStringFromName('update')));
|
|
|
|
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");
|
|
|
|
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 = {
|
2016-12-30 01:05:44 +03:00
|
|
|
unregisterSucceeded: function() {
|
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 01:05:44 +03:00
|
|
|
unregisterFailed: function() {
|
2015-04-15 20:11:17 +03:00
|
|
|
alert(bundle.GetStringFromName('unregisterError'));
|
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIServiceWorkerUnregisterCallback])
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2015-04-10 11:50:06 +03:00
|
|
|
let sep = document.createElement('hr');
|
|
|
|
div.appendChild(sep);
|
2015-04-15 20:11:17 +03:00
|
|
|
|
|
|
|
++gSWCount;
|
2015-04-10 11:50:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("DOMContentLoaded", function load() {
|
|
|
|
window.removeEventListener("DOMContentLoaded", load);
|
|
|
|
init();
|
|
|
|
});
|