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

Omnibox Command Palette #16947

Merged
merged 10 commits into from
Mar 31, 2023
Merged

Omnibox Command Palette #16947

merged 10 commits into from
Mar 31, 2023

Conversation

fallaciousreasoning
Copy link
Contributor

@fallaciousreasoning fallaciousreasoning commented Feb 1, 2023

Resolves brave/brave-browser#28178

Adds a prototype command palette in the Omnibox. Behind the Chromium brave://flags/#quick-commands flag. Note: This flag is set to expire in M111 so you might need to also enable the brave://flags/#temporary-unexpire-flags-m110 flag if you're running a recent version of Brave.

The crbug issue for this feature is here: https://bugs.chromium.org/p/chromium/issues/detail?id=1014639

commander-demo.webm

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • 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 lint, 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:

  1. Enable the brave://flags#quick-commands flag (if not present enable the Temporarily Enable M110 flags)
  2. Press Ctrl+Space
  3. The Omnibox should focus, and a list of available commands should be visible
  4. Type Create tab and select the Create new tab command. A new tab should open
  5. Press Ctrl+Space
  6. Type Move window and select Move tab to new window. The tab should move to a new window
  7. Navigate to https://readr.nz
  8. Press Ctrl+Space
  9. Type Move window and select Move tabs to window...
  10. Select the New tab (or whatever your original window was called).
  11. The readr.nz tab should move back to the original window.

@github-actions github-actions bot added the potential-layer-violation-fixes This PR touches a BUILD.gn file with check_includes=false label Feb 1, 2023
@fallaciousreasoning fallaciousreasoning force-pushed the commands-search branch 2 times, most recently from f802607 to e81a566 Compare February 1, 2023 03:12
@fallaciousreasoning fallaciousreasoning marked this pull request as ready for review February 1, 2023 03:48
Copy link
Contributor

@sangwoo108 sangwoo108 left a comment

Choose a reason for hiding this comment

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

@fallaciousreasoning , this is a awesome work! I've been craving for a feature like this on omnibox. I'm still loading the context of codes here so might be wrong about some comments.

browser/ui/commander/command_centre.h Outdated Show resolved Hide resolved
browser/ui/commander/command_centre.h Outdated Show resolved Hide resolved
components/commander/common/commander_url.cc Outdated Show resolved Hide resolved
components/commander/common/constants.h Outdated Show resolved Hide resolved
components/commander/common/commander_url.cc Outdated Show resolved Hide resolved
components/commander/common/commander_model.h Outdated Show resolved Hide resolved
components/omnibox/browser/brave_omnibox_edit_model.cc Outdated Show resolved Hide resolved
@fallaciousreasoning
Copy link
Contributor Author

Sorry ssangwoo, I've only got to about half your feedback so far!

Copy link
Contributor

@sangwoo108 sangwoo108 left a comment

Choose a reason for hiding this comment

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

Sorry ssangwoo, I've only got to about half your feedback so far!

No worries, I know I commented a lot 😭 I hope my new comments doesn't feel overwhelming.

browser/ui/commander/command_centre.cc Outdated Show resolved Hide resolved
browser/ui/commander/command_centre.cc Outdated Show resolved Hide resolved
browser/ui/commander/command_centre.cc Outdated Show resolved Hide resolved
browser/ui/commander/command_centre.cc Outdated Show resolved Hide resolved
browser/ui/commander/command_centre.cc Outdated Show resolved Hide resolved
components/commander/common/commander_model.cc Outdated Show resolved Hide resolved
components/commander/common/commander_url.cc Outdated Show resolved Hide resolved
components/commander/common/commander_url.cc Outdated Show resolved Hide resolved
components/commander/common/commander_url.h Outdated Show resolved Hide resolved
components/omnibox/browser/commander_provider.cc Outdated Show resolved Hide resolved
@fallaciousreasoning
Copy link
Contributor Author

Nah, thanks heaps for all your feedback @sangwoo108! You're my primary source of C++ tips & tricks 😆

browser/ui/commander/commander_service.cc Outdated Show resolved Hide resolved
browser/ui/commander/commander_service.cc Outdated Show resolved Hide resolved
if (!browser) {
return nullptr;
}
return browser->window()->GetLocationBar()->GetOmniboxView();
Copy link
Member

Choose a reason for hiding this comment

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

does window() always valid on MacOS?

Copy link
Contributor Author

@fallaciousreasoning fallaciousreasoning Mar 27, 2023

Choose a reason for hiding this comment

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

The only comment I see on window is this one:

  // |window()| will return NULL if called before |CreateBrowserWindow()|
  // is done.

but that doesn't mean it can't be. Maybe I'll add a CHECK?

browser/ui/commander/commander_service.cc Outdated Show resolved Hide resolved
browser/ui/commander/commander_service_factory.cc Outdated Show resolved Hide resolved
AutocompleteController* controller) {
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
if (commander::CommanderEnabled()) {
providers.push_back(new commander::CommanderProvider(
Copy link
Member

Choose a reason for hiding this comment

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

std::make_unique

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed this to base::MakeRefCounted but all the other providers are added via new ..... Should they be updated (in a future PR)? In the Chromium file they're all added/created via new too, so I almost feel this should be left as is?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, usually we should prefer make_foo over bare "new" if possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

I almost forgot why, but this post reminded me why 😄

https://herbsutter.com/2013/05/29/gotw-89-solution-smart-pointers/

  • make_unique is more robust to exceptions
  • Potential leak, which can be caused by expression order, can be prevented

components/commander/common/commander_frontend_delegate.h Outdated Show resolved Hide resolved
@fallaciousreasoning fallaciousreasoning force-pushed the commands-search branch 2 times, most recently from e43bc83 to b03c25a Compare March 30, 2023 20:09

#include "base/strings/string_util.h"

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

please replace all of these !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS) guards with a dedicated buildflag for this feature

@@ -36,3 +38,15 @@ brave_components_omnibox_browser_deps = [
"//components/prefs",
"//url",
]

if (!is_android && !is_ios) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above, please add a dedicated buildflag

# 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/.

assert(!is_android && !is_ios)
Copy link
Collaborator

Choose a reason for hiding this comment

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

replace with dedicated buildflag. In general os guards should only be used directly when you are guarding os-specific code. In other cases you should use them indirectly to set the dedicated buildflag value


namespace commander {

bool CommanderEnabled() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

IsCommanderEnabled, but this pattern is generally only used when there are more conditions than just a single buildflag so I would probably remove this


#include "brave/components/commander/common/constants.h"

#include "base/strings/string_piece.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is unused

#include <string>
#include <utility>

#include "base/functional/bind.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

a lot of these includes don't appear to be used

#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "brave/components/commander/browser/commander_frontend_delegate.h"
#include "brave/components/commander/browser/commander_item_model.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this include used here? Also it seems like many of these could be forward declarations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
potential-layer-violation-fixes This PR touches a BUILD.gn file with check_includes=false
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prototype Command Palette in the Omnibox
7 participants