Bug 1556489 - P25. Make nsIIdentChannel support conditional for nsBaseChannel. r=mayhemer

So that we can restrict QI(nsIIdentChannel) to nsIHttpChannel and DocumentChannelChild objects only.

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

MANUAL PUSH: multiple authors stack
This commit is contained in:
Jean-Yves Avenard 2019-08-30 15:15:29 +10:00
Родитель e93ff775a3
Коммит 1c657f7d19
3 изменённых файлов: 39 добавлений и 13 удалений

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

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

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

@ -7,6 +7,7 @@
#define nsBaseChannel_h__ #define nsBaseChannel_h__
#include "mozilla/net/NeckoTargetHolder.h" #include "mozilla/net/NeckoTargetHolder.h"
#include "mozilla/Maybe.h"
#include "mozilla/MozPromise.h" #include "mozilla/MozPromise.h"
#include "nsString.h" #include "nsString.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
@ -41,6 +42,12 @@ class nsIInputStream;
// //
// nsBaseChannel implements nsITransportEventSink to support progress & status // nsBaseChannel implements nsITransportEventSink to support progress & status
// notifications generated by the transport layer. // notifications generated by the transport layer.
//
// nsBaseChannel will only implement nsIIdentChannel if mChannelId is set.
// It is required for devtools to capture transfer information for network
// connection, and not all nsBaseChannel implementation should be logged.
// Currently only DocumentChannelChild implements nsIIdentChannel via
// nsBaseChannel.
class nsBaseChannel class nsBaseChannel
: public nsHashPropertyBag, : public nsHashPropertyBag,
@ -300,7 +307,7 @@ class nsBaseChannel
uint32_t mContentDispositionHint; uint32_t mContentDispositionHint;
nsAutoPtr<nsString> mContentDispositionFilename; nsAutoPtr<nsString> mContentDispositionFilename;
int64_t mContentLength; int64_t mContentLength;
uint64_t mChannelId; mozilla::Maybe<uint64_t> mChannelId;
bool mWasOpened; bool mWasOpened;
friend class mozilla::net::PrivateBrowsingChannel<nsBaseChannel>; friend class mozilla::net::PrivateBrowsingChannel<nsBaseChannel>;

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

@ -15,12 +15,13 @@
#include "mozilla/ipc/URIUtils.h" #include "mozilla/ipc/URIUtils.h"
#include "mozilla/net/HttpChannelChild.h" #include "mozilla/net/HttpChannelChild.h"
#include "mozilla/net/NeckoChild.h" #include "mozilla/net/NeckoChild.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "nsContentSecurityManager.h" #include "nsContentSecurityManager.h"
#include "nsDocShellLoadState.h" #include "nsDocShellLoadState.h"
#include "nsHttpHandler.h"
#include "nsQueryObject.h" #include "nsQueryObject.h"
#include "nsSerializationHelper.h" #include "nsSerializationHelper.h"
#include "nsStringStream.h" #include "nsStringStream.h"
#include "mozilla/net/UrlClassifierCommon.h"
using namespace mozilla::dom; using namespace mozilla::dom;
using namespace mozilla::ipc; using namespace mozilla::ipc;
@ -60,6 +61,10 @@ DocumentChannelChild::DocumentChannelChild(
SetURI(aLoadState->URI()); SetURI(aLoadState->URI());
SetLoadInfo(aLoadInfo); SetLoadInfo(aLoadInfo);
SetLoadFlags(aLoadFlags); SetLoadFlags(aLoadFlags);
RefPtr<nsHttpHandler> handler = nsHttpHandler::GetInstance();
uint64_t channelId;
Unused << handler->NewChannelId(channelId);
mChannelId.emplace(channelId);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -141,7 +146,7 @@ DocumentChannelChild::AsyncOpen(nsIStreamListener* aListener) {
args.cacheKey() = mCacheKey; args.cacheKey() = mCacheKey;
args.isActive() = mIsActive; args.isActive() = mIsActive;
args.isTopLevelDoc() = mIsTopLevelDoc; args.isTopLevelDoc() = mIsTopLevelDoc;
args.channelId() = mChannelId; args.channelId() = *mChannelId;
nsCOMPtr<nsILoadContext> loadContext; nsCOMPtr<nsILoadContext> loadContext;
NS_QueryNotificationCallbacks(this, loadContext); NS_QueryNotificationCallbacks(this, loadContext);