Bug 1556489 - P19. Fix devtools stack traces. r=honza,ochameau

DevTools rely on events when a new HttpChannel is opened, it needs to know when a DocumentChannel is.

Differential Revision: https://phabricator.services.mozilla.com/D40975
This commit is contained in:
Jean-Yves Avenard 2019-08-26 12:14:44 +10:00
Родитель 1b5f7c772a
Коммит d65c5e0309
4 изменённых файлов: 35 добавлений и 12 удалений

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

@ -35,6 +35,7 @@ function StackTraceCollector(filters, netmonitors) {
StackTraceCollector.prototype = {
init() {
Services.obs.addObserver(this, "http-on-opening-request");
Services.obs.addObserver(this, "document-on-opening-request");
Services.obs.addObserver(this, "network-monitor-alternate-stack");
ChannelEventSinkFactory.getService().registerCollector(this);
this.onGetStack = this.onGetStack.bind(this);
@ -48,6 +49,7 @@ StackTraceCollector.prototype = {
destroy() {
Services.obs.removeObserver(this, "http-on-opening-request");
Services.obs.removeObserver(this, "document-on-opening-request");
Services.obs.removeObserver(this, "network-monitor-alternate-stack");
ChannelEventSinkFactory.getService().unregisterCollector(this);
for (const { messageManager } of this.netmonitors) {
@ -77,22 +79,30 @@ StackTraceCollector.prototype = {
observe(subject, topic, data) {
let channel, id;
try {
channel = subject.QueryInterface(Ci.nsIIdentChannel);
// We need to QI nsIHttpChannel in order to load the interface's
// methods / attributes for later code that could assume we are dealing
// with a nsIHttpChannel.
channel = subject.QueryInterface(Ci.nsIHttpChannel);
id = channel.channelId;
} catch (e1) {
// WebSocketChannels do not have IDs, so use the URL. When a WebSocket is
// opened in a content process, a channel is created locally but the HTTP
// channel for the connection lives entirely in the parent process. When
// the server code running in the parent sees that HTTP channel, it will
// look for the creation stack using the websocket's URL.
try {
channel = subject.QueryInterface(Ci.nsIWebSocketChannel);
channel = subject.QueryInterface(Ci.nsIIdentChannel);
id = channel.channelId;
} catch (e2) {
// Channels which don't implement the above interfaces can appear here,
// such as nsIFileChannel. Ignore these channels.
return;
// WebSocketChannels do not have IDs, so use the URL. When a WebSocket is
// opened in a content process, a channel is created locally but the HTTP
// channel for the connection lives entirely in the parent process. When
// the server code running in the parent sees that HTTP channel, it will
// look for the creation stack using the websocket's URL.
try {
channel = subject.QueryInterface(Ci.nsIWebSocketChannel);
} catch (e3) {
// Channels which don't implement the above interfaces can appear here,
// such as nsIFileChannel. Ignore these channels.
return;
}
id = channel.URI.spec;
}
id = channel.URI.spec;
}
if (!matchRequest(channel, this.filters)) {
@ -101,7 +111,8 @@ StackTraceCollector.prototype = {
const stacktrace = [];
switch (topic) {
case "http-on-opening-request": {
case "http-on-opening-request":
case "document-on-opening-request": {
// The channel is being opened on the main thread, associate the current
// stack with it.
//

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

@ -113,6 +113,8 @@ DocumentChannelChild::AsyncOpen(nsIStreamListener* aListener) {
return mStatus;
}
gHttpHandler->OnOpeningDocumentRequest(this);
DocumentChannelCreationArgs args;
SerializeURI(topWindowURI, args.topWindowURI());

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

@ -361,6 +361,10 @@ class nsHttpHandler final : public nsIHttpProtocolHandler,
NotifyObservers(chan, NS_HTTP_ON_OPENING_REQUEST_TOPIC);
}
void OnOpeningDocumentRequest(nsIIdentChannel* chan) {
NotifyObservers(chan, NS_DOCUMENT_ON_OPENING_REQUEST_TOPIC);
}
// Called by the channel before writing a request
void OnModifyRequest(nsIHttpChannel* chan) {
NotifyObservers(chan, NS_HTTP_ON_MODIFY_REQUEST_TOPIC);

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

@ -120,6 +120,12 @@ interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler
*/
#define NS_HTTP_ON_OPENING_REQUEST_TOPIC "http-on-opening-request"
/**
* This observer topic is notified when an document channel is opened.
* It is similar to http-on-opening-request.
*/
#define NS_DOCUMENT_ON_OPENING_REQUEST_TOPIC "document-on-opening-request"
/**
* Before an HTTP request is sent to the server, this observer topic is
* notified. The observer of this topic can then choose to set any additional