1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11 let enabled = Services.prefs.getBoolPref("dom.serviceWorkers.enabled");
13 let div = document.getElementById("warning_not_enabled");
14 div.classList.add("active");
18 gSWM = Cc["@mozilla.org/serviceworkers/manager;1"].getService(
19 Ci.nsIServiceWorkerManager
23 "AboutServiceWorkers: Failed to get the ServiceWorkerManager service!\n"
28 let data = gSWM.getAllRegistrations();
30 dump("AboutServiceWorkers: Failed to retrieve the registrations.\n");
34 let length = data.length;
36 let div = document.getElementById("warning_no_serviceworkers");
37 div.classList.add("active");
43 ps = Cc["@mozilla.org/push/Service;1"].getService(Ci.nsIPushService);
45 dump("Could not acquire PushService\n");
48 for (let i = 0; i < length; ++i) {
49 let info = data.queryElementAt(i, Ci.nsIServiceWorkerRegistrationInfo);
52 "AboutServiceWorkers: Invalid nsIServiceWorkerRegistrationInfo interface.\n"
61 async function display(info, pushService) {
62 let parent = document.getElementById("serviceworkers");
64 let div = document.createElement("div");
65 parent.appendChild(div);
67 let title = document.createElement("h2");
68 document.l10n.setAttributes(title, "origin-title", {
69 originTitle: info.principal.origin,
71 div.appendChild(title);
73 let list = document.createElement("ul");
74 div.appendChild(list);
76 function createItem(l10nId, value, makeLink) {
77 let item = document.createElement("li");
78 list.appendChild(item);
79 let bold = document.createElement("strong");
80 bold.setAttribute("data-l10n-name", "item-label");
81 item.appendChild(bold);
82 // Falsey values like "" are still valid values, so check exactly against
83 // undefined for the cases where the caller did not provide any value.
84 if (value === undefined) {
85 document.l10n.setAttributes(item, l10nId);
86 } else if (makeLink) {
87 let link = document.createElement("a");
88 link.setAttribute("target", "_blank");
89 link.setAttribute("data-l10n-name", "link");
90 link.setAttribute("href", value);
91 item.appendChild(link);
92 document.l10n.setAttributes(item, l10nId, { url: value });
94 document.l10n.setAttributes(item, l10nId, { name: value });
99 createItem("scope", info.scope);
100 createItem("script-spec", info.scriptSpec, true);
101 let currentWorkerURL = info.activeWorker ? info.activeWorker.scriptSpec : "";
102 createItem("current-worker-url", currentWorkerURL, true);
103 let activeCacheName = info.activeWorker ? info.activeWorker.cacheName : "";
104 createItem("active-cache-name", activeCacheName);
105 let waitingCacheName = info.waitingWorker ? info.waitingWorker.cacheName : "";
106 createItem("waiting-cache-name", waitingCacheName);
108 let pushItem = createItem("push-end-point-waiting");
110 pushService.getSubscription(
113 (status, pushRecord) => {
114 if (Components.isSuccessCode(status)) {
115 document.l10n.setAttributes(pushItem, "push-end-point-result", {
116 name: JSON.stringify(pushRecord),
119 dump("about:serviceworkers - retrieving push registration failed\n");
125 let unregisterButton = document.createElement("button");
126 document.l10n.setAttributes(unregisterButton, "unregister-button");
127 div.appendChild(unregisterButton);
129 let loadingMessage = document.createElement("span");
130 document.l10n.setAttributes(loadingMessage, "waiting");
131 loadingMessage.classList.add("inactive");
132 div.appendChild(loadingMessage);
134 unregisterButton.onclick = function() {
136 unregisterSucceeded() {
137 parent.removeChild(div);
140 let div = document.getElementById("warning_no_serviceworkers");
141 div.classList.add("active");
145 async unregisterFailed() {
146 let [alertMsg] = await document.l10n.formatValues([
147 { id: "unregister-error" },
152 QueryInterface: ChromeUtils.generateQI([
153 "nsIServiceWorkerUnregisterCallback",
157 loadingMessage.classList.remove("inactive");
158 gSWM.propagateUnregister(info.principal, cb, info.scope);
161 let sep = document.createElement("hr");
162 div.appendChild(sep);
167 window.addEventListener(