-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/Issue URL: https://app.asana.com/0/72649045549333/1209114783599181/f iOS PR: duckduckgo/iOS#3805 macOS PR: duckduckgo/macos-browser#3726 What kind of version bump will this require?: Major
- Loading branch information
1 parent
0a526c5
commit 20e6eaf
Showing
10 changed files
with
435 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// | ||
// TrackerDataURLOverrider.swift | ||
// | ||
// Copyright © 2025 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import BrowserServicesKit | ||
import os.log | ||
|
||
public protocol TrackerDataURLProviding { | ||
var trackerDataURL: URL? { get } | ||
} | ||
|
||
public final class TrackerDataURLOverrider: TrackerDataURLProviding { | ||
|
||
var privacyConfigurationManager: PrivacyConfigurationManaging | ||
var featureFlagger: FeatureFlagger | ||
|
||
public enum Constants { | ||
public static let baseTdsURLString = "https://staticcdn.duckduckgo.com/trackerblocking/" | ||
} | ||
|
||
public init (privacyConfigurationManager: PrivacyConfigurationManaging, | ||
featureFlagger: FeatureFlagger) { | ||
self.privacyConfigurationManager = privacyConfigurationManager | ||
self.featureFlagger = featureFlagger | ||
} | ||
|
||
public var trackerDataURL: URL? { | ||
for experimentType in TdsExperimentType.allCases { | ||
if let cohort = featureFlagger.getCohortIfEnabled(for: experimentType.experiment) as? TdsNextExperimentFlag.Cohort, | ||
let url = trackerDataURL(for: experimentType.subfeature, cohort: cohort) { | ||
return url | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
private func trackerDataURL(for subfeature: any PrivacySubfeature, cohort: TdsNextExperimentFlag.Cohort) -> URL? { | ||
guard let settings = privacyConfigurationManager.privacyConfig.settings(for: subfeature), | ||
let jsonData = settings.data(using: .utf8) else { return nil } | ||
do { | ||
if let settingsDict = try JSONSerialization.jsonObject(with: jsonData) as? [String: String], | ||
let urlString = cohort == .control ? settingsDict["controlUrl"] : settingsDict["treatmentUrl"] { | ||
return URL(string: Constants.baseTdsURLString + urlString) | ||
} | ||
} catch { | ||
Logger.config.info("privacyConfiguration: Failed to parse subfeature settings JSON: \(error)") | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
public enum TdsExperimentType: Int, CaseIterable { | ||
case baseline | ||
case feb25 | ||
case mar25 | ||
case apr25 | ||
case may25 | ||
case jun25 | ||
case jul25 | ||
case aug25 | ||
case sep25 | ||
case oct25 | ||
case nov25 | ||
case dec25 | ||
|
||
public var experiment: any FeatureFlagExperimentDescribing { | ||
TdsNextExperimentFlag(subfeature: self.subfeature) | ||
} | ||
|
||
public var subfeature: any PrivacySubfeature { | ||
switch self { | ||
case .baseline: | ||
ContentBlockingSubfeature.tdsNextExperimentBaseline | ||
case .feb25: | ||
ContentBlockingSubfeature.tdsNextExperimentFeb25 | ||
case .mar25: | ||
ContentBlockingSubfeature.tdsNextExperimentMar25 | ||
case .apr25: | ||
ContentBlockingSubfeature.tdsNextExperimentApr25 | ||
case .may25: | ||
ContentBlockingSubfeature.tdsNextExperimentMay25 | ||
case .jun25: | ||
ContentBlockingSubfeature.tdsNextExperimentJun25 | ||
case .jul25: | ||
ContentBlockingSubfeature.tdsNextExperimentJul25 | ||
case .aug25: | ||
ContentBlockingSubfeature.tdsNextExperimentAug25 | ||
case .sep25: | ||
ContentBlockingSubfeature.tdsNextExperimentSep25 | ||
case .oct25: | ||
ContentBlockingSubfeature.tdsNextExperimentOct25 | ||
case .nov25: | ||
ContentBlockingSubfeature.tdsNextExperimentNov25 | ||
case .dec25: | ||
ContentBlockingSubfeature.tdsNextExperimentDec25 | ||
} | ||
} | ||
|
||
} | ||
|
||
public struct TdsNextExperimentFlag: FeatureFlagExperimentDescribing { | ||
public var rawValue: String | ||
public var source: FeatureFlagSource | ||
|
||
public init(subfeature: any PrivacySubfeature) { | ||
self.source = .remoteReleasable(.subfeature(subfeature)) | ||
self.rawValue = subfeature.rawValue | ||
} | ||
|
||
public typealias CohortType = Cohort | ||
|
||
public enum Cohort: String, FlagCohort { | ||
case control | ||
case treatment | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.