Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
startBulkSend: function({actor, type, length}) {
this.emit("startBulkSend", {actor, type, length});
let serial = this._serial.count++;
dumpn("Sent bulk packet " + serial + " for actor " + actor);
if (!this.other) {
return;
}
let pipe = new Pipe(true, true, 0, 0, null);
DevToolsUtils.executeSoon(DevToolsUtils.makeInfallible(() => {
dumpn("Received bulk packet " + serial);
if (!this.other.hooks) {
return;
}
// Receiver
let deferred = promise.defer();
let packet = {
actor: actor,
type: type,
length: length,
copyTo: (output) => {
let copying =
StreamUtils.copyStream(pipe.inputStream, output, length);
deferred.resolve(copying);
return copying;
onOpenWindow: DevToolsUtils.makeInfallible(function(aWindow) {
let handleLoad = DevToolsUtils.makeInfallible(() => {
if (this._checkedWindows.has(appShellDOMWindowType(aWindow))) {
// This is one of our windows, we need to check for browser
// elements. Notify is enough, iterate will do the actual actor
// creation.
this._notifyListChanged();
}
});
// You can hardly do anything at all with a XUL window at this point; it
// doesn't even have its document yet. Wait until its document has
// loaded, and then see what we've got. This also avoids
// nsIWindowMediator enumeration from within listeners (bug 873589).
aWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
aWindow.addEventListener("load", handleLoad, {capture: false, once: true});
}, "IRCTabList.prototype.onOpenWindow"),
BrowserTabList.prototype._listenForEventsIf = function(aShouldListen, aGuard, aEventNames) {
if (!aShouldListen !== !this[aGuard]) {
let op = aShouldListen ? "addEventListener" : "removeEventListener";
for (let win of allAppShellDOMWindows(DebuggerServer.chromeWindowType)) {
for (let name of aEventNames) {
win[op](name, this, false);
}
}
this[aGuard] = aShouldListen;
}
};
/**
* Implement nsIDOMEventListener.
*/
BrowserTabList.prototype.handleEvent = DevToolsUtils.makeInfallible(function(aEvent) {
switch (aEvent.type) {
case "TabOpen":
case "TabSelect":
/* Don't create a new actor; iterate will take care of that. Just notify. */
this._notifyListChanged();
this._checkListening();
break;
case "TabClose":
let browser = aEvent.target.linkedBrowser;
let actor = this._actorByBrowser.get(browser);
if (actor) {
this._handleActorClose(actor, browser);
}
break;
}
}, "BrowserTabList.prototype.handleEvent");
handler.removeEventListener("pageshow", this._onWindowCreated, true);
handler.removeEventListener("pagehide", this._onWindowHidden, true);
for (let win of this._getWindowsInDocShell(docShell)) {
this._knownWindowIDs.delete(getWindowID(win));
}
},
_getWindowsInDocShell: function(docShell) {
return getChildDocShells(docShell).map(d => {
return d.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
});
},
onWindowCreated: DevToolsUtils.makeInfallible(function(evt) {
if (!this._tabActor.attached) {
return;
}
// pageshow events for non-persisted pages have already been handled by a
// prior DOMWindowCreated event. For persisted pages, act as if the window
// had just been created since it's been unfrozen from bfcache.
if (evt.type == "pageshow" && !evt.persisted) {
return;
}
let window = evt.target.defaultView;
this._tabActor._windowReady(window);
if (evt.type !== "pageshow") {
this._knownWindowIDs.set(getWindowID(window), window);
actor.selected = foundSelected =
win == topWindow &&
!foundSelected &&
bo.height > 0 &&
bo.width > 0;
}
}
}
this._mustNotify = true;
this._checkListening();
return promise.resolve([...this._actorByBrowser.values()]);
},
onOpenWindow: DevToolsUtils.makeInfallible(function(aWindow) {
let handleLoad = DevToolsUtils.makeInfallible(() => {
if (this._checkedWindows.has(appShellDOMWindowType(aWindow))) {
// This is one of our windows, we need to check for browser
// elements. Notify is enough, iterate will do the actual actor
// creation.
this._notifyListChanged();
}
});
// You can hardly do anything at all with a XUL window at this point; it
// doesn't even have its document yet. Wait until its document has
// loaded, and then see what we've got. This also avoids
// nsIWindowMediator enumeration from within listeners (bug 873589).
aWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
aWindow.addEventListener("load", handleLoad, {capture: false, once: true});
/**
* Resume this transport's attempts to read from the input stream.
*/
resumeIncoming: function() {
this._incomingEnabled = true;
this._flushIncoming();
this._waitForIncoming();
},
// nsIInputStreamCallback
/**
* Called when the stream is either readable or closed.
*/
onInputStreamReady:
DevToolsUtils.makeInfallible(function(event) {
let data = event.data;
// TODO: ws-tcp-proxy decodes utf-8, but the transport expects to see the
// encoded bytes. Simplest step is to re-encode for now.
data = utf8.encode(data);
let stream = {
available() {
return data.length;
},
readBytes(count) {
let result = data.slice(0, count);
data = data.slice(count);
return result;
},
};
try {
// elements. Notify is enough, iterate will do the actual actor
// creation.
this._notifyListChanged();
}
});
// You can hardly do anything at all with a XUL window at this point; it
// doesn't even have its document yet. Wait until its document has
// loaded, and then see what we've got. This also avoids
// nsIWindowMediator enumeration from within listeners (bug 873589).
aWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
aWindow.addEventListener("load", handleLoad, {capture: false, once: true});
}, "IRCTabList.prototype.onOpenWindow"),
onCloseWindow: DevToolsUtils.makeInfallible(function(aWindow) {
aWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
// Only handle our window types
if (this._checkedWindows.has(appShellDOMWindowType(aWindow))) {
return;
}
// nsIWindowMediator deadlocks if you call its GetEnumerator method from
// a nsIWindowMediatorListener's onCloseWindow hook (bug 873589), so
// handle the close in a different tick.
Services.tm.currentThread.dispatch(DevToolsUtils.makeInfallible(() => {
let shouldNotify = false;
// Scan the whole map for browsers that were in this window.
for (let [browser, actor] of this._actorByBrowser) {
this.destroy();
break;
}
}),
/**
* Handler for new network requests. This method is invoked by the current
* NetworkMonitor instance.
*
* @param object event
* Object describing the network request.
* @return object
* A NetworkEventActorProxy instance which is notified when further
* data about the request is available.
*/
onNetworkEvent: DevToolsUtils.makeInfallible(function _onNetworkEvent(event) {
return new NetworkEventActorProxy(this.messageManager, this.id).init(event);
}),
destroy: function()
{
if (this.messageManager) {
this.messageManager.removeMessageListener("debug:netmonitor:" + this.id,
this.onNetMonitorMessage);
}
this.messageManager = null;
this.filters = null;
if (this.netMonitor) {
this.netMonitor.destroy();
this.netMonitor = null;
}
this._onNewEvent);
mm.addMessageListener("debug:netmonitor:" + this.connID + ":updateEvent",
this._onUpdateEvent);
mm.sendAsyncMessage("debug:netmonitor:" + this.connID, {
appId: this.appId,
action: "start",
});
},
_onNewEvent: DevToolsUtils.makeInfallible(function _onNewEvent(msg) {
let {id, event} = msg.data;
let actor = this.owner.onNetworkEvent(event);
this._netEvents.set(id, Cu.getWeakReference(actor));
}),
_onUpdateEvent: DevToolsUtils.makeInfallible(function _onUpdateEvent(msg) {
let {id, method, args} = msg.data;
let weakActor = this._netEvents.get(id);
let actor = weakActor ? weakActor.get() : null;
if (!actor) {
console.error("Received debug:netmonitor:updateEvent for unknown event ID: " + id);
return;
}
if (!(method in actor)) {
console.error("Received debug:netmonitor:updateEvent unsupported method: " + method);
return;
}
actor[method].apply(actor, args);
}),
destroy: function() {
let mm = this._messageManager;
}
},
/**
* Begin observing HTTP traffic that originates inside the current tab.
*
* @see https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIHttpActivityObserver
*
* @param nsIHttpChannel aChannel
* @param number aActivityType
* @param number aActivitySubtype
* @param number aTimestamp
* @param number aExtraSizeData
* @param string aExtraStringData
*/
observeActivity: DevToolsUtils.makeInfallible(function NM_observeActivity(aChannel, aActivityType, aActivitySubtype, aTimestamp, aExtraSizeData, aExtraStringData)
{
if (!this.owner ||
aActivityType != gActivityDistributor.ACTIVITY_TYPE_HTTP_TRANSACTION &&
aActivityType != gActivityDistributor.ACTIVITY_TYPE_SOCKET_TRANSPORT) {
return;
}
if (!(aChannel instanceof Ci.nsIHttpChannel)) {
return;
}
aChannel = aChannel.QueryInterface(Ci.nsIHttpChannel);
if (aActivitySubtype ==
gActivityDistributor.ACTIVITY_SUBTYPE_REQUEST_HEADER) {
this._onRequestHeader(aChannel, aTimestamp, aExtraStringData);