Skip to content

Commit

Permalink
Fix privacy icon glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp committed Sep 10, 2024
1 parent 93a1189 commit 1694957
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
4 changes: 2 additions & 2 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10772,8 +10772,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 191.2.3;
branch = "coldfix/191.2.3-1";
kind = branch;
};
};
9F8FE9472BAE50E50071E372 /* 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" : "b83ccf14b5844e8876de04bcc3074a15569f3b26",
"version" : "191.2.3"
"branch" : "coldfix/191.2.3-1",
"revision" : "3bac7c0924eeebd58b8868ef44489fac0fb7ec44"
}
},
{
Expand Down Expand Up @@ -138,7 +138,7 @@
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
"version" : "1.4.0"
Expand Down
5 changes: 3 additions & 2 deletions DuckDuckGo/PrivacyIconLogic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ final class PrivacyIconLogic {
} else {
let config = ContentBlocking.shared.privacyConfigurationManager.privacyConfig
let isUserUnprotected = config.isUserUnprotected(domain: privacyInfo.url.host)

let notFullyProtected = !privacyInfo.https || isUserUnprotected || privacyInfo.serverTrust == nil

let isServerTrustInvalid = (privacyInfo.shouldCheckServerTrust ? privacyInfo.serverTrust == nil : false)
let notFullyProtected = !privacyInfo.https || isUserUnprotected || isServerTrustInvalid

return notFullyProtected ? .shieldWithDot : .shield
}
Expand Down
7 changes: 4 additions & 3 deletions DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -993,22 +993,23 @@ class TabViewController: UIViewController {
self.privacyInfo = privacyInfo
didGoBackForward = false
} else {
privacyInfo = makePrivacyInfo(url: url)
privacyInfo = makePrivacyInfo(url: url, shouldCheckServerTrust: true)
}
} else {
privacyInfo = nil
}
onPrivacyInfoChanged()
}

public func makePrivacyInfo(url: URL) -> PrivacyInfo? {
public func makePrivacyInfo(url: URL, shouldCheckServerTrust: Bool = false) -> PrivacyInfo? {
guard let host = url.host else { return nil }

let entity = ContentBlocking.shared.trackerDataManager.trackerData.findParentEntityOrFallback(forHost: host)

let privacyInfo = PrivacyInfo(url: url,
parentEntity: entity,
protectionStatus: makeProtectionStatus(for: host))
protectionStatus: makeProtectionStatus(for: host),
shouldCheckServerTrust: shouldCheckServerTrust)
let isValid = certificateTrustEvaluator.evaluateCertificateTrust(trust: webView.serverTrust)
if let isValid {
privacyInfo.serverTrust = isValid ? webView.serverTrust : nil
Expand Down
15 changes: 14 additions & 1 deletion DuckDuckGoTests/PrivacyIconLogicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class PrivacyIconLogicTests: XCTestCase {
let url = PrivacyIconLogicTests.pageURL
let entity = Entity(displayName: "E", domains: [], prevalence: 100.0)
let protectionStatus = ProtectionStatus(unprotectedTemporary: false, enabledFeatures: [], allowlisted: false, denylisted: false)
let privacyInfo = PrivacyInfo(url: url, parentEntity: entity, protectionStatus: protectionStatus)
let privacyInfo = PrivacyInfo(url: url, parentEntity: entity, protectionStatus: protectionStatus, shouldCheckServerTrust: true)

let icon = PrivacyIconLogic.privacyIcon(for: privacyInfo)

Expand All @@ -105,6 +105,19 @@ class PrivacyIconLogicTests: XCTestCase {
XCTAssertEqual(icon, .shieldWithDot)
}

func testPrivacyIconIsShieldWithoutDotForNoSecTrustAndShouldCheckServerTrustIsFalse() {
let url = PrivacyIconLogicTests.pageURL
let entity = Entity(displayName: "E", domains: [], prevalence: 100.0)
let protectionStatus = ProtectionStatus(unprotectedTemporary: false, enabledFeatures: [], allowlisted: false, denylisted: false)
let privacyInfo = PrivacyInfo(url: url, parentEntity: entity, protectionStatus: protectionStatus)

let icon = PrivacyIconLogic.privacyIcon(for: privacyInfo)

XCTAssertTrue(url.isHttps)
XCTAssertTrue(privacyInfo.https)
XCTAssertEqual(icon, .shield)
}

}

final class MockSecTrust: SecurityTrust {}

0 comments on commit 1694957

Please sign in to comment.