Skip to content

Commit

Permalink
Expose cosmetic filters script in obj-c.
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHeaps committed Sep 23, 2024
1 parent f9dca14 commit 6e39d70
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ios/browser/api/brave_shields/adblock_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ OBJC_EXPORT

- (instancetype)init NS_UNAVAILABLE;

+ (NSString*)cosmeticFiltersScript;

@end

NS_ASSUME_NONNULL_END
Expand Down
17 changes: 17 additions & 0 deletions ios/browser/api/brave_shields/adblock_service.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include "brave/ios/browser/api/brave_shields/adblock_filter_list_catalog_entry+private.h"
#include "brave/ios/browser/api/brave_shields/adblock_service+private.h"
#include "components/component_updater/component_updater_service.h"
#include "components/grit/brave_components_resources.h"
#include "ios/chrome/browser/shared/model/application_context/application_context.h"
#include "ui/base/resource/resource_bundle.h"

namespace brave_shields {
using OnFilterListUpdatedCallback =
Expand Down Expand Up @@ -201,4 +203,19 @@ - (void)updateFilterLists:(void (^)(bool))callback {
_serviceManager->UpdateFilterLists(base::BindOnce(callback));
}

+ (NSString*)cosmeticFiltersScript {
// The resource bundle is not available until after WebMainParts is setup
auto& resource_bundle = ui::ResourceBundle::GetSharedInstance();
std::string resource_string = "";
if (resource_bundle.IsGzipped(
IDR_COSMETIC_FILTERS_COSMETIC_FILTERS_CORE_BUNDLE_JS)) {
resource_string = std::string(resource_bundle.LoadDataResourceString(
IDR_COSMETIC_FILTERS_COSMETIC_FILTERS_CORE_BUNDLE_JS));
} else {
resource_string = std::string(resource_bundle.GetRawDataResource(
IDR_COSMETIC_FILTERS_COSMETIC_FILTERS_CORE_BUNDLE_JS));
}
return base::SysUTF8ToNSString(resource_string);
}

@end

0 comments on commit 6e39d70

Please sign in to comment.