Skip to content

Commit

Permalink
Permission settings UI for Open Leo permission
Browse files Browse the repository at this point in the history
  • Loading branch information
yrliou committed Oct 18, 2024
1 parent 6fd69df commit a633639
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/brave_settings_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,17 @@
Allowed to access localhost resources
</message>

<!-- AI chat setting -->
<message name="IDS_SETTINGS_SITE_SETTINGS_BRAVE_AI_CHAT" desc="Label for Leo AI chat site settings.">
Leo AI chat
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_BRAVE_AI_CHAT_ASK" desc="Label for Leo AI chat site settings.">
Sites can ask to open Leo AI chat
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_BRAVE_AI_CHAT_BLOCK" desc="Label for Leo AI chat site settings.">
Don't allow site to open Leo AI chat
</message>

<!-- Settings / Privacy and security / Safety Check -->
<message name="IDS_SETTINGS_BRAVE_SAFETY_CHECK_SAFE_BROWSING_ENABLED_STANDARD_AVAILABLE_ENHANCED" desc="This text points out that Safe Browsing is enabled as standard protection.">
Standard protection is on.
Expand Down
35 changes: 35 additions & 0 deletions browser/resources/settings/brave_overrides/privacy_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,36 @@ function InsertShieldsSubpage (pages: Element)
`)
}

function InsertBraveAIChatSubpage (pages: Element)
{
pages.appendChild(
html`
<template is="dom-if" route-path="/content/braveAIChat" no-search>
<settings-subpage
associated-control="[[$$('#braveAIChat')]]"
page-title="${loadTimeData.getString('siteSettingsBraveAIChat')}">
<settings-category-default-radio-group
id="braveAIChatDefault"
category="[[contentSettingsTypesEnum_.BRAVE_AI_CHAT]]"
block-option-label=
"${loadTimeData.getString('siteSettingsBraveAIChatBlock')}"
allow-option-label=
"${loadTimeData.getString('siteSettingsBraveAIChatAsk')}"
allow-option-icon="user"
block-option-icon="user-off">
</settings-category-default-radio-group>
<category-setting-exceptions
id="braveAIChatExceptions"
category="[[contentSettingsTypesEnum_.BRAVE_AI_CHAT]]"
block-header="${loadTimeData.getString('siteSettingsBlock')}"
allow-header="${loadTimeData.getString('siteSettingsAllow')}"
read-only-list>
</category-setting-exceptions>
</settings-subpage>
</template>
`)
}

RegisterPolymerTemplateModifications({
'settings-privacy-page': (templateContent) => {
const pages = templateContent.getElementById('pages')
Expand Down Expand Up @@ -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')
Expand Down
24 changes: 24 additions & 0 deletions browser/resources/settings/brave_overrides/site_details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ RegisterPolymerTemplateModifications({
}
curChild++
}
// AI Chat feature
const isBraveAIChatFeatureEnabled =
loadTimeData.getBoolean('isBraveAIChatFeatureEnabled')
if (isBraveAIChatFeatureEnabled) {
firstPermissionItem.insertAdjacentHTML(
'beforebegin',
getTrustedHTML`
<site-details-permission
category="[[contentSettingsTypesEnum_.BRAVE_AI_CHAT]]"
icon="user">
</site-details-permission>
`)
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(
Expand Down
15 changes: 15 additions & 0 deletions browser/resources/settings/brave_overrides/site_settings_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down
4 changes: 4 additions & 0 deletions browser/resources/settings/brave_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export default function addBraveRoutes(r: Partial<SettingsRoutes>) {
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')
Expand Down
11 changes: 11 additions & 0 deletions browser/ui/webui/settings/brave_privacy_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}, \
Expand Down

0 comments on commit a633639

Please sign in to comment.