diff --git a/browser/brave_shields/ad_block_service_browsertest.cc b/browser/brave_shields/ad_block_service_browsertest.cc index 9cf50fbdce7e..2f6c49005ad3 100644 --- a/browser/brave_shields/ad_block_service_browsertest.cc +++ b/browser/brave_shields/ad_block_service_browsertest.cc @@ -287,7 +287,7 @@ bool AdBlockServiceTest::InstallRegionalAdBlockExtension( uuid, "https://easylist-downloads.adblockplus.org/liste_fr.txt", "EasyList Liste FR", {"fr"}, "https://forums.lanik.us/viewforum.php?f=91", kRegionalAdBlockComponentTestId, kRegionalAdBlockComponentTest64PublicKey, - "Removes advertisements from French websites", "", "")); + "Removes advertisements from French websites")); g_brave_browser_process->ad_block_service() ->regional_service_manager() ->SetFilterListCatalog(filter_list_catalog); diff --git a/browser/ui/views/brave_shields/cookie_list_opt_in_browsertest.cc b/browser/ui/views/brave_shields/cookie_list_opt_in_browsertest.cc index beb6d10829e8..78448eb1a5f4 100644 --- a/browser/ui/views/brave_shields/cookie_list_opt_in_browsertest.cc +++ b/browser/ui/views/brave_shields/cookie_list_opt_in_browsertest.cc @@ -129,7 +129,7 @@ class CookieListOptInBrowserTest : public InProcessBrowserTest { "Easylist-Cookie List - Filter Obtrusive Cookie Notices", {}, "https://forums.lanik.us/", kRegionalAdBlockComponentTestId, kRegionalAdBlockComponentTest64PublicKey, - "Removes obtrusive cookie law notices", "", "")}; + "Removes obtrusive cookie law notices")}; GetRegionalServiceManager()->SetFilterListCatalog(filter_list_catalog); } diff --git a/components/brave_shields/browser/ad_block_component_installer.cc b/components/brave_shields/browser/ad_block_component_installer.cc index 07a21132ac08..b89ee0d6bf02 100644 --- a/components/brave_shields/browser/ad_block_component_installer.cc +++ b/components/brave_shields/browser/ad_block_component_installer.cc @@ -1,7 +1,7 @@ -/* Copyright (c) 2021 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ +// Copyright (c) 2023 The Brave Authors. All rights reserved. +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at https://mozilla.org/MPL/2.0/. #include "brave/components/brave_shields/browser/ad_block_component_installer.h" @@ -48,17 +48,16 @@ const char kAdBlockFilterListCatalogComponentBase64PublicKey[] = "1H8y9SR970LqsUMozu3ioSHtFh/IVgq7Nqy4TljaKsTE+3AdtjiOyHpW9ZaOkA7j" "2QIDAQAB"; -const char kAdBlockIosDefaultDatComponentName[] = "Brave Ad Block Updater"; -const char kAdBlockIosDefaultDatComponentId[] = - "cffkpbalmllkdoenhmdmpbkajipdjfam"; -const char kAdBlockIosDefaultDatComponentBase64PublicKey[] = - "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs0qzJmHSgIiw7IGFCxij" - "1NnB5hJ5ZQ1LKW9htL4EBOaMJvmqaDs/wfq0nw/goBHWsqqkMBynRTu2Hxxirvdb" - "cugn1Goys5QKPgAvKwDHJp9jlnADWm5xQvPQ4GE1mK1/I3ka9cEOCzPW6GI+wGLi" - "VPx9VZrxHHsSBIJRaEB5Tyi5bj0CZ+kcfMnRTsXIBw3C6xJgCVKISQUkd8mawVvG" - "vqOhBOogCdb9qza5eJ1Cgx8RWKucFfaWWxKLOelCiBMT1Hm1znAoVBHG/blhJJOD" - "5HcH/heRrB4MvrE1J76WF3fvZ03aHVcnlLtQeiNNOZ7VbBDXdie8Nomf/QswbBGa" - "VwIDAQAB"; +const char kAdBlockDefaultComponentName[] = "Brave Ad Block Updater"; +const char kAdBlockDefaultComponentId[] = "iodkpdagapdfkphljnddpjlldadblomo"; +const char kAdBlockDefaultComponentBase64PublicKey[] = + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsD/B/MGdz0gh7WkcFARn" + "ZTBX9KAw2fuGeogijoI+fET38IK0L+P/trCT2NshqhRNmrDpLzV2+Dmes6PvkA+O" + "dQkUV6VbChJG+baTfr3Oo5PdE0WxmP9Xh8XD7p85DQrk0jJilKuElxpK7Yq0JhcT" + "Sc3XNHeTwBVqCnHwWZZ+XysYQfjuDQ0MgQpS/s7U04OZ63NIPe/iCQm32stvS/pE" + "ya7KdBZXgRBQ59U6M1n1Ikkp3vfECShbBld6VrrmNrl59yKWlEPepJ9oqUc2Wf2M" + "q+SDNXROG554RnU4BnDJaNETTkDTZ0Pn+rmLmp1qY5Si0yGsfHkrv3FS3vdxVozO" + "PQIDAQAB"; class AdBlockComponentInstallerPolicy : public component_updater::ComponentInstallerPolicy { @@ -170,7 +169,7 @@ void OnRegistered(const std::string& component_id) { } // namespace -void RegisterAdBlockIosDefaultDatComponent( +void RegisterAdBlockDefaultComponent( component_updater::ComponentUpdateService* cus, OnComponentReadyCallback callback) { // In test, |cus| could be nullptr. @@ -179,11 +178,10 @@ void RegisterAdBlockIosDefaultDatComponent( auto installer = base::MakeRefCounted( std::make_unique( - kAdBlockIosDefaultDatComponentBase64PublicKey, - kAdBlockIosDefaultDatComponentId, kAdBlockIosDefaultDatComponentName, - callback)); + kAdBlockDefaultComponentBase64PublicKey, kAdBlockDefaultComponentId, + kAdBlockDefaultComponentName, callback)); installer->Register( - cus, base::BindOnce(&OnRegistered, kAdBlockIosDefaultDatComponentId)); + cus, base::BindOnce(&OnRegistered, kAdBlockDefaultComponentId)); } void RegisterAdBlockDefaultResourceComponent( diff --git a/components/brave_shields/browser/ad_block_component_installer.h b/components/brave_shields/browser/ad_block_component_installer.h index c08edf4c88fc..db3c43e2383a 100644 --- a/components/brave_shields/browser/ad_block_component_installer.h +++ b/components/brave_shields/browser/ad_block_component_installer.h @@ -1,7 +1,7 @@ -/* Copyright (c) 2021 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ +// Copyright (c) 2023 The Brave Authors. All rights reserved. +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at https://mozilla.org/MPL/2.0/. #ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_AD_BLOCK_COMPONENT_INSTALLER_H_ #define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_AD_BLOCK_COMPONENT_INSTALLER_H_ @@ -20,7 +20,7 @@ namespace brave_shields { using OnComponentReadyCallback = base::RepeatingCallback; -void RegisterAdBlockIosDefaultDatComponent( +void RegisterAdBlockDefaultComponent( component_updater::ComponentUpdateService* cus, OnComponentReadyCallback callback); diff --git a/components/brave_shields/browser/ad_block_regional_service_unittest.cc b/components/brave_shields/browser/ad_block_regional_service_unittest.cc index 87309a4e4439..7d5a3ba582fb 100644 --- a/components/brave_shields/browser/ad_block_regional_service_unittest.cc +++ b/components/brave_shields/browser/ad_block_regional_service_unittest.cc @@ -11,15 +11,15 @@ TEST(AdBlockRegionalServiceTest, UserModelLanguages) { catalog.push_back(brave_shields::FilterListCatalogEntry( "uuid", "https://brave.com", "Testing Filter List #1", {"fr"}, "https://support.brave.com", "componentid", "base64publickey", - "Filter list for testing purposes", "", "")); + "Filter list for testing purposes")); catalog.push_back(brave_shields::FilterListCatalogEntry( "uuid", "https://brave.com", "Testing Filter List #2", {"en"}, "https://support.brave.com", "componentid", "base64publickey", - "Filter list for testing purposes", "", "")); + "Filter list for testing purposes")); catalog.push_back(brave_shields::FilterListCatalogEntry( "uuid", "https://brave.com", "Testing Filter List #2", {"fr"}, "https://support.brave.com", "componentid", "base64publickey", - "Filter list for testing purposes", "", "")); + "Filter list for testing purposes")); std::vector languages({"fr", "fR", "fr-FR", "fr-ca"}); std::for_each( diff --git a/components/brave_shields/browser/filter_list_catalog_entry.cc b/components/brave_shields/browser/filter_list_catalog_entry.cc index 65e675a8793b..4e2dd9c14edb 100644 --- a/components/brave_shields/browser/filter_list_catalog_entry.cc +++ b/components/brave_shields/browser/filter_list_catalog_entry.cc @@ -84,9 +84,7 @@ FilterListCatalogEntry::FilterListCatalogEntry( const std::string& support_url, const std::string& component_id, const std::string& base64_public_key, - const std::string& desc, - const std::string& ios_component_id, - const std::string& ios_base64_public_key) + const std::string& desc) : uuid(uuid), url(url), title(title), @@ -94,9 +92,7 @@ FilterListCatalogEntry::FilterListCatalogEntry( support_url(support_url), component_id(component_id), base64_public_key(base64_public_key), - desc(desc), - ios_component_id(ios_component_id), - ios_base64_public_key(ios_base64_public_key) {} + desc(desc) {} FilterListCatalogEntry::FilterListCatalogEntry( const FilterListCatalogEntry& other) = default; @@ -119,10 +115,6 @@ void FilterListCatalogEntry::RegisterJSONConverter( "list_text_component", &FilterListCatalogEntry::base64_public_key, &GetBase64PublicKey); converter->RegisterStringField("desc", &FilterListCatalogEntry::desc); - converter->RegisterStringField("component_id", - &FilterListCatalogEntry::ios_component_id); - converter->RegisterStringField( - "base64_public_key", &FilterListCatalogEntry::ios_base64_public_key); } std::vector::const_iterator FindAdBlockFilterListByUUID( diff --git a/components/brave_shields/browser/filter_list_catalog_entry.h b/components/brave_shields/browser/filter_list_catalog_entry.h index 807449a00d3d..7549b4629f9d 100644 --- a/components/brave_shields/browser/filter_list_catalog_entry.h +++ b/components/brave_shields/browser/filter_list_catalog_entry.h @@ -30,9 +30,7 @@ class FilterListCatalogEntry { const std::string& support_url, const std::string& component_id, const std::string& base64_public_key, - const std::string& desc, - const std::string& ios_component_id, - const std::string& ios_base64_public_key); + const std::string& desc); explicit FilterListCatalogEntry(const FilterListCatalogEntry& other); ~FilterListCatalogEntry(); @@ -44,8 +42,6 @@ class FilterListCatalogEntry { std::string component_id; std::string base64_public_key; std::string desc; - std::string ios_component_id; - std::string ios_base64_public_key; static void RegisterJSONConverter( base::JSONValueConverter*); diff --git a/ios/app/brave_core_main.mm b/ios/app/brave_core_main.mm index 9c295475436b..838cad1cbf80 100644 --- a/ios/app/brave_core_main.mm +++ b/ios/app/brave_core_main.mm @@ -314,8 +314,6 @@ - (void)registerComponentsForUpdate: RegisterSafetyTipsComponent(cus); brave_wallet::RegisterWalletDataFilesComponent(cus); - - [self.adblockService registerDefaultShieldsComponent]; } + (void)setLogHandler:(BraveCoreLogHandler)logHandler { diff --git a/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry+private.h b/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry+private.h index 5a1ab78b0b3a..c9a774d624a7 100644 --- a/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry+private.h +++ b/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry+private.h @@ -16,9 +16,10 @@ class FilterListCatalogEntry; NS_ASSUME_NONNULL_BEGIN @interface AdblockFilterListCatalogEntry (Private) +@property(readonly) NSString* base64PublicKey; + - (instancetype)initWithFilterListCatalogEntry: (brave_shields::FilterListCatalogEntry)entry; -- (brave_shields::FilterListCatalogEntry)entry; @end NS_ASSUME_NONNULL_END diff --git a/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry.h b/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry.h index 74de4ddd48bb..f957057ae633 100644 --- a/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry.h +++ b/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry.h @@ -20,8 +20,6 @@ OBJC_EXPORT @property(readonly) NSString* componentId; @property(readonly) NSString* base64PublicKey; @property(readonly) NSString* desc; -@property(readonly) NSString* iosComponentId; -@property(readonly) NSString* iosBase64PublicKey; - (instancetype)init NS_UNAVAILABLE; @end diff --git a/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry.mm b/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry.mm index 37dff599608c..551ea1aabe0a 100644 --- a/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry.mm +++ b/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry.mm @@ -18,8 +18,6 @@ @interface AdblockFilterListCatalogEntry () @property(nonatomic, copy) NSString* componentId; @property(nonatomic, copy) NSString* base64PublicKey; @property(nonatomic, copy) NSString* desc; -@property(nonatomic, copy) NSString* iosComponentId; -@property(nonatomic, copy) NSString* iosBase64PublicKey; @end @implementation AdblockFilterListCatalogEntry @@ -35,9 +33,6 @@ - (instancetype)initWithFilterListCatalogEntry: self.componentId = base::SysUTF8ToNSString(entry.component_id); self.base64PublicKey = base::SysUTF8ToNSString(entry.base64_public_key); self.desc = base::SysUTF8ToNSString(entry.desc); - self.iosComponentId = base::SysUTF8ToNSString(entry.ios_component_id); - self.iosBase64PublicKey = - base::SysUTF8ToNSString(entry.ios_base64_public_key); } return self; } @@ -50,9 +45,7 @@ - (instancetype)initWithFilterListCatalogEntry: base::SysNSStringToUTF8(self.supportURL), base::SysNSStringToUTF8(self.componentId), base::SysNSStringToUTF8(self.base64PublicKey), - base::SysNSStringToUTF8(self.desc), - base::SysNSStringToUTF8(self.iosComponentId), - base::SysNSStringToUTF8(self.iosBase64PublicKey)); + base::SysNSStringToUTF8(self.desc)); } @end diff --git a/ios/browser/api/brave_shields/adblock_service.h b/ios/browser/api/brave_shields/adblock_service.h index 95e7e2ee28fe..e9c13d8a8a34 100644 --- a/ios/browser/api/brave_shields/adblock_service.h +++ b/ios/browser/api/brave_shields/adblock_service.h @@ -15,27 +15,30 @@ NS_ASSUME_NONNULL_BEGIN OBJC_EXPORT @interface AdblockService : NSObject -/// The main shields file install path (KVO compiliant) -@property(readonly, nullable) NSString* shieldsInstallPath; - -/// Regional filter lists -@property(readonly, nullable) - NSArray* regionalFilterLists; - -/// Executed each time the main shields component is updated -@property(nonatomic, copy, nullable) void (^shieldsComponentReady) - (NSString* _Nullable installPath); +/// Registers the default filter list component and calls `componentReady` each +/// time the component is updated +- (void)registerDefaultComponent: + (void (^)(NSString* _Nullable installPath))componentReady; + +/// Registers the filter list catalog component and calls `componentReady` each +/// time the component is updated +- (void)registerFilterListCatalogComponent: + (void (^)(NSArray* filterLists)) + componentReady; + +/// Registers the resources component and calls `componentReady` +/// each time the component is updated +- (void)registerResourceComponent: + (void (^)(NSString* _Nullable installPath))componentReady; /// Registers a filter list with the component updater and calls /// `componentReady` each time the component is updated - (void)registerFilterListComponent:(AdblockFilterListCatalogEntry*)entry - useLegacyComponent:(bool)useLegacyComponent componentReady:(void (^)(NSString* _Nullable installPath)) componentReady; /// Unregisters a filter list with the component updater -- (void)unregisterFilterListComponent:(AdblockFilterListCatalogEntry*)entry - useLegacyComponent:(bool)useLegacyComponent; +- (void)unregisterFilterListComponent:(AdblockFilterListCatalogEntry*)entry; - (instancetype)init NS_UNAVAILABLE; diff --git a/ios/browser/api/brave_shields/adblock_service.mm b/ios/browser/api/brave_shields/adblock_service.mm index 9179da82e135..4b6695cf77b3 100644 --- a/ios/browser/api/brave_shields/adblock_service.mm +++ b/ios/browser/api/brave_shields/adblock_service.mm @@ -17,9 +17,6 @@ @interface AdblockService () { component_updater::ComponentUpdateService* _cus; // NOT OWNED } -@property(nonatomic, copy) NSString* shieldsInstallPath; -@property(nonatomic, copy) - NSArray* regionalFilterLists; @end @implementation AdblockService @@ -32,75 +29,66 @@ - (instancetype)initWithComponentUpdater: return self; } -- (void)registerDefaultShieldsComponent { - __weak auto weakSelf = self; - brave_shields::RegisterAdBlockIosDefaultDatComponent( +- (void)registerDefaultComponent: + (void (^)(NSString* _Nullable installPath))componentReady { + brave_shields::RegisterAdBlockDefaultComponent( _cus, base::BindRepeating(^(const base::FilePath& install_path) { - [weakSelf adblockComponentDidBecomeReady:install_path]; + const auto installPath = base::SysUTF8ToNSString(install_path.value()); + componentReady(installPath); })); } -- (void)adblockComponentDidBecomeReady:(base::FilePath)install_path { - // Update shields install path (w/ KVO) - [self willChangeValueForKey:@"shieldsInstallPath"]; - self.shieldsInstallPath = base::SysUTF8ToNSString(install_path.value()); - [self didChangeValueForKey:@"shieldsInstallPath"]; +- (void)registerResourceComponent: + (void (^)(NSString* _Nullable installPath))componentReady { + brave_shields::RegisterAdBlockDefaultResourceComponent( + _cus, base::BindRepeating(^(const base::FilePath& install_path) { + const auto installPath = base::SysUTF8ToNSString(install_path.value()); + componentReady(installPath); + })); +} - __weak auto weakSelf = self; - // Get filter lists from catalog - base::ThreadPool::PostTaskAndReplyWithResult( - FROM_HERE, {base::MayBlock()}, - base::BindOnce(&brave_component_updater::GetDATFileAsString, - install_path.AppendASCII("regional_catalog.json")), - base::BindOnce(^(const std::string& json) { - auto strongSelf = weakSelf; - if (!strongSelf) { - return; - } - auto catalog = brave_shields::FilterListCatalogFromJSON(json); +- (void)registerFilterListCatalogComponent: + (void (^)(NSArray* filterLists)) + componentReady { + brave_shields::RegisterAdBlockFilterListCatalogComponent( + _cus, base::BindRepeating(^(const base::FilePath& install_path) { + // Get filter lists from catalog + base::ThreadPool::PostTaskAndReplyWithResult( + FROM_HERE, {base::MayBlock()}, + base::BindOnce(&brave_component_updater::GetDATFileAsString, + install_path.AppendASCII("regional_catalog.json")), + base::BindOnce(^(const std::string& json) { + // Parse data + auto catalog = brave_shields::FilterListCatalogFromJSON(json); - NSMutableArray* lists = [[NSMutableArray alloc] init]; - for (const auto& entry : catalog) { - [lists - addObject:[[AdblockFilterListCatalogEntry alloc] - initWithFilterListCatalogEntry: - brave_shields::FilterListCatalogEntry(entry)]]; - } - strongSelf.regionalFilterLists = lists; + NSMutableArray* lists = [[NSMutableArray alloc] init]; + for (const auto& entry : catalog) { + [lists addObject:[[AdblockFilterListCatalogEntry alloc] + initWithFilterListCatalogEntry: + brave_shields::FilterListCatalogEntry( + entry)]]; + } - if (strongSelf.shieldsComponentReady) { - strongSelf.shieldsComponentReady(strongSelf.shieldsInstallPath); - } + componentReady(lists); + })); })); } - (void)registerFilterListComponent:(AdblockFilterListCatalogEntry*)entry - useLegacyComponent:(bool)useLegacyComponent componentReady:(void (^)(NSString* _Nullable installPath)) componentReady { - std::string base64PublicKey = base::SysNSStringToUTF8(entry.base64PublicKey); - std::string componentId = base::SysNSStringToUTF8(entry.componentId); - - if (useLegacyComponent) { - base64PublicKey = base::SysNSStringToUTF8(entry.iosBase64PublicKey); - componentId = base::SysNSStringToUTF8(entry.iosComponentId); - } - brave_shields::RegisterAdBlockFiltersComponent( - _cus, base64PublicKey, componentId, base::SysNSStringToUTF8(entry.title), + _cus, base::SysNSStringToUTF8(entry.base64PublicKey), + base::SysNSStringToUTF8(entry.componentId), + base::SysNSStringToUTF8(entry.title), base::BindRepeating(^(const base::FilePath& install_path) { const auto installPath = base::SysUTF8ToNSString(install_path.value()); componentReady(installPath); })); } -- (void)unregisterFilterListComponent:(AdblockFilterListCatalogEntry*)entry - useLegacyComponent:(bool)useLegacyComponent { - if (useLegacyComponent) { - _cus->UnregisterComponent(base::SysNSStringToUTF8(entry.iosComponentId)); - } else { - _cus->UnregisterComponent(base::SysNSStringToUTF8(entry.componentId)); - } +- (void)unregisterFilterListComponent:(AdblockFilterListCatalogEntry*)entry { + _cus->UnregisterComponent(base::SysNSStringToUTF8(entry.componentId)); } @end