diff --git a/components/brave_shields/browser/ad_block_component_installer.cc b/components/brave_shields/browser/ad_block_component_installer.cc index 1973df1feb21..910ddadb14d1 100644 --- a/components/brave_shields/browser/ad_block_component_installer.cc +++ b/components/brave_shields/browser/ad_block_component_installer.cc @@ -60,6 +60,17 @@ const char kAdBlockIosDefaultDatComponentBase64PublicKey[] = "5HcH/heRrB4MvrE1J76WF3fvZ03aHVcnlLtQeiNNOZ7VbBDXdie8Nomf/QswbBGa" "VwIDAQAB"; +const char kAdBlockIosComponentName[] = "Brave Ad Block Updater"; +const char kAdBlockIosComponentId[] = "iodkpdagapdfkphljnddpjlldadblomo"; +const char kAdBlockIosComponentBase64PublicKey[] = + "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 { public: @@ -172,6 +183,7 @@ void OnRegistered(const std::string& component_id) { void RegisterAdBlockIosDefaultDatComponent( component_updater::ComponentUpdateService* cus, + bool use_legacy_component, OnComponentReadyCallback callback) { // In test, |cus| could be nullptr. if (!cus) @@ -179,8 +191,12 @@ void RegisterAdBlockIosDefaultDatComponent( auto installer = base::MakeRefCounted( std::make_unique( - kAdBlockIosDefaultDatComponentBase64PublicKey, - kAdBlockIosDefaultDatComponentId, kAdBlockIosDefaultDatComponentName, + use_legacy_component ? kAdBlockIosDefaultDatComponentBase64PublicKey + : kAdBlockIosComponentBase64PublicKey, + use_legacy_component ? kAdBlockIosDefaultDatComponentId + : kAdBlockIosComponentId, + use_legacy_component ? kAdBlockIosDefaultDatComponentName + : kAdBlockIosComponentName, callback)); installer->Register( cus, base::BindOnce(&OnRegistered, kAdBlockIosDefaultDatComponentId)); diff --git a/components/brave_shields/browser/ad_block_component_installer.h b/components/brave_shields/browser/ad_block_component_installer.h index 213083b0426b..7e3fd10771f7 100644 --- a/components/brave_shields/browser/ad_block_component_installer.h +++ b/components/brave_shields/browser/ad_block_component_installer.h @@ -22,6 +22,7 @@ using OnComponentReadyCallback = void RegisterAdBlockIosDefaultDatComponent( component_updater::ComponentUpdateService* cus, + bool use_legacy_component, OnComponentReadyCallback callback); void RegisterAdBlockDefaultResourceComponent( diff --git a/ios/app/brave_core_main.mm b/ios/app/brave_core_main.mm index 1c96e3ab52d2..de766624f9ec 100644 --- a/ios/app/brave_core_main.mm +++ b/ios/app/brave_core_main.mm @@ -305,8 +305,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_service+private.h b/ios/browser/api/brave_shields/adblock_service+private.h index 7844e531b130..fff4bfed4726 100644 --- a/ios/browser/api/brave_shields/adblock_service+private.h +++ b/ios/browser/api/brave_shields/adblock_service+private.h @@ -15,7 +15,6 @@ class ComponentUpdateService; @interface AdblockService (Private) - (instancetype)initWithComponentUpdater: (component_updater::ComponentUpdateService*)componentUpdaterService; -- (void)registerDefaultShieldsComponent; @end #endif // BRAVE_IOS_BROWSER_API_BRAVE_SHIELDS_ADBLOCK_SERVICE_PRIVATE_H_ diff --git a/ios/browser/api/brave_shields/adblock_service.h b/ios/browser/api/brave_shields/adblock_service.h index 95e7e2ee28fe..78b4d72dff50 100644 --- a/ios/browser/api/brave_shields/adblock_service.h +++ b/ios/browser/api/brave_shields/adblock_service.h @@ -15,16 +15,23 @@ NS_ASSUME_NONNULL_BEGIN OBJC_EXPORT @interface AdblockService : NSObject -/// The main shields file install path (KVO compiliant) -@property(readonly, nullable) NSString* shieldsInstallPath; +/// Executed each time the main shields component is updated +@property(nonatomic, copy, nullable) void (^shieldsComponentReady) + (NSString* _Nullable installPath); /// 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); +- (void) + registerDefaultShieldsComponentUsingLegacyComponent:(bool)useLegacyComponent + componentReady: + (void (^)( + NSString* _Nullable shieldsInstallPath, + NSArray< + AdblockFilterListCatalogEntry*>* _Nullable regionalFilterLists)) + componentReady + NS_SWIFT_NAME(registerDefaultShieldsComponent(useLegacyComponent:componentReady:)); /// Registers a filter list with the component updater and calls /// `componentReady` each time the component is updated diff --git a/ios/browser/api/brave_shields/adblock_service.mm b/ios/browser/api/brave_shields/adblock_service.mm index 9179da82e135..b7700fabdefb 100644 --- a/ios/browser/api/brave_shields/adblock_service.mm +++ b/ios/browser/api/brave_shields/adblock_service.mm @@ -17,7 +17,6 @@ @interface AdblockService () { component_updater::ComponentUpdateService* _cus; // NOT OWNED } -@property(nonatomic, copy) NSString* shieldsInstallPath; @property(nonatomic, copy) NSArray* regionalFilterLists; @end @@ -32,45 +31,45 @@ - (instancetype)initWithComponentUpdater: return self; } -- (void)registerDefaultShieldsComponent { +- (void) + registerDefaultShieldsComponentUsingLegacyComponent:(bool)useLegacyComponent + componentReady: + (void (^)( + NSString* _Nullable shieldsInstallPath, + NSArray< + AdblockFilterListCatalogEntry*>* _Nullable regionalFilterLists)) + componentReady { __weak auto weakSelf = self; brave_shields::RegisterAdBlockIosDefaultDatComponent( - _cus, base::BindRepeating(^(const base::FilePath& install_path) { - [weakSelf adblockComponentDidBecomeReady:install_path]; - })); -} - -- (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"]; - - __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); - - NSMutableArray* lists = [[NSMutableArray alloc] init]; - for (const auto& entry : catalog) { - [lists - addObject:[[AdblockFilterListCatalogEntry alloc] - initWithFilterListCatalogEntry: - brave_shields::FilterListCatalogEntry(entry)]]; - } - strongSelf.regionalFilterLists = lists; + _cus, useLegacyComponent, + 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) { + auto strongSelf = weakSelf; + if (!strongSelf) { + return; + } + auto catalog = brave_shields::FilterListCatalogFromJSON(json); - if (strongSelf.shieldsComponentReady) { - strongSelf.shieldsComponentReady(strongSelf.shieldsInstallPath); - } + NSMutableArray* lists = [[NSMutableArray alloc] init]; + for (const auto& entry : catalog) { + [lists addObject:[[AdblockFilterListCatalogEntry alloc] + initWithFilterListCatalogEntry: + brave_shields::FilterListCatalogEntry( + entry)]]; + } + strongSelf.regionalFilterLists = lists; + if (strongSelf.shieldsComponentReady) { + strongSelf.shieldsComponentReady( + base::SysUTF8ToNSString(install_path.value())); + } + componentReady(base::SysUTF8ToNSString(install_path.value()), + lists); + })); })); }