Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breakage improvement #621

Merged
merged 29 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ebd0e6b
tap close enabled in privacy dashboard for macOS
federicocappelli Dec 14, 2023
f342036
Merge branch 'main' into fcappelli/breakage_improvement_mac
federicocappelli Dec 20, 2023
c131332
privacy dashboard code cleanup and model shared
federicocappelli Dec 20, 2023
12e535f
updated to latest dashboard
Jan 9, 2024
c49e72d
Report broken site refactored, all business logic and models are now …
federicocappelli Jan 9, 2024
d1a5357
Merge branch 'fcappelli/breakage_improvement_mac' of https://github.c…
federicocappelli Jan 9, 2024
6394810
Merge branch 'main' into fcappelli/breakage_improvement_mac
federicocappelli Jan 9, 2024
f1e796a
swiftlint --fix
federicocappelli Jan 10, 2024
7e1a7a4
Merge branch 'main' into fcappelli/breakage_improvement_mac
federicocappelli Jan 10, 2024
f4560fc
submodule updated
federicocappelli Jan 10, 2024
a9551e1
swiftlint violations fixed
federicocappelli Jan 10, 2024
3b8ac06
Website breakage init differentiated for iOS and macOS
federicocappelli Jan 10, 2024
e3d2ddd
swiftlint fix
federicocappelli Jan 10, 2024
b235408
debug logs sanithised
federicocappelli Jan 10, 2024
dc60cf4
unit tests fixed
federicocappelli Jan 10, 2024
1f8b8df
folder name reverted
federicocappelli Jan 10, 2024
6f7f380
schemes removed
federicocappelli Jan 10, 2024
37c369a
bsk scheme
federicocappelli Jan 10, 2024
fe51d88
.swiftpm/xcode/xcshareddata/xcschemes/BrowserServicesKit.xcscheme rev…
federicocappelli Jan 10, 2024
20fff59
allowedQueryReservedCharacters moved
federicocappelli Jan 10, 2024
252ebde
accessibility fix
federicocappelli Jan 10, 2024
7dd2e92
swiftlint fix
federicocappelli Jan 10, 2024
690024c
manufacturer: "Apple" added
federicocappelli Jan 10, 2024
18b7151
report broken site history url privacy sanitisation improved
federicocappelli Jan 11, 2024
d10308a
url sanitation and unit test improved
federicocappelli Jan 11, 2024
887e144
Merge branch 'main' into fcappelli/breakage_improvement_mac
federicocappelli Jan 17, 2024
ce5701c
Merge branch 'main' into fcappelli/breakage_improvement_mac
federicocappelli Jan 24, 2024
e50fe33
Merge branch 'main' into fcappelli/breakage_improvement_mac
federicocappelli Jan 29, 2024
e4d8dca
privacy dashboard v 3.2.0
federicocappelli Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/privacy-dashboard",
"state" : {
"revision" : "38336a574e13090764ba09a6b877d15ee514e371",
"version" : "3.1.1"
"revision" : "c67d268bf234760f49034a0fe7a6137a1b216b05",
"version" : "3.2.0"
}
},
{
Expand Down
11 changes: 10 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let package = Package(
.package(url: "https://github.com/duckduckgo/TrackerRadarKit", exact: "1.2.2"),
.package(url: "https://github.com/duckduckgo/sync_crypto", exact: "0.2.0"),
.package(url: "https://github.com/gumob/PunycodeSwift.git", exact: "2.1.0"),
.package(url: "https://github.com/duckduckgo/privacy-dashboard", exact: "3.1.1" ),
.package(url: "https://github.com/duckduckgo/privacy-dashboard", exact: "3.2.0"),
.package(url: "https://github.com/duckduckgo/content-scope-scripts", exact: "4.59.1"),
.package(url: "https://github.com/httpswift/swifter.git", exact: "1.5.0"),
.package(url: "https://github.com/duckduckgo/bloom_cpp.git", exact: "3.0.0"),
Expand Down Expand Up @@ -198,6 +198,7 @@ let package = Package(
"TrackerRadarKit",
"UserScript",
"ContentBlocking",
"Persistence",
.product(name: "PrivacyDashboardResources", package: "privacy-dashboard")
],
path: "Sources/PrivacyDashboard",
Expand Down Expand Up @@ -452,6 +453,14 @@ let package = Package(
],
plugins: [.plugin(name: "SwiftLintPlugin")]
),
.testTarget(
name: "PrivacyDashboardTests",
dependencies: [
"PrivacyDashboard",
"TestUtils"
],
plugins: [.plugin(name: "SwiftLintPlugin")]
),
],
cxxLanguageStandard: .cxx11
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>_XCCurrentVersionName</key>
<string>HTTPSUpgrade 3.xcdatamodel</string>
</dict>
</plist>
29 changes: 29 additions & 0 deletions Sources/Persistence/DictionaryRepresentable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// DictionaryRepresentable.swift
//
// Copyright © 2024 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

/// Something that can be represented as a Dictionary
public protocol DictionaryRepresentable {

/// Convenience method to return a Dictionary representation of this metadata.
/// - Returns: A Dictionary object containing the object representation
func dictionaryRepresentation() -> [String: Any]
}

extension UserDefaults: DictionaryRepresentable { }
10 changes: 5 additions & 5 deletions Sources/PrivacyDashboard/PrivacyDashboardController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ public enum PrivacyDashboardOpenSettingsTarget: String {

/// Navigation delegate for the pages provided by the PrivacyDashboardController
public protocol PrivacyDashboardNavigationDelegate: AnyObject {
#if os(iOS)
func privacyDashboardControllerDidTapClose(_ privacyDashboardController: PrivacyDashboardController)
#endif

func privacyDashboardControllerDidTapClose(_ privacyDashboardController: PrivacyDashboardController)
func privacyDashboardController(_ privacyDashboardController: PrivacyDashboardController, didSetHeight height: Int)
}

Expand Down Expand Up @@ -148,6 +146,8 @@ public protocol PrivacyDashboardControllerDelegate: AnyObject {
}
}

// MARK: - WKNavigationDelegate

extension PrivacyDashboardController: WKNavigationDelegate {

public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
Expand Down Expand Up @@ -257,6 +257,8 @@ extension PrivacyDashboardController: WKNavigationDelegate {
}
}

// MARK: - PrivacyDashboardUserScriptDelegate

extension PrivacyDashboardController: PrivacyDashboardUserScriptDelegate {

func userScript(_ userScript: PrivacyDashboardUserScript, didRequestOpenSettings target: String) {
Expand All @@ -280,9 +282,7 @@ extension PrivacyDashboardController: PrivacyDashboardUserScriptDelegate {
}

func userScriptDidRequestClosing(_ userScript: PrivacyDashboardUserScript) {
#if os(iOS)
privacyDashboardNavigationDelegate?.privacyDashboardControllerDidTapClose(self)
#endif
}

func userScriptDidRequestShowReportBrokenSite(_ userScript: PrivacyDashboardUserScript) {
Expand Down
56 changes: 56 additions & 0 deletions Sources/PrivacyDashboard/URL+Trimming.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// URL+Trimming.swift
//
// 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

extension URL {

/// To limit privacy risk, site URL is trimmed to not include query and fragment
/// - Returns: The original URL without query items and fragment
public func trimmingQueryItemsAndFragment() -> URL {

guard var components = URLComponents(url: self, resolvingAgainstBaseURL: true) else {
return self
}
components.queryItems = nil
components.fragment = nil

guard let result = components.url else {
return self
}
return result
}

/// To limit privacy risk, site URL is trimmed to include only schema, subdomain and domain
/// - Returns: The original URL without query items, fragment and path
public func privacySanitised() -> URL {

guard var components = URLComponents(url: self, resolvingAgainstBaseURL: true) else {
return self
}
components.queryItems = nil
components.fragment = nil
components.path = ""

guard let result = components.url else {
return self
}
return result
}

}
88 changes: 88 additions & 0 deletions Sources/PrivacyDashboard/WebsiteBreakage/ExpiryStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// ExpiryStorage.swift
//
// Copyright © 2024 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 Persistence

public typealias KeyValueStoringDictionaryRepresentable = KeyValueStoring & DictionaryRepresentable

/// A storage solution were each entry has an expiry date and a function for removing all expired entries is provided.
/// Any persistency solution implementing `KeyValueStoringDictionaryRepresentable` can be used.
public class ExpiryStorage {

enum Keys: String {
case expiryDatesStorage = "com.duckduckgo.UserDefaultExpiryStorage"
case valueExpiryDate = "com.duckduckgo.UserDefaultExpiryStorage.valueExpiryDate"
case valueData = "com.duckduckgo.UserDefaultExpiryStorage.valueData"
}

let localStorage: KeyValueStoringDictionaryRepresentable

/// Default initialiser
/// - Parameter keyValueStoring: An object managing the persistency of the key-value pairs that implements `KeyValueStoringDictionaryRepresentable`
public init(keyValueStoring: KeyValueStoringDictionaryRepresentable) {
self.localStorage = keyValueStoring
}

/// Store a value and the desired expiry date (or removes the value if nil is passed as the value) for the provided key
/// - Parameters:
/// - value: The value to store, must be
/// - key: The value key
/// - expiryDate: A date stored alongside the value, used by `removeExpiredItems(...)` for removing expired values.
public func set(value: Any?, forKey key: String, expiryDate: Date) {

let valueDic = [Keys.valueExpiryDate.rawValue: expiryDate, Keys.valueData.rawValue: value]
localStorage.set(valueDic, forKey: key)
}

/// - Returns: The stored value assiciated to the key, nil if not existent
public func value(forKey key: String) -> Any? {

return entry(forKey: key)?.value
}

/// - Returns: The tuple expiryDate+value associated to the key, nil if they don't exist
public func entry(forKey key: String) -> (expiryDate: Date, value: Any)? {
guard let valueDic = localStorage.object(forKey: key) as? [String: Any],
let expiryDate = valueDic[Keys.valueExpiryDate.rawValue] as? Date,
let value = valueDic[Keys.valueData.rawValue]
else {
return nil
}
return (expiryDate, value)
}

/// Search the entire storage for values that a re a dictionary containing 2 keys: `ExpiryStorage.Keys.valueExpiryDate` and `ExpiryStorage.Keys.valueData`, if found compares the `valueExpiryDate` with the `currentDate`, if the `currentDate` > `valueExpiryDate` then the value is removed form the storage
/// - Parameter currentDate: The date used in the comparison with the values `valueExpiryDate`
/// - Returns: The number of values removed
public func removeExpiredItems(currentDate: Date) -> Int {

var removedCount = 0
let allKeys = localStorage.dictionaryRepresentation().keys
for key in allKeys {
if let entry = entry(forKey: key) {
if currentDate > entry.expiryDate {
localStorage.removeObject(forKey: key)
removedCount += 1
}
}
}

return removedCount
}
}
Loading
Loading