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

Revert "C.S.S Patch Privacy Config on C.S.S for "internal" support in… #995

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,13 @@ public final class ContentScopeUserScript: NSObject, UserScript, UserScriptMessa
config: WebkitMessagingConfig
) -> String {

guard var privacyConfigJson = String(data: privacyConfigurationManager.currentConfig, encoding: .utf8) else {
return ""
}

if privacyConfigurationManager.internalUserDecider.isInternalUser {
privacyConfigJson = patchPrivacyConfigForDuckPlayerInternal(privacyConfigJson: privacyConfigJson)
}

guard let userUnprotectedDomains = try? JSONEncoder().encode(privacyConfigurationManager.privacyConfig.userUnprotectedDomains),
let userUnprotectedDomainsString = String(data: userUnprotectedDomains, encoding: .utf8),
let jsonProperties = try? JSONEncoder().encode(properties),
let jsonPropertiesString = String(data: jsonProperties, encoding: .utf8),
let jsonConfig = try? JSONEncoder().encode(config),
let jsonConfigString = String(data: jsonConfig, encoding: .utf8)
guard let privacyConfigJson = String(data: privacyConfigurationManager.currentConfig, encoding: .utf8),
let userUnprotectedDomains = try? JSONEncoder().encode(privacyConfigurationManager.privacyConfig.userUnprotectedDomains),
let userUnprotectedDomainsString = String(data: userUnprotectedDomains, encoding: .utf8),
let jsonProperties = try? JSONEncoder().encode(properties),
let jsonPropertiesString = String(data: jsonProperties, encoding: .utf8),
let jsonConfig = try? JSONEncoder().encode(config),
let jsonConfigString = String(data: jsonConfig, encoding: .utf8)
else {
return ""
}
Expand All @@ -195,34 +188,6 @@ public final class ContentScopeUserScript: NSObject, UserScript, UserScriptMessa
public let injectionTime: WKUserScriptInjectionTime = .atDocumentStart
public let forMainFrameOnly: Bool = false
public var requiresRunInPageContentWorld: Bool { !self.isIsolated }

// The Frontend does not support "internal" state for features, so in order to release
// DuckPlayer to internal users, we need to patch the Privacy Config to replace "internal" with "enabled"
// This will be removed once DuckPlayer is released to the public
private static func patchPrivacyConfigForDuckPlayerInternal(privacyConfigJson: String) -> String {
do {

guard let jsonData = privacyConfigJson.data(using: .utf8) else { return privacyConfigJson }

guard var jsonObject = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any] else {
return privacyConfigJson
}

if var features = jsonObject["features"] as? [String: Any],
var duckPlayer = features["duckPlayer"] as? [String: Any] {
duckPlayer["state"] = "enabled"
features["duckPlayer"] = duckPlayer
jsonObject["features"] = features
}

let modifiedData = try JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted)
return String(data: modifiedData, encoding: .utf8) ?? privacyConfigJson

} catch {
return privacyConfigJson
}
}

}

@available(macOS 11.0, iOS 14.0, *)
Expand Down
Loading