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

Bootstrap Web Discovery Native, add credential manager and server config loading #24969

Open
wants to merge 9 commits into
base: wdp-native-anon-creds
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import("//brave/components/ai_chat/core/common/buildflags/buildflags.gni")
import("//brave/components/p3a/buildflags.gni")
import("//brave/components/web_discovery/buildflags/buildflags.gni")
import("//brave/components/webcompat_reporter/buildflags/buildflags.gni")
import("//build/config/android/rules.gni")

Expand All @@ -26,5 +27,6 @@ java_cpp_template("brave_config_java") {
"BRAVE_ANDROID_P3A_ENABLED=$brave_p3a_enabled",
"BRAVE_ANDROID_WEBCOMPAT_REPORT_ENDPOINT=\"$webcompat_report_api_endpoint\"",
"BRAVE_ANDROID_AI_CHAT_ENABLED=$enable_ai_chat",
"BRAVE_ANDROID_WEB_DISCOVERY_ENABLED=$enable_web_discovery_native",
]
}
1 change: 1 addition & 0 deletions android/java/org/chromium/base/BraveFeatureList.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ public abstract class BraveFeatureList {
"BraveShowStrictFingerprintingMode";
public static final String BRAVE_DAY_ZERO_EXPERIMENT = "BraveDayZeroExperiment";
public static final String BRAVE_FALLBACK_DOH_PROVIDER = "BraveFallbackDoHProvider";
public static final String BRAVE_WEB_DISCOVERY_NATIVE = "BraveWebDiscoveryNative";
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.chromium.components.browser_ui.settings.SettingsUtils;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.components.web_discovery.WebDiscoveryPrefs;
import org.chromium.gms.ChromiumPlayServicesAvailability;
import org.chromium.mojo.bindings.ConnectionErrorHandler;
import org.chromium.mojo.system.MojoException;
Expand Down Expand Up @@ -84,6 +85,7 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE
public static final String PREF_FINGERPRINTING_PROTECTION2 = "fingerprinting_protection2";
private static final String PREF_CLOSE_TABS_ON_EXIT = "close_tabs_on_exit";
private static final String PREF_SEND_P3A = "send_p3a_analytics";
private static final String PREF_SEND_WEB_DISCOVERY = "send_web_discovery";
private static final String PREF_SEND_CRASH_REPORTS = "send_crash_reports";
private static final String PREF_BRAVE_STATS_USAGE_PING = "brave_stats_usage_ping";
public static final String PREF_APP_LINKS = "app_links";
Expand Down Expand Up @@ -149,6 +151,7 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE
PREF_PHONE_AS_A_SECURITY_KEY,
PREF_CLOSE_TABS_ON_EXIT,
PREF_SEND_P3A,
PREF_SEND_WEB_DISCOVERY,
PREF_SEND_CRASH_REPORTS,
PREF_BRAVE_STATS_USAGE_PING,
PREF_USAGE_STATS,
Expand Down Expand Up @@ -177,6 +180,7 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE
private ChromeSwitchPreference mForgetFirstPartyStoragePref;
private ChromeSwitchPreference mCloseTabsOnExitPref;
private ChromeSwitchPreference mSendP3A;
private ChromeSwitchPreference mSendWebDiscovery;
private ChromeSwitchPreference mSendCrashReports;
private ChromeSwitchPreference mBraveStatsUsagePing;
private ChromeSwitchPreference mBlockCookieConsentNoticesPref;
Expand Down Expand Up @@ -308,6 +312,14 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
mSendP3A = (ChromeSwitchPreference) findPreference(PREF_SEND_P3A);
mSendP3A.setOnPreferenceChangeListener(this);

if (BraveConfig.WEB_DISCOVERY_ENABLED
&& ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_WEB_DISCOVERY_NATIVE)) {
mSendWebDiscovery = (ChromeSwitchPreference) findPreference(PREF_SEND_WEB_DISCOVERY);
DJAndries marked this conversation as resolved.
Show resolved Hide resolved
mSendWebDiscovery.setOnPreferenceChangeListener(this);
} else {
removePreferenceIfPresent(PREF_SEND_WEB_DISCOVERY);
}

mSendCrashReports = (ChromeSwitchPreference) findPreference(PREF_SEND_CRASH_REPORTS);
mSendCrashReports.setOnPreferenceChangeListener(this);
mBraveStatsUsagePing = (ChromeSwitchPreference) findPreference(PREF_BRAVE_STATS_USAGE_PING);
Expand Down Expand Up @@ -522,6 +534,9 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
} else if (PREF_SEND_P3A.equals(key)) {
BraveLocalState.get().setBoolean(BravePref.P3A_ENABLED, (boolean) newValue);
BraveLocalState.commitPendingWrite();
} else if (PREF_SEND_WEB_DISCOVERY.equals(key)) {
UserPrefs.get(ProfileManager.getLastUsedRegularProfile())
.setBoolean(WebDiscoveryPrefs.WEB_DISCOVERY_ENABLED, (boolean) newValue);
} else if (PREF_SEND_CRASH_REPORTS.equals(key)) {
UmaSessionStats.changeMetricsReportingConsent(
(boolean) newValue, ChangeMetricsReportingStateCalledFrom.UI_SETTINGS);
Expand Down Expand Up @@ -682,6 +697,16 @@ private void updateBravePreferences() {
getPreferenceScreen().removePreference(mSendP3A);
}

if (mSendWebDiscovery != null) {
mSendWebDiscovery.setTitle(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove title/summary here as we already have those mentioned in .xml

getActivity().getResources().getString(R.string.send_web_discovery_title));
mSendWebDiscovery.setSummary(
getActivity().getResources().getString(R.string.send_web_discovery_summary));
mSendWebDiscovery.setChecked(
UserPrefs.get(ProfileManager.getLastUsedRegularProfile())
.getBoolean(WebDiscoveryPrefs.WEB_DISCOVERY_ENABLED));
}

mSendCrashReports.setChecked(mPrivacyPrefManager.isUsageAndCrashReportingPermittedByUser());

mBraveStatsUsagePing.setChecked(
Expand Down
6 changes: 6 additions & 0 deletions android/java/res/xml/brave_privacy_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
android:title="@string/send_p3a_analytics_title"
android:summary="@string/send_p3a_analytics_summary"
android:defaultValue="false" />
<org.chromium.components.browser_ui.settings.ChromeSwitchPreference
android:key="send_web_discovery"
android:order="25"
android:title="@string/send_web_discovery_title"
android:summary="@string/send_web_discovery_summary"
android:defaultValue="false" />
<org.chromium.components.browser_ui.settings.ChromeSwitchPreference
android:key="send_crash_reports"
android:order="25"
Expand Down
8 changes: 8 additions & 0 deletions browser/brave_local_state_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "brave/components/p3a/star_randomness_meta.h"
#include "brave/components/skus/browser/skus_utils.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "brave/components/web_discovery/buildflags/buildflags.h"
#include "build/build_config.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/metrics_pref_names.h"
Expand Down Expand Up @@ -73,6 +74,10 @@
#include "brave/components/ai_chat/core/common/pref_names.h"
#endif

#if BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
#include "brave/components/web_discovery/browser/web_discovery_service.h"
#endif

#if BUILDFLAG(ENABLE_WIDEVINE)
#include "brave/browser/widevine/widevine_utils.h"
#endif
Expand Down Expand Up @@ -179,6 +184,9 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
misc_metrics::GeneralBrowserUsage::RegisterPrefs(registry);

playlist::PlaylistServiceFactory::RegisterLocalStatePrefs(registry);
#if BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
web_discovery::WebDiscoveryService::RegisterLocalStatePrefs(registry);
#endif
}

} // namespace brave
12 changes: 10 additions & 2 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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/buildflags/buildflags.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 @@ -118,6 +119,10 @@
#include "brave/components/ai_chat/core/common/pref_names.h"
#endif

#if BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
#include "brave/components/web_discovery/browser/web_discovery_service.h"
#endif

#if BUILDFLAG(ENABLE_REQUEST_OTR)
#include "brave/components/request_otr/browser/request_otr_service.h"
#endif
Expand Down Expand Up @@ -429,8 +434,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
prefs::kBraveDefaultSearchVersion,
TemplateURLPrepopulateData::kBraveCurrentDataVersion);

#if BUILDFLAG(ENABLE_EXTENSIONS)
// Web discovery extension, default false
#if BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
registry->RegisterBooleanPref(kWebDiscoveryEnabled, false);
registry->RegisterDictionaryPref(kWebDiscoveryCTAState);
#endif
Expand Down Expand Up @@ -497,6 +501,10 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {

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

#if BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
web_discovery::WebDiscoveryService::RegisterProfilePrefs(registry);
#endif
}

} // namespace brave
6 changes: 3 additions & 3 deletions browser/brave_tab_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "brave/browser/misc_metrics/process_misc_metrics.h"
#include "brave/browser/ntp_background/ntp_tab_helper.h"
#include "brave/browser/ui/bookmark/brave_bookmark_tab_helper.h"
#include "brave/browser/ui/brave_ui_features.h"
#include "brave/components/ai_chat/core/common/buildflags/buildflags.h"
#include "brave/components/brave_perf_predictor/browser/perf_predictor_tab_helper.h"
#include "brave/components/brave_wayback_machine/buildflags/buildflags.h"
Expand All @@ -31,6 +30,7 @@
#include "brave/components/request_otr/common/buildflags/buildflags.h"
#include "brave/components/speedreader/common/buildflags/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "brave/components/web_discovery/buildflags/buildflags.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -88,7 +88,7 @@
#include "brave/components/tor/tor_tab_helper.h"
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
#include "brave/browser/web_discovery/web_discovery_tab_helper.h"
#endif

Expand Down Expand Up @@ -164,7 +164,7 @@ void AttachTabHelpers(content::WebContents* web_contents) {
web_contents);
psst::PsstTabHelper::MaybeCreateForWebContents(
web_contents, ISOLATED_WORLD_ID_BRAVE_INTERNAL);
#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
WebDiscoveryTabHelper::MaybeCreateForWebContents(web_contents);
#endif

Expand Down
9 changes: 9 additions & 0 deletions browser/browser_context_keyed_service_factories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "brave/components/request_otr/common/buildflags/buildflags.h"
#include "brave/components/speedreader/common/buildflags/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "brave/components/web_discovery/buildflags/buildflags.h"

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
Expand Down Expand Up @@ -102,6 +103,10 @@
#include "brave/components/ai_chat/content/browser/model_service_factory.h"
#endif

#if BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
#include "brave/browser/web_discovery/web_discovery_service_factory.h"
#endif

namespace brave {

void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
Expand Down Expand Up @@ -200,6 +205,10 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
ai_chat::AIChatServiceFactory::GetInstance();
ai_chat::ModelServiceFactory::GetInstance();
#endif

#if BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
web_discovery::WebDiscoveryServiceFactory::GetInstance();
#endif
}

} // namespace brave
8 changes: 8 additions & 0 deletions browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni")
import("//brave/components/playlist/common/buildflags/buildflags.gni")
import("//brave/components/speedreader/common/buildflags/buildflags.gni")
import("//brave/components/tor/buildflags/buildflags.gni")
import("//brave/components/web_discovery/buildflags/buildflags.gni")
import("//build/config/features.gni")
import("//build/config/ui.gni")
import("//components/gcm_driver/config.gni")
Expand Down Expand Up @@ -107,6 +108,8 @@ source_set("extensions") {
"api/rewards_notifications_api.h",
"api/settings_private/brave_prefs_util.cc",
"api/settings_private/brave_prefs_util.h",
"api/web_discovery_api.cc",
"api/web_discovery_api.h",
"brave_extension_management.cc",
"brave_extension_management.h",
"brave_extension_provider.cc",
Expand Down Expand Up @@ -173,6 +176,7 @@ source_set("extensions") {
"//brave/components/request_otr/common",
"//brave/components/sidebar/browser",
"//brave/components/tor/buildflags",
"//brave/components/web_discovery/buildflags",
"//chrome/browser:browser_process",
"//chrome/browser:browser_public_dependencies",
"//chrome/browser/extensions",
Expand Down Expand Up @@ -229,6 +233,10 @@ source_set("extensions") {
]
}

if (enable_web_discovery_native) {
deps += [ "//brave/components/web_discovery/common" ]
}

# It seems like this brave_wallet_api should be renamed to ethereum_remote_client_api.
# However this is not possible right now because the ethereum-remote-client extension
# uses chrome.braveWallet, so the API is intentionally not being renamed now.
Expand Down
3 changes: 2 additions & 1 deletion browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "brave/components/request_otr/common/pref_names.h"
#include "brave/components/speedreader/common/buildflags/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "brave/components/web_discovery/buildflags/buildflags.h"
#include "chrome/browser/extensions/api/settings_private/prefs_util.h"
#include "chrome/common/extensions/api/settings_private.h"
#include "chrome/common/pref_names.h"
Expand Down Expand Up @@ -182,7 +183,7 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() {
settings_api::PrefType::kBoolean;
(*s_brave_allowlist)[kNewTabPageShowsOptions] =
settings_api::PrefType::kNumber;
#if BUILDFLAG(ENABLE_EXTENSIONS)
#if BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
// Web discovery prefs
(*s_brave_allowlist)[kWebDiscoveryEnabled] = settings_api::PrefType::kBoolean;
#endif
Expand Down
27 changes: 27 additions & 0 deletions browser/extensions/api/web_discovery_api.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* 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/extensions/api/web_discovery_api.h"

#include "brave/components/web_discovery/buildflags/buildflags.h"

#if BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
#include "base/feature_list.h"
#include "brave/components/web_discovery/common/features.h"
#endif

namespace extensions::api {

ExtensionFunction::ResponseAction
WebDiscoveryIsWebDiscoveryNativeEnabledFunction::Run() {
bool result = false;
#if BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
result = base::FeatureList::IsEnabled(
web_discovery::features::kBraveWebDiscoveryNative);
#endif
return RespondNow(WithArguments(result));
}

} // namespace extensions::api
29 changes: 29 additions & 0 deletions browser/extensions/api/web_discovery_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* 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_EXTENSIONS_API_WEB_DISCOVERY_API_H_
#define BRAVE_BROWSER_EXTENSIONS_API_WEB_DISCOVERY_API_H_

#include "extensions/browser/extension_function.h"

namespace extensions {
namespace api {

class WebDiscoveryIsWebDiscoveryNativeEnabledFunction
: public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("webDiscovery.isWebDiscoveryNativeEnabled",
UNKNOWN)

protected:
~WebDiscoveryIsWebDiscoveryNativeEnabledFunction() override {}

ResponseAction Run() override;
};

} // namespace api
} // namespace extensions

#endif // BRAVE_BROWSER_EXTENSIONS_API_WEB_DISCOVERY_API_H_
2 changes: 2 additions & 0 deletions browser/resources/settings/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import("//brave/build/config.gni")
import("//brave/components/brave_vpn/common/buildflags/buildflags.gni")
import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni")
import("//brave/components/tor/buildflags/buildflags.gni")
import("//brave/components/web_discovery/buildflags/buildflags.gni")
import("//brave/resources/brave_grit.gni")
import("//chrome/common/features.gni")
import("//extensions/buildflags/buildflags.gni")
Expand Down Expand Up @@ -75,6 +76,7 @@ preprocess_if_expr("preprocess") {
"enable_brave_vpn_wireguard=$enable_brave_vpn_wireguard",
"enable_extensions=$enable_extensions",
"enable_pin_shortcut=$enable_pin_shortcut",
"enable_web_discovery_native=$enable_web_discovery_native",
]
out_folder =
"$root_gen_dir/chrome/browser/resources/settings/$preprocess_folder"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
sub-label="$i18n{searchSuggestDesc}">
</settings-toggle-button>
</template>
<if expr="enable_extensions">
<settings-toggle-button id="webDiscoveryEnabled"
<if expr="enable_extensions or enable_web_discovery_native">
<settings-toggle-button id="webDiscoveryEnabledExtension"
class="cr-row"
pref="{{prefs.brave.web_discovery_enabled}}"
label="$i18n{braveWebDiscoveryLabel}"
Expand Down
Loading
Loading