Skip to content

Commit

Permalink
Fix #32799: Use correct components for ad-blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
cuba committed Sep 20, 2023
1 parent 1ae7824 commit 3701bc2
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 140 deletions.
10 changes: 5 additions & 5 deletions browser/brave_shields/ad_block_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ bool AdBlockServiceTest::InstallDefaultAdBlockComponent(
"default", "", "Brave Ad Block Updater", {}, "",
"Default lists for Brave Browser", true, true, true, 0,
kDefaultAdBlockComponentTestId,
kDefaultAdBlockComponentTest64PublicKey, "", "")});
kDefaultAdBlockComponentTest64PublicKey)});
const extensions::Extension* ad_block_component = LoadExtensionAsComponent(
test_data_dir.AppendASCII("adblock-data").AppendASCII(component_dir));
if (!ad_block_component) {
Expand Down Expand Up @@ -279,8 +279,8 @@ bool AdBlockServiceTest::InstallRegionalAdBlockComponent(
uuid, "https://easylist-downloads.adblockplus.org/liste_fr.txt",
"EasyList Liste FR", {"fr"}, "https://forums.lanik.us/viewforum.php?f=91",
"Removes advertisements from French websites", false, false, false, 0,
kRegionalAdBlockComponentTestId, kRegionalAdBlockComponentTest64PublicKey,
"", ""));
kRegionalAdBlockComponentTestId,
kRegionalAdBlockComponentTest64PublicKey));
g_brave_browser_process->ad_block_service()
->component_service_manager()
->SetFilterListCatalog(filter_list_catalog);
Expand Down Expand Up @@ -1860,11 +1860,11 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, HiddenListsNotPresented) {
filter_list_catalog.push_back(brave_shields::FilterListCatalogEntry(
"uuid1", "https://example.com", "Hidden list", {},
"https://support.example.com", "first list", true, false, false, 0,
"testid1", "pubkey1", "", ""));
"testid1", "pubkey1"));
filter_list_catalog.push_back(brave_shields::FilterListCatalogEntry(
"uuid2", "https://example.com", "Normal list", {},
"https://support.example.com", "second list", false, false, false, 0,
"testid2", "pubkey2", "", ""));
"testid2", "pubkey2"));
g_brave_browser_process->ad_block_service()
->component_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/", "Removes obtrusive cookie law notices",
false, false, false, 0, kRegionalAdBlockComponentTestId,
kRegionalAdBlockComponentTest64PublicKey, "", "")};
kRegionalAdBlockComponentTest64PublicKey)};
GetComponentServiceManager()->SetFilterListCatalog(filter_list_catalog);
}

Expand Down
29 changes: 8 additions & 21 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,18 +48,6 @@ 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";

class AdBlockComponentInstallerPolicy
: public component_updater::ComponentInstallerPolicy {
public:
Expand Down Expand Up @@ -170,7 +158,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 +167,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
21 changes: 16 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 @@ -11,6 +11,17 @@
#include "base/files/file_path.h"
#include "base/functional/callback.h"

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";

namespace component_updater {
class ComponentUpdateService;
} // namespace component_updater
Expand All @@ -20,7 +31,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(AdBlockComponentServiceTest, UserModelLanguages) {
catalog.push_back(brave_shields::FilterListCatalogEntry(
"uuid", "https://brave.com", "Testing Filter List #1", {"fr"},
"https://support.brave.com", "Filter list for testing purposes", false,
false, false, 0, "componentid", "base64publickey", "", ""));
false, false, 0, "componentid", "base64publickey"));
catalog.push_back(brave_shields::FilterListCatalogEntry(
"uuid", "https://brave.com", "Testing Filter List #2", {"en"},
"https://support.brave.com", "Filter list for testing purposes", false,
false, false, 0, "componentid", "base64publickey", "", ""));
false, false, 0, "componentid", "base64publickey"));
catalog.push_back(brave_shields::FilterListCatalogEntry(
"uuid", "https://brave.com", "Testing Filter List #2", {"fr"},
"https://support.brave.com", "Filter list for testing purposes", false,
false, false, 0, "componentid", "base64publickey", "", ""));
false, false, 0, "componentid", "base64publickey"));

std::vector<std::string> languages({"fr", "fR", "fr-FR", "fr-ca"});
std::for_each(
Expand Down
1 change: 1 addition & 0 deletions components/brave_shields/browser/ad_block_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/threading/thread_restrictions.h"
#include "brave/components/brave_shields/adblock/rs/src/lib.rs.h"
#include "brave/components/brave_shields/browser/ad_block_component_filters_provider.h"
#include "brave/components/brave_shields/browser/ad_block_component_installer.h"
#include "brave/components/brave_shields/browser/ad_block_component_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_custom_filters_provider.h"
#include "brave/components/brave_shields/browser/ad_block_default_resource_provider.h"
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 @@ -103,9 +103,7 @@ FilterListCatalogEntry::FilterListCatalogEntry(
bool first_party_protections,
uint8_t permission_mask,
const std::string& component_id,
const std::string& base64_public_key,
const std::string& ios_component_id,
const std::string& ios_base64_public_key)
const std::string& base64_public_key)
: uuid(uuid),
url(url),
title(title),
Expand All @@ -117,9 +115,7 @@ FilterListCatalogEntry::FilterListCatalogEntry(
first_party_protections(first_party_protections),
permission_mask(permission_mask),
component_id(component_id),
base64_public_key(base64_public_key),
ios_component_id(ios_component_id),
ios_base64_public_key(ios_base64_public_key) {}
base64_public_key(base64_public_key) {}

FilterListCatalogEntry::FilterListCatalogEntry(
const FilterListCatalogEntry& other) = default;
Expand Down Expand Up @@ -150,10 +146,6 @@ void FilterListCatalogEntry::RegisterJSONConverter(
converter->RegisterCustomValueField(
"list_text_component", &FilterListCatalogEntry::base64_public_key,
&GetBase64PublicKey);
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 @@ -36,9 +36,7 @@ class FilterListCatalogEntry {
bool first_party_protections,
uint8_t permission_mask,
const std::string& component_id,
const std::string& base64_public_key,
const std::string& ios_component_id,
const std::string& ios_base64_public_key);
const std::string& base64_public_key);
explicit FilterListCatalogEntry(const FilterListCatalogEntry& other);
~FilterListCatalogEntry();

Expand All @@ -57,8 +55,6 @@ class FilterListCatalogEntry {

std::string component_id;
std::string base64_public_key;
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 @@ -319,8 +319,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 @@ -23,9 +23,6 @@ OBJC_EXPORT
@property(readonly) bool firstPartyProtections;
@property(readonly) uint8_t permissionMask;
@property(readonly) NSString* componentId;
@property(readonly) NSString* base64PublicKey;
@property(readonly) NSString* iosComponentId;
@property(readonly) NSString* iosBase64PublicKey;
- (instancetype)init NS_UNAVAILABLE;
@end

Expand Down
19 changes: 0 additions & 19 deletions ios/browser/api/brave_shields/adblock_filter_list_catalog_entry.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ @interface AdblockFilterListCatalogEntry ()
@property(nonatomic) uint8_t permissionMask;
@property(nonatomic, copy) NSString* componentId;
@property(nonatomic, copy) NSString* base64PublicKey;
@property(nonatomic, copy) NSString* iosComponentId;
@property(nonatomic, copy) NSString* iosBase64PublicKey;
@end

@implementation AdblockFilterListCatalogEntry
Expand All @@ -43,25 +41,8 @@ - (instancetype)initWithFilterListCatalogEntry:
self.permissionMask = entry.permission_mask;
self.componentId = base::SysUTF8ToNSString(entry.component_id);
self.base64PublicKey = base::SysUTF8ToNSString(entry.base64_public_key);
self.iosComponentId = base::SysUTF8ToNSString(entry.ios_component_id);
self.iosBase64PublicKey =
base::SysUTF8ToNSString(entry.ios_base64_public_key);
}
return self;
}

- (brave_shields::FilterListCatalogEntry)entry {
return brave_shields::FilterListCatalogEntry(
base::SysNSStringToUTF8(self.uuid), base::SysNSStringToUTF8(self.url),
base::SysNSStringToUTF8(self.title),
brave::ns_to_vector<std::string>(self.languages),
base::SysNSStringToUTF8(self.supportURL),
base::SysNSStringToUTF8(self.desc), self.hidden, self.defaultEnabled,
self.firstPartyProtections, self.permissionMask,
base::SysNSStringToUTF8(self.componentId),
base::SysNSStringToUTF8(self.base64PublicKey),
base::SysNSStringToUTF8(self.iosComponentId),
base::SysNSStringToUTF8(self.iosBase64PublicKey));
}

@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 3701bc2

Please sign in to comment.