Skip to content

Commit

Permalink
Bug 1328293 - Show if a service worker is listening for fetch events …
Browse files Browse the repository at this point in the history
…in about:debugging. r=jdescottes
  • Loading branch information
catalinb committed Jan 21, 2017
1 parent 2dfa565 commit 9eb245e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions devtools/client/aboutdebugging/components/workers/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ module.exports = createClass({
name: form.url,
url: form.url,
scope: form.scope,
fetch: form.fetch,
registrationActor: form.actor,
active: form.active
});
Expand All @@ -99,6 +100,8 @@ module.exports = createClass({
}
registration.workerActor = form.actor;
} else {
worker.fetch = form.fetch;

// If a service worker registration could not be found, this means we are in
// e10s, and registrations are not forwarded to other processes until they
// reach the activated state. Augment the worker as a registration worker to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = createClass({
debugDisabled: PropTypes.bool,
target: PropTypes.shape({
active: PropTypes.bool,
fetch: PropTypes.bool.isRequired,
icon: PropTypes.string,
name: PropTypes.string.isRequired,
url: PropTypes.string,
Expand Down Expand Up @@ -195,6 +196,9 @@ module.exports = createClass({
let { pushSubscription } = this.state;
let status = this.getServiceWorkerStatus();

let fetch = target.fetch ? Strings.GetStringFromName("listeningForFetchEvents") :
Strings.GetStringFromName("notListeningForFetchEvents");

return dom.div({ className: "target-container" },
dom.img({
className: "target-icon",
Expand All @@ -215,6 +219,12 @@ module.exports = createClass({
}, pushSubscription.endpoint)) :
null
),
dom.li({ className: "target-detail" },
dom.strong(null, Strings.GetStringFromName("fetch")),
dom.span({
className: "service-worker-fetch-flag",
title: fetch
}, fetch)),
dom.li({ className: "target-detail" },
dom.strong(null, Strings.GetStringFromName("scope")),
dom.span({
Expand Down
12 changes: 12 additions & 0 deletions devtools/client/locales/en-US/aboutdebugging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ unregister = unregister

pushService = Push Service

# LOCALIZATION NOTE (fetch):
# Fetch is an event type and should not be translated.
fetch = Fetch

# LOCALIZATION NOTE (listeningForFetchEvents):
# This is used to display the state of the SW in regard to fetch events.
listeningForFetchEvents = Listening for fetch events.

# LOCALIZATION NOTE (notListeningForFetchEvents):
# This is used to display the state of the SW in regard to fetch events.
notListeningForFetchEvents = Not listening for fetch events.

# LOCALIZATION NOTE (addons):
# This string is displayed as a header of the about:debugging#addons page.
addons = Add-ons
Expand Down
8 changes: 8 additions & 0 deletions devtools/server/actors/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ let WorkerActor = protocol.ActorClassWithSpec(workerSpec, {
if (this._dbg.type === Ci.nsIWorkerDebugger.TYPE_SERVICE) {
let registration = this._getServiceWorkerRegistrationInfo();
form.scope = registration.scope;
let newestWorker = (registration.activeWorker ||
registration.waitingWorker ||
registration.installingWorker);
form.fetch = newestWorker && newestWorker.handlesFetchEvents;
}
return form;
},
Expand Down Expand Up @@ -229,6 +233,7 @@ let ServiceWorkerActor = protocol.ActorClassWithSpec(serviceWorkerSpec, {
return {
url: this._worker.scriptSpec,
state: this._worker.state,
fetch: this._worker.handlesFetchEvents
};
},

Expand Down Expand Up @@ -287,6 +292,8 @@ protocol.ActorClassWithSpec(serviceWorkerRegistrationSpec, {
let waitingWorker = this._waitingWorker.form();
let activeWorker = this._activeWorker.form();

let newestWorker = (activeWorker || waitingWorker || installingWorker);

let isE10s = Services.appinfo.browserTabsRemoteAutostart;
return {
actor: this.actorID,
Expand All @@ -295,6 +302,7 @@ protocol.ActorClassWithSpec(serviceWorkerRegistrationSpec, {
installingWorker,
waitingWorker,
activeWorker,
fetch: newestWorker && newestWorker.fetch,
// - In e10s: only active registrations are available.
// - In non-e10s: registrations always have at least one worker, if the worker is
// active, the registration is active.
Expand Down
2 changes: 2 additions & 0 deletions dom/interfaces/base/nsIServiceWorkerManager.idl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ interface nsIServiceWorkerInfo : nsISupports

readonly attribute nsIWorkerDebugger debugger;

readonly attribute bool handlesFetchEvents;

void attachDebugger();

void detachDebugger();
Expand Down
9 changes: 9 additions & 0 deletions dom/workers/ServiceWorkerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ ServiceWorkerInfo::GetDebugger(nsIWorkerDebugger** aResult)
return mServiceWorkerPrivate->GetDebugger(aResult);
}

NS_IMETHODIMP
ServiceWorkerInfo::GetHandlesFetchEvents(bool* aValue)
{
MOZ_ASSERT(aValue);
AssertIsOnMainThread();
*aValue = HandlesFetch();
return NS_OK;
}

NS_IMETHODIMP
ServiceWorkerInfo::AttachDebugger()
{
Expand Down

0 comments on commit 9eb245e

Please sign in to comment.