Skip to content

Commit

Permalink
Fix #32799: Use correct components for ad-blocking (#20137)
Browse files Browse the repository at this point in the history
  • Loading branch information
cuba authored and bsclifton committed Oct 21, 2023
1 parent af70dc6 commit 8a7704b
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 123 deletions.
2 changes: 1 addition & 1 deletion browser/brave_shields/ad_block_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
38 changes: 18 additions & 20 deletions components/brave_shields/browser/ad_block_component_installer.cc
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -179,11 +178,10 @@ void RegisterAdBlockIosDefaultDatComponent(

auto installer = base::MakeRefCounted<component_updater::ComponentInstaller>(
std::make_unique<AdBlockComponentInstallerPolicy>(
kAdBlockIosDefaultDatComponentBase64PublicKey,
kAdBlockIosDefaultDatComponentId, kAdBlockIosDefaultDatComponentName,
callback));
kAdBlockDefaultComponentBase64PublicKey, kAdBlockDefaultComponentId,
kAdBlockDefaultComponentName, callback));
installer->Register(
cus, base::BindOnce(&OnRegistered, kAdBlockIosDefaultDatComponentId));
cus, base::BindOnce(&OnRegistered, kAdBlockDefaultComponentId));
}

void RegisterAdBlockDefaultResourceComponent(
Expand Down
10 changes: 5 additions & 5 deletions components/brave_shields/browser/ad_block_component_installer.h
Original file line number Diff line number Diff line change
@@ -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_
Expand All @@ -20,7 +20,7 @@ namespace brave_shields {
using OnComponentReadyCallback =
base::RepeatingCallback<void(const base::FilePath& install_path)>;

void RegisterAdBlockIosDefaultDatComponent(
void RegisterAdBlockDefaultComponent(
component_updater::ComponentUpdateService* cus,
OnComponentReadyCallback callback);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> languages({"fr", "fR", "fr-FR", "fr-ca"});
std::for_each(
Expand Down
12 changes: 2 additions & 10 deletions components/brave_shields/browser/filter_list_catalog_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,15 @@ 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),
langs(langs),
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;
Expand All @@ -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<FilterListCatalogEntry>::const_iterator FindAdBlockFilterListByUUID(
Expand Down
6 changes: 1 addition & 5 deletions components/brave_shields/browser/filter_list_catalog_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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<FilterListCatalogEntry>*);
Expand Down
2 changes: 0 additions & 2 deletions ios/app/brave_core_main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,6 @@ - (void)registerComponentsForUpdate:

RegisterSafetyTipsComponent(cus);
brave_wallet::RegisterWalletDataFilesComponent(cus);

[self.adblockService registerDefaultShieldsComponent];
}

+ (void)setLogHandler:(BraveCoreLogHandler)logHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -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
29 changes: 16 additions & 13 deletions ios/browser/api/brave_shields/adblock_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<AdblockFilterListCatalogEntry*>* 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<AdblockFilterListCatalogEntry*>* 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;

Expand Down
Loading

0 comments on commit 8a7704b

Please sign in to comment.