From b8ac300b15ec0919063cac8e2040ab189dc55b57 Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Thu, 31 Oct 2024 21:31:17 +0100 Subject: [PATCH 1/6] Update event mapping --- ...riptionCookieManageEventPixelMapping.swift | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/DuckDuckGo/Subscription/SubscriptionCookieManageEventPixelMapping.swift b/DuckDuckGo/Subscription/SubscriptionCookieManageEventPixelMapping.swift index c18cf2e6d4..fc5128756d 100644 --- a/DuckDuckGo/Subscription/SubscriptionCookieManageEventPixelMapping.swift +++ b/DuckDuckGo/Subscription/SubscriptionCookieManageEventPixelMapping.swift @@ -24,21 +24,18 @@ import Subscription enum SubscriptionCookieManagerPixel: PixelKitEventV2 { case missingTokenOnSignIn - case missingCookieOnSignOut - case cookieRefreshedWithUpdate - case cookieRefreshedWithDelete + case cookieRefreshedWithAccessToken + case cookieRefreshedWithEmptyValue case failedToSetSubscriptionCookie var name: String { switch self { case .missingTokenOnSignIn: return "m_mac_privacy-pro_subscription-cookie-missing_token_on_sign_in" - case .missingCookieOnSignOut: - return "m_mac_privacy-pro_subscription-cookie-missing_cookie_on_sign_out" - case .cookieRefreshedWithUpdate: - return "m_mac_privacy-pro_subscription-cookie-refreshed_with_update" - case .cookieRefreshedWithDelete: - return "m_mac_privacy-pro_subscription-cookie-refreshed_with_delete" + case .cookieRefreshedWithAccessToken: + return "m_mac_privacy-pro_subscription-cookie-refreshed_with_access_token" + case .cookieRefreshedWithEmptyValue: + return "m_mac_privacy-pro_subscription-cookie-refreshed_with_empty_value" case .failedToSetSubscriptionCookie: return "m_mac_privacy-pro_subscription-cookie-failed_to_set_subscription_cookie" } @@ -61,12 +58,10 @@ public final class SubscriptionCookieManageEventPixelMapping: EventMapping Date: Fri, 1 Nov 2024 00:56:37 +0100 Subject: [PATCH 2/6] Switch to remote BSK branch --- DuckDuckGo.xcodeproj/project.pbxproj | 4 ++-- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index a3acccb424..30e6eab992 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -14509,8 +14509,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { - kind = exactVersion; - version = 201.0.0; + branch = "michal/update-subs-cookie"; + kind = branch; }; }; 9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 51a522e596..1f3d3ba73d 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/duckduckgo/BrowserServicesKit", "state" : { - "revision" : "e5946eee6af859690cc1cc5e51daef3c8368981b", - "version" : "201.0.0" + "branch" : "michal/update-subs-cookie", + "revision" : "9506581ae99273681073f9993fc6d881d3edaa7f" } }, { From 721b6dce4e1669dc36bb2fb1335d80253f0e2564 Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Fri, 1 Nov 2024 00:57:02 +0100 Subject: [PATCH 3/6] Support feature flag --- DuckDuckGo/Application/AppDelegate.swift | 29 +++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/DuckDuckGo/Application/AppDelegate.swift b/DuckDuckGo/Application/AppDelegate.swift index a3ef983fee..04693c9659 100644 --- a/DuckDuckGo/Application/AppDelegate.swift +++ b/DuckDuckGo/Application/AppDelegate.swift @@ -96,7 +96,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate { public let subscriptionManager: SubscriptionManager public let subscriptionUIHandler: SubscriptionUIHandling - public let subscriptionCookieManager: SubscriptionCookieManaging + private let subscriptionCookieManager: SubscriptionCookieManaging + private var subscriptionCookieManagerFeatureFlagCancellable: AnyCancellable? public let vpnSettings = VPNSettings(defaults: .netP) @@ -344,6 +345,30 @@ final class AppDelegate: NSObject, NSApplicationDelegate { subscriptionManager.loadInitialData() + let privacyConfigurationManager = ContentBlocking.shared.privacyConfigurationManager + + // Enable subscriptionCookieManager if feature flag is present + if privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(PrivacyProSubfeature.setAccessTokenCookieForSubscriptionDomains) { + subscriptionCookieManager.enableSettingSubscriptionCookie() + } + + // Keep track of feature flag changes + subscriptionCookieManagerFeatureFlagCancellable = privacyConfigurationManager.updatesPublisher + .sink { [weak self, weak privacyConfigurationManager] in + guard let self, let privacyConfigurationManager else { return } + + let isEnabled = privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(PrivacyProSubfeature.setAccessTokenCookieForSubscriptionDomains) + + Task { [weak self] in + if isEnabled { + self?.subscriptionCookieManager.enableSettingSubscriptionCookie() + await self?.subscriptionCookieManager.refreshSubscriptionCookie() + } else { + await self?.subscriptionCookieManager.disableSettingSubscriptionCookie() + } + } + } + if [.normal, .uiTests].contains(NSApp.runType) { stateRestorationManager.applicationDidFinishLaunching() } @@ -454,6 +479,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate { Task { @MainActor in await subscriptionCookieManager.refreshSubscriptionCookie() } + + } private func initializeSync() { From a15bb001c2262c55cc15250693fbc8046351d398 Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Fri, 1 Nov 2024 07:39:57 +0100 Subject: [PATCH 4/6] Add cookie domain to the exclusion filter --- DuckDuckGo/Tab/Services/WebsiteDataStore.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DuckDuckGo/Tab/Services/WebsiteDataStore.swift b/DuckDuckGo/Tab/Services/WebsiteDataStore.swift index 69504c873e..e4c167a284 100644 --- a/DuckDuckGo/Tab/Services/WebsiteDataStore.swift +++ b/DuckDuckGo/Tab/Services/WebsiteDataStore.swift @@ -19,6 +19,7 @@ import Common import WebKit import GRDB +import Subscription import os.log public protocol HTTPCookieStore { @@ -154,7 +155,7 @@ internal class WebCacheManager { // Don't clear fireproof domains let cookiesToRemove = cookies.filter { cookie in - !self.fireproofDomains.isFireproof(cookieDomain: cookie.domain) && cookie.domain != URL.cookieDomain + !self.fireproofDomains.isFireproof(cookieDomain: cookie.domain) && ![URL.cookieDomain, SubscriptionCookieManager.cookieDomain].contains(cookie.domain) } for cookie in cookiesToRemove { From 9ba3735d070b0cce8ef445f4218530e480eb76bd Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Fri, 1 Nov 2024 13:12:21 +0100 Subject: [PATCH 5/6] Switch to a hotfix BSK version 201.0.0-1 --- DuckDuckGo.xcodeproj/project.pbxproj | 4 ++-- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- LocalPackages/DataBrokerProtection/Package.swift | 2 +- LocalPackages/NetworkProtectionMac/Package.swift | 2 +- LocalPackages/SubscriptionUI/Package.swift | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 30e6eab992..a7737cf420 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -14509,8 +14509,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { - branch = "michal/update-subs-cookie"; - kind = branch; + kind = exactVersion; + version = "201.0.0-1"; }; }; 9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 1f3d3ba73d..3d5c0df68d 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/duckduckgo/BrowserServicesKit", "state" : { - "branch" : "michal/update-subs-cookie", - "revision" : "9506581ae99273681073f9993fc6d881d3edaa7f" + "revision" : "9506581ae99273681073f9993fc6d881d3edaa7f", + "version" : "201.0.0-1" } }, { diff --git a/LocalPackages/DataBrokerProtection/Package.swift b/LocalPackages/DataBrokerProtection/Package.swift index 7a924e71d0..e0dc5b9da9 100644 --- a/LocalPackages/DataBrokerProtection/Package.swift +++ b/LocalPackages/DataBrokerProtection/Package.swift @@ -29,7 +29,7 @@ let package = Package( targets: ["DataBrokerProtection"]) ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "201.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "201.0.0-1"), .package(path: "../SwiftUIExtensions"), .package(path: "../XPCHelper"), ], diff --git a/LocalPackages/NetworkProtectionMac/Package.swift b/LocalPackages/NetworkProtectionMac/Package.swift index 684c8f86b8..dbb26cb39e 100644 --- a/LocalPackages/NetworkProtectionMac/Package.swift +++ b/LocalPackages/NetworkProtectionMac/Package.swift @@ -32,7 +32,7 @@ let package = Package( .library(name: "VPNAppLauncher", targets: ["VPNAppLauncher"]), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "201.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "201.0.0-1"), .package(url: "https://github.com/airbnb/lottie-spm", exact: "4.4.3"), .package(path: "../AppLauncher"), .package(path: "../UDSHelper"), diff --git a/LocalPackages/SubscriptionUI/Package.swift b/LocalPackages/SubscriptionUI/Package.swift index 2f7f0c808d..f03047f89b 100644 --- a/LocalPackages/SubscriptionUI/Package.swift +++ b/LocalPackages/SubscriptionUI/Package.swift @@ -12,7 +12,7 @@ let package = Package( targets: ["SubscriptionUI"]), ], dependencies: [ - .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "201.0.0"), + .package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "201.0.0-1"), .package(path: "../SwiftUIExtensions") ], targets: [ From 76f17eb3e835d2f0f191e36c407e15130f38b6d4 Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Fri, 1 Nov 2024 13:17:24 +0100 Subject: [PATCH 6/6] Swiftlint fix --- DuckDuckGo/Application/AppDelegate.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DuckDuckGo/Application/AppDelegate.swift b/DuckDuckGo/Application/AppDelegate.swift index 04693c9659..8546ec81b1 100644 --- a/DuckDuckGo/Application/AppDelegate.swift +++ b/DuckDuckGo/Application/AppDelegate.swift @@ -303,6 +303,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate { vpnUninstaller: vpnUninstaller) } + // swiftlint:disable:next cyclomatic_complexity func applicationDidFinishLaunching(_ notification: Notification) { guard NSApp.runType.requiresEnvironment else { return } defer { @@ -479,8 +480,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate { Task { @MainActor in await subscriptionCookieManager.refreshSubscriptionCookie() } - - } private func initializeSync() {