Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into alex/swiftlint-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mallexxx committed Dec 6, 2023
2 parents f9ff5ef + 0a71603 commit 5aaa848
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ final class PrivacyDashboardViewController: NSViewController {
super.viewDidLoad()

initWebView()
privacyDashboardController.setup(for: webView)
privacyDashboardController.setup(for: webView, reportBrokenSiteOnly: false)

setupHeightChangeHandler()
}

override func viewWillAppear() {
super.viewWillAppear()

privacyDashboardController.delegate = self
privacyDashboardController.privacyDashboardNavigationDelegate = self
privacyDashboardController.privacyDashboardDelegate = self
privacyDashboardController.privacyDashboardReportBrokenSiteDelegate = self
privacyDashboardController.preferredLocale = "en" // fixed until app is localised

webView.reload()
Expand All @@ -95,7 +97,9 @@ final class PrivacyDashboardViewController: NSViewController {
override func viewWillDisappear() {
super.viewWillDisappear()

privacyDashboardController.delegate = nil
privacyDashboardController.privacyDashboardNavigationDelegate = nil
privacyDashboardController.privacyDashboardDelegate = nil
privacyDashboardController.privacyDashboardReportBrokenSiteDelegate = nil
shouldAnimateHeightChange = false
}

Expand Down Expand Up @@ -167,27 +171,35 @@ final class PrivacyDashboardViewController: NSViewController {
self.contentHeightConstraint.constant = height
}
}
}

extension PrivacyDashboardViewController: PrivacyDashboardControllerDelegate {

func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didChangeProtectionSwitch protectionState: ProtectionState) {
private func privacyDashboardProtectionSwitchChangeHandler(state: ProtectionState) {
guard let domain = privacyDashboardController.privacyInfo?.url.host else {
return
}

let configuration = ContentBlocking.shared.privacyConfigurationManager.privacyConfig
if protectionState.isProtected && configuration.isUserUnprotected(domain: domain) {
if state.isProtected && configuration.isUserUnprotected(domain: domain) {
configuration.userEnabledProtection(forDomain: domain)
Pixel.fire(.dashboardProtectionAllowlistRemove(triggerOrigin: protectionState.eventOrigin.screen.rawValue), includeAppVersionParameter: false)
Pixel.fire(.dashboardProtectionAllowlistRemove(triggerOrigin: state.eventOrigin.screen.rawValue), includeAppVersionParameter: false)
} else {
configuration.userDisabledProtection(forDomain: domain)
Pixel.fire(.dashboardProtectionAllowlistAdd(triggerOrigin: protectionState.eventOrigin.screen.rawValue), includeAppVersionParameter: false)
Pixel.fire(.dashboardProtectionAllowlistAdd(triggerOrigin: state.eventOrigin.screen.rawValue), includeAppVersionParameter: false)
}

let completionToken = ContentBlocking.shared.contentBlockingManager.scheduleCompilation()
rulesUpdateObserver.didStartCompilation(for: domain, token: completionToken)
}
}

extension PrivacyDashboardViewController: PrivacyDashboardControllerDelegate {

func privacyDashboardControllerDidRequestShowReportBrokenSite(_ privacyDashboardController: PrivacyDashboard.PrivacyDashboardController) {
// Not used in macOS: Pixel.fire(.privacyDashboardReportBrokenSite)
}

func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didChangeProtectionSwitch protectionState: ProtectionState) {
privacyDashboardProtectionSwitchChangeHandler(state: protectionState)
}

func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didRequestOpenUrlInNewTab url: URL) {
guard let tabCollection = WindowControllersManager.shared.lastKeyMainWindowController?.mainViewController.tabCollectionViewModel
Expand All @@ -214,14 +226,6 @@ extension PrivacyDashboardViewController: PrivacyDashboardControllerDelegate {
}
}

func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didSetHeight height: Int) {
currentContentHeight = height
}

func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didRequestSubmitBrokenSiteReportWithCategory category: String, description: String) {
websiteBreakageReporter.reportBreakage(category: category, description: description, reportFlow: .privacyDashboard)
}

func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didSetPermission permissionName: String, to state: PermissionAuthorizationState) {
guard let domain = self.privacyDashboardController.privacyInfo?.url.host else { return }

Expand All @@ -231,5 +235,22 @@ extension PrivacyDashboardViewController: PrivacyDashboardControllerDelegate {
func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, setPermission permissionName: String, paused: Bool) {
permissionHandler.setPermission(with: permissionName, paused: paused)
}
}

extension PrivacyDashboardViewController: PrivacyDashboardNavigationDelegate {

func privacyDashboardController(_ privacyDashboardController: PrivacyDashboard.PrivacyDashboardController, didSetHeight height: Int) {
currentContentHeight = height
}
}

extension PrivacyDashboardViewController: PrivacyDashboardReportBrokenSiteDelegate {

func privacyDashboardController(_ privacyDashboardController: PrivacyDashboard.PrivacyDashboardController, didRequestSubmitBrokenSiteReportWithCategory category: String, description: String) {
websiteBreakageReporter.reportBreakage(category: category, description: description, reportFlow: .privacyDashboard)
}

func privacyDashboardController(_ privacyDashboardController: PrivacyDashboard.PrivacyDashboardController, reportBrokenSiteDidChangeProtectionSwitch protectionState: PrivacyDashboard.ProtectionState) {
privacyDashboardProtectionSwitchChangeHandler(state: protectionState)
}
}
2 changes: 1 addition & 1 deletion LocalPackages/Account/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
targets: ["Account"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "90.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "91.0.1"),
.package(path: "../Purchase"),
],
targets: [
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: "90.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "91.0.1"),
.package(path: "../PixelKit"),
.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 @@ -30,7 +30,7 @@ let package = Package(
.library(name: "NetworkProtectionUI", targets: ["NetworkProtectionUI"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "90.0.0"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "91.0.1"),
.package(path: "../XPCHelper"),
.package(path: "../SwiftUIExtensions")
],
Expand Down
6 changes: 3 additions & 3 deletions UnitTests/Tab/ViewModel/TabViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ final class TabViewModelTests: XCTestCase {
let addressBarStringExpectation = expectation(description: "Address bar string")

tabViewModel.simulateLoadingCompletion()

tabViewModel.$addressBarString.debounce(for: 0.1, scheduler: RunLoop.main).sink { _ in
XCTAssertEqual(tabViewModel.addressBarString, urlString)
XCTAssertEqual(tabViewModel.passiveAddressBarString, urlString)
Expand All @@ -90,7 +90,7 @@ final class TabViewModelTests: XCTestCase {
let addressBarStringExpectation = expectation(description: "Address bar string")

tabViewModel.simulateLoadingCompletion()

tabViewModel.$addressBarString.debounce(for: 0.1, scheduler: RunLoop.main).sink { _ in
XCTAssertEqual(tabViewModel.addressBarString, urlString)
XCTAssertEqual(tabViewModel.passiveAddressBarString, "data:")
Expand Down Expand Up @@ -230,7 +230,7 @@ extension TabViewModel {
let tab = Tab(content: .url(url))
return TabViewModel(tab: tab)
}

func simulateLoadingCompletion() {
self.updateAddressBarStrings()
}
Expand Down

0 comments on commit 5aaa848

Please sign in to comment.