From 01ed3cd357b41a1b2311642299513d4cd577a0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20=C5=81yp?= Date: Fri, 6 Oct 2023 21:59:22 +0200 Subject: [PATCH 1/2] Add new experiment for fixed UA logic --- Core/DefaultVariantManager.swift | 4 ++++ Core/UserAgentManager.swift | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Core/DefaultVariantManager.swift b/Core/DefaultVariantManager.swift index 1f0a250f4e..7539b2981b 100644 --- a/Core/DefaultVariantManager.swift +++ b/Core/DefaultVariantManager.swift @@ -25,6 +25,8 @@ import BrowserServicesKit extension FeatureName { // Define your feature e.g.: // public static let experimentalFeature = FeatureName(rawValue: "experimentalFeature") + + public static let fixedUserAgent = FeatureName(rawValue: "fixedUserAgent") } public struct VariantIOS: Variant { @@ -59,6 +61,8 @@ public struct VariantIOS: Variant { VariantIOS(name: "sc", weight: doNotAllocate, isIncluded: When.always, features: []), VariantIOS(name: "sd", weight: doNotAllocate, isIncluded: When.always, features: []), VariantIOS(name: "se", weight: doNotAllocate, isIncluded: When.always, features: []), + VariantIOS(name: "me", weight: 1, isIncluded: When.always, features: []), + VariantIOS(name: "mf", weight: 1, isIncluded: When.always, features: [.fixedUserAgent]), returningUser ] diff --git a/Core/UserAgentManager.swift b/Core/UserAgentManager.swift index 577922f317..186fde34c3 100644 --- a/Core/UserAgentManager.swift +++ b/Core/UserAgentManager.swift @@ -130,7 +130,7 @@ struct UserAgent { private let applicationComponent = "DuckDuckGo/\(AppVersion.shared.majorVersionNumber)" private let statistics: StatisticsStore private let isTesting: Bool = ProcessInfo().arguments.contains("testing") - + init(defaultAgent: String = Constants.fallbackDefaultAgent, statistics: StatisticsStore = StatisticsUserDefaults()) { versionComponent = UserAgent.createVersionComponent(fromAgent: defaultAgent) baseAgent = UserAgent.createBaseAgent(fromAgent: defaultAgent, versionComponent: versionComponent) @@ -209,6 +209,10 @@ struct UserAgent { return ddgFixedLogic(forUrl: url, isDesktop: isDesktop, privacyConfig: privacyConfig) } + if DefaultVariantManager().isSupported(feature: .fixedUserAgent) { + return ddgFixedLogic(forUrl: url, isDesktop: isDesktop, privacyConfig: privacyConfig) + } + switch defaultPolicy(forConfig: privacyConfig) { case .ddg: return oldLogic(forUrl: url, isDesktop: isDesktop, privacyConfig: privacyConfig) case .ddgFixed: return ddgFixedLogic(forUrl: url, isDesktop: isDesktop, privacyConfig: privacyConfig) From 9a5497a7b4ef6cc8f6ab3bccce917b34fa947902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20=C5=81yp?= Date: Fri, 6 Oct 2023 22:10:19 +0200 Subject: [PATCH 2/2] Fix swiftlint --- Core/UserAgentManager.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/UserAgentManager.swift b/Core/UserAgentManager.swift index 186fde34c3..0e03659e2e 100644 --- a/Core/UserAgentManager.swift +++ b/Core/UserAgentManager.swift @@ -181,6 +181,7 @@ struct UserAgent { return versions } + // swiftlint:disable:next cyclomatic_complexity public func agent(forUrl url: URL?, isDesktop: Bool, privacyConfig: PrivacyConfiguration = ContentBlocking.shared.privacyConfigurationManager.privacyConfig) -> String {