Bug 1344158 - PART 1: wrap webconsole;r=honza
MozReview-Commit-ID: ERugtMV58ak
--- a/devtools/client/netmonitor/netmonitor-controller.js
+++ b/devtools/client/netmonitor/netmonitor-controller.js
@@ -8,16 +8,17 @@ const { TimelineFront } = require("devto
const { CurlUtils } = require("devtools/client/shared/curl");
const { ACTIVITY_TYPE, EVENTS } = require("./constants");
const Actions = require("./actions/index");
const {
fetchHeaders,
formDataURI,
} = require("./utils/request-utils");
const {
+ getWebConsoleClient,
onFirefoxConnect,
onFirefoxDisconnect,
} = require("./utils/client");
const {
getRequestById,
getDisplayedRequestById,
} = require("./selectors/index");
@@ -82,34 +83,37 @@ var NetMonitorController = {
this._onTabDetached = this.shutdownNetMonitor.bind(this);
this._connection = new Promise(async (resolve) => {
// Some actors like AddonActor or RootActor for chrome debugging
// aren't actual tabs.
if (this._target.isTabActor) {
this.tabClient = this._target.activeTab;
}
- this.webConsoleClient = this._target.activeConsole;
let connectTimeline = () => {
// Don't start up waiting for timeline markers if the server isn't
// recent enough to emit the markers we're interested in.
if (this._target.getTrait("documentLoadingMarkers")) {
this.timelineFront = new TimelineFront(this._target.client,
this._target.form);
return this.timelineFront.start({ withDocLoadingEvents: true });
}
return undefined;
};
await connectTimeline();
onFirefoxConnect(this._target);
this._target.on("close", this._onTabDetached);
+
+ this.webConsoleClient = getWebConsoleClient();
+ this.NetworkEventsHandler = new NetworkEventsHandler();
this.NetworkEventsHandler.connect();
+ window.gNetwork = this.NetworkEventsHandler;
window.emit(EVENTS.CONNECTED);
resolve();
this._connected = true;
});
return this._connection;
},
@@ -819,16 +823,9 @@ NetworkEventsHandler.prototype = {
if (typeof stringGrip === "string") {
return Promise.resolve(stringGrip);
}
return this.webConsoleClient.getString(stringGrip);
}
};
-/**
- * Preliminary setup for the NetMonitorController object.
- */
-NetMonitorController.NetworkEventsHandler = new NetworkEventsHandler();
-window.NetMonitorController = NetMonitorController;
-window.gNetwork = NetMonitorController.NetworkEventsHandler;
-
exports.NetMonitorController = NetMonitorController;
--- a/devtools/client/netmonitor/utils/client.js
+++ b/devtools/client/netmonitor/utils/client.js
@@ -5,16 +5,18 @@
/* global gStore */
"use strict";
const Services = require("Services");
const Actions = require("../actions/index");
const { EVENTS } = require("../constants");
+let activeConsole;
+
/**
* Called for each location change in the monitored tab.
*
* @param {String} type Packet type.
* @param {Object} packet Packet received from the server.
*/
function navigated(type) {
window.emit(EVENTS.TARGET_DID_NAVIGATE);
@@ -40,26 +42,38 @@ function willNavigate(type) {
}
/**
* Process connection events.
*
* @param {Object} tabTarget
*/
function onFirefoxConnect(tabTarget) {
+ activeConsole = tabTarget.activeConsole;
tabTarget.on("navigate", navigated);
tabTarget.on("will-navigate", willNavigate);
}
/**
* Process disconnect events.
*
* @param {Object} tabTarget
*/
function onFirefoxDisconnect(tabTarget) {
+ activeConsole = null;
tabTarget.off("navigate", navigated);
tabTarget.off("will-navigate", willNavigate);
}
+/**
+ * Retrieve webconsole object
+ *
+ * @returns {Object} webConsole
+ */
+function getWebConsoleClient() {
+ return activeConsole;
+}
+
module.exports = {
+ getWebConsoleClient,
onFirefoxConnect,
onFirefoxDisconnect,
};