-
Notifications
You must be signed in to change notification settings - Fork 868
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
Open Leo from search #26082
base: master
Are you sure you want to change the base?
Open Leo from search #26082
Conversation
dce4a3c
to
1f2c4c1
Compare
A Storybook has been deployed to preview UI for the latest push |
0c99be2
to
9ef822a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving some comments for now. Be back later.
browser/ui/ai_chat/ai_chat_brave_search_throttle_delegate_impl.h
Outdated
Show resolved
Hide resolved
- Only get nonce from HTML in PageContentExtractor
c973c0b
to
0db3a85
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work - my review mainly focuses on naming and keeping consistent with "AI Chat" and not "Leo" - sorry!
browser/ui/ai_chat/utils.h
Outdated
|
||
namespace ai_chat { | ||
|
||
void OpenLeo(content::WebContents* web_contents); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid the brand name in the code, since this is subject to change. Let's keep it AIChat
. In this case we want to open a conversation associated with a Tab, so perhaps the function name should be OpenAIChatForTab
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to OpenAIChatForTab
in ab4ea07.
@@ -96,6 +102,14 @@ void BravePrivacyHandler::AddLoadTimeData(content::WebUIDataSource* data_source, | |||
"isLocalhostAccessFeatureEnabled", | |||
base::FeatureList::IsEnabled( | |||
brave_shields::features::kBraveLocalhostAccessPermission)); | |||
data_source->AddBoolean( | |||
"isOpenLeoFromBraveSearchEnabled", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isOpenAIChatFromBraveSearchEnabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -24,6 +24,7 @@ enum ContentSettingsType { | |||
BRAVE_HTTPS_UPGRADE, | |||
BRAVE_REMEMBER_1P_STORAGE, | |||
BRAVE_LOCALHOST_ACCESS, | |||
BRAVE_AI_CHAT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think it would be clearer to understand if it was something like BRAVE_CONTINUE_IN_AI_CHAT
as it's not "enabling AI Chat" for that site.
@@ -24,6 +24,9 @@ enum ContentSettingsType { | |||
BRAVE_HTTPS_UPGRADE, | |||
BRAVE_REMEMBER_1P_STORAGE, | |||
BRAVE_LOCALHOST_ACCESS, | |||
// Allow a site to open Leo (in side panel on Desktop). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI Chat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
void OnPermissionPromptResult(blink::mojom::PermissionStatus status); | ||
void OnOpenLeo(); | ||
|
||
void OpenLeoWithStagedConversations(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it's clearer as OpenConversationWithStagedEntries
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renames as OpenAIChatWithStagedEntries
in ab4ea07.
@@ -60,4 +60,16 @@ bool IsPageContentRefineEnabled() { | |||
return base::FeatureList::IsEnabled(features::kPageContentRefine); | |||
} | |||
|
|||
BASE_FEATURE(kOpenLeoFromBraveSearch, | |||
"OpenLeoFromBraveSearch", | |||
#if !BUILDFLAG(IS_ANDROID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this condition also include iOS? Also, why is it disabled on android? Nearly all the logic should be the same, aside from the UI-opening delegate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could just enable the whole feature when it's done.
Currently this feature flag is mainly gating the navigation throttle, and without UI opening, there's really no much point have it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add iOS, tho currently this feature flag is used only in webui and contents folder, so not really affecting anything on iOS atm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added ios in ab4ea07
|
||
namespace permissions { | ||
|
||
class BraveAIChatPermissionContext : public PermissionContextBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this could never encompass all possible AI Chat content settings permissions (should we gain any more in the future), should this be named specifically for the permission it's describing? e.g. BraveAIChatContinueConversationPermissionContext
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a similar comment about the content setting BRAVE_AI_CHAT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petemill How about BraveOpenAIChatPermissionContext
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to BraveOpenAIChatPermissionContext
and BRAVE_OPEN_AI_CHAT
in ab1e047
@@ -21,4 +21,10 @@ | |||
<message name="IDS_PERMISSIONS_BUBBLE_SITE_PERMISSION_LINK" desc="Site permission link in the footnote description."> | |||
site permission | |||
</message> | |||
<message name="IDS_OPEN_AI_CHAT_PERMISSION_FRAGMENT" desc="Label for Leo AI chat permission prompt."> | |||
Allow opening Leo in Brave? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps Allow opening Leo AI conversations in Brave
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow opening Leo in Brave? | ||
</message> | ||
<message name="IDS_AI_CHAT_INFOBAR_TEXT" desc="Label for Leo AI chat permission prompt (Android)."> | ||
Allow <ph name="URL">$1<ex>search.brave.com</ex></ph> to open Leo in Brave? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Allow search.brave.com to open related Leo AI conversations in Brave?"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Allow search.brave.com to open Leo AI conversations in Brave?"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Allow search.brave.com to open Leo AI conversations in Brave?" in ab4ea07
test/data/leo/open_leo_button.html
Outdated
@@ -0,0 +1,22 @@ | |||
<!DOCTYPE html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: continue_conversation_button.html
or anything without the leo
string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the directory should be aichat as well? Internally everything should be aichat for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or are we differentiating between aichat in general and the sidebar specifically? If so I would go with aichat_sidebar or something. It's very confusing when some of the code uses leo and other parts use aichat as we discussed before @petemill
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go for open_ai_chat_button.html
for now.
Historically we have two folders under test/data, I'll do a quick follow-up after this PR to only have test/data/ai_chat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
763155e
to
be1b396
Compare
This commit also - updates permission strings - adds IOS buildflag in feature flag
[puLL-Merge] - brave/brave-core@26082 DescriptionThis pull request adds functionality to open Leo AI chat from Brave Search. The changes include new permission handling, UI modifications, and backend logic to support this feature. The implementation is primarily focused on desktop platforms, with some groundwork laid for potential future Android support. ChangesChanges
Possible Issues
Security Hotspots
Overall, this PR introduces a significant new feature with careful implementation of permissions and security checks. The main security considerations revolve around ensuring that the Leo AI chat can only be opened from legitimate Brave Search pages and that the permission system is robust. |
Resolves brave/brave-browser#41711
open_leo_from_search_480p.mov
UI was updated on search side after the above demo video was recorded, it now looks like this, with a "Save chat in Brave Leo" at upper-right corner:
See Requirements
#2
and#3
in https://docs.google.com/document/d/1idelFPpUEcKDNcyKYf3M5yw91tuIddjrlYfpaWEJjNk/edit?tab=t.0 for reference.S&P review: https://github.com/brave/reviews/issues/1776
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan:
Answer with AI
Test opt-out case:
Try the feature in a profile that hasn't opted-in to Leo, when the continue with Leo button is clicked, accept the permission prompt, Leo should be opened with opt-in screen with disclaimer, search entries should appear after opt-in.
Test private window:
Try the feature in private window, shouldn't have any actions such as opening Leo or permission prompt.