diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ToolbarDelegate.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ToolbarDelegate.swift index 2f8563896b1..6e1c1614378 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ToolbarDelegate.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ToolbarDelegate.swift @@ -402,7 +402,7 @@ extension BrowserViewController: TopToolbarDelegate { feedDataSource: self.feedDataSource, historyAPI: self.braveCore.historyAPI, p3aUtilities: self.braveCore.p3aUtils, - clearDataCallback: { [weak self] isLoading in + clearDataCallback: { [weak self] isLoading, isHistoryCleared in guard let view = self?.navigationController?.view, view.window != nil else { assertionFailure() return @@ -416,6 +416,13 @@ extension BrowserViewController: TopToolbarDelegate { spinner?.dismiss() spinner = nil } + + if isHistoryCleared { + // Donate Clear Browser History for suggestions + let clearBrowserHistoryActivity = ActivityShortcutManager.shared.createShortcutActivity(type: .clearBrowsingHistory) + self?.userActivity = clearBrowserHistoryActivity + clearBrowserHistoryActivity.becomeCurrent() + } } )) diff --git a/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/HistoryViewController.swift b/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/HistoryViewController.swift index b062e7faa69..887e9a3516f 100644 --- a/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/HistoryViewController.swift +++ b/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/HistoryViewController.swift @@ -206,6 +206,11 @@ class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol // Clearing History should clear Recently Closed RecentlyClosed.removeAll() + + // Donate Clear Browser History for suggestions + let clearBrowserHistoryActivity = ActivityShortcutManager.shared.createShortcutActivity(type: .clearBrowsingHistory) + self.userActivity = clearBrowserHistoryActivity + clearBrowserHistoryActivity.becomeCurrent() } // Asking Sync Engine To Remove Visits diff --git a/Sources/Brave/Frontend/Settings/Features/ShieldsPrivacy/AdvancedShieldSettings.swift b/Sources/Brave/Frontend/Settings/Features/ShieldsPrivacy/AdvancedShieldSettings.swift index 94b396191a6..ef5d2869b8b 100644 --- a/Sources/Brave/Frontend/Settings/Features/ShieldsPrivacy/AdvancedShieldSettings.swift +++ b/Sources/Brave/Frontend/Settings/Features/ShieldsPrivacy/AdvancedShieldSettings.swift @@ -52,7 +52,7 @@ import os } } - typealias ClearDataCallback = @MainActor (Bool) -> Void + typealias ClearDataCallback = @MainActor (Bool, Bool) -> Void @Published var clearableSettings: [ClearableSetting] private var subscriptions: [AnyCancellable] = [] @@ -106,12 +106,12 @@ import os } func clearPrivateData(_ clearables: [Clearable]) async { - clearDataCallback(true) - await clearPrivateDataInternal(clearables) - clearDataCallback(false) + clearDataCallback(true, false) + let isHistoryCleared = await clearPrivateDataInternal(clearables) + clearDataCallback(false, isHistoryCleared) } - private func clearPrivateDataInternal(_ clearables: [Clearable]) async { + private func clearPrivateDataInternal(_ clearables: [Clearable]) async -> Bool { @Sendable func _clear(_ clearables: [Clearable], secondAttempt: Bool = false) async { await withThrowingTaskGroup(of: Void.self) { group in for clearable in clearables { @@ -176,6 +176,8 @@ import os } _toggleFolderAccessForBlockCookies(locked: true) + + return historyCleared } private func registerSubscriptions() { diff --git a/Sources/Brave/Frontend/Settings/SettingsViewController.swift b/Sources/Brave/Frontend/Settings/SettingsViewController.swift index 40eafcbcf83..d9714e06b5e 100644 --- a/Sources/Brave/Frontend/Settings/SettingsViewController.swift +++ b/Sources/Brave/Frontend/Settings/SettingsViewController.swift @@ -245,7 +245,7 @@ class SettingsViewController: TableViewController { feedDataSource: self.feedDataSource, historyAPI: self.historyAPI, p3aUtilities: self.p3aUtilities, - clearDataCallback: { [weak self] isLoading in + clearDataCallback: { [weak self] isLoading, isHistoryCleared in guard let view = self?.navigationController?.view, view.window != nil else { assertionFailure() return @@ -259,6 +259,13 @@ class SettingsViewController: TableViewController { spinner?.dismiss() spinner = nil } + + if isHistoryCleared { + // Donate Clear Browser History for suggestions + let clearBrowserHistoryActivity = ActivityShortcutManager.shared.createShortcutActivity(type: .clearBrowsingHistory) + self?.userActivity = clearBrowserHistoryActivity + clearBrowserHistoryActivity.becomeCurrent() + } } ))