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

update ClickToLoad to use shared C-S-S #2162

Merged
merged 62 commits into from
Jun 14, 2024
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 Feb 6, 2024
cf561f1
fire "displayCLickToLoadPlaceholders" on load completion
ladamski Feb 7, 2024
98cb9c5
disable old CTL user script
ladamski Feb 12, 2024
8a3f6d6
test - trigger CTL on FB tracker match
ladamski Feb 12, 2024
367f031
switch to isolated scope, hook up overlay trigger
ladamski Feb 13, 2024
e19f103
use v6 TDS, updated config
ladamski Mar 2, 2024
ae481dc
move CTL code to subfolder
ladamski Mar 2, 2024
50f1411
update CTL rule management to use main TDS
ladamski Mar 2, 2024
b603ed7
WIP rule splitting for custom actions
ladamski Mar 5, 2024
f971774
cleanup FB protection state management
ladamski Mar 7, 2024
daf57ad
update embedded config and TDS
ladamski Mar 16, 2024
0d2c7a4
remove dead code
ladamski Mar 16, 2024
3a0c7fd
switch back to separate blocking CTL rule set
ladamski Mar 18, 2024
7156d78
switch back to previous CTL rules, part 2
ladamski Mar 20, 2024
fd7287e
combine rules for surrogates user script
ladamski Mar 21, 2024
7025ba1
cleanup surrogate code to remove need for vars
ladamski Apr 5, 2024
d3d0c87
update embeds
ladamski Apr 11, 2024
4879680
update config clickToPlay -> clickToLoad
ladamski Apr 11, 2024
909e53b
burn with fire (dead code)
ladamski Apr 11, 2024
be1a4ea
dead code cleanup part 2
ladamski Apr 15, 2024
12cce92
clarify method naming
ladamski Apr 15, 2024
7ed7200
handle empty ruleset in in surrogate generation (unit tests)
ladamski Apr 16, 2024
b249af6
use fallback TDS for CTL test vs old embedded CTL TDS
ladamski Apr 17, 2024
a5e1287
bump TDS test to v6
ladamski Apr 17, 2024
a93d49d
remove remapping of custom action .blockCtlFB to .block
ladamski Apr 19, 2024
5069df9
remove dead fonts, post-merge cleanup
ladamski Apr 23, 2024
f77d0c7
TEMP disable CTL assertions while testing
ladamski Apr 24, 2024
7c3f672
address @MainActor warnings, remove debug spam
ladamski Apr 24, 2024
1bc59ed
lint nit
ladamski Apr 24, 2024
841de53
try special casing NavigationType.backForward for CTL
ladamski Apr 24, 2024
838d6f8
remove MD5 func
ladamski Apr 30, 2024
abdb4f0
move FB entity string to const in FBProtectionTabExtension
ladamski Apr 30, 2024
1999c4a
update splitter logic per PR review, fix test
ladamski May 1, 2024
3ca418b
Update CTL rule splitting logic with alternate path (#2733)
ladamski May 1, 2024
95a798c
update rule combining logic per last rule splitting update
ladamski May 2, 2024
1856498
remove dead ClickToLoadModel code
ladamski May 21, 2024
4a05050
Update ClickToLoadRulesSplitter.swift
ladamski May 21, 2024
0072d09
code review nits
ladamski May 21, 2024
2a61134
Merge branch 'main' into la/update-ctl
ladamski May 21, 2024
d19a19f
cleanup FIXME
ladamski May 21, 2024
223b434
update to BSK WIP branch
ladamski May 21, 2024
cb42dd6
Update proj file and BSK ref
jaceklyp May 21, 2024
098696e
remove unused var
ladamski May 22, 2024
b01f13e
update CTL action to blockCTLFB
ladamski May 23, 2024
084d24d
add CTL test for rules splitting
ladamski May 23, 2024
2a2cf71
test nits
ladamski May 23, 2024
85cc309
move ClickToLoadRulesSpliter to BSK
ladamski May 31, 2024
3673f70
Update ClickToLoadTDSTests.swift
ladamski May 31, 2024
6ca5394
move ClickToLoadRulesSplitter to BSK
ladamski May 31, 2024
d55102c
review nits
ladamski May 31, 2024
77993dd
Update ClickToLoadTDSTests.swift
ladamski Jun 3, 2024
13af034
test tweaks
ladamski Jun 7, 2024
f5c56fd
Update ClickToLoadTDSTests.swift
ladamski Jun 8, 2024
24566fd
remove forward/back nav exception in FB protections
ladamski Jun 12, 2024
98c095b
revert config URL to prod and update embeds
ladamski Jun 13, 2024
2d04a7c
release BSK
ladamski Jun 14, 2024
0479655
update BSK dep
ladamski Jun 14, 2024
84d76eb
Merge branch 'main' into la/update-ctl
ladamski Jun 14, 2024
ef74977
Restore NetP Package.swift
bwaresiak Jun 14, 2024
388d73e
version bump to 1.93.0
ladamski Jun 14, 2024
a0ab778
Revert "version bump to 1.93.0"
ladamski Jun 14, 2024
5e5feb1
nit
ladamski Jun 14, 2024
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
Next Next commit
swap embedded user script with CSS one
ladamski committed Apr 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 01c8a5368b44e5068c1f7409a96239f26209e639
116 changes: 61 additions & 55 deletions DuckDuckGo/ContentBlocker/ClickToLoadUserScript.swift
Original file line number Diff line number Diff line change
@@ -17,77 +17,83 @@
//

import WebKit
import Common
import UserScript
import BrowserServicesKit

protocol ClickToLoadUserScriptDelegate: AnyObject {

func clickToLoadUserScriptAllowFB(_ script: UserScript, replyHandler: @escaping (Bool) -> Void)
func clickToLoadUserScriptAllowFB() -> Bool
}

final class ClickToLoadUserScript: NSObject, UserScript, WKScriptMessageHandlerWithReply {
final class ClickToLoadUserScript: NSObject, Subfeature {

var injectionTime: WKUserScriptInjectionTime { .atDocumentEnd }
var forMainFrameOnly: Bool { false }
var messageNames: [String] { ["getImage", "enableFacebook", "initClickToLoad" ] }
let source: String
weak var broker: UserScriptMessageBroker?
weak var webView: WKWebView?

init(scriptSourceProvider: ScriptSourceProviding) {
self.source = scriptSourceProvider.clickToLoadSource
}
var devMode = false

weak var delegate: ClickToLoadUserScriptDelegate?

@MainActor
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage,
replyHandler: @escaping (Any?, String?) -> Void) {
if message.name == "initClickToLoad" {
let host = message.body as? String
let controller = userContentController as? UserContentController
let privacyConfigurationManager = controller!.privacyConfigurationManager
let privacyConfiguration = privacyConfigurationManager.privacyConfig

let locallyProtected = privacyConfiguration.isProtected(domain: host)
let featureEnabled = privacyConfiguration.isFeature(.clickToPlay, enabledForDomain: host)
if locallyProtected && featureEnabled {
replyHandler(true, nil)
} else {
replyHandler(false, nil)
}
return
}
if message.name == "enableFacebook" {
guard let delegate = delegate else { return }
delegate.clickToLoadUserScriptAllowFB(self) { _ in
guard let isLogin = message.body as? Bool else {
replyHandler(nil, nil)
return
}

replyHandler(isLogin, nil)
}

return
}
// this isn't an issue to be set to 'all' because the page
public let messageOriginPolicy: MessageOriginPolicy = .all
public let featureName: String = "clickToLoad"

var image: String
// MARK: - Subfeature

guard let arg = message.body as? String else {
replyHandler(nil, nil)
return
}
if message.name == "getImage" {
image = ClickToLoadModel.getImage[arg]!
} else {
assertionFailure("Uknown message type")
replyHandler(nil, nil)
return
public func with(broker: UserScriptMessageBroker) {
self.broker = broker
}

// MARK: - MessageNames

enum MessageNames: String, CaseIterable {
case getClickToLoadState
case displayClickToLoadPlaceholders
case unblockClickToLoadContent
case updateFacebookCTLBreakageFlags
case addDebugFlag
}

public func handler(forMethodNamed methodName: String) -> Handler? {
switch MessageNames(rawValue: methodName) {
case .getClickToLoadState:
return handleGetClickToLoadState
case .unblockClickToLoadContent:
return handleUnblockClickToLoadContent
case .updateFacebookCTLBreakageFlags:
return nil
case .addDebugFlag:
return nil
default:
assertionFailure("ClickToLoadUserScript: Failed to parse User Script message: \(methodName)")
return nil
}
replyHandler(image, nil)
}

func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
assertionFailure("SHOULDN'T BE HERE!")
private func handleGetClickToLoadState(params: Any, message: UserScriptMessage) -> Encodable? {
return [
"devMode": devMode,
"youtubePreviewsEnabled": false
]
}

private func handleUnblockClickToLoadContent(params: Any, message: UserScriptMessage) -> Encodable? {
struct UnblockMessage: Decodable {
let action: String
let isLogin: Bool
let isSurrogateLogin: Bool
let entity: String
}

guard let delegate = delegate else { return false }

// only worry about CTL FB for now
return delegate.clickToLoadUserScriptAllowFB()
}

public func displayClickToLoadPlaceholders() {
if let webView = webView {
broker?.push(method: MessageNames.displayClickToLoadPlaceholders.rawValue, params: ["ruleAction": ["block"]], for: self, into: webView)
}
}
}
9 changes: 4 additions & 5 deletions DuckDuckGo/Tab/TabExtensions/FBProtectionTabExtension.swift
Original file line number Diff line number Diff line change
@@ -90,16 +90,15 @@ extension FBProtectionTabExtension {

extension FBProtectionTabExtension: ClickToLoadUserScriptDelegate {

func clickToLoadUserScriptAllowFB(_ script: UserScript, replyHandler: @escaping (Bool) -> Void) {
func clickToLoadUserScriptAllowFB() -> Bool {
guard self.fbBlockingEnabled else {
replyHandler(true)
return
return true
}

if setFBProtection(enabled: false) {
replyHandler(true)
return true
} else {
replyHandler(false)
return false
}
}
}
5 changes: 3 additions & 2 deletions DuckDuckGo/Tab/UserScripts/UserScripts.swift
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ final class UserScripts: UserScriptsProvider {
let sslErrorPageUserScript: SSLErrorPageUserScript?

init(with sourceProvider: ScriptSourceProviding) {
clickToLoadScript = ClickToLoadUserScript(scriptSourceProvider: sourceProvider)
clickToLoadScript = ClickToLoadUserScript()
contentBlockerRulesScript = ContentBlockerRulesUserScript(configuration: sourceProvider.contentBlockerRulesConfig!)
surrogatesScript = SurrogatesUserScript(configuration: sourceProvider.surrogatesConfig!)
let isGPCEnabled = WebTrackingProtectionPreferences.shared.isGPCEnabled
@@ -77,6 +77,8 @@ final class UserScripts: UserScriptsProvider {

userScripts.append(autoconsentUserScript)

contentScopeUserScript.registerSubfeature(delegate: clickToLoadScript)

if let youtubeOverlayScript {
contentScopeUserScriptIsolated.registerSubfeature(delegate: youtubeOverlayScript)
}
@@ -109,7 +111,6 @@ final class UserScripts: UserScriptsProvider {
pageObserverScript,
printingUserScript,
hoverUserScript,
clickToLoadScript,
contentScopeUserScript,
contentScopeUserScriptIsolated,
autofillScript