From a6336394bbd84a7deeb6fe2790cb817d472f0aa8 Mon Sep 17 00:00:00 2001 From: Jocelyn Liu Date: Thu, 12 Sep 2024 12:00:54 -0700 Subject: [PATCH] Permission settings UI for Open Leo permission --- app/brave_settings_strings.grdp | 11 ++++++ .../settings/brave_overrides/privacy_page.ts | 35 +++++++++++++++++++ .../settings/brave_overrides/site_details.ts | 24 +++++++++++++ .../brave_overrides/site_settings_page.ts | 15 ++++++++ browser/resources/settings/brave_routes.ts | 4 +++ .../webui/settings/brave_privacy_handler.cc | 11 ++++++ ...ave_settings_localized_strings_provider.cc | 8 +++++ .../ui/webui/settings/site_settings_helper.cc | 2 +- 8 files changed, 109 insertions(+), 1 deletion(-) diff --git a/app/brave_settings_strings.grdp b/app/brave_settings_strings.grdp index e18de2ee52fc..26719003f85b 100644 --- a/app/brave_settings_strings.grdp +++ b/app/brave_settings_strings.grdp @@ -712,6 +712,17 @@ Allowed to access localhost resources + + + Leo AI chat + + + Sites can ask to open Leo AI chat + + + Don't allow site to open Leo AI chat + + Standard protection is on. diff --git a/browser/resources/settings/brave_overrides/privacy_page.ts b/browser/resources/settings/brave_overrides/privacy_page.ts index 1379800d2b60..1ed4fff54196 100644 --- a/browser/resources/settings/brave_overrides/privacy_page.ts +++ b/browser/resources/settings/brave_overrides/privacy_page.ts @@ -181,6 +181,36 @@ function InsertShieldsSubpage (pages: Element) `) } +function InsertBraveAIChatSubpage (pages: Element) +{ + pages.appendChild( + html` + + `) +} + RegisterPolymerTemplateModifications({ 'settings-privacy-page': (templateContent) => { const pages = templateContent.getElementById('pages') @@ -208,6 +238,11 @@ RegisterPolymerTemplateModifications({ if (isLocalhostAccessFeatureEnabled) { InsertLocalhostAccessSubpage(pages) } + const isBraveAIChatFeatureEnabled = + loadTimeData.getBoolean('isBraveAIChatFeatureEnabled') + if (isBraveAIChatFeatureEnabled) { + InsertBraveAIChatSubpage(pages) + } InsertAutoplaySubpage(pages) const isNativeBraveWalletEnabled = loadTimeData.getBoolean('isNativeBraveWalletFeatureEnabled') diff --git a/browser/resources/settings/brave_overrides/site_details.ts b/browser/resources/settings/brave_overrides/site_details.ts index 4d6f70cb96d7..f8d44654b87d 100644 --- a/browser/resources/settings/brave_overrides/site_details.ts +++ b/browser/resources/settings/brave_overrides/site_details.ts @@ -99,6 +99,30 @@ RegisterPolymerTemplateModifications({ } curChild++ } + // AI Chat feature + const isBraveAIChatFeatureEnabled = + loadTimeData.getBoolean('isBraveAIChatFeatureEnabled') + if (isBraveAIChatFeatureEnabled) { + firstPermissionItem.insertAdjacentHTML( + 'beforebegin', + getTrustedHTML` + + + `) + const braveAIChatSettings = templateContent. + querySelector(`div.list-frame > site-details-permission:nth-child(${curChild})`) + if (!braveAIChatSettings) { + console.error( + '[Brave Settings Overrides] Couldn\'t find Brave AI chat settings') + } + else { + braveAIChatSettings.setAttribute( + 'label', loadTimeData.getString('siteSettingsBraveAIChat')) + } + curChild++ + } const isNativeBraveWalletEnabled = loadTimeData.getBoolean('isNativeBraveWalletFeatureEnabled') if (isNativeBraveWalletEnabled) { firstPermissionItem.insertAdjacentHTML( diff --git a/browser/resources/settings/brave_overrides/site_settings_page.ts b/browser/resources/settings/brave_overrides/site_settings_page.ts index 64eaa1c2c804..3c1c2a1af24f 100644 --- a/browser/resources/settings/brave_overrides/site_settings_page.ts +++ b/browser/resources/settings/brave_overrides/site_settings_page.ts @@ -137,6 +137,21 @@ RegisterPolymerComponentReplacement( lists_.permissionsAdvanced.splice(currentIndex, 0, localhostAccessItem) } + const isBraveAIChatFeatureEnabled = + loadTimeData.getBoolean('isBraveAIChatFeatureEnabled') + if (isBraveAIChatFeatureEnabled) { + currentIndex++ + const AIChatItem = { + route: routes.SITE_SETTINGS_BRAVE_AI_CHAT, + id: 'braveAIChat', + label: 'siteSettingsBraveAIChat', + icon: 'product-brave-leo', + enabledLabel: 'siteSettingsBraveAIChatAsk', + disabledLabel: 'siteSettingsBraveAIChatBlock' + } + lists_.permissionsAdvanced.splice(currentIndex, 0, + AIChatItem) + } const isNativeBraveWalletEnabled = loadTimeData.getBoolean('isNativeBraveWalletFeatureEnabled') if (isNativeBraveWalletEnabled) { currentIndex++ diff --git a/browser/resources/settings/brave_routes.ts b/browser/resources/settings/brave_routes.ts index 1d2106d728d4..a1dc34ce8a27 100644 --- a/browser/resources/settings/brave_routes.ts +++ b/browser/resources/settings/brave_routes.ts @@ -75,6 +75,10 @@ export default function addBraveRoutes(r: Partial) { r.SITE_SETTINGS_LOCALHOST_ACCESS = r.SITE_SETTINGS .createChild('localhostAccess') } + const isBraveAIChatFeatureEnabled = loadTimeData.getBoolean('isBraveAIChatFeatureEnabled') + if (isBraveAIChatFeatureEnabled) { + r.SITE_SETTINGS_BRAVE_AI_CHAT = r.SITE_SETTINGS.createChild('braveAIChat') + } const isNativeBraveWalletFeatureEnabled = loadTimeData.getBoolean('isNativeBraveWalletFeatureEnabled') if (isNativeBraveWalletFeatureEnabled) { r.SITE_SETTINGS_ETHEREUM = r.SITE_SETTINGS.createChild('ethereum') diff --git a/browser/ui/webui/settings/brave_privacy_handler.cc b/browser/ui/webui/settings/brave_privacy_handler.cc index 34abdd43200d..bf4a57f8d8e3 100644 --- a/browser/ui/webui/settings/brave_privacy_handler.cc +++ b/browser/ui/webui/settings/brave_privacy_handler.cc @@ -7,6 +7,7 @@ #include "base/functional/bind.h" #include "base/values.h" +#include "brave/components/ai_chat/core/common/buildflags/buildflags.h" #include "brave/components/brave_shields/core/common/features.h" #include "brave/components/constants/pref_names.h" #include "brave/components/de_amp/common/features.h" @@ -22,6 +23,10 @@ #include "content/public/browser/web_ui_data_source.h" #include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h" +#if BUILDFLAG(ENABLE_AI_CHAT) +#include "brave/components/ai_chat/core/browser/utils.h" +#endif + #if BUILDFLAG(ENABLE_REQUEST_OTR) #include "brave/components/request_otr/common/features.h" #endif @@ -96,6 +101,12 @@ void BravePrivacyHandler::AddLoadTimeData(content::WebUIDataSource* data_source, "isLocalhostAccessFeatureEnabled", base::FeatureList::IsEnabled( brave_shields::features::kBraveLocalhostAccessPermission)); + data_source->AddBoolean("isBraveAIChatFeatureEnabled", +#if BUILDFLAG(ENABLE_AI_CHAT) + ai_chat::IsAIChatEnabled(profile->GetPrefs())); +#else + false); +#endif } void BravePrivacyHandler::SetLocalStateBooleanEnabled( diff --git a/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc b/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc index 8c9a3f5307a4..a16f95b7b11e 100644 --- a/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc +++ b/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc @@ -105,6 +105,14 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source, {"siteSettingsGoogleSignInAllowExceptions", IDS_SETTINGS_SITE_SETTINGS_GOOGLE_SIGN_IN_ALLOW_EXCEPTIONS}, + {"siteSettingsBraveAIChat", IDS_SETTINGS_SITE_SETTINGS_BRAVE_AI_CHAT}, + {"siteSettingsCategoryBraveAIChat", + IDS_SETTINGS_SITE_SETTINGS_BRAVE_AI_CHAT}, + {"siteSettingsBraveAIChatAsk", + IDS_SETTINGS_SITE_SETTINGS_BRAVE_AI_CHAT_ASK}, + {"siteSettingsBraveAIChatBlock", + IDS_SETTINGS_SITE_SETTINGS_BRAVE_AI_CHAT_BLOCK}, + {"siteSettingsLocalhostAccess", IDS_SETTINGS_SITE_SETTINGS_LOCALHOST_ACCESS}, {"siteSettingsCategoryLocalhostAccess", diff --git a/chromium_src/chrome/browser/ui/webui/settings/site_settings_helper.cc b/chromium_src/chrome/browser/ui/webui/settings/site_settings_helper.cc index fb1c5030362c..1792faa78de1 100644 --- a/chromium_src/chrome/browser/ui/webui/settings/site_settings_helper.cc +++ b/chromium_src/chrome/browser/ui/webui/settings/site_settings_helper.cc @@ -31,7 +31,7 @@ {ContentSettingsType::BRAVE_HTTPS_UPGRADE, nullptr}, \ {ContentSettingsType::BRAVE_REMEMBER_1P_STORAGE, nullptr}, \ {ContentSettingsType::BRAVE_LOCALHOST_ACCESS, "localhostAccess"}, \ - {ContentSettingsType::BRAVE_AI_CHAT, nullptr}, \ + {ContentSettingsType::BRAVE_AI_CHAT, "braveAIChat"}, \ {ContentSettingsType::BRAVE_WEBCOMPAT_NONE, nullptr}, \ {ContentSettingsType::BRAVE_WEBCOMPAT_AUDIO, nullptr}, \ {ContentSettingsType::BRAVE_WEBCOMPAT_CANVAS, nullptr}, \