-
Notifications
You must be signed in to change notification settings - Fork 11
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 Content Blocking to use BSK stack #354
Changes from 20 commits
b017c3a
7d17294
888fbf3
f178f43
da4005a
823af8b
72cceae
c3208cc
dba8534
1e9c984
763a944
5bd2073
86226e3
ef70870
8e63a81
3f04dfe
69f9dfe
110d2b9
ba505e8
9102a99
4a8ebe2
a00b5d3
826e6ab
238ddab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
import Foundation | ||
import os.log | ||
import BrowserServicesKit | ||
|
||
extension URL { | ||
|
||
|
@@ -429,29 +430,27 @@ extension URL { | |
} | ||
|
||
// MARK: - GPC | ||
|
||
static func gpcHeadersEnabled(config: PrivacyConfiguration) -> [String] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest, these two methods are weird. They are static on URL, but the main point is to look into the instance of PrivacyConfiguration. I would define them there. Definitely not scope of this PR, I added a task into my tech debt list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely good idea, I didn't want to touch "too much" to not add to the scope creep. |
||
let settings = config.settings(for: .gpc) | ||
|
||
guard let enabledSites = settings["gpcHeaderEnabledSites"] as? [String] else { | ||
return [] | ||
} | ||
|
||
return enabledSites | ||
} | ||
|
||
static func isGPCEnabled(url: URL, | ||
config: PrivacyConfigurationManager = PrivacyConfigurationManager.shared) -> Bool { | ||
let enabledSites = config.gpcHeadersEnabled() | ||
config: PrivacyConfiguration = ContentBlocking.privacyConfigurationManager.privacyConfig) -> Bool { | ||
let enabledSites = gpcHeadersEnabled(config: config) | ||
|
||
for gpcHost in enabledSites { | ||
if url.isPart(ofDomain: gpcHost) { | ||
|
||
// Check if url is on exception list | ||
// Since headers are only enabled for a small numbers of sites | ||
// perfrom this check here for efficency | ||
let exceptions = config.tempUnprotectedDomains + config.exceptionsList(forFeature: .gpc) | ||
let protectionStore = DomainsProtectionUserDefaultsStore() | ||
if protectionStore.unprotectedDomains.contains(url.host ?? "") { | ||
return false | ||
} | ||
for exception in exceptions { | ||
if url.isPart(ofDomain: exception) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
return config.isFeature(.gpc, enabledForDomain: url.host) | ||
} | ||
} | ||
|
||
|
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.
We could check the diff of the rules here (e.g. for the presence of unprotected sites changes) and reload the tab here, instead of doing that from Dashboard (but it would require figuring out if current tab is the one for which change has been triggered, or if it matches the unprotected sites change).
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.
+1
Not sure if it helps, but active tab state can be easily determined with webview.superview != nil
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.
We still need to know if that tab is relevant to the change - hard to do that now, probably should be tackled elsewhere.