Bug 1477597 - Part 1: Implement updateTabs action. r?jdescottes
MozReview-Commit-ID: 4iFFarQV8H7
--- a/devtools/client/aboutdebugging-new/aboutdebugging.js
+++ b/devtools/client/aboutdebugging-new/aboutdebugging.js
@@ -22,28 +22,28 @@ const Provider =
const actions = require("./src/actions/index");
const { configureStore } = require("./src/create-store");
const ThisFirefox = require("./src/runtimes/this-firefox");
const App = createFactory(require("./src/components/App"));
const AboutDebugging = {
- init() {
+ async init() {
if (!Services.prefs.getBoolPref("devtools.enabled", true)) {
// If DevTools are disabled, navigate to about:devtools.
window.location = "about:devtools?reason=AboutDebugging";
return;
}
this.store = configureStore();
this.actions = bindActionCreators(actions, this.store.dispatch);
const thisFirefox = new ThisFirefox();
- this.updateSelectedRuntime(thisFirefox);
+ await this.updateSelectedRuntime(thisFirefox);
render(Provider({ store: this.store }, App({ thisFirefox })), this.mount);
},
destroy() {
unmountComponentAtNode(this.mount);
},
@@ -51,20 +51,27 @@ const AboutDebugging = {
return document.getElementById("mount");
},
async updateRuntimeInfo(runtime) {
const info = await runtime.getRuntimeInfo();
this.actions.updateRuntimeInfo(info);
},
- updateSelectedRuntime(runtime) {
+ async updateSelectedRuntime(runtime) {
+ await runtime.connect();
this.actions.updateSelectedRuntime(runtime);
this.updateRuntimeInfo(runtime);
+ this.updateTabs(runtime);
+ },
+
+ async updateTabs(runtime) {
+ const tabs = await runtime.getTabs();
+ this.actions.updateTabs(tabs);
},
};
window.addEventListener("DOMContentLoaded", () => {
AboutDebugging.init();
}, { once: true });
window.addEventListener("unload", () => {
--- a/devtools/client/aboutdebugging-new/src/actions/debugtargets.js
+++ b/devtools/client/aboutdebugging-new/src/actions/debugtargets.js
@@ -1,20 +1,29 @@
/* 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_RUNTIME_INFO,
+ UPDATE_TABS,
} = require("../constants");
function updateRuntimeInfo(runtimeInfo) {
return {
type: UPDATE_RUNTIME_INFO,
runtimeInfo,
};
}
+function updateTabs(tabs) {
+ return {
+ type: UPDATE_TABS,
+ tabs,
+ };
+}
+
module.exports = {
updateRuntimeInfo,
+ updateTabs,
};
--- a/devtools/client/aboutdebugging-new/src/constants.js
+++ b/devtools/client/aboutdebugging-new/src/constants.js
@@ -2,11 +2,12 @@
* 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_RUNTIME_INFO: "UPDATE_RUNTIME_INFO",
UPDATE_SELECTED_RUNTIME: "UPDATE_SELECTED_RUNTIME",
+ UPDATE_TABS: "UPDATE_TABS",
};
module.exports = Object.assign({}, actionTypes);
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/src/debugtargets/debug-target.js
@@ -0,0 +1,16 @@
+/* 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";
+
+/**
+ * This class represents a debug target, such as a tab, an extension or a worker.
+ */
+class DebugTarget {
+ constructor(target) {
+ this.target = target;
+ }
+}
+
+module.exports = DebugTarget;
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/src/debugtargets/moz.build
@@ -0,0 +1,8 @@
+# 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(
+ 'debug-target.js',
+ 'tab.js'
+)
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/src/debugtargets/tab.js
@@ -0,0 +1,18 @@
+/* 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 DebugTarget = require("./debug-target");
+
+/**
+ * This class represents a tab as debug target.
+ */
+class Tab extends DebugTarget {
+ constructor(target) {
+ super(target);
+ }
+}
+
+module.exports = Tab;
--- a/devtools/client/aboutdebugging-new/src/moz.build
+++ b/devtools/client/aboutdebugging-new/src/moz.build
@@ -1,15 +1,16 @@
# 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/.
DIRS += [
'actions',
'components',
+ 'debugtargets',
'runtimes',
'reducers',
]
DevToolsModules(
'constants.js',
'create-store.js'
)
--- a/devtools/client/aboutdebugging-new/src/reducers/debugtargets-state.js
+++ b/devtools/client/aboutdebugging-new/src/reducers/debugtargets-state.js
@@ -1,31 +1,38 @@
/* 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_RUNTIME_INFO,
+ UPDATE_TABS,
} = require("../constants");
function DebugTargetsState() {
return {
runtimeInfo: {},
+ tabs: [],
};
}
function debugtargetsReducer(state = DebugTargetsState(), action) {
switch (action.type) {
case UPDATE_RUNTIME_INFO: {
return Object.assign({}, state, {
runtimeInfo: action.runtimeInfo,
});
}
+ case UPDATE_TABS: {
+ return Object.assign({}, state, {
+ tabs: action.tabs,
+ });
+ }
default:
return state;
}
}
module.exports = {
DebugTargetsState,
--- a/devtools/client/aboutdebugging-new/src/runtimes/runtime.js
+++ b/devtools/client/aboutdebugging-new/src/runtimes/runtime.js
@@ -4,16 +4,24 @@
"use strict";
/**
* This class represents a runtime, such as a remote Firefox.
*/
class Runtime {
/**
+ * Connect to this runtime.
+ * Subclass should override this method.
+ */
+ async connect() {
+ throw new Error("Subclass of Runtime should override connect()");
+ }
+
+ /**
* Return icon of this runtime on sidebar.
* Subclass should override this method.
* @return {String}
*/
getIcon() {
throw new Error("Subclass of Runtime should override getIcon()");
}
@@ -37,11 +45,20 @@ class Runtime {
* e.g. Firefox
* version: Version of this runtime
* e.g. 62.0a1
* }
*/
async getRuntimeInfo() {
throw new Error("Subclass of Runtime should override getRuntimeInfo()");
}
+
+ /**
+ * Return tabs on this runtime.
+ * Subclass should override this method.
+ * @return {Array}
+ */
+ async getTabs() {
+ throw new Error("Subclass of Runtime should override getTabs()");
+ }
}
module.exports = Runtime;
--- a/devtools/client/aboutdebugging-new/src/runtimes/this-firefox.js
+++ b/devtools/client/aboutdebugging-new/src/runtimes/this-firefox.js
@@ -1,33 +1,50 @@
/* 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 { DebuggerClient } = require("devtools/shared/client/debugger-client");
+const { DebuggerServer } = require("devtools/server/main");
const Services = require("Services");
const Runtime = require("./runtime");
+const Tab = require("../debugtargets/tab");
/**
* This class represents the Firefox instance which runs in the same environment that
* opened about:debugging.
*/
class ThisFirefox extends Runtime {
+ async connect() {
+ // Setup a server if we don't have one already running
+ DebuggerServer.init();
+ DebuggerServer.registerAllActors();
+ const transport = DebuggerServer.connectPipe();
+ this.client = new DebuggerClient(transport);
+ return this.client.connect();
+ }
+
getIcon() {
return "chrome://devtools/skin/images/firefox-logo-glyph.svg";
}
getName() {
return "This Firefox";
}
async getRuntimeInfo() {
return {
icon: "chrome://branding/content/icon64.png",
name: Services.appinfo.name,
version: Services.appinfo.version,
};
}
+
+ async getTabs() {
+ const { tabs } = await this.client.listTabs({ favicons: true });
+ return tabs.map(t => new Tab(t));
+ }
}
module.exports = ThisFirefox;