Skip to content

Commit

Permalink
Merge pull request #15287 from brave/js/register-components-ios
Browse files Browse the repository at this point in the history
[iOS] Allow registering both legacy and raw adblock components
  • Loading branch information
kylehickinson authored Nov 25, 2022
2 parents 50ebdb9 + fbe2ece commit 2b986e4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
13 changes: 6 additions & 7 deletions ios/browser/api/brave_shields/adblock_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ OBJC_EXPORT

/// Registers a filter list with the component updater and calls
/// `componentReady` each time the component is updated
- (void)registerFilterListComponent:(AdblockFilterListCatalogEntry*)filterList
componentReady:
(void (^)(AdblockFilterListCatalogEntry* filterList,
NSString* _Nullable installPath))
componentReady;
- (void)registerFilterListComponent:(AdblockFilterListCatalogEntry*)entry
useLegacyComponent:(bool)useLegacyComponent
componentReady:(void (^)(NSString* _Nullable installPath))
componentReady;

/// Unregisters a filter list with the component updater
- (void)unregisterFilterListComponent:
(AdblockFilterListCatalogEntry*)filterList;
- (void)unregisterFilterListComponent:(AdblockFilterListCatalogEntry*)entry
useLegacyComponent:(bool)useLegacyComponent;

- (instancetype)init NS_UNAVAILABLE;

Expand Down
30 changes: 20 additions & 10 deletions ios/browser/api/brave_shields/adblock_service.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,32 @@ - (void)adblockComponentDidBecomeReady:(base::FilePath)install_path {
}

- (void)registerFilterListComponent:(AdblockFilterListCatalogEntry*)entry
componentReady:
(void (^)(AdblockFilterListCatalogEntry* entry,
NSString* _Nullable installPath))
componentReady {
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, base::SysNSStringToUTF8(entry.iosBase64PublicKey),
base::SysNSStringToUTF8(entry.iosComponentId),
base::SysNSStringToUTF8(entry.title),
_cus, base64PublicKey, componentId, base::SysNSStringToUTF8(entry.title),
base::BindRepeating(^(const base::FilePath& install_path) {
const auto installPath = base::SysUTF8ToNSString(install_path.value());
componentReady(entry, installPath);
componentReady(installPath);
}));
}

- (void)unregisterFilterListComponent:(AdblockFilterListCatalogEntry*)entry {
_cus->UnregisterComponent(base::SysNSStringToUTF8(entry.iosComponentId));
- (void)unregisterFilterListComponent:(AdblockFilterListCatalogEntry*)entry
useLegacyComponent:(bool)useLegacyComponent {
if (useLegacyComponent) {
_cus->UnregisterComponent(base::SysNSStringToUTF8(entry.iosComponentId));
} else {
_cus->UnregisterComponent(base::SysNSStringToUTF8(entry.componentId));
}
}

@end

0 comments on commit 2b986e4

Please sign in to comment.