summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/extensions/api/omnibox/omnibox_api.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2022-05-12 15:59:20 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-05-25 06:57:22 +0000
commitf7eaed5286974984ba5f9e3189d8f49d03e99f81 (patch)
treecaed19b2af2024f35449fb0b781d0a25e09d4f8f /chromium/chrome/browser/extensions/api/omnibox/omnibox_api.cc
parent9729c4479fe23554eae6e6dd1f30ff488f470c84 (diff)
BASELINE: Update Chromium to 100.0.4896.167
Change-Id: I98cbeb5d7543d966ffe04d8cefded0c493a11333 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/chrome/browser/extensions/api/omnibox/omnibox_api.cc')
-rw-r--r--chromium/chrome/browser/extensions/api/omnibox/omnibox_api.cc94
1 files changed, 61 insertions, 33 deletions
diff --git a/chromium/chrome/browser/extensions/api/omnibox/omnibox_api.cc b/chromium/chrome/browser/extensions/api/omnibox/omnibox_api.cc
index 127ddf7df12..5b27df51242 100644
--- a/chromium/chrome/browser/extensions/api/omnibox/omnibox_api.cc
+++ b/chromium/chrome/browser/extensions/api/omnibox/omnibox_api.cc
@@ -16,20 +16,19 @@
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "build/build_config.h"
+#include "chrome/browser/extensions/api/omnibox/suggestion_parser.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/common/extensions/api/omnibox.h"
#include "chrome/common/extensions/api/omnibox/omnibox_handler.h"
-#include "components/omnibox/browser/omnibox_watcher.h"
+#include "components/omnibox/browser/omnibox_input_watcher.h"
+#include "components/omnibox/browser/omnibox_suggestions_watcher.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_service.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_prefs_factory.h"
-#include "extensions/browser/notification_types.h"
#include "ui/gfx/image/image.h"
namespace extensions {
@@ -113,12 +112,12 @@ bool ExtensionOmniboxEventRouter::OnInputChanged(
return false;
auto args(std::make_unique<base::ListValue>());
- args->Set(0, std::make_unique<base::Value>(input));
- args->Set(1, std::make_unique<base::Value>(suggest_id));
+ args->Append(input);
+ args->Append(suggest_id);
- auto event = std::make_unique<Event>(events::OMNIBOX_ON_INPUT_CHANGED,
- omnibox::OnInputChanged::kEventName,
- std::move(*args).TakeList(), profile);
+ auto event = std::make_unique<Event>(
+ events::OMNIBOX_ON_INPUT_CHANGED, omnibox::OnInputChanged::kEventName,
+ std::move(*args).TakeListDeprecated(), profile);
event_router->DispatchEventToExtension(extension_id, std::move(event));
return true;
}
@@ -140,21 +139,21 @@ void ExtensionOmniboxEventRouter::OnInputEntered(
active_tab_permission_granter()->GrantIfRequested(extension);
auto args(std::make_unique<base::ListValue>());
- args->Set(0, std::make_unique<base::Value>(input));
+ args->Append(input);
if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB)
- args->Set(1, std::make_unique<base::Value>(kForegroundTabDisposition));
+ args->Append(kForegroundTabDisposition);
else if (disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
- args->Set(1, std::make_unique<base::Value>(kBackgroundTabDisposition));
+ args->Append(kBackgroundTabDisposition);
else
- args->Set(1, std::make_unique<base::Value>(kCurrentTabDisposition));
+ args->Append(kCurrentTabDisposition);
- auto event = std::make_unique<Event>(events::OMNIBOX_ON_INPUT_ENTERED,
- omnibox::OnInputEntered::kEventName,
- std::move(*args).TakeList(), profile);
+ auto event = std::make_unique<Event>(
+ events::OMNIBOX_ON_INPUT_ENTERED, omnibox::OnInputEntered::kEventName,
+ std::move(*args).TakeListDeprecated(), profile);
EventRouter::Get(profile)
->DispatchEventToExtension(extension_id, std::move(event));
- OmniboxWatcher::GetForBrowserContext(profile)->NotifyInputEntered();
+ OmniboxInputWatcher::GetForBrowserContext(profile)->NotifyInputEntered();
}
// static
@@ -172,11 +171,12 @@ void ExtensionOmniboxEventRouter::OnDeleteSuggestion(
const std::string& extension_id,
const std::string& suggestion_text) {
auto args(std::make_unique<base::ListValue>());
- args->Set(0, std::make_unique<base::Value>(suggestion_text));
+ args->Append(suggestion_text);
- auto event = std::make_unique<Event>(events::OMNIBOX_ON_DELETE_SUGGESTION,
- omnibox::OnDeleteSuggestion::kEventName,
- std::move(*args).TakeList(), profile);
+ auto event =
+ std::make_unique<Event>(events::OMNIBOX_ON_DELETE_SUGGESTION,
+ omnibox::OnDeleteSuggestion::kEventName,
+ std::move(*args).TakeListDeprecated(), profile);
EventRouter::Get(profile)->DispatchEventToExtension(extension_id,
std::move(event));
@@ -277,11 +277,10 @@ ExtensionFunction::ResponseAction OmniboxSendSuggestionsFunction::Run() {
SendSuggestions::Params::Create(args()));
EXTENSION_FUNCTION_VALIDATE(params);
- content::NotificationService::current()->Notify(
- extensions::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY,
- content::Source<Profile>(
- Profile::FromBrowserContext(browser_context())->GetOriginalProfile()),
- content::Details<SendSuggestions::Params>(params.get()));
+ Profile* profile =
+ Profile::FromBrowserContext(browser_context())->GetOriginalProfile();
+ OmniboxSuggestionsWatcher::GetForBrowserContext(profile)
+ ->NotifySuggestionsReady(params.get());
return RespondNow(NoArguments());
}
@@ -291,18 +290,47 @@ ExtensionFunction::ResponseAction OmniboxSetDefaultSuggestionFunction::Run() {
SetDefaultSuggestion::Params::Create(args()));
EXTENSION_FUNCTION_VALIDATE(params);
- Profile* profile = Profile::FromBrowserContext(browser_context());
- if (SetOmniboxDefaultSuggestion(profile, extension_id(),
- params->suggestion)) {
- content::NotificationService::current()->Notify(
- extensions::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED,
- content::Source<Profile>(profile->GetOriginalProfile()),
- content::NotificationService::NoDetails());
+ if (!params->suggestion.description_styles) {
+ ParseDescriptionAndStyles(
+ params->suggestion.description,
+ base::BindOnce(
+ &OmniboxSetDefaultSuggestionFunction::OnParsedDescriptionAndStyles,
+ this));
+ return RespondLater();
}
+ SetDefaultSuggestion(params->suggestion);
return RespondNow(NoArguments());
}
+void OmniboxSetDefaultSuggestionFunction::OnParsedDescriptionAndStyles(
+ std::unique_ptr<DescriptionAndStyles> description_and_styles) {
+ if (!description_and_styles) {
+ // TODO(devlin): Provide a more descriptive error.
+ Respond(Error("Failed to parse suggestion."));
+ return;
+ }
+
+ omnibox::DefaultSuggestResult default_suggestion;
+ default_suggestion.description =
+ base::UTF16ToUTF8(description_and_styles->description);
+ default_suggestion.description_styles =
+ std::make_unique<std::vector<api::omnibox::MatchClassification>>();
+ default_suggestion.description_styles->swap(description_and_styles->styles);
+ SetDefaultSuggestion(default_suggestion);
+ Respond(NoArguments());
+}
+
+void OmniboxSetDefaultSuggestionFunction::SetDefaultSuggestion(
+ const omnibox::DefaultSuggestResult& suggestion) {
+ Profile* profile = Profile::FromBrowserContext(browser_context());
+ if (SetOmniboxDefaultSuggestion(profile, extension_id(), suggestion)) {
+ OmniboxSuggestionsWatcher::GetForBrowserContext(
+ profile->GetOriginalProfile())
+ ->NotifyDefaultSuggestionChanged();
+ }
+}
+
// This function converts style information populated by the JSON schema
// compiler into an ACMatchClassifications object.
ACMatchClassifications StyleTypesToACMatchClassifications(