-
Notifications
You must be signed in to change notification settings - Fork 921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collapse HTML elements with blocked image/iframe requests #9144
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
#include "base/task/post_task.h" | ||
#include "brave/browser/net/brave_request_handler.h" | ||
#include "brave/components/brave_shields/browser/adblock_stub_response.h" | ||
#include "brave/components/brave_shields/common/features.h" | ||
#include "content/public/browser/browser_context.h" | ||
#include "content/public/browser/browser_task_traits.h" | ||
#include "content/public/browser/browser_thread.h" | ||
|
@@ -610,7 +611,17 @@ void BraveProxyingURLLoaderFactory::InProgressRequest:: | |
void BraveProxyingURLLoaderFactory::InProgressRequest::OnRequestError( | ||
const network::URLLoaderCompletionStatus& status) { | ||
if (!request_completed_) { | ||
target_client_->OnComplete(status); | ||
// Make a non-const copy of status so that |should_collapse_initiator| can | ||
// be modified | ||
network::URLLoaderCompletionStatus collapse_status(status); | ||
|
||
if (base::FeatureList::IsEnabled( | ||
::brave_shields::features::kBraveAdblockCollapseBlockedElements) && | ||
ctx_->blocked_by == brave::kAdBlocked) { | ||
collapse_status.should_collapse_initiator = true; | ||
} | ||
|
||
target_client_->OnComplete(collapse_status); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we please add a test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did look into this briefly - collapsed elements cannot be detected in JS, and the only API Chromium exposes for this is Is it allowed to access the Blink elements in browsertests? Otherwise we could probably try some hacky JS where we check the size of a parent element, but it seems fragile. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried for a bit to access |
||
} | ||
|
||
// Deletes |this|. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,10 @@ namespace features { | |
// substituted for any canonical name found. | ||
const base::Feature kBraveAdblockCnameUncloaking{ | ||
"BraveAdblockCnameUncloaking", base::FEATURE_ENABLED_BY_DEFAULT}; | ||
// When enabled, Brave will apply HTML element collapsing to all images and | ||
// iframes that initiate a blocked network request. | ||
const base::Feature kBraveAdblockCollapseBlockedElements{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please add a comment? |
||
"BraveAdblockCollapseBlockedElements", base::FEATURE_ENABLED_BY_DEFAULT}; | ||
const base::Feature kBraveAdblockCosmeticFiltering{ | ||
"BraveAdblockCosmeticFiltering", | ||
base::FEATURE_ENABLED_BY_DEFAULT}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a comment