Skip to content

Commit

Permalink
Revert "C.S.S Patch Privacy Config on C.S.S for "internal" support in… (
Browse files Browse the repository at this point in the history
#995)

Task/Issue URL:
https://app.asana.com/0/1199230911884351/1208292211771741/f

What kind of version bump will this require?: Minor

**Description**:
- This reverts commit 09b4901. Change
is not safe, and it comes with more risks than benefits, considering
it's only for internal users.
  • Loading branch information
afterxleep authored Sep 13, 2024
1 parent 09b4901 commit 0464f4e
Showing 1 changed file with 7 additions and 42 deletions.
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

0 comments on commit 0464f4e

Please sign in to comment.