Skip to content
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

bugfix(Privacy): Improve iOS Shields standard mode logic #25499

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,10 @@ window.__firefox__.execute(function($) {
return false
} else if (queryResults.foundFirstPartyResource) {
return true
} else if (showsSignificantText(element)) {
// If the subtree HAS a significant amount of text (e.g., it doesn't just says "Advertisement")
// it should be unhidden.
return true
} else if (queryResults.foundThirdPartyResource || queryResults.pendingSrcAttributes.size > 0) {
if (pendingSrcAttributes !== undefined) {
queryResults.pendingSrcAttributes.forEach((src) => {
Expand All @@ -572,12 +576,8 @@ window.__firefox__.execute(function($) {
}

return false
} else {
// If the subtree doesn't have a significant amount of text (e.g., it
// just says "Advertisement"), then no need to change anything; it should
// stay hidden.
return showsSignificantText(element)
}
return false
}

const shouldUnhideElementAsync = async (element) => {
Expand Down
7 changes: 6 additions & 1 deletion ios/brave-ios/Tests/ClientTests/Resources/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ <h1>Test Ads</h1>

<div id="test-ad-3rd-party">
<img src="http://3rd_party.localhost/image.gif">
This element should be always hidden (standard or aggressive mode) because it's a 3rd party ad.
</div>

<div id="test-ad-3rd-party-sig-text">
<img src="http://3rd_party.localhost/image.gif">
This element should be not be hidden in standard mode because it contains significant amount of text.
It should still be hidden in aggressive mode.
</div>

<div id="test-ad-simple">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ final class ScriptExecutionTests: XCTestCase {
let initialStandardSelectors = Set([".test-ads-primary-standard div"])
let initialAggressiveSelectors = Set([".test-ads-primary-aggressive div"])
let polledAggressiveIds = ["test-ad-aggressive"]
let polledStandardIds = ["test-ad-1st-party", "test-ad-3rd-party", "test-ad-simple"]
let polledStandardIds = [
"test-ad-1st-party", "test-ad-3rd-party", "test-ad-3rd-party-sig-text", "test-ad-simple",
]
let nestedIds = [
"test-ad-primary-standard-1st-party", "test-ad-primary-standard-3rd-party",
"test-ad-primary-aggressive-1st-party", "test-ad-primary-aggressive-3rd-party",
Expand Down Expand Up @@ -378,7 +380,10 @@ final class ScriptExecutionTests: XCTestCase {
)
XCTAssertEqual(resultsAfterPump?.unhiddenIds.contains("test-ad-1st-party"), true)
XCTAssertEqual(resultsAfterPump?.hiddenIds.contains("test-ad-aggressive"), true)
// hidden because of 3rd party src
XCTAssertEqual(resultsAfterPump?.hiddenIds.contains("test-ad-3rd-party"), true)
// unhidden because it contains significant amount of text
XCTAssertEqual(resultsAfterPump?.unhiddenIds.contains("test-ad-3rd-party-sig-text"), true)
XCTAssertEqual(resultsAfterPump?.hiddenIds.contains("test-ad-simple"), true)
XCTAssertEqual(
resultsAfterPump?.hiddenIds.contains("test-ad-primary-aggressive-1st-party"),
Expand Down
Loading