Bug 1603176: Install target-switing mechanism. r=jdescottes

Depends on D61347

Differential Revision: https://phabricator.services.mozilla.com/D61348

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Daisuke Akatsuka 2020-02-20 12:31:54 +00:00
Родитель a6ec55dfdd
Коммит 7a67417ac2
10 изменённых файлов: 37 добавлений и 33 удалений

Просмотреть файл

@ -23,7 +23,7 @@ let root, store, unsubscribe;
const initialize = async function() {
// Exposed by panel.js
const { gFront, gToolbox, gHeapAnalysesClient } = window;
const { gToolbox, gHeapAnalysesClient } = window;
root = document.querySelector("#app");
store = Store();
@ -35,13 +35,14 @@ const initialize = async function() {
ReactDOM.render(provider, root);
unsubscribe = store.subscribe(onStateChange);
// Connect memory front and component.
store.dispatch(updateMemoryFront(gFront));
// Exposed for tests.
window.gStore = store;
};
const updateFront = front => {
store.dispatch(updateMemoryFront(front));
};
const destroy = function() {
const ok = ReactDOM.unmountComponentAtNode(root);
assert(
@ -76,4 +77,4 @@ function onStateChange() {
isHighlighted = isRecording;
}
module.exports = { initialize, destroy };
module.exports = { initialize, updateFront, destroy };

Просмотреть файл

@ -21,36 +21,38 @@ function MemoryPanel(iframeWindow, toolbox) {
}).require;
this.initializer = browserRequire("devtools/client/memory/initializer");
this._onTargetAvailable = this._onTargetAvailable.bind(this);
EventEmitter.decorate(this);
}
MemoryPanel.prototype = {
async open() {
if (this._opening) {
return this._opening;
}
this.panelWin.gToolbox = this._toolbox;
this.panelWin.gFront = await this.target.getFront("memory");
this.panelWin.gHeapAnalysesClient = new HeapAnalysesClient();
await this.panelWin.gFront.attach();
await this.initializer.initialize();
this._opening = this.initializer.initialize().then(() => {
this.isReady = true;
this.emit("ready");
return this;
});
await this._toolbox.targetList.watchTargets(
[this._toolbox.targetList.TYPES.FRAME],
this._onTargetAvailable
);
return this._opening;
this.emit("ready");
return this;
},
async _onTargetAvailable({ targetFront, isTopLevel }) {
if (isTopLevel) {
const front = await targetFront.getFront("memory");
await front.attach();
this.initializer.updateFront(front);
}
},
// DevToolPanel API
get target() {
return this._toolbox.target;
},
destroy() {
// Make sure this panel is not already destroyed.
if (this._destroyed) {
@ -58,14 +60,15 @@ MemoryPanel.prototype = {
}
this._destroyed = true;
this._toolbox.targetList.unwatchTargets(
[this._toolbox.targetList.TYPES.FRAME],
this._onTargetAvailable
);
this.initializer.destroy();
// Destroy front to ensure packet handler is removed from client
this.panelWin.gFront.destroy();
this.panelWin.gHeapAnalysesClient.destroy();
this.panelWin = null;
this._opening = null;
this.isReady = false;
this.emit("destroyed");
},
};

Просмотреть файл

@ -20,8 +20,8 @@ const TEST_URL =
this.test = makeMemoryTest(TEST_URL, async function({ tab, panel }) {
const heapWorker = panel.panelWin.gHeapAnalysesClient;
const front = panel.panelWin.gFront;
const { getState, dispatch } = panel.panelWin.gStore;
const front = getState().front;
const doc = panel.panelWin.document;
dispatch(changeView(viewState.CENSUS));

Просмотреть файл

@ -20,9 +20,9 @@ this.test = makeMemoryTest(TEST_URL, async function({ panel }) {
requestLongerTimeout(2);
const heapWorker = panel.panelWin.gHeapAnalysesClient;
const front = panel.panelWin.gFront;
const store = panel.panelWin.gStore;
const { dispatch } = store;
const front = store.getState().front;
const doc = panel.panelWin.document;
dispatch(changeView(viewState.CENSUS));

Просмотреть файл

@ -39,9 +39,9 @@ function waitUntilExpanded(store, node) {
this.test = makeMemoryTest(TEST_URL, async function({ tab, panel }) {
const heapWorker = panel.panelWin.gHeapAnalysesClient;
const front = panel.panelWin.gFront;
const store = panel.panelWin.gStore;
const { getState, dispatch } = store;
const front = getState().front;
const doc = panel.panelWin.document;
dispatch(changeView(viewState.CENSUS));

Просмотреть файл

@ -17,8 +17,8 @@ const TEST_URL =
this.test = makeMemoryTest(TEST_URL, async function({ tab, panel }) {
const heapWorker = panel.panelWin.gHeapAnalysesClient;
const front = panel.panelWin.gFront;
const { getState, dispatch } = panel.panelWin.gStore;
const front = getState().front;
const doc = panel.panelWin.document;
dispatch(changeView(viewState.CENSUS));

Просмотреть файл

@ -17,8 +17,8 @@ const TEST_URL =
this.test = makeMemoryTest(TEST_URL, async function({ tab, panel }) {
const heapWorker = panel.panelWin.gHeapAnalysesClient;
const front = panel.panelWin.gFront;
const { getState, dispatch } = panel.panelWin.gStore;
const front = getState().front;
const doc = panel.panelWin.document;
dispatch(changeView(viewState.CENSUS));

Просмотреть файл

@ -29,8 +29,8 @@ function checkCells(cells) {
this.test = makeMemoryTest(TEST_URL, async function({ tab, panel }) {
const heapWorker = panel.panelWin.gHeapAnalysesClient;
const front = panel.panelWin.gFront;
const { getState, dispatch } = panel.panelWin.gStore;
const front = getState().front;
const doc = panel.panelWin.document;
dispatch(changeView(viewState.CENSUS));

Просмотреть файл

@ -54,7 +54,7 @@ const DESCRIPTION = {
};
this.test = makeMemoryTest(TEST_URL, async function({ tab, panel }) {
const front = panel.panelWin.gFront;
const front = panel.panelWin.gStore.getState().front;
const startWindows = await getWindowsInSnapshot(front);
dumpn(

Просмотреть файл

@ -12,7 +12,7 @@
const TEST_URL = "data:text/html,<html><body></body></html>";
this.test = makeMemoryTest(TEST_URL, async function({ tab, panel }) {
const memoryFront = panel.panelWin.gFront;
const memoryFront = panel.panelWin.gStore.getState().front;
ok(memoryFront, "Should get the MemoryFront");
const snapshotFilePath = await memoryFront.saveHeapSnapshot({