Skip to content

Commit

Permalink
Merge branch 'develop' into michal/kingfisher-bump-to-7.0.0
Browse files Browse the repository at this point in the history
* develop:
  Stop web views from loading during Fire button calls (#1010)
  Fix `Unprotected Sites` toolbar was kept hidden. (#990)
  Add a check for the Homebrew location on M1 Macs. (#1000)
  Bump version number
  Fixes and enhanced stats for recently added debug pixel (#1007)
  • Loading branch information
samsymons committed Nov 26, 2021
2 parents 8f63bd2 + c0f7c6d commit dcb0f22
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Configuration/Version.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MARKETING_VERSION = 7.64.16
MARKETING_VERSION = 7.64.17

20 changes: 14 additions & 6 deletions Core/Pixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ public enum PixelName: String {
case blankOverlayNotDismissed = "m_d_ovs"

case cookieDeletionTimedOut = "m_d_csto"
case cookieDeletionLeftovers = "cookie_deletion_leftovers"
case legacyCookieMigration = "legacy_cookie_migration"
case legacyCookieCleanupError = "legacy_cookie_cleanup_error"
case cookieDeletionLeftovers = "m_cookie_deletion_leftovers"
case legacyCookieMigration = "m_legacy_cookie_migration"
case legacyCookieCleanupError = "m_legacy_cookie_cleanup_error"

case cachedTabPreviewsExceedsTabCount = "m_d_tpetc"
case cachedTabPreviewRemovalError = "m_d_tpre"
Expand Down Expand Up @@ -243,8 +243,16 @@ public struct PixelParameters {
public static let emailCohort = "cohort"
public static let emailLastUsed = "duck_address_last_used"

public static let cookieStoreDiff = "cookie_store_diff"
public static let cookieStorageDiff = "cookie_storage_diff"
// Cookie clearing
public static let storeInitialCount = "store_initial_count"
public static let storeProtectedCount = "store_protected_count"
public static let didStoreDeletionTimeOut = "did_store_deletion_time_out"
public static let storageInitialCount = "storage_initial_count"
public static let storageProtectedCount = "storage_protected_count"
public static let storeAfterDeletionCount = "store_after_deletion_count"
public static let storageAfterDeletionCount = "storage_after_deletion_count"
public static let storeAfterDeletionDiffCount = "store_after_deletion_diff_count"
public static let storageAfterDeletionDiffCount = "storage_after_deletion_diff_count"

public static let count = "count"
}
Expand Down Expand Up @@ -336,7 +344,7 @@ public class TimedPixel {
self.date = date
}

public func fire(_ fireDate: Date = Date(), withAdditionalParmaeters params: [String: String] = [:]) {
public func fire(_ fireDate: Date = Date(), withAdditionalParameters params: [String: String] = [:]) {
let duration = String(fireDate.timeIntervalSince(date))
var newParams = params
newParams[PixelParameters.duration] = duration
Expand Down
79 changes: 61 additions & 18 deletions Core/WebCacheManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,17 @@ public class WebCacheManager {
completion()
return
}

let cookieClearingSummary = WebStoreCookieClearingSummary()

cookieStore.getAllCookies { cookies in
let group = DispatchGroup()
let cookiesToRemove = cookies.filter { !logins.isAllowed(cookieDomain: $0.domain) && $0.domain != Constants.cookieDomain }
let protectedCookiesCount = cookies.count - cookiesToRemove.count

cookieClearingSummary.storeInitialCount = cookies.count
cookieClearingSummary.storeProtectedCount = protectedCookiesCount

for cookie in cookiesToRemove {
group.enter()
cookieStore.delete(cookie) {
Expand All @@ -164,6 +169,7 @@ public class WebCacheManager {
let result = group.wait(timeout: .now() + 5)

if result == .timedOut {
cookieClearingSummary.didStoreDeletionTimeOut = true
Pixel.fire(pixel: .cookieDeletionTimedOut, withAdditionalParameters: [
PixelParameters.clearWebDataTimedOut: "1"
])
Expand All @@ -177,27 +183,14 @@ public class WebCacheManager {

let protectedStorageCookiesCount = storageCookies.count - storageCookiesToRemove.count

cookieClearingSummary.storageInitialCount = storageCookies.count
cookieClearingSummary.storageProtectedCount = protectedStorageCookiesCount

for storageCookie in storageCookiesToRemove {
HTTPCookieStorage.shared.deleteCookie(storageCookie)
}

// Sanity check
cookieStore.getAllCookies { cookiesAfterCleaning in
let storageCookiesAfterCleaning = HTTPCookieStorage.shared.cookies ?? []

let cookieStoreDiff = cookiesAfterCleaning.count - protectedCookiesCount
let cookieStorageDiff = storageCookiesAfterCleaning.count - protectedStorageCookiesCount

if cookieStoreDiff + cookieStorageDiff > 0 {
os_log("Error removing cookies: %d cookies left in WKHTTPCookieStore, %d cookies left in HTTPCookieStorage",
log: generalLog, type: .debug, cookieStoreDiff, cookieStorageDiff)

Pixel.fire(pixel: .cookieDeletionLeftovers, withAdditionalParameters: [
PixelParameters.cookieStoreDiff: "\(cookieStoreDiff)",
PixelParameters.cookieStorageDiff: "\(cookieStorageDiff)"
])
}
}

self.performSanityCheck(for: cookieStore, summary: cookieClearingSummary)

DispatchQueue.main.async {
completion()
Expand All @@ -206,6 +199,31 @@ public class WebCacheManager {
}
}
}

private func performSanityCheck(for cookieStore: WebCacheManagerCookieStore, summary: WebStoreCookieClearingSummary) {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
cookieStore.getAllCookies { cookiesAfterCleaning in
let storageCookiesAfterCleaning = HTTPCookieStorage.shared.cookies ?? []

summary.storeAfterDeletionCount = cookiesAfterCleaning.count
summary.storageAfterDeletionCount = storageCookiesAfterCleaning.count

let cookieStoreDiff = cookiesAfterCleaning.count - summary.storeProtectedCount
let cookieStorageDiff = storageCookiesAfterCleaning.count - summary.storageProtectedCount

summary.storeAfterDeletionDiffCount = cookieStoreDiff
summary.storageAfterDeletionDiffCount = cookieStorageDiff

if cookieStoreDiff + cookieStorageDiff > 0 {
os_log("Error removing cookies: %d cookies left in WKHTTPCookieStore, %d cookies left in HTTPCookieStorage",
log: generalLog, type: .debug, cookieStoreDiff, cookieStorageDiff)

Pixel.fire(pixel: .cookieDeletionLeftovers,
withAdditionalParameters: summary.makeDictionaryRepresentation())
}
}
}
}

/// The Fire Button does not delete the user's DuckDuckGo search settings, which are saved as cookies. Removing these cookies would reset them and have undesired
/// consequences, i.e. changing the theme, default language, etc. These cookies are not stored in a personally identifiable way. For example, the large size setting
Expand Down Expand Up @@ -241,3 +259,28 @@ extension WKWebsiteDataStore: WebCacheManagerDataStore {
}

}

final class WebStoreCookieClearingSummary {
var storeInitialCount: Int = 0
var storeProtectedCount: Int = 0
var didStoreDeletionTimeOut: Bool = false
var storageInitialCount: Int = 0
var storageProtectedCount: Int = 0

var storeAfterDeletionCount: Int = 0
var storageAfterDeletionCount: Int = 0
var storeAfterDeletionDiffCount: Int = 0
var storageAfterDeletionDiffCount: Int = 0

func makeDictionaryRepresentation() -> [String: String] {
[PixelParameters.storeInitialCount: "\(storeInitialCount)",
PixelParameters.storeProtectedCount: "\(storeProtectedCount)",
PixelParameters.didStoreDeletionTimeOut: didStoreDeletionTimeOut ? "true" : "false",
PixelParameters.storageInitialCount: "\(storageInitialCount)",
PixelParameters.storageProtectedCount: "\(storageProtectedCount)",
PixelParameters.storeAfterDeletionCount: "\(storeAfterDeletionCount)",
PixelParameters.storageAfterDeletionCount: "\(storageAfterDeletionCount)",
PixelParameters.storeAfterDeletionDiffCount: "\(storeAfterDeletionDiffCount)",
PixelParameters.storageAfterDeletionDiffCount: "\(storageAfterDeletionDiffCount)"]
}
}
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4345,7 +4345,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n if [ ! -z \"$BITRISE_PROJECT_PATH\" ] || [ \"$CONFIGURATION\" = \"Release\" ]; then\n swiftlint lint --strict\n if [ $? -ne 0 ]; then\n echo \"error: SwiftLint validation failed.\"\n exit 1\n fi\n else\n swiftlint lint\n fi\nelse\n echo \"error: SwiftLint not installed. Install using \\`brew install swiftlint\\`\"\n exit 1\nfi\n";
shellScript = "if test -d \"/opt/homebrew/bin/\"; then\n PATH=\"/opt/homebrew/bin/:${PATH}\"\nfi\n\nexport PATH\n\nif which swiftlint >/dev/null; then\n if [ ! -z \"$BITRISE_PROJECT_PATH\" ] || [ \"$CONFIGURATION\" = \"Release\" ]; then\n swiftlint lint --strict\n if [ $? -ne 0 ]; then\n echo \"error: SwiftLint validation failed.\"\n exit 1\n fi\n else\n swiftlint lint\n fi\nelse\n echo \"error: SwiftLint not installed. Install using \\`brew install swiftlint\\`\"\n exit 1\nfi\n";
};
85CA9A212644081300145393 /* Check Filename Headers */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ extension MainViewController: AutoClearWorker {

let pixel = TimedPixel(.forgetAllDataCleared)
WebCacheManager.shared.clear {
pixel.fire(withAdditionalParmaeters: [PixelParameters.tabCount: "\(self.tabManager.count)"])
pixel.fire(withAdditionalParameters: [PixelParameters.tabCount: "\(self.tabManager.count)"])
}
}

Expand All @@ -1566,6 +1566,7 @@ extension MainViewController: AutoClearWorker {
Pixel.fire(pixel: .forgetAllExecuted)

fireButtonAnimator?.animate {
self.tabManager.stopLoadingInAllTabs()
self.forgetData()
DaxDialogs.shared.resumeRegularFlow()
self.forgetTabs()
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Settings.bundle/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<array>
<dict>
<key>DefaultValue</key>
<string>7.64.16</string>
<string>7.64.17</string>
<key>Key</key>
<string>version</string>
<key>Title</key>
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ class TabManager {
func save() {
model.save()
}

func stopLoadingInAllTabs() {
tabControllerCache.forEach { $0.stopLoading() }
}

}

Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ class TabViewController: UIViewController {
load(urlRequest: URLRequest(url: url))
}

func stopLoading() {
webView.stopLoading()
}

private func load(urlRequest: URLRequest) {
loadViewIfNeeded()

Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/UnprotectedSitesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class UnprotectedSitesViewController: UITableViewController {
infoText.attributedText = text
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

navigationController?.setToolbarHidden(true, animated: false)
}
Expand Down

0 comments on commit dcb0f22

Please sign in to comment.