Skip to content

Commit

Permalink
Promote autofill features to remotely trigger-able (duckduckgo#1565)
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Symons <sam@samsymons.com>
  • Loading branch information
graeme and samsymons authored Apr 6, 2023
1 parent d659c20 commit 37f0ab2
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 15 deletions.
4 changes: 3 additions & 1 deletion Core/ContentBlocking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ public final class ContentBlocking {


private init(privacyConfigurationManager: PrivacyConfigurationManaging? = nil) {
let internalUserDecider = DefaultInternalUserDecider(store: InternalUserStore())
let privacyConfigurationManager = privacyConfigurationManager
?? PrivacyConfigurationManager(fetchedETag: UserDefaultsETagStorage().loadEtag(for: .privacyConfiguration),
fetchedData: FileStore().loadAsData(for: .privacyConfiguration),
embeddedDataProvider: AppPrivacyConfigurationDataProvider(),
localProtection: DomainsProtectionUserDefaultsStore(),
errorReporting: Self.debugEvents)
errorReporting: Self.debugEvents,
internalUserDecider: internalUserDecider)
self.privacyConfigurationManager = privacyConfigurationManager

trackerDataManager = TrackerDataManager(etag: UserDefaultsETagStorage().loadEtag(for: .trackerDataSet),
Expand Down
12 changes: 9 additions & 3 deletions Core/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ public enum FeatureFlag: String {
extension FeatureFlag: FeatureFlagSourceProviding {
public var source: FeatureFlagSource {
switch self {
// swiftlint:disable line_length
case .debugMenu, .sync, .autofillCredentialInjecting, .autofillCredentialsSaving, .autofillInlineIconCredentials, .autofillAccessCredentialManagement:
case .debugMenu, .sync:
return .internalOnly
case .autofillCredentialInjecting:
return .remoteDevelopment(.subfeature(AutofillSubfeature.credentialsAutofill))
case .autofillCredentialsSaving:
return .remoteDevelopment(.subfeature(AutofillSubfeature.credentialsSaving))
case .autofillInlineIconCredentials:
return .remoteDevelopment(.subfeature(AutofillSubfeature.inlineIconCredentials))
case .autofillAccessCredentialManagement:
return .remoteDevelopment(.subfeature(AutofillSubfeature.accessCredentialManagement))
}
// swiftlint:enable line_length
}
}

Expand Down
16 changes: 15 additions & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@
CBDD5DE129A6741300832877 /* MockBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBDD5DE029A6741300832877 /* MockBundle.swift */; };
EA39B7E2268A1A35000C62CD /* privacy-reference-tests in Resources */ = {isa = PBXBuildFile; fileRef = EA39B7E1268A1A35000C62CD /* privacy-reference-tests */; };
EAB19EDA268963510015D3EA /* DomainMatchingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB19ED9268963510015D3EA /* DomainMatchingTests.swift */; };
EE3B226B29DE0F110082298A /* MockInternalUserStoring.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE3B226A29DE0F110082298A /* MockInternalUserStoring.swift */; };
EE3B226C29DE0FD30082298A /* MockInternalUserStoring.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE3B226A29DE0F110082298A /* MockInternalUserStoring.swift */; };
EE50052E29C369D300AE0773 /* FeatureFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE50052D29C369D300AE0773 /* FeatureFlag.swift */; };
EE50053029C3BA0800AE0773 /* InternalUserStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE50052F29C3BA0800AE0773 /* InternalUserStore.swift */; };
F103073B1E7C91330059FEC7 /* BookmarksDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F103073A1E7C91330059FEC7 /* BookmarksDataSource.swift */; };
Expand Down Expand Up @@ -2026,6 +2028,7 @@
CBF14FC627970C8A001D94D0 /* HomeMessageCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeMessageCollectionViewCell.swift; sourceTree = "<group>"; };
EA39B7E1268A1A35000C62CD /* privacy-reference-tests */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "privacy-reference-tests"; path = "submodules/privacy-reference-tests"; sourceTree = SOURCE_ROOT; };
EAB19ED9268963510015D3EA /* DomainMatchingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DomainMatchingTests.swift; sourceTree = "<group>"; };
EE3B226A29DE0F110082298A /* MockInternalUserStoring.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockInternalUserStoring.swift; sourceTree = "<group>"; };
EE50052D29C369D300AE0773 /* FeatureFlag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureFlag.swift; sourceTree = "<group>"; };
EE50052F29C3BA0800AE0773 /* InternalUserStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InternalUserStore.swift; sourceTree = "<group>"; };
F103073A1E7C91330059FEC7 /* BookmarksDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookmarksDataSource.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3628,6 +3631,14 @@
name = PrivacyReferenceTests;
sourceTree = "<group>";
};
EE3B226929DE0EE10082298A /* FeatureFlags */ = {
isa = PBXGroup;
children = (
EE3B226A29DE0F110082298A /* MockInternalUserStoring.swift */,
);
name = FeatureFlags;
sourceTree = "<group>";
};
EE50052C29C3692700AE0773 /* FeatureFlags */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -4295,6 +4306,7 @@
C14882DD27F20D7300D59F0C /* Bookmarks */,
830FA79B1F8E81FB00FCE105 /* ContentBlocker */,
F17D722C1E8B3563003E8B0E /* Domain */,
EE3B226929DE0EE10082298A /* FeatureFlags */,
85D2186E24BF24BA004373D2 /* Favicons */,
F1134EC91F40E74800B73467 /* Statistics */,
F198D78F1E3976300088DA8A /* Utilities */,
Expand Down Expand Up @@ -5562,6 +5574,7 @@
F1D477C91F2139410031ED49 /* SmallOmniBarStateTests.swift in Sources */,
987130C9294AAB9F00AB05E0 /* BookmarkUtilsTests.swift in Sources */,
C1BF0BA929B63E2200482B73 /* AutofillLoginPromptViewModelTests.swift in Sources */,
EE3B226B29DE0F110082298A /* MockInternalUserStoring.swift in Sources */,
987130C8294AAB9F00AB05E0 /* BookmarksTestHelpers.swift in Sources */,
F198D7981E3A45D90088DA8A /* WKWebViewConfigurationExtensionTests.swift in Sources */,
8521FDE6238D414B00A44CC3 /* FileStoreTests.swift in Sources */,
Expand Down Expand Up @@ -5626,6 +5639,7 @@
files = (
CB5516D1286500290079B175 /* ContentBlockingRulesTests.swift in Sources */,
1E1D8B6629953B9800C96994 /* WebViewTestHelper.swift in Sources */,
EE3B226C29DE0FD30082298A /* MockInternalUserStoring.swift in Sources */,
CB5516D0286500290079B175 /* TrackerRadarIntegrationTests.swift in Sources */,
1E1D8B6129950FD200C96994 /* AutoconsentBackgroundTests.swift in Sources */,
CB5516D2286500290079B175 /* AtbServerTests.swift in Sources */,
Expand Down Expand Up @@ -7446,7 +7460,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 55.0.0;
version = 55.1.0;
};
};
C14882EB27F211A000D59F0C /* XCRemoteSwiftPackageReference "SwiftSoup" */ = {
Expand Down
1 change: 0 additions & 1 deletion DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class TabViewController: UIViewController {

private lazy var autofillWebsiteAccountMatcher = AutofillWebsiteAccountMatcher(autofillUrlMatcher: AutofillDomainNameUrlMatcher(),
tld: TabViewController.tld)

private(set) var tabModel: Tab
private(set) var privacyInfo: PrivacyInfo?
private var previousPrivacyInfosByURL: [URL: PrivacyInfo] = [:]
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGoTests/AppPrivacyConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class AppPrivacyConfigurationTests: XCTestCase {

let config = AppPrivacyConfiguration(data: configData,
identifier: "",
localProtection: MockDomainsProtectionStore())
localProtection: MockDomainsProtectionStore(),
internalUserDecider: DefaultInternalUserDecider(store: InternalUserStore()))

XCTAssert(config.isEnabled(featureKey: .contentBlocking))

Expand Down
5 changes: 4 additions & 1 deletion DuckDuckGoTests/AppURLsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ final class AppURLsTests: XCTestCase {
unprotectedTemporary: [],
trackerAllowlist: [:])
let localProtection = MockDomainsProtectionStore()
appConfig = AppPrivacyConfiguration(data: privacyData, identifier: "", localProtection: localProtection)
appConfig = AppPrivacyConfiguration(data: privacyData,
identifier: "",
localProtection: localProtection,
internalUserDecider: DefaultInternalUserDecider())
}

func testWhenRemoveInternalSearchParametersFromSearchUrlThenUrlIsChanged() throws {
Expand Down
4 changes: 3 additions & 1 deletion DuckDuckGoTests/AutoconsentMessageProtocolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ final class AutoconsentMessageProtocolTests: XCTestCase {

let mockEmbeddedData = MockEmbeddedDataProvider(data: embeddedConfig, etag: "embedded")


let manager = PrivacyConfigurationManager(fetchedETag: nil,
fetchedData: nil,
embeddedDataProvider: mockEmbeddedData,
localProtection: MockDomainsProtectionStore())
localProtection: MockDomainsProtectionStore(),
internalUserDecider: DefaultInternalUserDecider())
return AutoconsentUserScript(config: manager.privacyConfig, preferences: MockAutoconsentPreferences())
}()

Expand Down
5 changes: 4 additions & 1 deletion DuckDuckGoTests/ContentBlockerProtectionStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ class ContentBlockerProtectionStoreTests: XCTestCase {

if let newConfig = newConfig {
XCTAssertEqual(newConfig.etag, "new etag")
let config = AppPrivacyConfiguration(data: newConfig.data, identifier: "", localProtection: DomainsProtectionUserDefaultsStore())
let config = AppPrivacyConfiguration(data: newConfig.data,
identifier: "",
localProtection: DomainsProtectionUserDefaultsStore(),
internalUserDecider: DefaultInternalUserDecider())

XCTAssertFalse(config.isTempUnprotected(domain: "main1.com"))
XCTAssertFalse(config.isTempUnprotected(domain: "notdomain1.com"))
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGoTests/FaviconRequestModifierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class FaviconRequestModifierTests: XCTestCase {
let manager = PrivacyConfigurationManager(fetchedETag: nil,
fetchedData: nil,
embeddedDataProvider: mockEmbeddedData,
localProtection: mockProtectionStore)
localProtection: mockProtectionStore,
internalUserDecider: DefaultInternalUserDecider())

let config = manager.privacyConfig

Expand Down
31 changes: 31 additions & 0 deletions DuckDuckGoTests/MockInternalUserStoring.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// MockInternalUserStoring.swift
// DuckDuckGo
//
// Copyright © 2023 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

final class MockInternalUserStoring: InternalUserStoring {
var isInternalUser: Bool = false
}

extension DefaultInternalUserDecider {
convenience init(mockedStore: MockInternalUserStoring = MockInternalUserStoring()) {
self.init(store: mockedStore)
}
}
6 changes: 4 additions & 2 deletions DuckDuckGoTests/UserAgentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class UserAgentTests: XCTestCase {
let manager = PrivacyConfigurationManager(fetchedETag: nil,
fetchedData: nil,
embeddedDataProvider: mockEmbeddedData,
localProtection: mockProtectionStore)
localProtection: mockProtectionStore,
internalUserDecider: DefaultInternalUserDecider())

privacyConfig = manager.privacyConfig
}
Expand Down Expand Up @@ -156,7 +157,8 @@ class UserAgentTests: XCTestCase {
let manager = PrivacyConfigurationManager(fetchedETag: nil,
fetchedData: nil,
embeddedDataProvider: mockEmbeddedData,
localProtection: mockProtectionStore)
localProtection: mockProtectionStore,
internalUserDecider: DefaultInternalUserDecider())

let testee = UserAgent(defaultAgent: DefaultAgent.mobile)
XCTAssertEqual(ExpectedAgent.mobileNoApplication, testee.agent(forUrl: Constants.url, isDesktop: false,
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGoTests/WebViewTestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class WebKitTestHelper {

return AppPrivacyConfiguration(data: privacyData,
identifier: "",
localProtection: localProtection)
localProtection: localProtection,
internalUserDecider: DefaultInternalUserDecider())
}

static func prepareContentBlockingRules(trackerData: TrackerData,
Expand Down
3 changes: 2 additions & 1 deletion IntegrationTests/AutoconsentBackgroundTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ final class AutoconsentBackgroundTests: XCTestCase {
let manager = PrivacyConfigurationManager(fetchedETag: nil,
fetchedData: nil,
embeddedDataProvider: mockEmbeddedData,
localProtection: MockDomainsProtectionStore())
localProtection: MockDomainsProtectionStore(),
internalUserDecider: DefaultInternalUserDecider())
return AutoconsentUserScript(config: manager.privacyConfig,
preferences: MockAutoconsentPreferences(),
ignoreNonHTTPURLs: false)
Expand Down
Binary file modified fonts/licensed/proximanova-bold.otf
Binary file not shown.
Binary file modified fonts/licensed/proximanova-extrabold.otf
Binary file not shown.
Binary file modified fonts/licensed/proximanova-light.otf
Binary file not shown.
Binary file modified fonts/licensed/proximanova-regular.otf
Binary file not shown.
Binary file modified fonts/licensed/proximanova-semibold.otf
Binary file not shown.

0 comments on commit 37f0ab2

Please sign in to comment.