Bug 1613873 - P1: Implementation of SimpleHttpChannel r=dragana

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kershaw Chang 2020-03-03 09:31:35 +00:00
Родитель c603f2f85e
Коммит e32252cd65
7 изменённых файлов: 1347 добавлений и 25 удалений

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

@ -385,6 +385,7 @@ nsresult HttpBaseChannel::Init(nsIURI* aURI, uint32_t aCaps,
!type.EqualsLiteral("unknown"))
mProxyInfo = aProxyInfo;
mCurrentThread = GetCurrentThreadEventTarget();
return rv;
}
@ -2983,7 +2984,8 @@ HttpBaseChannel::SetNewListener(nsIStreamListener* aListener,
//-----------------------------------------------------------------------------
void HttpBaseChannel::ReleaseListeners() {
MOZ_ASSERT(NS_IsMainThread(), "Should only be called on the main thread.");
MOZ_ASSERT(mCurrentThread->IsOnCurrentThread(),
"Should only be called on the current thread");
mListener = nullptr;
mCallbacks = nullptr;

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

@ -621,6 +621,7 @@ class HttpBaseChannel : public nsHashPropertyBag,
nsCOMPtr<nsIStreamListener> mListener;
// An instance of nsHTTPCompressConv
nsCOMPtr<nsIStreamListener> mCompressListener;
nsCOMPtr<nsIEventTarget> mCurrentThread;
private:
// Proxy release all members above on main thread.

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -0,0 +1,145 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_net_SimpleHttpChannel_h
#define mozilla_net_SimpleHttpChannel_h
#include "HttpBaseChannel.h"
#include "nsIDNSListener.h"
#include "nsIStreamListener.h"
#include "nsWeakReference.h"
class nsDNSPrefetch;
namespace mozilla {
namespace net {
class HttpTransactionShell;
class nsHttpHandler;
// Use to support QI nsIChannel to SimpleHttpChannel
#define NS_SIMPLEHTTPCHANNEL_IID \
{ \
0x361c4bb1, 0xd6b2, 0x493b, { \
0x86, 0xbc, 0x88, 0xd3, 0x5d, 0x16, 0x38, 0xfa \
} \
}
class SimpleHttpChannel : public HttpBaseChannel,
public HttpAsyncAborter<SimpleHttpChannel>,
public nsIDNSListener,
public nsIStreamListener,
public nsITransportEventSink,
public nsIProxiedChannel,
public nsSupportsWeakReference {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDNSLISTENER
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSITRANSPORTEVENTSINK
NS_DECL_NSIPROXIEDCHANNEL
NS_DECLARE_STATIC_IID_ACCESSOR(NS_SIMPLEHTTPCHANNEL_IID)
// nsIRequest
NS_IMETHOD Cancel(nsresult status) override;
NS_IMETHOD Suspend() override;
NS_IMETHOD Resume() override;
NS_IMETHOD GetLoadFlags(nsLoadFlags* aLoadFlags) override;
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) override;
NS_IMETHOD GetURI(nsIURI** aURI) override;
NS_IMETHOD GetNotificationCallbacks(
nsIInterfaceRequestor** aCallbacks) override;
NS_IMETHOD GetLoadGroup(nsILoadGroup** aLoadGroup) override;
NS_IMETHOD GetRequestMethod(nsACString& aMethod) override;
// nsIChannel
NS_IMETHOD GetSecurityInfo(nsISupports** aSecurityInfo) override;
NS_IMETHOD AsyncOpen(nsIStreamListener* aListener) override;
NS_IMETHOD LogBlockedCORSRequest(const nsAString& aMessage,
const nsACString& aCategory) override;
NS_IMETHOD LogMimeTypeMismatch(const nsACString& aMessageName, bool aWarning,
const nsAString& aURL,
const nsAString& aContentType) override;
NS_IMETHOD SetupFallbackChannel(const char* aFallbackKey) override;
NS_IMETHOD SetNotificationCallbacks(
nsIInterfaceRequestor* aCallbacks) override;
// nsISupportsPriority
NS_IMETHOD SetPriority(int32_t value) override;
// nsIClassOfService
NS_IMETHOD SetClassFlags(uint32_t inFlags) override;
NS_IMETHOD AddClassFlags(uint32_t inFlags) override;
NS_IMETHOD ClearClassFlags(uint32_t inFlags) override;
// nsIResumableChannel
NS_IMETHOD ResumeAt(uint64_t startPos, const nsACString& entityID) override;
MOZ_MUST_USE nsresult OnPush(uint32_t aPushedStreamId, const nsACString& aUrl,
const nsACString& aRequestString,
HttpTransactionShell* aTransaction);
void SetPushedStreamTransactionAndId(
HttpTransactionShell* aTransWithPushedStream, uint32_t aPushedStreamId);
// nsITimedChannel
NS_IMETHOD GetDomainLookupStart(
mozilla::TimeStamp* aDomainLookupStart) override;
NS_IMETHOD GetDomainLookupEnd(mozilla::TimeStamp* aDomainLookupEnd) override;
NS_IMETHOD GetConnectStart(mozilla::TimeStamp* aConnectStart) override;
NS_IMETHOD GetTcpConnectEnd(mozilla::TimeStamp* aTcpConnectEnd) override;
NS_IMETHOD GetSecureConnectionStart(
mozilla::TimeStamp* aSecureConnectionStart) override;
NS_IMETHOD GetConnectEnd(mozilla::TimeStamp* aConnectEnd) override;
NS_IMETHOD GetRequestStart(mozilla::TimeStamp* aRequestStart) override;
NS_IMETHOD GetResponseStart(mozilla::TimeStamp* aResponseStart) override;
NS_IMETHOD GetResponseEnd(mozilla::TimeStamp* aResponseEnd) override;
protected:
SimpleHttpChannel();
virtual ~SimpleHttpChannel();
void CancelNetworkRequest(nsresult aStatus);
const nsCString& GetTopWindowOrigin();
nsresult BeginConnect();
nsresult ContinueOnBeforeConnect();
nsresult Connect();
nsresult SetupTransaction();
void OnClassOfServiceUpdated();
virtual void DoNotifyListenerCleanup() override;
virtual void DoAsyncAbort(nsresult aStatus) override;
bool IsIsolated() { return false; };
void ProcessAltService();
nsresult CallOnStartRequest();
void MaybeStartDNSPrefetch();
void DoNotifyListener();
// True only when we have computed the value of the top window origin.
bool mTopWindowOriginComputed;
nsCString mUsername;
// The origin of the top window, only valid when mTopWindowOriginComputed is
// true.
nsCString mTopWindowOrigin;
// Needed for accurate DNS timing
RefPtr<nsDNSPrefetch> mDNSPrefetch;
nsCOMPtr<nsIRequest> mTransactionPump;
RefPtr<HttpTransactionShell> mTransaction;
uint32_t mPushedStreamId;
RefPtr<HttpTransactionShell> mTransWithPushedStream;
friend class HttpAsyncAborter<SimpleHttpChannel>;
friend class nsHttpHandler;
};
NS_DEFINE_STATIC_IID_ACCESSOR(SimpleHttpChannel, NS_SIMPLEHTTPCHANNEL_IID)
} // namespace net
} // namespace mozilla
#endif // mozilla_net_SimpleHttpChannel_h

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

@ -59,6 +59,7 @@ EXPORTS.mozilla.net += [
'ParentChannelListener.h',
'PHttpChannelParams.h',
'PSpdyPush.h',
'SimpleHttpChannel.h',
'TimingStruct.h',
]
@ -122,6 +123,7 @@ UNIFIED_SOURCES += [
'NullHttpTransaction.cpp',
'ParentChannelListener.cpp',
'QuicSocketControl.cpp',
'SimpleHttpChannel.cpp',
'TunnelUtils.cpp',
]

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

@ -66,6 +66,7 @@
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/LazyIdleThread.h"
#include "mozilla/SyncRunnable.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/Navigator.h"
@ -73,6 +74,7 @@
#include "mozilla/dom/network/Connection.h"
#include "nsNSSComponent.h"
#include "SimpleHttpChannel.h"
#if defined(XP_UNIX)
# include <sys/utsname.h>
@ -1986,6 +1988,23 @@ static nsresult PrepareAcceptLanguages(const char* i_AcceptLanguages,
}
nsresult nsHttpHandler::SetAcceptLanguages() {
if (!NS_IsMainThread()) {
nsCOMPtr<nsIThread> mainThread;
nsresult rv = NS_GetMainThread(getter_AddRefs(mainThread));
if (NS_FAILED(rv)) {
return rv;
}
// Forward to the main thread synchronously.
SyncRunnable::DispatchToThread(
mainThread, new SyncRunnable(NS_NewRunnableFunction(
"nsHttpHandler::SetAcceptLanguages",
[&rv]() { rv = gHttpHandler->SetAcceptLanguages(); })));
return rv;
}
MOZ_ASSERT(NS_IsMainThread());
mAcceptLanguagesIsDirty = false;
nsAutoCString acceptLanguages;
@ -2072,13 +2091,11 @@ nsHttpHandler::AllowPort(int32_t port, const char* scheme, bool* _retval) {
// nsHttpHandler::nsIProxiedProtocolHandler
//-----------------------------------------------------------------------------
NS_IMETHODIMP
nsHttpHandler::NewProxiedChannel(nsIURI* uri, nsIProxyInfo* givenProxyInfo,
uint32_t proxyResolveFlags, nsIURI* proxyURI,
nsILoadInfo* aLoadInfo, nsIChannel** result) {
RefPtr<HttpBaseChannel> httpChannel;
LOG(("nsHttpHandler::NewProxiedChannel [proxyInfo=%p]\n", givenProxyInfo));
nsresult nsHttpHandler::SetupChannelInternal(
HttpBaseChannel* aChannel, nsIURI* uri, nsIProxyInfo* givenProxyInfo,
uint32_t proxyResolveFlags, nsIURI* proxyURI, nsILoadInfo* aLoadInfo,
nsIChannel** result) {
RefPtr<HttpBaseChannel> httpChannel = aChannel;
#ifdef MOZ_TASK_TRACER
if (tasktracer::IsStartLogging()) {
@ -2094,19 +2111,8 @@ nsHttpHandler::NewProxiedChannel(nsIURI* uri, nsIProxyInfo* givenProxyInfo,
NS_ENSURE_ARG(proxyInfo);
}
if (IsNeckoChild()) {
httpChannel = new HttpChannelChild();
} else {
httpChannel = new nsHttpChannel();
}
uint32_t caps = mCapabilities;
if (!IsNeckoChild()) {
// HACK: make sure PSM gets initialized on the main thread.
net_EnsurePSMInit();
}
uint64_t channelId;
nsresult rv = NewChannelId(channelId);
NS_ENSURE_SUCCESS(rv, rv);
@ -2119,16 +2125,51 @@ nsHttpHandler::NewProxiedChannel(nsIURI* uri, nsIProxyInfo* givenProxyInfo,
channelId, contentPolicyType);
if (NS_FAILED(rv)) return rv;
// set the loadInfo on the new channel
rv = httpChannel->SetLoadInfo(aLoadInfo);
if (NS_FAILED(rv)) {
return rv;
// SimpleHttpChannel doesn't need loadInfo.
if (aLoadInfo) {
// set the loadInfo on the new channel
rv = httpChannel->SetLoadInfo(aLoadInfo);
if (NS_FAILED(rv)) {
return rv;
}
}
httpChannel.forget(result);
return NS_OK;
}
NS_IMETHODIMP
nsHttpHandler::NewProxiedChannel(nsIURI* uri, nsIProxyInfo* givenProxyInfo,
uint32_t proxyResolveFlags, nsIURI* proxyURI,
nsILoadInfo* aLoadInfo, nsIChannel** result) {
HttpBaseChannel* httpChannel;
LOG(("nsHttpHandler::NewProxiedChannel [proxyInfo=%p]\n", givenProxyInfo));
if (IsNeckoChild()) {
httpChannel = new HttpChannelChild();
} else {
// HACK: make sure PSM gets initialized on the main thread.
net_EnsurePSMInit();
httpChannel = new nsHttpChannel();
}
return SetupChannelInternal(httpChannel, uri, givenProxyInfo,
proxyResolveFlags, proxyURI, aLoadInfo, result);
}
nsresult nsHttpHandler::CreateSimpleHttpChannel(
nsIURI* uri, nsIProxyInfo* givenProxyInfo, uint32_t proxyResolveFlags,
nsIURI* proxyURI, nsILoadInfo* aLoadInfo, nsIChannel** result) {
HttpBaseChannel* httpChannel = new SimpleHttpChannel();
LOG(("nsHttpHandler::CreateSimpleHttpChannel [proxyInfo=%p]\n",
givenProxyInfo));
return SetupChannelInternal(httpChannel, uri, givenProxyInfo,
proxyResolveFlags, proxyURI, aLoadInfo, result);
}
//-----------------------------------------------------------------------------
// nsHttpHandler::nsIHttpProtocolHandler
//-----------------------------------------------------------------------------
@ -2655,7 +2696,6 @@ void nsHttpHandler::ShutdownConnectionManager() {
}
nsresult nsHttpHandler::NewChannelId(uint64_t& channelId) {
MOZ_ASSERT(NS_IsMainThread());
channelId =
((static_cast<uint64_t>(mProcessId) << 32) & 0xFFFFFFFF00000000LL) |
mNextChannelId++;

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

@ -53,6 +53,8 @@ class nsHttpConnection;
class nsHttpConnectionInfo;
class HttpTransactionShell;
class AltSvcMapping;
class SimpleHttpChannel;
class TRR;
/*
* FRAMECHECK_LAX - no check
@ -501,6 +503,17 @@ class nsHttpHandler final : public nsIHttpProtocolHandler,
// thread. Updates mSpeculativeConnectEnabled when done.
void MaybeEnableSpeculativeConnect();
// We only allow TRR and SimpleHttpChannel itself to create SimpleHttpChannel.
friend class SimpleHttpChannel;
friend class TRR;
nsresult CreateSimpleHttpChannel(nsIURI* uri, nsIProxyInfo* givenProxyInfo,
uint32_t proxyResolveFlags, nsIURI* proxyURI,
nsILoadInfo* aLoadInfo, nsIChannel** result);
nsresult SetupChannelInternal(HttpBaseChannel* aChannel, nsIURI* uri,
nsIProxyInfo* givenProxyInfo,
uint32_t proxyResolveFlags, nsIURI* proxyURI,
nsILoadInfo* aLoadInfo, nsIChannel** result);
private:
// cached services
nsMainThreadPtrHandle<nsIIOService> mIOService;
@ -773,7 +786,7 @@ class nsHttpHandler final : public nsIHttpProtocolHandler,
// State for generating channelIds
uint32_t mProcessId;
uint32_t mNextChannelId;
Atomic<uint32_t, Relaxed> mNextChannelId;
// The last time any of the active tab page load optimization took place.
// This is accessed on multiple threads, hence a lock is needed.