Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native re-implementation of Web Discovery (part 1) #24421

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a90fc6a
Add anonymous-credentials lib/cxx for Web Discovery
DJAndries Jul 2, 2024
64aec05
Accept opaque types in anonymous-credentials functions
DJAndries Jul 4, 2024
f13dbca
Add anonymous-credentials crate and cxx binding
DJAndries Apr 24, 2024
3588802
Add WDP keyed service
DJAndries Apr 26, 2024
55959d4
Add WDP server config loader
DJAndries Apr 29, 2024
4c9f06f
Add credential manager for Web Discovery
DJAndries May 6, 2024
bb9f2ae
Replace Web Discovery webcrypto usages with boringssl, misc bug fixes
DJAndries May 11, 2024
dca6a55
Execute WDP credential crypto operations on thread pool
DJAndries May 16, 2024
d9be342
Fetch, store and parse web discovery patterns
DJAndries May 23, 2024
ca74dc7
Add Web Discovery page scraping via Blink
DJAndries May 27, 2024
36a9fa5
Add Web Discovery double fetch, page parsing and scraping
DJAndries May 30, 2024
42934f4
Add Web Discovery payload generator
DJAndries Jun 1, 2024
6c63f17
Add Web Discovery reporter, ECDH-AES encryption
DJAndries Jun 5, 2024
c736a10
Various Web Discovery fixes, add refine functions
DJAndries Jun 7, 2024
5e2c762
Retrieve Web Discovery quorum config, add country code to messages
DJAndries Jun 7, 2024
043a041
Add Web Discovery privacy risk assessment & data sanitization
DJAndries Jun 11, 2024
e61b4e6
Fix misc Web Discovery bugs, add URL masking refine function
DJAndries Jun 12, 2024
60a2b78
Add Web Discovery refine functions
DJAndries Jun 12, 2024
49f7c85
Cache Web Discovery regexes
DJAndries Jun 13, 2024
904d119
Add Web discovery 'alive' message
DJAndries Jun 13, 2024
102e55e
Move ownership of Web Discovery ServerConfig and PatternsGroup to Ser…
DJAndries Jun 13, 2024
52f3501
Only omit Web Discovery results for query actions
DJAndries Jun 14, 2024
c6d22ad
Add first batch of Web Discovery tests
DJAndries Jun 20, 2024
628804d
Update anonymous-credentials for Web Discovery
DJAndries Jun 21, 2024
dd55f4a
Add more Web Discovery tests, misc fixes
DJAndries Jun 25, 2024
ee3d3eb
Add Web Discovery Android pref, add buildflag and feature guards
DJAndries Jun 26, 2024
4dba090
Add separate pref for Web Discovery native
DJAndries Jun 26, 2024
308288f
Update Web Discovery CTA to set correct pref
DJAndries Jun 27, 2024
8d07c02
Add comments for Web Discovery
DJAndries Jun 27, 2024
e7d5399
Update anonymous-credentials and brave-miracl
DJAndries Jun 27, 2024
a4aede9
Move anonymous-credentials from third_party to web_discovery component
DJAndries Jul 2, 2024
af6779c
Add document_extractor license exception
DJAndries Jul 2, 2024
0a15ebe
Add Web Discovery factory test for OTR profiles
DJAndries Jul 2, 2024
a81304d
Fix WebDiscovery Windows FilePath append
DJAndries Jul 2, 2024
fad93bf
Fix Web Discovery Android test
DJAndries Jul 3, 2024
072fdfc
Fix anonymous-credentials calls after cxx api change, misc feedback c…
DJAndries Jul 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "brave/components/search_engines/brave_prepopulated_engines.h"
#include "brave/components/speedreader/common/buildflags/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "brave/components/web_discovery/browser/wdp_service.h"
#include "build/build_config.h"
#include "chrome/browser/prefetch/pref_names.h"
#include "chrome/browser/prefs/session_startup_pref.h"
Expand Down Expand Up @@ -508,6 +509,8 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {

registry->SetDefaultPrefValue(prefs::kSearchSuggestEnabled,
base::Value(false));

web_discovery::WDPService::RegisterProfilePrefs(registry);
}

} // namespace brave
3 changes: 3 additions & 0 deletions browser/browser_context_keyed_service_factories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "brave/browser/search_engines/search_engine_tracker.h"
#include "brave/browser/sync/brave_sync_alerts_service_factory.h"
#include "brave/browser/url_sanitizer/url_sanitizer_service_factory.h"
#include "brave/browser/web_discovery/wdp_service_factory.h"
#include "brave/components/ai_chat/core/common/buildflags/buildflags.h"
#include "brave/components/brave_perf_predictor/browser/named_third_party_registry_factory.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
Expand Down Expand Up @@ -216,6 +217,8 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
#if BUILDFLAG(ENABLE_AI_CHAT)
ai_chat::ModelServiceFactory::GetInstance();
#endif

web_discovery::WDPServiceFactory::GetInstance();
}

} // namespace brave
2 changes: 2 additions & 0 deletions browser/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ brave_chrome_browser_deps = [
"//brave/browser/sync",
"//brave/browser/themes",
"//brave/browser/ui",
"//brave/browser/web_discovery",
"//brave/common",
"//brave/components/ai_chat/core/common/buildflags",
"//brave/components/ai_rewriter/common/buildflags",
Expand Down Expand Up @@ -204,6 +205,7 @@ brave_chrome_browser_deps = [
"//brave/components/speedreader/common/buildflags",
"//brave/components/tor/buildflags",
"//brave/components/version_info",
"//brave/components/web_discovery/browser",
"//brave/components/webcompat:core",
"//brave/services/network/public/cpp",
"//brave/third_party/blink/renderer",
Expand Down
14 changes: 14 additions & 0 deletions browser/web_discovery/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@

import("//extensions/buildflags/buildflags.gni")

source_set("web_discovery") {
sources = [
"wdp_service_factory.cc",
"wdp_service_factory.h",
]
deps = [
"//base",
"//brave/components/web_discovery/browser",
"//components/keyed_service/content",
"//components/user_prefs",
"//content/public/browser",
]
}

source_set("unit_tests") {
if (enable_extensions) {
testonly = true
Expand Down
47 changes: 47 additions & 0 deletions browser/web_discovery/wdp_service_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Copyright (c) 2024 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/browser/web_discovery/wdp_service_factory.h"

#include "brave/components/web_discovery/browser/wdp_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h"

namespace web_discovery {

WDPServiceFactory* WDPServiceFactory::GetInstance() {
static base::NoDestructor<WDPServiceFactory> instance;
return instance.get();
}

WDPServiceFactory::WDPServiceFactory()
: BrowserContextKeyedServiceFactory(
"WDPService",
BrowserContextDependencyManager::GetInstance()) {}

WDPServiceFactory::~WDPServiceFactory() = default;

KeyedService* WDPServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
auto* default_storage_partition = context->GetDefaultStoragePartition();
auto shared_url_loader_factory =
default_storage_partition->GetURLLoaderFactoryForBrowserProcess();
return new WDPService(user_prefs::UserPrefs::Get(context),
shared_url_loader_factory);
}

content::BrowserContext* WDPServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
// Prevents creation of service instance for incognito/OTR profiles
return context->IsOffTheRecord() ? nullptr : context;
DJAndries marked this conversation as resolved.
Show resolved Hide resolved
}

bool WDPServiceFactory::ServiceIsCreatedWithBrowserContext() const {
return true;
}

} // namespace web_discovery
36 changes: 36 additions & 0 deletions browser/web_discovery/wdp_service_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright (c) 2024 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_BROWSER_WEB_DISCOVERY_WDP_SERVICE_FACTORY_H_
#define BRAVE_BROWSER_WEB_DISCOVERY_WDP_SERVICE_FACTORY_H_

#include "base/no_destructor.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"

namespace web_discovery {

class WDPServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static WDPServiceFactory* GetInstance();

private:
friend base::NoDestructor<WDPServiceFactory>;

WDPServiceFactory();
~WDPServiceFactory() override;

WDPServiceFactory(const WDPServiceFactory&) = delete;
WDPServiceFactory& operator=(const WDPServiceFactory&) = delete;

KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
};

} // namespace web_discovery

#endif // BRAVE_BROWSER_WEB_DISCOVERY_WDP_SERVICE_FACTORY_H_
32 changes: 32 additions & 0 deletions components/web_discovery/browser/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2024 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/.

static_library("browser") {
sources = [
"credential_manager.cc",
"credential_manager.h",
"pref_names.h",
"rsa.cc",
"rsa.h",
"server_config_loader.cc",
"server_config_loader.h",
"util.cc",
"util.h",
"wdp_service.cc",
"wdp_service.h",
]
deps = [
"anonymous_credentials/rs:rust_lib",
"//base",
"//brave/brave_domains",
"//brave/components/constants",
"//components/keyed_service/core",
"//components/prefs",
"//net",
"//services/network/public/cpp",
"//third_party/boringssl",
"//url",
]
}
4 changes: 4 additions & 0 deletions components/web_discovery/browser/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include_rules = [
"+services/network/public",
"+third_party/boringssl/src/include",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
example/main
Cargo.lock
21 changes: 21 additions & 0 deletions components/web_discovery/browser/anonymous_credentials/rs/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2024 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/.

import("//build/rust/rust_static_library.gni")

rust_static_library("rust_lib") {
crate_name = "anonymous_credentials_cxx"
crate_root = "src/lib.rs"
allow_unsafe = true

edition = "2021"
sources = [ "src/lib.rs" ]

visibility = [ "//brave/components/web_discovery/browser:*" ]

cxx_bindings = [ "src/lib.rs" ]

deps = [ "//brave/third_party/rust/anonymous_credentials/v0_1:lib" ]
}
Loading