Bug 1450064 - Show only service workers for current domain. r=jdescottes
MozReview-Commit-ID: CTULmSRUgHG
--- a/devtools/client/application/initializer.js
+++ b/devtools/client/application/initializer.js
@@ -22,16 +22,17 @@ const App = createFactory(require("./src
/**
* Global Application object in this panel. This object is expected by panel.js and is
* called to start the UI for the panel.
*/
window.Application = {
async bootstrap({ toolbox, panel }) {
this.updateWorkers = this.updateWorkers.bind(this);
+ this.updateDomain = this.updateDomain.bind(this);
this.mount = document.querySelector("#mount");
this.toolbox = toolbox;
this.client = toolbox.target.client;
this.store = configureStore();
this.actions = bindActionCreators(actions, this.store.dispatch);
@@ -54,30 +55,38 @@ window.Application = {
// Render the root Application component.
const app = App({ client: this.client, serviceContainer });
render(Provider({ store: this.store }, app), this.mount);
this.client.addListener("workerListChanged", this.updateWorkers);
this.client.addListener("serviceWorkerRegistrationListChanged", this.updateWorkers);
this.client.addListener("registration-changed", this.updateWorkers);
this.client.addListener("processListChanged", this.updateWorkers);
+ this.toolbox.target.on("navigate", this.updateDomain);
+ this.updateDomain();
await this.updateWorkers();
},
async updateWorkers() {
let { service } = await this.client.mainRoot.listAllWorkers();
this.actions.updateWorkers(service);
},
+ updateDomain() {
+ this.actions.updateDomain(this.toolbox.target.url);
+ },
+
destroy() {
this.client.removeListener("workerListChanged", this.updateWorkers);
this.client.removeListener("serviceWorkerRegistrationListChanged",
this.updateWorkers);
this.client.removeListener("registration-changed", this.updateWorkers);
this.client.removeListener("processListChanged", this.updateWorkers);
+ this.toolbox.target.off("navigate", this.updateDomain);
+
unmountComponentAtNode(this.mount);
this.mount = null;
this.toolbox = null;
this.client = null;
},
};
--- a/devtools/client/application/src/actions/index.js
+++ b/devtools/client/application/src/actions/index.js
@@ -1,11 +1,13 @@
/* 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";
const workers = require("./workers");
+const page = require("./page");
Object.assign(exports,
workers,
+ page
);
--- a/devtools/client/application/src/actions/moz.build
+++ b/devtools/client/application/src/actions/moz.build
@@ -1,8 +1,9 @@
# 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/.
DevToolsModules(
'index.js',
+ 'page.js',
'workers.js',
)
new file mode 100644
--- /dev/null
+++ b/devtools/client/application/src/actions/page.js
@@ -0,0 +1,20 @@
+/* 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";
+
+const {
+ UPDATE_DOMAIN,
+} = require("../constants");
+
+function updateDomain(url) {
+ return {
+ type: UPDATE_DOMAIN,
+ url
+ };
+}
+
+module.exports = {
+ updateDomain,
+};
--- a/devtools/client/application/src/components/App.js
+++ b/devtools/client/application/src/components/App.js
@@ -16,31 +16,35 @@ const WorkerListEmpty = createFactory(re
* This is the main component for the application panel.
*/
class App extends Component {
static get propTypes() {
return {
client: PropTypes.object.isRequired,
workers: PropTypes.object.isRequired,
serviceContainer: PropTypes.object.isRequired,
+ domain: PropTypes.string.isRequired,
};
}
render() {
- let { workers, client, serviceContainer } = this.props;
- const isEmpty = workers.length == 0;
+ let { workers, domain, client, serviceContainer } = this.props;
+
+ // Filter out workers from other domains
+ workers = workers.filter((x) => new URL(x.url).hostname === domain);
+ const isEmpty = workers.length === 0;
return (
div(
{ className: `application ${isEmpty ? "empty" : ""}` },
isEmpty
? WorkerListEmpty({ serviceContainer })
: WorkerList({ workers, client, serviceContainer })
)
);
}
}
// Exports
module.exports = connect(
- (state) => ({ workers: state.workers.list }),
+ (state) => ({ workers: state.workers.list, domain: state.page.domain }),
)(App);
--- a/devtools/client/application/src/constants.js
+++ b/devtools/client/application/src/constants.js
@@ -1,12 +1,13 @@
/* 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";
const actionTypes = {
UPDATE_WORKERS: "UPDATE_WORKERS",
+ UPDATE_DOMAIN: "UPDATE_DOMAIN",
};
// flatten constants
module.exports = Object.assign({}, actionTypes);
--- a/devtools/client/application/src/create-store.js
+++ b/devtools/client/application/src/create-store.js
@@ -4,19 +4,21 @@
"use strict";
const { createStore } = require("devtools/client/shared/vendor/redux");
// Reducers
const rootReducer = require("./reducers/index");
const { WorkersState } = require("./reducers/workers-state");
+const { PageState } = require("./reducers/page-state");
function configureStore() {
// Prepare initial state.
const initialState = {
workers: new WorkersState(),
+ page: new PageState(),
};
return createStore(rootReducer, initialState);
}
exports.configureStore = configureStore;
--- a/devtools/client/application/src/reducers/index.js
+++ b/devtools/client/application/src/reducers/index.js
@@ -1,12 +1,14 @@
/* 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";
const { combineReducers } = require("devtools/client/shared/vendor/redux");
const { workersReducer } = require("./workers-state");
+const { pageReducer } = require("./page-state");
module.exports = combineReducers({
workers: workersReducer,
+ page: pageReducer,
});
--- a/devtools/client/application/src/reducers/moz.build
+++ b/devtools/client/application/src/reducers/moz.build
@@ -1,8 +1,9 @@
# 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/.
DevToolsModules(
'index.js',
+ 'page-state.js',
'workers-state.js',
)
new file mode 100644
--- /dev/null
+++ b/devtools/client/application/src/reducers/page-state.js
@@ -0,0 +1,39 @@
+/* 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";
+
+const {
+ UPDATE_DOMAIN,
+} = require("../constants");
+
+function PageState() {
+ return {
+ // Domain
+ domain: null
+ };
+}
+
+function getDomainFromUrl(url) {
+ return new URL(url).hostname;
+}
+
+function pageReducer(state = PageState(), action) {
+ switch (action.type) {
+ case UPDATE_DOMAIN: {
+ let { url } = action;
+ return {
+ domain: getDomainFromUrl(url)
+ };
+ }
+
+ default:
+ return state;
+ }
+}
+
+module.exports = {
+ PageState,
+ pageReducer,
+};