Skip to content

Commit

Permalink
support privacy config for clickToLoad (#407)
Browse files Browse the repository at this point in the history
* support privacy config for clickToLoad

* update BSK commit

Co-authored-by: [email protected] <[email protected]>
  • Loading branch information
ladamski and [email protected] authored Jan 28, 2022
1 parent 1a8b7c8 commit ece4c49
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5315,7 +5315,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = revision;
revision = da3f840edb7d9adf681c3fed0b4da6ad841fd288;
revision = 03b42987d765e92b58a5975f6f6edad503100ec8;
};
};
AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repositoryURL": "https://github.com/duckduckgo/BrowserServicesKit",
"state": {
"branch": null,
"revision": "da3f840edb7d9adf681c3fed0b4da6ad841fd288",
"revision": "03b42987d765e92b58a5975f6f6edad503100ec8",
"version": null
}
},
Expand Down
15 changes: 10 additions & 5 deletions DuckDuckGo/BrowserTab/Model/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,6 @@ final class Tab: NSObject {
return false
}

private func clickToLoadBlockFB() {
setFBProtection(enabled: true)
}

private func reloadIfNeeded(shouldLoadInBackground: Bool = false) {
let url: URL
switch self.content {
Expand Down Expand Up @@ -783,6 +779,16 @@ extension Tab: WKNavigationDelegate {
decisionHandler(.allow)
return
}

let privacyConfigurationManager = ContentBlocking.privacyConfigurationManager
let privacyConfiguration = privacyConfigurationManager.privacyConfig

let featureEnabled = privacyConfiguration.isFeature(.clickToPlay, enabledForDomain: url.host)
if featureEnabled {
setFBProtection(enabled: true)
} else {
setFBProtection(enabled: false)
}

if navigationAction.shouldDownload {
// register the navigationAction for legacy _WKDownload to be called back on the Tab
Expand Down Expand Up @@ -863,7 +869,6 @@ extension Tab: WKNavigationDelegate {
}

func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
self.clickToLoadBlockFB()
delegate?.tabDidStartNavigation(self)

// Unnecessary assignment triggers publishing
Expand Down
6 changes: 4 additions & 2 deletions DuckDuckGo/ContentBlocker/ClickToLoadUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ final class ClickToLoadUserScript: NSObject, UserScript, WKScriptMessageHandlerW
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 protected = privacyConfiguration.isProtected(domain: message.body as? String)
if protected {
let locallyProtected = privacyConfiguration.isProtected(domain: host)
let featureEnabled = privacyConfiguration.isFeature(.clickToPlay, enabledForDomain: host)
if locallyProtected && featureEnabled {
replyHandler(true, nil)
} else {
replyHandler(false, nil)
Expand Down

0 comments on commit ece4c49

Please sign in to comment.