Bug 1572442 - Refactor how we create Console's network data provider. r=Honza.

The DataProvider is what allows us to use the Netmonitor
components. The way it was created before was non optimal,
as it were inside an enhancer, and was then attached to
a proxy.
As we may now have multiple proxies, this could cause
some issue.
So we take this as an opportunity to create the DataProvider
in the WebConsoleWrapper (where live the actions we need for
the provider), and remove the now unused function on the
WebConsoleConnectionProxy.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nicolas Chevobbe 2019-08-19 14:53:52 +00:00
Родитель f07d2560ed
Коммит 91cb50a784
7 изменённых файлов: 36 добавлений и 71 удалений

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

@ -4,8 +4,6 @@
"use strict";
const DataProvider = require("devtools/client/netmonitor/src/connector/firefox-data-provider");
const {
getAllNetworkMessagesUpdateById,
} = require("devtools/client/webconsole/selectors/messages");
@ -29,37 +27,17 @@ const {
* unnecessary data over RDP.
*/
function enableNetProvider(webConsoleUI) {
let dataProvider;
return next => (reducer, initialState, enhancer) => {
function netProviderEnhancer(state, action) {
const proxy = webConsoleUI ? webConsoleUI.getProxy() : null;
if (!proxy) {
const dataProvider =
webConsoleUI &&
webConsoleUI.wrapper &&
webConsoleUI.wrapper.networkDataProvider;
if (!dataProvider) {
return reducer(state, action);
}
const actions = {
updateRequest: (id, data, batch) => {
return proxy.dispatchRequestUpdate(id, data);
},
};
// Data provider implements async logic for fetching
// data from the backend. It's created the first
// time it's needed.
if (!dataProvider && proxy.webConsoleClient) {
dataProvider = new DataProvider({
actions,
webConsoleClient: proxy.webConsoleClient,
});
// /!\ This is terrible, but it allows ResponsePanel to be able to call
// `dataProvider.requestData` to fetch response content lazily.
// `proxy.networkDataProvider` is put by WebConsoleOutputWrapper on
// `serviceContainer` which allow NetworkEventMessage to expose requestData on
// the fake `connector` object it hands over to ResponsePanel.
proxy.networkDataProvider = dataProvider;
}
const type = action.type;
const newState = reducer(state, action);

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

@ -60,15 +60,3 @@ async function testNetworkMessage(messageNode) {
messageNode.querySelector("#headers-panel .headers-overview")
);
}
/**
* Wait until all lazily fetch requests in netmonitor get finished.
* Otherwise test will be shutdown too early and cause failure.
*/
async function waitForLazyRequests(toolbox) {
const { ui } = toolbox.getCurrentPanel().hud;
const proxy = ui.proxy;
return waitUntil(() => {
return !proxy.networkDataProvider.lazyRequestData.size;
});
}

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

@ -346,15 +346,3 @@ function expandXhrMessage(node) {
node.querySelector(".url").click();
return waitFor(() => node.querySelector(".network-info"));
}
/**
* Wait until all lazily fetch requests in netmonitor get finished.
* Otherwise test will be shutdown too early and cause failure.
*/
async function waitForLazyRequests(toolbox) {
const { ui } = toolbox.getCurrentPanel().hud;
const proxy = ui.proxy;
return waitUntil(() => {
return !proxy.networkDataProvider.lazyRequestData.size;
});
}

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

@ -1520,3 +1520,14 @@ function toggleLayout(hud) {
});
return waitFor(() => isEditorModeEnabled(hud) === !enabled);
}
/**
* Wait until all lazily fetch requests in netmonitor get finished.
* Otherwise test will be shutdown too early and cause failure.
*/
async function waitForLazyRequests(toolbox) {
const { wrapper } = toolbox.getCurrentPanel().hud.ui;
return waitUntil(() => {
return !wrapper.networkDataProvider.lazyRequestData.size;
});
}

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

@ -21,7 +21,10 @@ const WebConsoleWrapper = require("devtools/client/webconsole/webconsole-wrapper
const { messagesAdd } = require("devtools/client/webconsole/actions/messages");
async function getWebConsoleWrapper() {
const hud = { target: { client: {} }, getMappedExpression: () => {} };
const hud = {
target: { client: {}, getFront: () => {} },
getMappedExpression: () => {},
};
const webConsoleUi = getWebConsoleUiMock(hud);
const wcow = new WebConsoleWrapper(null, webConsoleUi, null, null);

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

@ -355,15 +355,6 @@ class WebConsoleConnectionProxy {
this.webConsoleUI.wrapper.dispatchMessageUpdate(networkInfo, response);
}
dispatchRequestUpdate(id, data) {
// Some request might try to update while we are closing the toolbox.
if (!this.webConsoleUI) {
return Promise.resolve();
}
return this.webConsoleUI.wrapper.dispatchRequestUpdate(id, data);
}
/**
* Release an object actor.
*

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

@ -34,6 +34,8 @@ const EventEmitter = require("devtools/shared/event-emitter");
const App = createFactory(require("devtools/client/webconsole/components/App"));
const ObjectClient = require("devtools/shared/client/object-client");
const LongStringClient = require("devtools/shared/client/long-string-client");
const DataProvider = require("devtools/client/netmonitor/src/connector/firefox-data-provider");
loader.lazyRequireGetter(
this,
"Constants",
@ -73,18 +75,27 @@ class WebConsoleWrapper {
this.queuedMessageUpdates = [];
this.queuedRequestUpdates = [];
this.throttledDispatchPromise = null;
this.telemetry = new Telemetry();
}
init() {
return new Promise(resolve => {
return new Promise(async resolve => {
const attachRefToWebConsoleUI = (id, node) => {
this.webConsoleUI[id] = node;
};
const { webConsoleUI } = this;
const debuggerClient = this.hud.target.client;
const webConsoleClient = await this.hud.target.getFront("console");
this.networkDataProvider = new DataProvider({
actions: {
updateRequest: (id, data) => {
return this.batchedRequestUpdates({ id, data });
},
},
webConsoleClient,
});
const serviceContainer = {
attachRefToWebConsoleUI,
emitNewMessage: (node, messageId, timeStamp) => {
@ -136,9 +147,8 @@ class WebConsoleWrapper {
const proxy = webConsoleUI.getProxy();
return proxy.webConsoleClient.getString(grip);
},
requestData(id, type) {
const proxy = webConsoleUI.getProxy();
return proxy.networkDataProvider.requestData(id, type);
requestData: (id, type) => {
return this.networkDataProvider.requestData(id, type);
},
onViewSource(frame) {
if (webConsoleUI && webConsoleUI.hud && webConsoleUI.hud.viewSource) {
@ -584,10 +594,6 @@ class WebConsoleWrapper {
}
}
dispatchRequestUpdate(id, data) {
return this.batchedRequestUpdates({ id, data });
}
dispatchSidebarClose() {
store.dispatch(actions.sidebarClose());
}