From 0464f4e6b076a06a8de1d9e607200048bfec296b Mon Sep 17 00:00:00 2001 From: Daniel Bernal Date: Fri, 13 Sep 2024 14:45:34 +0200 Subject: [PATCH] =?UTF-8?q?Revert=20"C.S.S=20Patch=20Privacy=20Config=20on?= =?UTF-8?q?=20C.S.S=20for=20"internal"=20support=20in=E2=80=A6=20(#995)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task/Issue URL: https://app.asana.com/0/1199230911884351/1208292211771741/f What kind of version bump will this require?: Minor **Description**: - This reverts commit 09b4901eeab71625c4796c0819d0066278b7b6d6. Change is not safe, and it comes with more risks than benefits, considering it's only for internal users. --- .../ContentScopeUserScript.swift | 49 +++---------------- 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/Sources/BrowserServicesKit/ContentScopeScript/ContentScopeUserScript.swift b/Sources/BrowserServicesKit/ContentScopeScript/ContentScopeUserScript.swift index a7c311336..69f058183 100644 --- a/Sources/BrowserServicesKit/ContentScopeScript/ContentScopeUserScript.swift +++ b/Sources/BrowserServicesKit/ContentScopeScript/ContentScopeUserScript.swift @@ -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 "" } @@ -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, *)