Bug 1563313 - URL-Classifier should process nsIChannel before the proxy, r=mayhemer

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-07-15 19:57:23 +00:00
Родитель 36a14d5002
Коммит 4e5ad511f5
3 изменённых файлов: 56 добавлений и 93 удалений

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

@ -6989,13 +6989,6 @@ VARCACHE_PREF(
RelaxedAtomicBool, false
)
VARCACHE_PREF(
Live,
"network.delay.tracking.load",
network_delay_tracking_load,
uint32_t, 0
)
// Max time to shutdown the resolver threads
VARCACHE_PREF(
Live,

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

@ -6495,8 +6495,6 @@ nsHttpChannel::AsyncOpen(nsIStreamListener* aListener) {
nsresult nsHttpChannel::AsyncOpenFinal(TimeStamp aTimeStamp) {
// Added due to PauseTask/DelayHttpChannel
nsresult rv;
if (mLoadGroup) mLoadGroup->AddRequest(this, nullptr);
// record asyncopen time unconditionally and clear it if we
@ -6511,6 +6509,39 @@ nsresult nsHttpChannel::AsyncOpenFinal(TimeStamp aTimeStamp) {
// just once and early, AsyncOpen is the best place.
mCustomAuthHeader = mRequestHead.HasHeader(nsHttp::Authorization);
if (!NS_ShouldClassifyChannel(this)) {
return MaybeResolveProxyAndBeginConnect();
}
// We are about to do an async lookup to check if the URI is a tracker. If
// yes, this channel will be canceled by channel classifier. Chances are the
// lookup is not needed so CheckIsTrackerWithLocalTable() will return an
// error and then we can MaybeResolveProxyAndBeginConnect() right away.
RefPtr<nsHttpChannel> self = this;
bool willCallback = NS_SUCCEEDED(
AsyncUrlChannelClassifier::CheckChannel(this, [self]() -> void {
nsresult rv = self->MaybeResolveProxyAndBeginConnect();
if (NS_FAILED(rv)) {
// Since this error is thrown asynchronously so that the caller
// of BeginConnect() will not do clean up for us. We have to do
// it on our own.
self->CloseCacheEntry(false);
Unused << self->AsyncAbort(rv);
}
}));
if (!willCallback) {
// We can do MaybeResolveProxyAndBeginConnect immediately if
// CheckIsTrackerWithLocalTable is failed. Note that we don't need to
// handle the failure because BeginConnect() will return synchronously and
// the caller will be responsible for handling it.
return MaybeResolveProxyAndBeginConnect();
}
return NS_OK;
}
nsresult nsHttpChannel::MaybeResolveProxyAndBeginConnect() {
// The common case for HTTP channels is to begin proxy resolution and return
// at this point. The only time we know mProxyInfo already is if we're
// proxying a non-http protocol like ftp. We don't need to discover proxy
@ -6521,7 +6552,7 @@ nsresult nsHttpChannel::AsyncOpenFinal(TimeStamp aTimeStamp) {
return NS_OK;
}
rv = BeginConnect();
nsresult rv = BeginConnect();
if (NS_FAILED(rv)) {
CloseCacheEntry(false);
Unused << AsyncAbort(rv);
@ -6739,57 +6770,30 @@ nsresult nsHttpChannel::BeginConnect() {
return mStatus;
}
if (!NS_ShouldClassifyChannel(this)) {
MaybeStartDNSPrefetch();
return ContinueBeginConnectWithResult();
if (mChannelClassifierCancellationPending) {
LOG(
("Waiting for safe-browsing protection cancellation in BeginConnect "
"[this=%p]\n",
this));
return NS_OK;
}
// We are about to do an async lookup to check if the URI is a
// tracker. If yes, this channel will be canceled by channel classifier.
// Chances are the lookup is not needed so CheckIsTrackerWithLocalTable()
// will return an error and then we can BeginConnectActual() right away.
RefPtr<nsHttpChannel> self = this;
bool willCallback = NS_SUCCEEDED(
AsyncUrlChannelClassifier::CheckChannel(this, [self]() -> void {
auto nextFunc = [self]() -> void {
nsresult rv = self->BeginConnectActual();
if (NS_FAILED(rv)) {
// Since this error is thrown asynchronously so that the caller
// of BeginConnect() will not do clean up for us. We have to do
// it on our own.
self->CloseCacheEntry(false);
Unused << self->AsyncAbort(rv);
}
};
ReEvaluateReferrerAfterTrackingStatusIsKnown();
uint32_t delayMillisec = StaticPrefs::network_delay_tracking_load();
if (self->IsThirdPartyTrackingResource() && delayMillisec) {
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction(
"nsHttpChannel::BeginConnect-delayed", nextFunc);
nsresult rv = NS_DelayedDispatchToCurrentThread(runnable.forget(),
delayMillisec);
if (NS_SUCCEEDED(rv)) {
LOG(
("nsHttpChannel::BeginConnect delaying 3rd-party tracking "
"resource for %u ms [this=%p]",
delayMillisec, self.get()));
return;
}
LOG(("nsHttpChannel::BeginConnect unable to delay loading. [this=%p]",
self.get()));
}
MaybeStartDNSPrefetch();
nextFunc();
}));
if (!willCallback) {
// We can do BeginConnectActual immediately if CheckIsTrackerWithLocalTable
// is failed. Note that we don't need to handle the failure because
// BeginConnect() will return synchronously and the caller will be
// responsible for handling it.
return BeginConnectActual();
rv = ContinueBeginConnectWithResult();
if (NS_FAILED(rv)) {
return rv;
}
// Start nsChannelClassifier to catch phishing and malware URIs.
RefPtr<nsChannelClassifier> channelClassifier =
GetOrCreateChannelClassifier();
LOG(("nsHttpChannel::Starting nsChannelClassifier %p [this=%p]",
channelClassifier.get(), this));
channelClassifier->Start();
return NS_OK;
}
@ -6819,40 +6823,6 @@ void nsHttpChannel::MaybeStartDNSPrefetch() {
}
}
nsresult nsHttpChannel::BeginConnectActual() {
if (mCanceled) {
return mStatus;
}
AUTO_PROFILER_LABEL("nsHttpChannel::BeginConnectActual", NETWORK);
if (mChannelClassifierCancellationPending) {
LOG(
("Waiting for safe-browsing protection cancellation in "
"BeginConnectActual [this=%p]\n",
this));
return NS_OK;
}
ReEvaluateReferrerAfterTrackingStatusIsKnown();
MaybeStartDNSPrefetch();
nsresult rv = ContinueBeginConnectWithResult();
if (NS_FAILED(rv)) {
return rv;
}
// Start nsChannelClassifier to catch phishing and malware URIs.
RefPtr<nsChannelClassifier> channelClassifier =
GetOrCreateChannelClassifier();
LOG(("nsHttpChannel::Starting nsChannelClassifier %p [this=%p]",
channelClassifier.get(), this));
channelClassifier->Start();
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetEncodedBodySize(uint64_t* aEncodedBodySize) {
if (mCacheEntry && !mCacheEntryIsWriteOnly) {

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

@ -316,13 +316,13 @@ class nsHttpChannel final : public HttpBaseChannel,
// Connections will only be established in this function.
// (including DNS prefetch and speculative connection.)
nsresult BeginConnectActual();
nsresult MaybeResolveProxyAndBeginConnect();
void MaybeStartDNSPrefetch();
// We might synchronously or asynchronously call BeginConnectActual,
// We might synchronously or asynchronously call BeginConnect,
// which includes DNS prefetch and speculative connection, according to
// whether an async tracker lookup is required. If the tracker lookup
// is required, this funciton will just return NS_OK and BeginConnectActual()
// is required, this funciton will just return NS_OK and BeginConnect()
// will be called when callback. See Bug 1325054 for more information.
nsresult BeginConnect();
MOZ_MUST_USE nsresult ContinueBeginConnectWithResult();
@ -587,7 +587,7 @@ class nsHttpChannel final : public HttpBaseChannel,
// nsChannelClassifier checks this channel's URI against
// the URI classifier service.
// nsChannelClassifier will be invoked twice in InitLocalBlockList() and
// BeginConnectActual(), so save the nsChannelClassifier here to keep the
// BeginConnect(), so save the nsChannelClassifier here to keep the
// state of whether tracking protection is enabled or not.
RefPtr<nsChannelClassifier> mChannelClassifier;