diff --git a/firefox-ios/Client/Frontend/TrackingProtection/TrackigProtectionRedux/TrackingProtectionAction.swift b/firefox-ios/Client/Frontend/TrackingProtection/TrackigProtectionRedux/TrackingProtectionAction.swift index fda59d2086dd..14ff08795bb9 100644 --- a/firefox-ios/Client/Frontend/TrackingProtection/TrackigProtectionRedux/TrackingProtectionAction.swift +++ b/firefox-ios/Client/Frontend/TrackingProtection/TrackigProtectionRedux/TrackingProtectionAction.swift @@ -19,6 +19,7 @@ enum TrackingProtectionActionType: ActionType { case tappedShowClearCookiesAlert case goBack case updateBlockedTrackerStats + case showCookiesClearedToast } final class TrackingProtectionMiddlewareAction: Action { } diff --git a/firefox-ios/Client/Frontend/TrackingProtection/TrackigProtectionRedux/TrackingProtectionModel.swift b/firefox-ios/Client/Frontend/TrackingProtection/TrackigProtectionRedux/TrackingProtectionModel.swift index 6faacf09196a..5c4b4447dd12 100644 --- a/firefox-ios/Client/Frontend/TrackingProtection/TrackigProtectionRedux/TrackingProtectionModel.swift +++ b/firefox-ios/Client/Frontend/TrackingProtection/TrackigProtectionRedux/TrackingProtectionModel.swift @@ -32,6 +32,7 @@ class TrackingProtectionModel { let clearCookiesAlertText: String = .Menu.EnhancedTrackingProtection.clearDataAlertText let clearCookiesAlertButton: String = .Menu.EnhancedTrackingProtection.clearDataAlertButton let clearCookiesAlertCancelButton: String = .Menu.EnhancedTrackingProtection.clearDataAlertCancelButton + let clearCookiesToastMessage: String = .Menu.EnhancedTrackingProtection.clearDataToastMessage // MARK: Accessibility Identifiers let foxImageA11yId: String = AccessibilityIdentifiers.EnhancedTrackingProtection.MainScreen.foxImage @@ -169,7 +170,7 @@ class TrackingProtectionModel { } func onTapClearCookiesAndSiteData(controller: UIViewController) { - let alertMessage = String(format: clearCookiesAlertText, url.absoluteDisplayString) + let alertMessage = String(format: clearCookiesAlertText, url.baseDomain ?? url.shortDisplayString) let alert = UIAlertController( title: clearCookiesAlertTitle, message: alertMessage, @@ -181,15 +182,20 @@ class TrackingProtectionModel { let confirmAction = UIAlertAction(title: clearCookiesAlertButton, style: .destructive) { [weak self] _ in - self?.clearCookiesAndSiteData(cookiesClearable: CookiesClearable(), siteDataClearable: SiteDataClearable()) + self?.clearCookiesAndSiteData() self?.selectedTab?.webView?.reload() + guard let windowUUID = self?.selectedTab?.windowUUID else { return } + store.dispatch( + TrackingProtectionAction(windowUUID: windowUUID, + actionType: TrackingProtectionActionType.showCookiesClearedToast) + ) } alert.addAction(confirmAction) controller.present(alert, animated: true, completion: nil) } - func clearCookiesAndSiteData(cookiesClearable: Clearable, siteDataClearable: Clearable) { - _ = cookiesClearable.clear() - _ = siteDataClearable.clear() + func clearCookiesAndSiteData() { + _ = CookiesClearable().clear() + _ = SiteDataClearable().clear() } } diff --git a/firefox-ios/Client/Frontend/TrackingProtection/TrackigProtectionRedux/TrackingProtectionState.swift b/firefox-ios/Client/Frontend/TrackingProtection/TrackigProtectionRedux/TrackingProtectionState.swift index fbedac1bb323..d330298829fd 100644 --- a/firefox-ios/Client/Frontend/TrackingProtection/TrackigProtectionRedux/TrackingProtectionState.swift +++ b/firefox-ios/Client/Frontend/TrackingProtection/TrackigProtectionRedux/TrackingProtectionState.swift @@ -18,6 +18,7 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { var showsClearCookiesAlert: Bool var shouldClearCookies: Bool var shouldUpdateBlockedTrackerStats: Bool + var showCookiesClearedToast: Bool init(appState: AppState, uuid: WindowUUID) { @@ -40,7 +41,8 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: trackingProtectionState.showBlockedTrackers, showsClearCookiesAlert: trackingProtectionState.showsClearCookiesAlert, shouldClearCookies: trackingProtectionState.shouldClearCookies, - shouldUpdateBlockedTrackerStats: trackingProtectionState.shouldUpdateBlockedTrackerStats + shouldUpdateBlockedTrackerStats: trackingProtectionState.shouldUpdateBlockedTrackerStats, + showCookiesClearedToast: trackingProtectionState.showCookiesClearedToast ) } @@ -57,7 +59,8 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: false, showsClearCookiesAlert: false, shouldClearCookies: false, - shouldUpdateBlockedTrackerStats: false + shouldUpdateBlockedTrackerStats: false, + showCookiesClearedToast: false ) } @@ -71,7 +74,8 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: Bool, showsClearCookiesAlert: Bool, shouldClearCookies: Bool, - shouldUpdateBlockedTrackerStats: Bool + shouldUpdateBlockedTrackerStats: Bool, + showCookiesClearedToast: Bool ) { self.windowUUID = windowUUID self.shouldDismiss = shouldDismiss @@ -83,6 +87,7 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { self.showsClearCookiesAlert = showsClearCookiesAlert self.shouldClearCookies = shouldClearCookies self.shouldUpdateBlockedTrackerStats = shouldUpdateBlockedTrackerStats + self.showCookiesClearedToast = showCookiesClearedToast } static let reducer: Reducer = { state, action in @@ -103,7 +108,8 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: false, showsClearCookiesAlert: false, shouldClearCookies: true, - shouldUpdateBlockedTrackerStats: false + shouldUpdateBlockedTrackerStats: false, + showCookiesClearedToast: false ) case TrackingProtectionMiddlewareActionType.navigateToSettings: return TrackingProtectionState( @@ -116,7 +122,8 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: false, showsClearCookiesAlert: false, shouldClearCookies: false, - shouldUpdateBlockedTrackerStats: false + shouldUpdateBlockedTrackerStats: false, + showCookiesClearedToast: false ) case TrackingProtectionMiddlewareActionType.showTrackingProtectionDetails: return TrackingProtectionState( @@ -129,7 +136,8 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: false, showsClearCookiesAlert: false, shouldClearCookies: false, - shouldUpdateBlockedTrackerStats: false + shouldUpdateBlockedTrackerStats: false, + showCookiesClearedToast: false ) case TrackingProtectionMiddlewareActionType.showBlockedTrackersDetails: return TrackingProtectionState( @@ -142,7 +150,8 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: true, showsClearCookiesAlert: false, shouldClearCookies: false, - shouldUpdateBlockedTrackerStats: false + shouldUpdateBlockedTrackerStats: false, + showCookiesClearedToast: false ) case TrackingProtectionActionType.goBack: return TrackingProtectionState( @@ -155,7 +164,8 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: false, showsClearCookiesAlert: false, shouldClearCookies: false, - shouldUpdateBlockedTrackerStats: false + shouldUpdateBlockedTrackerStats: false, + showCookiesClearedToast: false ) case TrackingProtectionActionType.updateBlockedTrackerStats: return TrackingProtectionState( @@ -168,7 +178,8 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: false, showsClearCookiesAlert: false, shouldClearCookies: false, - shouldUpdateBlockedTrackerStats: true + shouldUpdateBlockedTrackerStats: true, + showCookiesClearedToast: false ) case TrackingProtectionMiddlewareActionType.showAlert: return TrackingProtectionState( @@ -181,7 +192,8 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: false, showsClearCookiesAlert: true, shouldClearCookies: false, - shouldUpdateBlockedTrackerStats: false + shouldUpdateBlockedTrackerStats: false, + showCookiesClearedToast: false ) case TrackingProtectionActionType.toggleTrackingProtectionStatus: return TrackingProtectionState( @@ -194,7 +206,8 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: false, showsClearCookiesAlert: false, shouldClearCookies: false, - shouldUpdateBlockedTrackerStats: false + shouldUpdateBlockedTrackerStats: false, + showCookiesClearedToast: false ) case TrackingProtectionMiddlewareActionType.dismissTrackingProtection: return TrackingProtectionState( @@ -207,7 +220,22 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: false, showsClearCookiesAlert: false, shouldClearCookies: false, - shouldUpdateBlockedTrackerStats: false + shouldUpdateBlockedTrackerStats: false, + showCookiesClearedToast: false + ) + case TrackingProtectionActionType.showCookiesClearedToast: + return TrackingProtectionState( + windowUUID: state.windowUUID, + shouldDismiss: false, + showTrackingProtectionSettings: false, + trackingProtectionEnabled: state.trackingProtectionEnabled, + connectionSecure: state.connectionSecure, + showDetails: false, + showBlockedTrackers: false, + showsClearCookiesAlert: false, + shouldClearCookies: false, + shouldUpdateBlockedTrackerStats: state.shouldUpdateBlockedTrackerStats, + showCookiesClearedToast: true ) default: return defaultState(from: state) @@ -225,7 +253,8 @@ struct TrackingProtectionState: StateType, Equatable, ScreenState { showBlockedTrackers: false, showsClearCookiesAlert: false, shouldClearCookies: false, - shouldUpdateBlockedTrackerStats: false + shouldUpdateBlockedTrackerStats: false, + showCookiesClearedToast: false ) } } diff --git a/firefox-ios/Client/Frontend/TrackingProtection/TrackingProtectionViewController.swift b/firefox-ios/Client/Frontend/TrackingProtection/TrackingProtectionViewController.swift index 1c5036a8092b..12eddad923b2 100644 --- a/firefox-ios/Client/Frontend/TrackingProtection/TrackingProtectionViewController.swift +++ b/firefox-ios/Client/Frontend/TrackingProtection/TrackingProtectionViewController.swift @@ -204,6 +204,8 @@ class TrackingProtectionViewController: UIViewController, updateBlockedTrackersCount() } else if trackingProtectionState.shouldDismiss { enhancedTrackingProtectionMenuDelegate?.didFinish() + } else if trackingProtectionState.showCookiesClearedToast { + showToast() } } @@ -544,6 +546,12 @@ class TrackingProtectionViewController: UIViewController, model.onTapClearCookiesAndSiteData(controller: self) } + func showToast() { + SimpleToast().showAlertWithText(model.clearCookiesToastMessage, + bottomContainer: view, + theme: self.themeManager.getCurrentTheme(for: self.windowUUID)) + } + func clearCookies() {} // MARK: - Gesture Recognizer