Skip to content

Commit

Permalink
Fix privacy icon glitch (#3343)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/414235014887631/1208264183723705/f

**Description**:
Fix privacy icon glitching when loading sites.

---------

Co-authored-by: Bartek Waresiak <[email protected]>
  • Loading branch information
jaceklyp and bwaresiak authored Sep 10, 2024
1 parent f4077f8 commit 17af939
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10773,7 +10773,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 191.2.3;
version = "191.2.3-1";
};
};
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"
"revision" : "3bac7c0924eeebd58b8868ef44489fac0fb7ec44",
"version" : "191.2.3-1"
}
},
{
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 17af939

Please sign in to comment.