Commit 8797c99e authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS Settings] Add SearchStringsProvider

This CL migrates device UI strings to a per-page provider and adds
TODOs for adding relevant search tags.

Bug: 1069849
Change-Id: Ia1c5a845ed54e377d8db6f4880759d9dca7f13b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2162106
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762086}
parent d8050c9b
......@@ -2069,6 +2069,8 @@ jumbo_static_library("ui") {
"webui/settings/chromeos/search/search_handler_factory.h",
"webui/settings/chromeos/search/settings_user_action_tracker.cc",
"webui/settings/chromeos/search/settings_user_action_tracker.h",
"webui/settings/chromeos/search_strings_provider.cc",
"webui/settings/chromeos/search_strings_provider.h",
"webui/settings/chromeos/server_printer_url_util.cc",
"webui/settings/chromeos/server_printer_url_util.h",
"webui/settings/chromeos/wallpaper_handler.cc",
......
......@@ -19,7 +19,6 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/assistant/assistant_util.h"
#include "chrome/browser/chromeos/crostini/crostini_features.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h"
#include "chrome/browser/chromeos/local_search_service/local_search_service.h"
......@@ -28,7 +27,6 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_utils.h"
#include "chrome/browser/ui/webui/chromeos/network_element_localized_strings_provider.h"
#include "chrome/browser/ui/webui/chromeos/smb_shares/smb_shares_localized_strings_provider.h"
#include "chrome/browser/ui/webui/management_ui.h"
......@@ -41,6 +39,7 @@
#include "chrome/browser/ui/webui/settings/chromeos/people_strings_provider.h"
#include "chrome/browser/ui/webui/settings/chromeos/personalization_strings_provider.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_concept.h"
#include "chrome/browser/ui/webui/settings/chromeos/search_strings_provider.h"
#include "chrome/browser/ui/webui/settings/shared_settings_localized_strings_provider.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/chrome_features.h"
......@@ -52,7 +51,6 @@
#include "chrome/grit/locale_settings.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/services/assistant/public/cpp/features.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
......@@ -746,57 +744,6 @@ void AddFilesStrings(content::WebUIDataSource* html_source) {
GetHelpUrlWithBoard(chrome::kSmbSharesLearnMoreURL));
}
void AddGoogleAssistantStrings(content::WebUIDataSource* html_source,
Profile* profile) {
static constexpr webui::LocalizedString kLocalizedStrings[] = {
{"googleAssistantPageTitle", IDS_SETTINGS_GOOGLE_ASSISTANT},
{"googleAssistantEnableContext", IDS_ASSISTANT_SCREEN_CONTEXT_TITLE},
{"googleAssistantEnableContextDescription",
IDS_ASSISTANT_SCREEN_CONTEXT_DESC},
{"googleAssistantEnableQuickAnswers",
IDS_ASSISTANT_QUICK_ANSWERS_SETTING_TITLE},
{"googleAssistantEnableQuickAnswersDescription",
IDS_ASSISTANT_QUICK_ANSWERS_SETTING_DESC},
{"googleAssistantEnableHotword",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_HOTWORD},
{"googleAssistantEnableHotwordDescription",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_HOTWORD_DESCRIPTION},
{"googleAssistantVoiceSettings",
IDS_SETTINGS_GOOGLE_ASSISTANT_VOICE_SETTINGS},
{"googleAssistantVoiceSettingsDescription",
IDS_ASSISTANT_VOICE_MATCH_RECORDING},
{"googleAssistantVoiceSettingsRetrainButton",
IDS_SETTINGS_GOOGLE_ASSISTANT_VOICE_SETTINGS_RETRAIN},
{"googleAssistantEnableHotwordWithoutDspDescription",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_HOTWORD_WITHOUT_DSP_DESCRIPTION},
{"googleAssistantEnableHotwordWithoutDspRecommended",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_HOTWORD_WITHOUT_DSP_RECOMMENDED},
{"googleAssistantEnableHotwordWithoutDspAlwaysOn",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_HOTWORD_WITHOUT_DSP_ALWAYS_ON},
{"googleAssistantEnableHotwordWithoutDspOff",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_HOTWORD_WITHOUT_DSP_OFF},
{"googleAssistantEnableNotification",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_NOTIFICATION},
{"googleAssistantEnableNotificationDescription",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_NOTIFICATION_DESCRIPTION},
{"googleAssistantLaunchWithMicOpen",
IDS_SETTINGS_GOOGLE_ASSISTANT_LAUNCH_WITH_MIC_OPEN},
{"googleAssistantLaunchWithMicOpenDescription",
IDS_SETTINGS_GOOGLE_ASSISTANT_LAUNCH_WITH_MIC_OPEN_DESCRIPTION},
{"googleAssistantSettings", IDS_SETTINGS_GOOGLE_ASSISTANT_SETTINGS},
};
AddLocalizedStringsBulk(html_source, kLocalizedStrings);
html_source->AddBoolean("hotwordDspAvailable",
chromeos::IsHotwordDspAvailable());
html_source->AddBoolean(
"voiceMatchDisabled",
chromeos::assistant::features::IsVoiceMatchDisabled());
html_source->AddBoolean(
"quickAnswersAvailable",
chromeos::features::IsQuickAnswersSettingToggleEnabled());
}
void AddPrintingStrings(content::WebUIDataSource* html_source) {
static constexpr webui::LocalizedString kLocalizedStrings[] = {
{"printingPageTitle", IDS_SETTINGS_PRINTING},
......@@ -1121,37 +1068,6 @@ void AddResetStrings(content::WebUIDataSource* html_source) {
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
}
void AddSearchStrings(content::WebUIDataSource* html_source, Profile* profile) {
static constexpr webui::LocalizedString kLocalizedStrings[] = {
{"osSearchEngineLabel", IDS_OS_SETTINGS_SEARCH_ENGINE_LABEL},
{"searchGoogleAssistant", IDS_SETTINGS_SEARCH_GOOGLE_ASSISTANT},
{"searchGoogleAssistantEnabled",
IDS_SETTINGS_SEARCH_GOOGLE_ASSISTANT_ENABLED},
{"searchGoogleAssistantDisabled",
IDS_SETTINGS_SEARCH_GOOGLE_ASSISTANT_DISABLED},
{"searchGoogleAssistantOn", IDS_SETTINGS_SEARCH_GOOGLE_ASSISTANT_ON},
{"searchGoogleAssistantOff", IDS_SETTINGS_SEARCH_GOOGLE_ASSISTANT_OFF},
};
AddLocalizedStringsBulk(html_source, kLocalizedStrings);
// NOTE: This will be false when the flag is disabled.
const bool is_assistant_allowed =
::assistant::IsAssistantAllowedForProfile(profile) ==
ash::mojom::AssistantAllowedState::ALLOWED;
html_source->AddBoolean("isAssistantAllowed", is_assistant_allowed);
html_source->AddLocalizedString("osSearchPageTitle",
is_assistant_allowed
? IDS_SETTINGS_SEARCH_AND_ASSISTANT
: IDS_SETTINGS_SEARCH);
html_source->AddString("searchExplanation",
l10n_util::GetStringFUTF16(
IDS_SETTINGS_SEARCH_EXPLANATION,
base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL)));
html_source->AddString(
"osSearchEngineTooltip",
ui::SubstituteChromeOSDeviceType(IDS_OS_SETTINGS_SEARCH_ENGINE_TOOLTIP));
}
void AddPrivacyStrings(content::WebUIDataSource* html_source) {
static constexpr webui::LocalizedString kLocalizedStrings[] = {
{"privacyPageTitle", IDS_SETTINGS_PRIVACY},
......@@ -1195,6 +1111,8 @@ OsSettingsLocalizedStringsProvider::OsSettingsLocalizedStringsProvider(
per_page_providers_.push_back(
std::make_unique<PersonalizationStringsProvider>(
profile, /*delegate=*/this, profile->GetPrefs()));
per_page_providers_.push_back(
std::make_unique<SearchStringsProvider>(profile, /*delegate=*/this));
}
OsSettingsLocalizedStringsProvider::~OsSettingsLocalizedStringsProvider() =
......@@ -1218,14 +1136,12 @@ void OsSettingsLocalizedStringsProvider::AddOsLocalizedStrings(
AddCrostiniStrings(html_source, profile);
AddDateTimeStrings(html_source);
AddFilesStrings(html_source);
AddGoogleAssistantStrings(html_source, profile);
AddLanguagesStrings(html_source);
AddPluginVmStrings(html_source, profile);
AddPrintingStrings(html_source);
AddPrivacyStrings(html_source);
AddResetStrings(html_source);
AddSearchInSettingsStrings(html_source);
AddSearchStrings(html_source, profile);
policy_indicator::AddLocalizedStrings(html_source);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/settings/chromeos/search_strings_provider.h"
#include "ash/public/cpp/assistant/assistant_state.h"
#include "base/no_destructor.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/assistant/assistant_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_utils.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/services/assistant/public/cpp/assistant_prefs.h"
#include "chromeos/services/assistant/public/cpp/features.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/chromeos/devicetype_utils.h"
namespace chromeos {
namespace settings {
namespace {
const std::vector<SearchConcept>& GetSearchPageSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
// TODO(khorimoto): Add "Search" search concepts.
});
return *tags;
}
const std::vector<SearchConcept>& GetAssistantSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
// TODO(khorimoto): Add "Assistant" search concepts.
});
return *tags;
}
const std::vector<SearchConcept>& GetAssistantOnSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
// TODO(khorimoto): Add "Assistant on" search concepts.
});
return *tags;
}
const std::vector<SearchConcept>& GetAssistantOffSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
// TODO(khorimoto): Add "Assistant off" search concepts.
});
return *tags;
}
const std::vector<SearchConcept>& GetAssistantQuickAnswersSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
// TODO(khorimoto): Add "Assistant Quick Answers" search concepts.
});
return *tags;
}
const std::vector<SearchConcept>& GetAssistantHotwordDspSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
// TODO(khorimoto): Add "Assistant hotword DSP" search concepts.
});
return *tags;
}
const std::vector<SearchConcept>& GetAssistantVoiceMatchSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
// TODO(khorimoto): Add "Assistant hotword DSP" search concepts.
});
return *tags;
}
bool IsVoiceMatchAllowed() {
return !assistant::features::IsVoiceMatchDisabled();
}
bool AreQuickAnswersAllowed() {
return features::IsQuickAnswersSettingToggleEnabled();
}
void AddGoogleAssistantStrings(content::WebUIDataSource* html_source) {
static constexpr webui::LocalizedString kLocalizedStrings[] = {
{"googleAssistantPageTitle", IDS_SETTINGS_GOOGLE_ASSISTANT},
{"googleAssistantEnableContext", IDS_ASSISTANT_SCREEN_CONTEXT_TITLE},
{"googleAssistantEnableContextDescription",
IDS_ASSISTANT_SCREEN_CONTEXT_DESC},
{"googleAssistantEnableQuickAnswers",
IDS_ASSISTANT_QUICK_ANSWERS_SETTING_TITLE},
{"googleAssistantEnableQuickAnswersDescription",
IDS_ASSISTANT_QUICK_ANSWERS_SETTING_DESC},
{"googleAssistantEnableHotword",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_HOTWORD},
{"googleAssistantEnableHotwordDescription",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_HOTWORD_DESCRIPTION},
{"googleAssistantVoiceSettings",
IDS_SETTINGS_GOOGLE_ASSISTANT_VOICE_SETTINGS},
{"googleAssistantVoiceSettingsDescription",
IDS_ASSISTANT_VOICE_MATCH_RECORDING},
{"googleAssistantVoiceSettingsRetrainButton",
IDS_SETTINGS_GOOGLE_ASSISTANT_VOICE_SETTINGS_RETRAIN},
{"googleAssistantEnableHotwordWithoutDspDescription",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_HOTWORD_WITHOUT_DSP_DESCRIPTION},
{"googleAssistantEnableHotwordWithoutDspRecommended",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_HOTWORD_WITHOUT_DSP_RECOMMENDED},
{"googleAssistantEnableHotwordWithoutDspAlwaysOn",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_HOTWORD_WITHOUT_DSP_ALWAYS_ON},
{"googleAssistantEnableHotwordWithoutDspOff",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_HOTWORD_WITHOUT_DSP_OFF},
{"googleAssistantEnableNotification",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_NOTIFICATION},
{"googleAssistantEnableNotificationDescription",
IDS_SETTINGS_GOOGLE_ASSISTANT_ENABLE_NOTIFICATION_DESCRIPTION},
{"googleAssistantLaunchWithMicOpen",
IDS_SETTINGS_GOOGLE_ASSISTANT_LAUNCH_WITH_MIC_OPEN},
{"googleAssistantLaunchWithMicOpenDescription",
IDS_SETTINGS_GOOGLE_ASSISTANT_LAUNCH_WITH_MIC_OPEN_DESCRIPTION},
{"googleAssistantSettings", IDS_SETTINGS_GOOGLE_ASSISTANT_SETTINGS},
};
AddLocalizedStringsBulk(html_source, kLocalizedStrings);
html_source->AddBoolean("hotwordDspAvailable", IsHotwordDspAvailable());
html_source->AddBoolean("voiceMatchDisabled", !IsVoiceMatchAllowed());
html_source->AddBoolean("quickAnswersAvailable", AreQuickAnswersAllowed());
}
} // namespace
SearchStringsProvider::SearchStringsProvider(Profile* profile,
Delegate* per_page_delegate)
: OsSettingsPerPageStringsProvider(profile, per_page_delegate) {
delegate()->AddSearchTags(GetSearchPageSearchConcepts());
ash::AssistantState* assistant_state = ash::AssistantState::Get();
if (IsAssistantAllowed() && assistant_state) {
delegate()->AddSearchTags(GetAssistantSearchConcepts());
assistant_state->AddObserver(this);
UpdateAssistantSearchTags();
}
}
SearchStringsProvider::~SearchStringsProvider() {
ash::AssistantState* assistant_state = ash::AssistantState::Get();
if (IsAssistantAllowed() && assistant_state)
assistant_state->RemoveObserver(this);
}
void SearchStringsProvider::AddUiStrings(
content::WebUIDataSource* html_source) {
static constexpr webui::LocalizedString kLocalizedStrings[] = {
{"osSearchEngineLabel", IDS_OS_SETTINGS_SEARCH_ENGINE_LABEL},
{"searchGoogleAssistant", IDS_SETTINGS_SEARCH_GOOGLE_ASSISTANT},
{"searchGoogleAssistantEnabled",
IDS_SETTINGS_SEARCH_GOOGLE_ASSISTANT_ENABLED},
{"searchGoogleAssistantDisabled",
IDS_SETTINGS_SEARCH_GOOGLE_ASSISTANT_DISABLED},
{"searchGoogleAssistantOn", IDS_SETTINGS_SEARCH_GOOGLE_ASSISTANT_ON},
{"searchGoogleAssistantOff", IDS_SETTINGS_SEARCH_GOOGLE_ASSISTANT_OFF},
};
AddLocalizedStringsBulk(html_source, kLocalizedStrings);
const bool is_assistant_allowed = IsAssistantAllowed();
html_source->AddBoolean("isAssistantAllowed", is_assistant_allowed);
html_source->AddLocalizedString("osSearchPageTitle",
is_assistant_allowed
? IDS_SETTINGS_SEARCH_AND_ASSISTANT
: IDS_SETTINGS_SEARCH);
html_source->AddString("searchExplanation",
l10n_util::GetStringFUTF16(
IDS_SETTINGS_SEARCH_EXPLANATION,
base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL)));
html_source->AddString(
"osSearchEngineTooltip",
ui::SubstituteChromeOSDeviceType(IDS_OS_SETTINGS_SEARCH_ENGINE_TOOLTIP));
AddGoogleAssistantStrings(html_source);
}
void SearchStringsProvider::OnAssistantConsentStatusChanged(
int consent_status) {
UpdateAssistantSearchTags();
}
void SearchStringsProvider::OnAssistantContextEnabled(bool enabled) {
UpdateAssistantSearchTags();
}
void SearchStringsProvider::OnAssistantSettingsEnabled(bool enabled) {
UpdateAssistantSearchTags();
}
void SearchStringsProvider::OnAssistantHotwordEnabled(bool enabled) {
UpdateAssistantSearchTags();
}
bool SearchStringsProvider::IsAssistantAllowed() {
// NOTE: This will be false when the flag is disabled.
return ::assistant::IsAssistantAllowedForProfile(profile()) ==
ash::mojom::AssistantAllowedState::ALLOWED;
}
void SearchStringsProvider::UpdateAssistantSearchTags() {
// Start without any Assistant search concepts, then add if needed below.
delegate()->RemoveSearchTags(GetAssistantOnSearchConcepts());
delegate()->RemoveSearchTags(GetAssistantOffSearchConcepts());
delegate()->RemoveSearchTags(GetAssistantQuickAnswersSearchConcepts());
delegate()->RemoveSearchTags(GetAssistantHotwordDspSearchConcepts());
delegate()->RemoveSearchTags(GetAssistantVoiceMatchSearchConcepts());
ash::AssistantState* assistant_state = ash::AssistantState::Get();
// The setting_enabled() function is the top-level enabled state. If this is
// off, none of the sub-features are enabled.
if (!assistant_state->settings_enabled() ||
!assistant_state->settings_enabled().value()) {
delegate()->AddSearchTags(GetAssistantOffSearchConcepts());
return;
}
delegate()->AddSearchTags(GetAssistantOnSearchConcepts());
if (AreQuickAnswersAllowed() && assistant_state->context_enabled() &&
assistant_state->context_enabled().value()) {
delegate()->AddSearchTags(GetAssistantQuickAnswersSearchConcepts());
}
if (IsHotwordDspAvailable())
delegate()->AddSearchTags(GetAssistantHotwordDspSearchConcepts());
if (IsVoiceMatchAllowed() && assistant_state->hotword_enabled() &&
assistant_state->hotword_enabled().value() &&
assistant_state->consent_status() &&
assistant_state->consent_status().value() ==
assistant::prefs::ConsentStatus::kActivityControlAccepted) {
delegate()->AddSearchTags(GetAssistantVoiceMatchSearchConcepts());
}
}
} // namespace settings
} // namespace chromeos
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_SEARCH_STRINGS_PROVIDER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_SEARCH_STRINGS_PROVIDER_H_
#include "ash/public/cpp/assistant/assistant_state_base.h"
#include "chrome/browser/ui/webui/settings/chromeos/os_settings_per_page_strings_provider.h"
namespace content {
class WebUIDataSource;
} // namespace content
namespace chromeos {
namespace settings {
// Provides UI strings and search tags for Search & Assistant settings. Search
// tags for Assistant settings are added/removed depending on whether the
// feature and relevant flags are enabled/disabled.
class SearchStringsProvider : public OsSettingsPerPageStringsProvider,
public ash::AssistantStateObserver {
public:
SearchStringsProvider(Profile* profile, Delegate* per_page_delegate);
~SearchStringsProvider() override;
private:
// OsSettingsPerPageStringsProvider:
void AddUiStrings(content::WebUIDataSource* html_source) override;
// ash::AssistantStateObserver:
void OnAssistantConsentStatusChanged(int consent_status) override;
void OnAssistantContextEnabled(bool enabled) override;
void OnAssistantSettingsEnabled(bool enabled) override;
void OnAssistantHotwordEnabled(bool enabled) override;
bool IsAssistantAllowed();
void UpdateAssistantSearchTags();
};
} // namespace settings
} // namespace chromeos
#endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_SEARCH_STRINGS_PROVIDER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment