Detect starter pack keyword mode entry and open lens overlay for '@page'
This CL creates some event handling structure around the omnibox controllers and clients so that '@page' keyword mode entry can be detected and lens overlay machinery can be invoked, e.g. to select part of the page as context. The OmniboxAction::Client is used as the main hook to OpenLensOverlay because there's a decent chance we may want to invoke the flow via an OmniboxAction in the future. For now this just invokes the context menu command, and the UX is probably heavier than we want for the omnibox. A TODO is left for setting up the lighter weight UX where the lens overlay is prepared in the background while the omnibox can continue receiving keystrokes. Bug: 401583049 Change-Id: I7d78a9e576537cc6ce16cb2205649cf24fe0d4f0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6338589 Reviewed-by: Orin Jaworski <orinj@chromium.org> Reviewed-by: Robbie Gibson <rkgibson@google.com> Reviewed-by: Nihar Majmudar <niharm@google.com> Commit-Queue: Orin Jaworski <orinj@chromium.org> Cr-Commit-Position: refs/heads/main@{#1430930}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
f9c398ad06
commit
d3bdc385be
chrome/browser/autocomplete
components/omnibox/browser
actions
mock_autocomplete_provider_client.homnibox_controller.ccomnibox_controller.homnibox_edit_model.ccios/chrome/browser/autocomplete/model
@ -573,6 +573,16 @@ bool ChromeAutocompleteProviderClient::OpenJourneys(const std::string& query) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ChromeAutocompleteProviderClient::OpenLensOverlay() {
|
||||
#if !BUILDFLAG(IS_ANDROID)
|
||||
// TODO(crbug.com/401583049): Prepare lens overlay controller directly.
|
||||
if (Browser* browser = BrowserList::GetInstance()->GetLastActive()) {
|
||||
browser->command_controller()->ExecuteCommand(
|
||||
IDC_CONTENT_CONTEXT_LENS_OVERLAY);
|
||||
}
|
||||
#endif // !BUILDFLAG(IS_ANDROID)
|
||||
}
|
||||
|
||||
void ChromeAutocompleteProviderClient::PromptPageTranslation() {
|
||||
#if !BUILDFLAG(IS_ANDROID)
|
||||
Browser* browser = BrowserList::GetInstance()->GetLastActive();
|
||||
|
@ -123,6 +123,7 @@ class ChromeAutocompleteProviderClient : public AutocompleteProviderClient {
|
||||
void CloseIncognitoWindows() override;
|
||||
void PromptPageTranslation() override;
|
||||
bool OpenJourneys(const std::string& query) override;
|
||||
void OpenLensOverlay() override;
|
||||
|
||||
// For testing.
|
||||
void set_storage_partition(content::StoragePartition* storage_partition) {
|
||||
|
@ -91,6 +91,9 @@ class OmniboxAction : public base::RefCountedThreadSafe<OmniboxAction> {
|
||||
// means that the embedder successfully opened Journeys, and the caller can
|
||||
// early exit. If this returns false, the caller should open the WebUI.
|
||||
virtual bool OpenJourneys(const std::string& query);
|
||||
|
||||
// Opens the lens overlay.
|
||||
virtual void OpenLensOverlay() = 0;
|
||||
};
|
||||
|
||||
// ExecutionContext provides the necessary structure for Action
|
||||
|
@ -185,6 +185,7 @@ class MockAutocompleteProviderClient
|
||||
MOCK_METHOD0(OpenIncognitoClearBrowsingDataDialog, void());
|
||||
MOCK_METHOD0(CloseIncognitoWindows, void());
|
||||
MOCK_METHOD0(PromptPageTranslation, void());
|
||||
MOCK_METHOD0(OpenLensOverlay, void());
|
||||
|
||||
private:
|
||||
network::TestURLLoaderFactory test_url_loader_factory_;
|
||||
|
@ -161,6 +161,13 @@ void OmniboxController::ClearPopupKeywordMode() const {
|
||||
}
|
||||
}
|
||||
|
||||
void OmniboxController::OnStarterPackKeywordModeEntered(
|
||||
TemplateURLStarterPackData::StarterPackID id) const {
|
||||
if (id == TemplateURLStarterPackData::StarterPackID::kPage) {
|
||||
autocomplete_controller_->autocomplete_provider_client()->OpenLensOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
std::u16string OmniboxController::GetHeaderForSuggestionGroup(
|
||||
omnibox::GroupId suggestion_group_id) const {
|
||||
return autocomplete_controller_->result().GetHeaderForSuggestionGroup(
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "components/omnibox/browser/autocomplete_match.h"
|
||||
#include "components/omnibox/browser/omnibox_edit_model.h"
|
||||
#include "components/prefs/pref_change_registrar.h"
|
||||
#include "components/search_engines/template_url_starter_pack_data.h"
|
||||
|
||||
class OmniboxClient;
|
||||
class OmniboxView;
|
||||
@ -69,6 +70,10 @@ class OmniboxController : public AutocompleteController::Observer {
|
||||
// Turns off keyword mode for the current match.
|
||||
void ClearPopupKeywordMode() const;
|
||||
|
||||
// Called when keyword mode is entered for a starter pack template URL.
|
||||
void OnStarterPackKeywordModeEntered(
|
||||
TemplateURLStarterPackData::StarterPackID id) const;
|
||||
|
||||
// Returns the header string associated with `suggestion_group_id`, or an
|
||||
// empty string if `suggestion_group_id` is not found in the results.
|
||||
std::u16string GetHeaderForSuggestionGroup(
|
||||
|
@ -933,6 +933,12 @@ bool OmniboxEditModel::AcceptKeyword(
|
||||
keyword_);
|
||||
EmitEnteredKeywordModeHistogram(entry_method, turl);
|
||||
|
||||
if (turl && turl->starter_pack_id() > 0) {
|
||||
controller_->OnStarterPackKeywordModeEntered(
|
||||
static_cast<TemplateURLStarterPackData::StarterPackID>(
|
||||
turl->starter_pack_id()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -104,6 +104,7 @@ class AutocompleteProviderClientImpl : public AutocompleteProviderClient {
|
||||
void OpenIncognitoClearBrowsingDataDialog() override {}
|
||||
void CloseIncognitoWindows() override {}
|
||||
void PromptPageTranslation() override {}
|
||||
void OpenLensOverlay() override {}
|
||||
|
||||
private:
|
||||
raw_ptr<ProfileIOS> profile_;
|
||||
|
Reference in New Issue
Block a user