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

Update to subscription cookie #3489

Merged
merged 6 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14510,7 +14510,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 201.0.0;
version = "201.0.0-1";
};
};
9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "e5946eee6af859690cc1cc5e51daef3c8368981b",
"version" : "201.0.0"
"revision" : "9506581ae99273681073f9993fc6d881d3edaa7f",
"version" : "201.0.0-1"
}
},
{
Expand Down
28 changes: 27 additions & 1 deletion DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -302,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 {
Expand Down Expand Up @@ -344,6 +346,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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -61,12 +58,10 @@ public final class SubscriptionCookieManageEventPixelMapping: EventMapping<Subsc
switch event {
case .errorHandlingAccountDidSignInTokenIsMissing:
return .missingTokenOnSignIn
case .errorHandlingAccountDidSignOutCookieIsMissing:
return .missingCookieOnSignOut
case .subscriptionCookieRefreshedWithUpdate:
return .cookieRefreshedWithUpdate
case .subscriptionCookieRefreshedWithDelete:
return .cookieRefreshedWithDelete
case .subscriptionCookieRefreshedWithAccessToken:
return .cookieRefreshedWithAccessToken
case .subscriptionCookieRefreshedWithEmptyValue:
return .cookieRefreshedWithEmptyValue
case .failedToSetSubscriptionCookie:
return .failedToSetSubscriptionCookie
}
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/Tab/Services/WebsiteDataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import Common
import WebKit
import GRDB
import Subscription
import os.log

public protocol HTTPCookieStore {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/DataBrokerProtection/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
],
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/NetworkProtectionMac/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SubscriptionUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
Loading