-
Notifications
You must be signed in to change notification settings - Fork 14
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
update ClickToLoad to use shared C-S-S #2162
Merged
Merged
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
01c8a53
swap embedded user script with CSS one
ladamski cf561f1
fire "displayCLickToLoadPlaceholders" on load completion
ladamski 98cb9c5
disable old CTL user script
ladamski 8a3f6d6
test - trigger CTL on FB tracker match
ladamski 367f031
switch to isolated scope, hook up overlay trigger
ladamski e19f103
use v6 TDS, updated config
ladamski ae481dc
move CTL code to subfolder
ladamski 50f1411
update CTL rule management to use main TDS
ladamski b603ed7
WIP rule splitting for custom actions
ladamski f971774
cleanup FB protection state management
ladamski daf57ad
update embedded config and TDS
ladamski 0d2c7a4
remove dead code
ladamski 3a0c7fd
switch back to separate blocking CTL rule set
ladamski 7156d78
switch back to previous CTL rules, part 2
ladamski fd7287e
combine rules for surrogates user script
ladamski 7025ba1
cleanup surrogate code to remove need for vars
ladamski d3d0c87
update embeds
ladamski 4879680
update config clickToPlay -> clickToLoad
ladamski 909e53b
burn with fire (dead code)
ladamski be1a4ea
dead code cleanup part 2
ladamski 12cce92
clarify method naming
ladamski 7ed7200
handle empty ruleset in in surrogate generation (unit tests)
ladamski b249af6
use fallback TDS for CTL test vs old embedded CTL TDS
ladamski a5e1287
bump TDS test to v6
ladamski a93d49d
remove remapping of custom action .blockCtlFB to .block
ladamski 5069df9
remove dead fonts, post-merge cleanup
ladamski f77d0c7
TEMP disable CTL assertions while testing
ladamski 7c3f672
address @MainActor warnings, remove debug spam
ladamski 1bc59ed
lint nit
ladamski 841de53
try special casing NavigationType.backForward for CTL
ladamski 838d6f8
remove MD5 func
ladamski abdb4f0
move FB entity string to const in FBProtectionTabExtension
ladamski 1999c4a
update splitter logic per PR review, fix test
ladamski 3ca418b
Update CTL rule splitting logic with alternate path (#2733)
ladamski 95a798c
update rule combining logic per last rule splitting update
ladamski 1856498
remove dead ClickToLoadModel code
ladamski 4a05050
Update ClickToLoadRulesSplitter.swift
ladamski 0072d09
code review nits
ladamski 2a61134
Merge branch 'main' into la/update-ctl
ladamski d19a19f
cleanup FIXME
ladamski 223b434
update to BSK WIP branch
ladamski cb42dd6
Update proj file and BSK ref
jaceklyp 098696e
remove unused var
ladamski b01f13e
update CTL action to blockCTLFB
ladamski 084d24d
add CTL test for rules splitting
ladamski 2a2cf71
test nits
ladamski 85cc309
move ClickToLoadRulesSpliter to BSK
ladamski 3673f70
Update ClickToLoadTDSTests.swift
ladamski 6ca5394
move ClickToLoadRulesSplitter to BSK
ladamski d55102c
review nits
ladamski 77993dd
Update ClickToLoadTDSTests.swift
ladamski 13af034
test tweaks
ladamski f5c56fd
Update ClickToLoadTDSTests.swift
ladamski 24566fd
remove forward/back nav exception in FB protections
ladamski 98c095b
revert config URL to prod and update embeds
ladamski 2d04a7c
release BSK
ladamski 0479655
update BSK dep
ladamski 84d76eb
Merge branch 'main' into la/update-ctl
ladamski ef74977
Restore NetP Package.swift
bwaresiak 388d73e
version bump to 1.93.0
ladamski a0ab778
Revert "version bump to 1.93.0"
ladamski 5e5feb1
nit
ladamski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
update CTL rule management to use main TDS
- Loading branch information
commit 50f14111a9302d9cd9583e65bf60d16036ab7130
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
DuckDuckGo/ContentBlocker/ClickToLoad/ClickToLoadRulesSplitter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// | ||
// ClickToLoadRulesSplitter.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2023 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import TrackerRadarKit | ||
import BrowserServicesKit | ||
|
||
struct ClickToLoadRulesSplitter { | ||
|
||
public enum Constant { | ||
|
||
public static let clickToLoadRuleListPrefix = "CTL_" | ||
|
||
} | ||
|
||
private let rulesList: ContentBlockerRulesList | ||
|
||
init(rulesList: ContentBlockerRulesList) { | ||
self.rulesList = rulesList | ||
} | ||
|
||
func split() -> (withoutBlockCTL: ContentBlockerRulesList, withBlockCTL: ContentBlockerRulesList)? { | ||
let splitTDS = rulesList.trackerData != nil ? split(trackerData: rulesList.trackerData!) : nil | ||
let splitFallbackTDS = split(trackerData: rulesList.fallbackTrackerData) | ||
|
||
if splitTDS != nil || splitFallbackTDS != nil { | ||
return ( | ||
ContentBlockerRulesList(name: rulesList.name, | ||
trackerData: splitTDS?.withoutBlockCTL ?? rulesList.trackerData, | ||
fallbackTrackerData: splitFallbackTDS?.withoutBlockCTL ?? rulesList.fallbackTrackerData), | ||
ladamski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ContentBlockerRulesList(name: "XD", | ||
trackerData: splitTDS?.withBlockCTL ?? rulesList.trackerData, | ||
fallbackTrackerData: splitFallbackTDS?.withBlockCTL ?? rulesList.fallbackTrackerData) | ||
) | ||
} | ||
return nil | ||
} | ||
|
||
private func split(trackerData: TrackerDataManager.DataSet) -> (withoutBlockCTL: TrackerDataManager.DataSet, withBlockCTL: TrackerDataManager.DataSet)? { | ||
let trackersWithBlockCTL = filterTrackersByBlockCTLAction(trackerData.tds.trackers, hasBlockCTL: true) | ||
|
||
if !trackersWithBlockCTL.isEmpty { | ||
let trackersWithoutBlockCTL = filterTrackersByBlockCTLAction(trackerData.tds.trackers, hasBlockCTL: false) | ||
let trackerDataWithoutBlockCTL = makeTrackerData(using: trackersWithoutBlockCTL, originalTDS: trackerData.tds) | ||
let trackerDataWithBlockCTL = makeTrackerData(using: trackersWithBlockCTL, originalTDS: trackerData.tds) | ||
|
||
return ( | ||
(tds: trackerDataWithoutBlockCTL, etag: Constant.clickToLoadRuleListPrefix + trackerData.etag), | ||
(tds: trackerDataWithBlockCTL, etag: Constant.clickToLoadRuleListPrefix + trackerData.etag) | ||
) | ||
} | ||
return nil | ||
} | ||
|
||
private func makeTrackerData(using trackers: [String: KnownTracker], originalTDS: TrackerData) -> TrackerData { | ||
let entities = originalTDS.extractEntities(for: trackers) | ||
let domains = extractDomains(from: entities) | ||
return TrackerData(trackers: trackers, | ||
entities: entities, | ||
domains: domains, | ||
cnames: originalTDS.cnames) | ||
} | ||
|
||
private func filterTrackersByBlockCTLAction(_ trackers: [String: KnownTracker], hasBlockCTL: Bool) -> [String: KnownTracker] { | ||
trackers.filter { (_, tracker) in tracker.containsCTLActions == hasBlockCTL } | ||
} | ||
|
||
private func extractDomains(from entities: [String: Entity]) -> [String: String] { | ||
var domains = [String: String]() | ||
for entity in entities { | ||
for domain in entity.value.domains ?? [] { | ||
domains[domain] = entity.key | ||
} | ||
} | ||
ladamski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return domains | ||
} | ||
|
||
} | ||
|
||
private extension TrackerData { | ||
|
||
func extractEntities(for trackers: [String: KnownTracker]) -> [String: Entity] { | ||
let trackerOwners = Set(trackers.values.compactMap { $0.owner?.name }) | ||
let entities = entities.filter { trackerOwners.contains($0.key) } | ||
return entities | ||
} | ||
|
||
} | ||
|
||
private extension KnownTracker { | ||
|
||
var containsCTLActions: Bool { | ||
if let defaultAction = defaultAction, defaultAction == .blockCtlFB { | ||
return true | ||
} | ||
|
||
if let rules = rules { | ||
for rule in rules { | ||
if let action = rule.action, action == .blockCtlFB { | ||
return true | ||
} | ||
} | ||
} | ||
return false | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't see any tests for the splitter, I'd expect it to be unit tested really
This comment was marked as resolved.
Sorry, something went wrong.