From ece4c4902f98ec57c8f68484c7e69d5a9acfb6cb Mon Sep 17 00:00:00 2001 From: Lucas Adamski Date: Fri, 28 Jan 2022 11:51:08 -0800 Subject: [PATCH] support privacy config for clickToLoad (#407) * support privacy config for clickToLoad * update BSK commit Co-authored-by: ladamski@duckduckgo.com --- DuckDuckGo.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 2 +- DuckDuckGo/BrowserTab/Model/Tab.swift | 15 ++++++++++----- .../ContentBlocker/ClickToLoadUserScript.swift | 6 ++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 43855c7873..7f79d053da 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -5315,7 +5315,7 @@ repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { kind = revision; - revision = da3f840edb7d9adf681c3fed0b4da6ad841fd288; + revision = 03b42987d765e92b58a5975f6f6edad503100ec8; }; }; AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 4f4172e228..4affe5a3af 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,7 +6,7 @@ "repositoryURL": "https://github.com/duckduckgo/BrowserServicesKit", "state": { "branch": null, - "revision": "da3f840edb7d9adf681c3fed0b4da6ad841fd288", + "revision": "03b42987d765e92b58a5975f6f6edad503100ec8", "version": null } }, diff --git a/DuckDuckGo/BrowserTab/Model/Tab.swift b/DuckDuckGo/BrowserTab/Model/Tab.swift index 11588406e1..9698fbbed6 100644 --- a/DuckDuckGo/BrowserTab/Model/Tab.swift +++ b/DuckDuckGo/BrowserTab/Model/Tab.swift @@ -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 { @@ -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 @@ -863,7 +869,6 @@ extension Tab: WKNavigationDelegate { } func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { - self.clickToLoadBlockFB() delegate?.tabDidStartNavigation(self) // Unnecessary assignment triggers publishing diff --git a/DuckDuckGo/ContentBlocker/ClickToLoadUserScript.swift b/DuckDuckGo/ContentBlocker/ClickToLoadUserScript.swift index 53505107eb..26720c518a 100644 --- a/DuckDuckGo/ContentBlocker/ClickToLoadUserScript.swift +++ b/DuckDuckGo/ContentBlocker/ClickToLoadUserScript.swift @@ -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)