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

Added search promotion button in omnibox #25409

Merged
merged 1 commit into from
Sep 17, 2024
Merged

Conversation

simonhong
Copy link
Member

@simonhong simonhong commented Sep 3, 2024

fix brave/brave-browser#40776

image

Resolves

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Manual test: see the linked issue
BraveLocationBarViewBrowserTest.SearchConversionButtonTest

@simonhong simonhong self-assigned this Sep 3, 2024
@simonhong simonhong added the CI/skip Do not run CI builds (except noplatform) label Sep 3, 2024
@simonhong simonhong force-pushed the search_conversion_button branch 11 times, most recently from 1ea573f to cad4c85 Compare September 11, 2024 03:07
@simonhong simonhong removed the CI/skip Do not run CI builds (except noplatform) label Sep 11, 2024
@simonhong simonhong force-pushed the search_conversion_button branch 5 times, most recently from 4586a2f to d06f456 Compare September 12, 2024 11:39
@simonhong simonhong marked this pull request as ready for review September 12, 2024 11:40
@simonhong simonhong requested review from a team as code owners September 12, 2024 11:40
@@ -36,6 +36,15 @@
add_trailing_decoration(item, /*intra_item_padding=*/0); \
}

#define BRAVE_LAYOUT_HANDLE_SEARCH_PROMOTION_BUTTON_VISIBILITY \
} \
else if (GetSearchPromotionButton() && \
Copy link
Member Author

Choose a reason for hiding this comment

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

Can't avoid this presubmit error. @goodov can you advice how should I handle this?

brave/chromium_src/chrome/browser/ui/views/location_bar/location_bar_view.cc:41:  (cpplint) If an else has a brace on one side, it should have it on both  [readability/braces] [5]

Copy link
Contributor

Choose a reason for hiding this comment

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

Would combining this line with the above help? Or does that trigger the formatter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, it's the formatter. Even with that style, still presubmit has same complaints.

Copy link
Member

Choose a reason for hiding this comment

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

// NOLINT ?

Copy link
Member Author

Choose a reason for hiding this comment

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

wow, NOLINT works! thanks.


// Unretained here is safe as |close_button| is the child of this class.
close_button->SetCallback(base::BindOnce(&PromotionButtonView::OnClosePressed,
base::Unretained(this)));
Copy link
Contributor

Choose a reason for hiding this comment

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

reported by reviewdog 🐶
[semgrep] base::Unretained is most of the time unrequited, and a weak reference is better suited for secure coding.
Consider swapping Unretained for a weak reference.
base::Unretained usage may be acceptable when a callback owner is guaranteed
to be destroyed with the object base::Unretained is pointing to, for example:

- PrefChangeRegistrar
- base::*Timer
- mojo::Receiver
- any other class member destroyed when the class is deallocated


Source: https://github.com/brave/security-action/blob/main/assets/semgrep_rules/client/chromium-uaf.yaml


Cc @thypon @goodov @iefremov


// Unretained here is safe as this callback is used by itself.
SetCallback(base::BindOnce(&PromotionButtonView::OnButtonPressed,
base::Unretained(this)));
Copy link
Contributor

Choose a reason for hiding this comment

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

reported by reviewdog 🐶
[semgrep] base::Unretained is most of the time unrequited, and a weak reference is better suited for secure coding.
Consider swapping Unretained for a weak reference.
base::Unretained usage may be acceptable when a callback owner is guaranteed
to be destroyed with the object base::Unretained is pointing to, for example:

- PrefChangeRegistrar
- base::*Timer
- mojo::Receiver
- any other class member destroyed when the class is deallocated


Source: https://github.com/brave/security-action/blob/main/assets/semgrep_rules/client/chromium-uaf.yaml


Cc @thypon @goodov @iefremov

Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

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

lgtm % nits

browser/ui/color/brave_color_mixer.cc Show resolved Hide resolved
Comment on lines +64 to +68
base::OnceClosure dismissed_callback_;
base::OnceClosure make_default_callback_;
Copy link
Contributor

Choose a reason for hiding this comment

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

I take it that its fine to have these as OnceClosures because the button hides after being interacted with?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching here.
Right, OnceClosure fits for dismissed_callback_ as this button is not shown again after dismissed.
However, make_default_callback_ should be RepeatingClosure because we show this button again
if user set to non brave search again.
@rebron when user clicks this button, brave search is set as a default and not set dismissed bit.
So, user will see this promotion button again if user change to another search provider again.
Is this what we want?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't show the promotion button again if the user already set or dismissed it already.

@@ -36,6 +36,15 @@
add_trailing_decoration(item, /*intra_item_padding=*/0); \
}

#define BRAVE_LAYOUT_HANDLE_SEARCH_PROMOTION_BUTTON_VISIBILITY \
} \
else if (GetSearchPromotionButton() && \
Copy link
Contributor

Choose a reason for hiding this comment

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

Would combining this line with the above help? Or does that trigger the formatter?


// Unretained here is safe as |close_button| is the child of this class.
close_button->SetCallback(base::BindOnce(&PromotionButtonView::OnClosePressed,
base::Unretained(this)));
Copy link
Contributor

Choose a reason for hiding this comment

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

reported by reviewdog 🐶
[semgrep] base::Unretained is most of the time unrequited, and a weak reference is better suited for secure coding.
Consider swapping Unretained for a weak reference.
base::Unretained usage may be acceptable when a callback owner is guaranteed
to be destroyed with the object base::Unretained is pointing to, for example:

- PrefChangeRegistrar
- base::*Timer
- mojo::Receiver
- any other class member destroyed when the class is deallocated


Source: https://github.com/brave/security-action/blob/main/assets/semgrep_rules/client/chromium-uaf.yaml


Cc @thypon @goodov @iefremov

}
selected_keyword_view_->SetCustomImage(image);
}
+ BRAVE_LAYOUT_HANDLE_SEARCH_PROMOTION_BUTTON_VISIBILITY
Copy link
Member

Choose a reason for hiding this comment

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

nit: BRAVE_LOCATION_BAR_VIEW_LAYOUT_... (all defines in this file can be updated).

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Collaborator

@mkarolin mkarolin left a comment

Choose a reason for hiding this comment

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

strings++

Copy link
Contributor

[puLL-Merge] - brave/brave-core@25409

Description

This PR adds a new search conversion promotion button to the location bar in Brave browser. The button aims to encourage users to switch to Brave Search as their default search engine.

Changes

Changes

  1. app/brave_generated_resources.grd:

    • Added a new message string for the search conversion promotion button label.
  2. app/theme/brave_theme_resources.grd:

    • Added a new image resource for the Brave Search icon in the conversion button.
  3. browser/ui/BUILD.gn:

    • Added new source files for the promotion button controller and view.
  4. browser/ui/color/brave_color_id.h and browser/ui/color/brave_color_mixer.cc:

    • Added new color definitions for the search conversion button.
  5. browser/ui/views/location_bar/brave_location_bar_view.cc and .h:

    • Integrated the new promotion button into the location bar view.
    • Added logic to show/hide the button based on certain conditions.
  6. New files:

    • browser/ui/views/location_bar/brave_search_conversion/promotion_button_controller.cc and .h:
      • Implements the controller logic for the promotion button.
    • browser/ui/views/location_bar/brave_search_conversion/promotion_button_view.cc and .h:
      • Implements the view for the promotion button.
  7. browser/ui/views/location_bar/brave_location_bar_view_browsertest.cc:

    • Added browser tests for the new search conversion button functionality.
  8. components/brave_search_conversion/features.cc and .h:

    • Added a new feature flag for the omnibox promotion button.
  9. components/vector_icons/BUILD.gn:

    • Added new vector icons for the promotion button.
  10. patches/chrome-browser-ui-views-location_bar-location_bar_view.cc.patch:

    • Modified the layout of the location bar to include the new promotion button.
  11. test/BUILD.gn:

    • Added the new browser tests to the build configuration.

Possible Issues

  1. The animation for the promotion button expansion might cause performance issues on low-end devices.
  2. The button's visibility logic might interfere with other location bar elements in certain scenarios.

Security Hotspots

None identified. The changes primarily involve UI elements and don't directly interact with sensitive data or security-critical components.

@simonhong simonhong merged commit 5287f50 into master Sep 17, 2024
17 checks passed
@simonhong simonhong deleted the search_conversion_button branch September 17, 2024 07:11
@github-actions github-actions bot added this to the 1.72.x - Nightly milestone Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add search promotion button in omnibox
7 participants