Skip to content

Commit

Permalink
Merge pull request #5545 from brave/francois-add-referrer-tests-7933
Browse files Browse the repository at this point in the history
Add referrer test cases in preparation for overhaul
  • Loading branch information
fmarier authored May 22, 2020
2 parents a63c567 + 534f3e6 commit 858cd58
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 56 deletions.
16 changes: 13 additions & 3 deletions browser/net/brave_request_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/constants.h"

#if BUILDFLAG(ENABLE_BRAVE_REFERRALS)
#include "brave/browser/net/brave_referrals_network_delegate_helper.h"
Expand All @@ -42,6 +44,12 @@
#include "brave/browser/net/brave_translate_redirect_network_delegate_helper.h"
#endif

static bool IsInternalScheme(std::shared_ptr<brave::BraveRequestInfo> ctx) {
DCHECK(ctx);
return ctx->request_url.SchemeIs(extensions::kExtensionScheme) ||
ctx->request_url.SchemeIs(content::kChromeUIScheme);
}

BraveRequestHandler::BraveRequestHandler() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
SetupCallbacks();
Expand Down Expand Up @@ -125,7 +133,7 @@ int BraveRequestHandler::OnBeforeURLRequest(
std::shared_ptr<brave::BraveRequestInfo> ctx,
net::CompletionOnceCallback callback,
GURL* new_url) {
if (before_url_request_callbacks_.empty()) {
if (before_url_request_callbacks_.empty() || IsInternalScheme(ctx)) {
return net::OK;
}
SCOPED_UMA_HISTOGRAM_TIMER("Brave.OnBeforeURLRequest_Handler");
Expand All @@ -140,7 +148,7 @@ int BraveRequestHandler::OnBeforeStartTransaction(
std::shared_ptr<brave::BraveRequestInfo> ctx,
net::CompletionOnceCallback callback,
net::HttpRequestHeaders* headers) {
if (before_start_transaction_callbacks_.empty()) {
if (before_start_transaction_callbacks_.empty() || IsInternalScheme(ctx)) {
return net::OK;
}
ctx->event_type = brave::kOnBeforeStartTransaction;
Expand All @@ -163,7 +171,9 @@ int BraveRequestHandler::OnHeadersReceived(
original_response_headers, override_response_headers);
}

if (headers_received_callbacks_.empty()) {
if (headers_received_callbacks_.empty() &&
!ctx->request_url.SchemeIs(content::kChromeUIScheme)) {
// Extension scheme not excluded since brave_webtorrent needs it.
return net::OK;
}

Expand Down
Loading

0 comments on commit 858cd58

Please sign in to comment.