Bug 1556489 - P11. Add nIIdentChannel interface. r=mayhemer

The devtools listens to http-on-opening-request event which is expected to receive a nsIHttpChannel. However future changes will make it that it's not always a nsIHttpChannel that can fire such event.

As such we create an intermediary interface nsIIdentChannel and move the subset generating such event in nsIHttpChannel there.

Differential Revision: https://phabricator.services.mozilla.com/D40968
This commit is contained in:
Jean-Yves Avenard 2019-08-06 20:30:58 +10:00
parent b1aa62197e
commit b43fd91ea2
12 changed files with 57 additions and 30 deletions

View File

@ -77,7 +77,7 @@ StackTraceCollector.prototype = {
observe(subject, topic, data) {
let channel, id;
try {
channel = subject.QueryInterface(Ci.nsIHttpChannel);
channel = subject.QueryInterface(Ci.nsIIdentChannel);
id = channel.channelId;
} catch (e1) {
// WebSocketChannels do not have IDs, so use the URL. When a WebSocket is

View File

@ -23,6 +23,7 @@
#include "LoadInfo.h"
#include "nsServiceManagerUtils.h"
#include "nsRedirectHistoryEntry.h"
#include "nsHttpHandler.h"
using namespace mozilla;
@ -66,6 +67,8 @@ nsBaseChannel::nsBaseChannel()
mContentLength(-1),
mWasOpened(false) {
mContentType.AssignLiteral(UNKNOWN_CONTENT_TYPE);
RefPtr<nsHttpHandler> handler = nsHttpHandler::GetInstance();
Unused << handler->NewChannelId(mChannelId);
}
nsBaseChannel::~nsBaseChannel() {
@ -347,13 +350,11 @@ void nsBaseChannel::ClassifyURI() {
//-----------------------------------------------------------------------------
// nsBaseChannel::nsISupports
NS_IMPL_ISUPPORTS_INHERITED(nsBaseChannel, nsHashPropertyBag, nsIRequest,
nsIChannel, nsIThreadRetargetableRequest,
nsIInterfaceRequestor, nsITransportEventSink,
nsIRequestObserver, nsIStreamListener,
nsIThreadRetargetableStreamListener,
nsIAsyncVerifyRedirectCallback,
nsIPrivateBrowsingChannel)
NS_IMPL_ISUPPORTS_INHERITED(
nsBaseChannel, nsHashPropertyBag, nsIRequest, nsIChannel, nsIIdentChannel,
nsIThreadRetargetableRequest, nsIInterfaceRequestor, nsITransportEventSink,
nsIRequestObserver, nsIStreamListener, nsIThreadRetargetableStreamListener,
nsIAsyncVerifyRedirectCallback, nsIPrivateBrowsingChannel)
//-----------------------------------------------------------------------------
// nsBaseChannel::nsIRequest
@ -699,6 +700,21 @@ nsBaseChannel::AsyncOpen(nsIStreamListener* aListener) {
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsBaseChannel::nsIIdentChannel
NS_IMETHODIMP
nsBaseChannel::GetChannelId(uint64_t* aChannelId) {
*aChannelId = mChannelId;
return NS_OK;
}
NS_IMETHODIMP
nsBaseChannel::SetChannelId(uint64_t aChannelId) {
mChannelId = aChannelId;
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsBaseChannel::nsITransportEventSink

View File

@ -44,7 +44,7 @@ class nsIInputStream;
class nsBaseChannel
: public nsHashPropertyBag,
public nsIChannel,
public nsIIdentChannel,
public nsIThreadRetargetableRequest,
public nsIInterfaceRequestor,
public nsITransportEventSink,
@ -57,6 +57,7 @@ class nsBaseChannel
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSIIDENTCHANNEL
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSITRANSPORTEVENTSINK
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
@ -299,6 +300,7 @@ class nsBaseChannel
uint32_t mContentDispositionHint;
nsAutoPtr<nsString> mContentDispositionFilename;
int64_t mContentLength;
uint64_t mChannelId;
bool mWasOpened;
friend class mozilla::net::PrivateBrowsingChannel<nsBaseChannel>;

View File

@ -367,3 +367,25 @@ interface nsIChannel : nsIRequest
%}
};
[builtinclass, scriptable, uuid(1ebbff64-d742-4f4a-aad5-4df2d1eb937a)]
interface nsIIdentChannel : nsIChannel
{
/**
* Unique ID of the channel, shared between parent and child. Needed if
* the channel activity needs to be monitored across process boundaries,
* like in devtools net monitor. See bug 1274556.
*/
[must_use] attribute uint64_t channelId;
%{ C++
inline uint64_t ChannelId()
{
uint64_t value = 0;
if (NS_SUCCEEDED(GetChannelId(&value))) {
return value;
}
return 0;
}
%}
};

View File

@ -405,6 +405,7 @@ NS_IMPL_RELEASE(HttpBaseChannel)
NS_INTERFACE_MAP_BEGIN(HttpBaseChannel)
NS_INTERFACE_MAP_ENTRY(nsIRequest)
NS_INTERFACE_MAP_ENTRY(nsIChannel)
NS_INTERFACE_MAP_ENTRY(nsIIdentChannel)
NS_INTERFACE_MAP_ENTRY(nsIEncodedChannel)
NS_INTERFACE_MAP_ENTRY(nsIHttpChannel)
NS_INTERFACE_MAP_ENTRY(nsIHttpChannelInternal)

View File

@ -12,7 +12,7 @@ namespace mozilla {
namespace net {
NS_IMPL_ISUPPORTS(NullHttpChannel, nsINullChannel, nsIHttpChannel,
nsITimedChannel)
nsIIdentChannel, nsITimedChannel)
NullHttpChannel::NullHttpChannel()
: mAllRedirectsSameOrigin(false), mAllRedirectsPassTimingAllowCheck(false) {

View File

@ -28,6 +28,7 @@ class NullHttpChannel final : public nsINullChannel,
NS_DECL_NSITIMEDCHANNEL
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSIIDENTCHANNEL
NullHttpChannel();

View File

@ -818,7 +818,7 @@ uint32_t nsHttpHandler::Get32BitsOfPseudoRandom() {
#endif
}
void nsHttpHandler::NotifyObservers(nsIHttpChannel* chan, const char* event) {
void nsHttpHandler::NotifyObservers(nsIChannel* chan, const char* event) {
LOG(("nsHttpHandler::NotifyObservers [chan=%p event=\"%s\"]\n", chan, event));
nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
if (obsService) obsService->NotifyObservers(chan, event, nullptr);

View File

@ -479,7 +479,7 @@ class nsHttpHandler final : public nsIHttpProtocolHandler,
MOZ_MUST_USE nsresult InitConnectionMgr();
void NotifyObservers(nsIHttpChannel* chan, const char* event);
void NotifyObservers(nsIChannel* chan, const char* event);
void SetFastOpenOSSupport();

View File

@ -16,7 +16,7 @@ interface nsIReferrerInfo;
* become available.
*/
[builtinclass, scriptable, uuid(c5a4a073-4539-49c7-a3f2-cec3f0619c6c)]
interface nsIHttpChannel : nsIChannel
interface nsIHttpChannel : nsIIdentChannel
{
/**************************************************************************
* REQUEST CONFIGURATION
@ -452,23 +452,6 @@ interface nsIHttpChannel : nsIChannel
*/
[noscript, must_use] attribute uint64_t requestContextID;
/**
* Unique ID of the channel, shared between parent and child. Needed if
* the channel activity needs to be monitored across process boundaries,
* like in devtools net monitor. See bug 1274556.
*/
[must_use] attribute uint64_t channelId;
%{ C++
inline uint64_t ChannelId()
{
uint64_t value = 0;
if (NS_SUCCEEDED(GetChannelId(&value))) {
return value;
}
return 0;
}
%}
/**
* ID of the top-level document's inner window. Identifies the content
* this channels is being load in.

View File

@ -28,6 +28,7 @@ NS_INTERFACE_MAP_BEGIN(nsViewSourceChannel)
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannel, mHttpChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIIdentChannel, mHttpChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannelInternal,
mHttpChannelInternal)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsICachingChannel, mCachingChannel)

View File

@ -30,6 +30,7 @@ class nsViewSourceChannel final : public nsIViewSourceChannel,
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSIIDENTCHANNEL
NS_DECL_NSIVIEWSOURCECHANNEL
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIREQUESTOBSERVER