diff --git a/components/brave_shields/core/common/features.cc b/components/brave_shields/core/common/features.cc index 7c8089f19da2..22d52593f075 100644 --- a/components/brave_shields/core/common/features.cc +++ b/components/brave_shields/core/common/features.cc @@ -93,6 +93,10 @@ BASE_FEATURE(kBraveReduceLanguage, BASE_FEATURE(kBraveShredFeature, "BraveShredFeature", base::FEATURE_DISABLED_BY_DEFAULT); +// When enabled, brave shred will clear all cache data when shredding. +BASE_FEATURE(kBraveShredCacheData, + "BraveShredCacheData", + base::FEATURE_DISABLED_BY_DEFAULT); // When enabled, show Strict (aggressive) fingerprinting mode in Brave Shields. BASE_FEATURE(kBraveShowStrictFingerprintingMode, "BraveShowStrictFingerprintingMode", diff --git a/components/brave_shields/core/common/features.h b/components/brave_shields/core/common/features.h index dca25c5a1f70..a173a63e547f 100644 --- a/components/brave_shields/core/common/features.h +++ b/components/brave_shields/core/common/features.h @@ -32,6 +32,7 @@ BASE_DECLARE_FEATURE(kBraveExtensionNetworkBlocking); BASE_DECLARE_FEATURE(kBraveLocalhostAccessPermission); BASE_DECLARE_FEATURE(kBraveReduceLanguage); BASE_DECLARE_FEATURE(kBraveShredFeature); +BASE_DECLARE_FEATURE(kBraveShredCacheData); BASE_DECLARE_FEATURE(kBraveShowStrictFingerprintingMode); BASE_DECLARE_FEATURE(kCosmeticFilteringExtraPerfMetrics); BASE_DECLARE_FEATURE(kCosmeticFilteringJsPerformance); diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/TabManager.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/TabManager.swift index 96e5f9ba2263..93b82685b90b 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/TabManager.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/TabManager.swift @@ -859,6 +859,8 @@ class TabManager: NSObject { ) { guard let etldP1 = url.baseDomain else { return } forgetTasks[tab.type] = forgetTasks[tab.type] ?? [:] + // Start a task to delete all data for this etldP1 + // The task may be delayed in case we want to cancel it forgetTasks[tab.type]?[etldP1] = Task { try await Task.sleep(seconds: delay) await self.forgetData(for: url, in: tab) @@ -869,12 +871,21 @@ class TabManager: NSObject { await FaviconFetcher.deleteCache(for: url) guard let etldP1 = url.baseDomain else { return } - // Start a task to delete all data for this etldP1 - // The task may be delayed in case we want to cancel it let dataStore = tab.webView?.configuration.websiteDataStore + // Delete 1P data records await dataStore?.deleteDataRecords( forDomain: etldP1 ) + if BraveCore.FeatureList.kBraveShredCacheData.enabled { + // Delete all cache data (otherwise 3P cache entries left behind + // are visible in Manage Website Data view brave-browser #41095) + let cacheTypes = Set([ + WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeDiskCache, + WKWebsiteDataTypeOfflineWebApplicationCache, + ]) + let cacheRecords = await dataStore?.dataRecords(ofTypes: cacheTypes) ?? [] + await dataStore?.removeData(ofTypes: cacheTypes, for: cacheRecords) + } // Delete the history for forgotten websites if let historyAPI = self.historyAPI { diff --git a/ios/browser/api/features/features.h b/ios/browser/api/features/features.h index 4abcfe44af7b..1dd636bf56c0 100644 --- a/ios/browser/api/features/features.h +++ b/ios/browser/api/features/features.h @@ -51,6 +51,7 @@ OBJC_EXPORT @property(class, nonatomic, readonly) Feature* kBraveReduceLanguage; @property(class, nonatomic, readonly) Feature* kBraveSearchDefaultAPIFeature; @property(class, nonatomic, readonly) Feature* kBraveShredFeature; +@property(class, nonatomic, readonly) Feature* kBraveShredCacheData; @property(class, nonatomic, readonly) Feature* kBraveShowStrictFingerprintingMode; @property(class, nonatomic, readonly) Feature* kBraveSync; diff --git a/ios/browser/api/features/features.mm b/ios/browser/api/features/features.mm index d94bfb98e950..d7b036f5d9e5 100644 --- a/ios/browser/api/features/features.mm +++ b/ios/browser/api/features/features.mm @@ -202,6 +202,11 @@ + (Feature*)kBraveShredFeature { initWithFeature:&brave_shields::features::kBraveShredFeature]; } ++ (Feature*)kBraveShredCacheData { + return [[Feature alloc] + initWithFeature:&brave_shields::features::kBraveShredCacheData]; +} + + (Feature*)kBraveShowStrictFingerprintingMode { return [[Feature alloc] initWithFeature:&brave_shields::features:: diff --git a/ios/browser/flags/about_flags.mm b/ios/browser/flags/about_flags.mm index d5415da895e7..d30c20a840fb 100644 --- a/ios/browser/flags/about_flags.mm +++ b/ios/browser/flags/about_flags.mm @@ -75,33 +75,41 @@ kBraveWalletTransactionSimulationsFeature), \ }) -#define BRAVE_SHIELDS_FEATURE_ENTRIES \ - EXPAND_FEATURE_ENTRIES( \ - { \ - "brave-shred", \ - "Enable Brave 'Shred' Feature", \ - "Enable the Brave ‘Shred’ feature which will allow a user to " \ - "easily delete all site data on demand or automatically when " \ - "closing a site or terminating the application.", \ - flags_ui::kOsIos, \ - FEATURE_VALUE_TYPE(brave_shields::features::kBraveShredFeature), \ - }, \ - { \ - "https-by-default", \ - "Use HTTPS by Default", \ - "Attempt to connect to all websites using HTTPS before falling " \ - "back to HTTP.", \ - flags_ui::kOsIos, \ - FEATURE_VALUE_TYPE(net::features::kBraveHttpsByDefault), \ - }, \ - { \ - "https-only-mode", \ - "Enable HTTPS By Default Strict Mode", \ - "Connect to all websites using HTTPS and display an intersitital " \ - "to fallback to HTTP", \ - flags_ui::kOsIos, \ - FEATURE_VALUE_TYPE( \ - security_interstitials::features::kHttpsOnlyMode), \ +#define BRAVE_SHIELDS_FEATURE_ENTRIES \ + EXPAND_FEATURE_ENTRIES( \ + { \ + "brave-shred", \ + "Enable Brave 'Shred' Feature", \ + "Enable the Brave ‘Shred’ feature which will allow a user to " \ + "easily delete all site data on demand or automatically when " \ + "closing a site or terminating the application.", \ + flags_ui::kOsIos, \ + FEATURE_VALUE_TYPE(brave_shields::features::kBraveShredFeature), \ + }, \ + { \ + "brave-shred-cache-data", \ + "Shred Clears All Cache Data", \ + "Shred feature will also remove all cache data, in addition to the " \ + "data associated with the site being shred.", \ + flags_ui::kOsIos, \ + FEATURE_VALUE_TYPE(brave_shields::features::kBraveShredCacheData), \ + }, \ + { \ + "https-by-default", \ + "Use HTTPS by Default", \ + "Attempt to connect to all websites using HTTPS before falling " \ + "back to HTTP.", \ + flags_ui::kOsIos, \ + FEATURE_VALUE_TYPE(net::features::kBraveHttpsByDefault), \ + }, \ + { \ + "https-only-mode", \ + "Enable HTTPS By Default Strict Mode", \ + "Connect to all websites using HTTPS and display an intersitital " \ + "to fallback to HTTP", \ + flags_ui::kOsIos, \ + FEATURE_VALUE_TYPE( \ + security_interstitials::features::kHttpsOnlyMode), \ }) #if BUILDFLAG(ENABLE_AI_CHAT)