Commit d273c844 authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS Settings] Add BluetoothStringsProvider

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

Bug: 1069849
Change-Id: I3ab1680691b10bf1b41f01e4bbee7974106700b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2146287
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759094}
parent 4dfe5a31
...@@ -1989,6 +1989,8 @@ jumbo_static_library("ui") { ...@@ -1989,6 +1989,8 @@ jumbo_static_library("ui") {
"webui/settings/chromeos/android_apps_handler.h", "webui/settings/chromeos/android_apps_handler.h",
"webui/settings/chromeos/app_management/app_management_page_handler_factory.cc", "webui/settings/chromeos/app_management/app_management_page_handler_factory.cc",
"webui/settings/chromeos/app_management/app_management_page_handler_factory.h", "webui/settings/chromeos/app_management/app_management_page_handler_factory.h",
"webui/settings/chromeos/bluetooth_strings_provider.cc",
"webui/settings/chromeos/bluetooth_strings_provider.h",
"webui/settings/chromeos/calculator/size_calculator.cc", "webui/settings/chromeos/calculator/size_calculator.cc",
"webui/settings/chromeos/calculator/size_calculator.h", "webui/settings/chromeos/calculator/size_calculator.h",
"webui/settings/chromeos/change_picture_handler.cc", "webui/settings/chromeos/change_picture_handler.cc",
......
// 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/bluetooth_strings_provider.h"
#include "base/bind.h"
#include "base/no_destructor.h"
#include "chrome/browser/ui/webui/chromeos/bluetooth_dialog_localized_strings_provider.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/web_ui_data_source.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "device/bluetooth/strings/grit/bluetooth_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/webui/web_ui_util.h"
namespace chromeos {
namespace settings {
namespace {
const std::vector<SearchConcept>& GetBluetoothSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
// TODO(khorimoto): Add "Bluetooth" search concepts.
});
return *tags;
}
const std::vector<SearchConcept>& GetBluetoothOnSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
// TODO(khorimoto): Add "Bluetooth on" search concepts.
});
return *tags;
}
const std::vector<SearchConcept>& GetBluetoothOffSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
// TODO(khorimoto): Add "Bluetooth off" search concepts.
});
return *tags;
}
} // namespace
BluetoothStringsProvider::BluetoothStringsProvider(Profile* profile,
Delegate* per_page_delegate)
: OsSettingsPerPageStringsProvider(profile, per_page_delegate) {
// Note: May be uninitialized in tests.
if (bluez::BluezDBusManager::IsInitialized()) {
device::BluetoothAdapterFactory::GetAdapter(
base::Bind(&BluetoothStringsProvider::OnFetchBluetoothAdapter,
weak_ptr_factory_.GetWeakPtr()));
}
}
BluetoothStringsProvider::~BluetoothStringsProvider() {
if (bluetooth_adapter_)
bluetooth_adapter_->RemoveObserver(this);
}
void BluetoothStringsProvider::AddUiStrings(
content::WebUIDataSource* html_source) const {
static constexpr webui::LocalizedString kLocalizedStrings[] = {
{"bluetoothConnected", IDS_SETTINGS_BLUETOOTH_CONNECTED},
{"bluetoothConnectedWithBattery",
IDS_SETTINGS_BLUETOOTH_CONNECTED_WITH_BATTERY},
{"bluetoothConnecting", IDS_SETTINGS_BLUETOOTH_CONNECTING},
{"bluetoothDeviceListPaired", IDS_SETTINGS_BLUETOOTH_DEVICE_LIST_PAIRED},
{"bluetoothDeviceListUnpaired",
IDS_SETTINGS_BLUETOOTH_DEVICE_LIST_UNPAIRED},
{"bluetoothConnect", IDS_SETTINGS_BLUETOOTH_CONNECT},
{"bluetoothDisconnect", IDS_SETTINGS_BLUETOOTH_DISCONNECT},
{"bluetoothToggleA11yLabel",
IDS_SETTINGS_BLUETOOTH_TOGGLE_ACCESSIBILITY_LABEL},
{"bluetoothExpandA11yLabel",
IDS_SETTINGS_BLUETOOTH_EXPAND_ACCESSIBILITY_LABEL},
{"bluetoothNoDevices", IDS_SETTINGS_BLUETOOTH_NO_DEVICES},
{"bluetoothNoDevicesFound", IDS_SETTINGS_BLUETOOTH_NO_DEVICES_FOUND},
{"bluetoothNotConnected", IDS_SETTINGS_BLUETOOTH_NOT_CONNECTED},
{"bluetoothPageTitle", IDS_SETTINGS_BLUETOOTH},
{"bluetoothPairDevicePageTitle",
IDS_SETTINGS_BLUETOOTH_PAIR_DEVICE_TITLE},
{"bluetoothRemove", IDS_SETTINGS_BLUETOOTH_REMOVE},
{"bluetoothPrimaryUserControlled",
IDS_SETTINGS_BLUETOOTH_PRIMARY_USER_CONTROLLED},
{"bluetoothDeviceType_computer",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_COMPUTER},
{"bluetoothDeviceType_phone",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_PHONE},
{"bluetoothDeviceType_modem",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_MODEM},
{"bluetoothDeviceType_audio",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_AUDIO},
{"bluetoothDeviceType_carAudio",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_CAR_AUDIO},
{"bluetoothDeviceType_video",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_VIDEO},
{"bluetoothDeviceType_peripheral",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_PERIPHERAL},
{"bluetoothDeviceType_joystick",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_JOYSTICK},
{"bluetoothDeviceType_gamepad",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_GAMEPAD},
{"bluetoothDeviceType_keyboard",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_KEYBOARD},
{"bluetoothDeviceType_mouse",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_MOUSE},
{"bluetoothDeviceType_tablet",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_TABLET},
{"bluetoothDeviceType_keyboardMouseCombo",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_KEYBOARD_MOUSE_COMBO},
{"bluetoothDeviceType_unknown",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_UNKNOWN},
};
AddLocalizedStringsBulk(html_source, kLocalizedStrings);
chromeos::bluetooth_dialog::AddLocalizedStrings(html_source);
}
void BluetoothStringsProvider::AdapterPresentChanged(
device::BluetoothAdapter* adapter,
bool present) {
UpdateSearchTags();
}
void BluetoothStringsProvider::AdapterPoweredChanged(
device::BluetoothAdapter* adapter,
bool powered) {
UpdateSearchTags();
}
void BluetoothStringsProvider::OnFetchBluetoothAdapter(
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter) {
bluetooth_adapter_ = bluetooth_adapter;
bluetooth_adapter_->AddObserver(this);
UpdateSearchTags();
}
void BluetoothStringsProvider::UpdateSearchTags() {
// Start with no search tags, then add them below if appropriate.
delegate()->RemoveSearchTags(GetBluetoothSearchConcepts());
delegate()->RemoveSearchTags(GetBluetoothOnSearchConcepts());
delegate()->RemoveSearchTags(GetBluetoothOffSearchConcepts());
if (!bluetooth_adapter_->IsPresent())
return;
delegate()->AddSearchTags(GetBluetoothSearchConcepts());
if (bluetooth_adapter_->IsPowered())
delegate()->AddSearchTags(GetBluetoothOnSearchConcepts());
else
delegate()->AddSearchTags(GetBluetoothOffSearchConcepts());
}
} // 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_BLUETOOTH_STRINGS_PROVIDER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_BLUETOOTH_STRINGS_PROVIDER_H_
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/webui/settings/chromeos/os_settings_per_page_strings_provider.h"
#include "device/bluetooth/bluetooth_adapter.h"
namespace content {
class WebUIDataSource;
} // namespace content
namespace chromeos {
namespace settings {
// Provides UI strings and search tags for Bluetooth settings. Different search
// tags are registered depending on whether the device has a Bluetooth chip and
// whether it is turned on or off.
class BluetoothStringsProvider : public OsSettingsPerPageStringsProvider,
public device::BluetoothAdapter::Observer {
public:
BluetoothStringsProvider(Profile* profile, Delegate* per_page_delegate);
~BluetoothStringsProvider() override;
private:
// OsSettingsPerPageStringsProvider:
void AddUiStrings(content::WebUIDataSource* html_source) const override;
// device::BluetoothAdapter::Observer:
void AdapterPresentChanged(device::BluetoothAdapter* adapter,
bool present) override;
void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
bool powered) override;
void OnFetchBluetoothAdapter(
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter);
void UpdateSearchTags();
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_;
base::WeakPtrFactory<BluetoothStringsProvider> weak_ptr_factory_{this};
};
} // namespace settings
} // namespace chromeos
#endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_BLUETOOTH_STRINGS_PROVIDER_H_
...@@ -34,11 +34,11 @@ ...@@ -34,11 +34,11 @@
#include "chrome/browser/supervised_user/supervised_user_service.h" #include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h" #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_utils.h" #include "chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_utils.h"
#include "chrome/browser/ui/webui/chromeos/bluetooth_dialog_localized_strings_provider.h"
#include "chrome/browser/ui/webui/chromeos/network_element_localized_strings_provider.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/chromeos/smb_shares/smb_shares_localized_strings_provider.h"
#include "chrome/browser/ui/webui/management_ui.h" #include "chrome/browser/ui/webui/management_ui.h"
#include "chrome/browser/ui/webui/policy_indicator_localized_strings_provider.h" #include "chrome/browser/ui/webui/policy_indicator_localized_strings_provider.h"
#include "chrome/browser/ui/webui/settings/chromeos/bluetooth_strings_provider.h"
#include "chrome/browser/ui/webui/settings/chromeos/internet_strings_provider.h" #include "chrome/browser/ui/webui/settings/chromeos/internet_strings_provider.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_concept.h" #include "chrome/browser/ui/webui/settings/chromeos/search/search_concept.h"
#include "chrome/browser/ui/webui/settings/shared_settings_localized_strings_provider.h" #include "chrome/browser/ui/webui/settings/shared_settings_localized_strings_provider.h"
...@@ -63,7 +63,6 @@ ...@@ -63,7 +63,6 @@
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "device/bluetooth/strings/grit/bluetooth_strings.h"
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
#include "ui/accessibility/accessibility_switches.h" #include "ui/accessibility/accessibility_switches.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -931,63 +930,6 @@ void AddParentalControlStrings(content::WebUIDataSource* html_source, ...@@ -931,63 +930,6 @@ void AddParentalControlStrings(content::WebUIDataSource* html_source,
} }
} }
void AddBluetoothStrings(content::WebUIDataSource* html_source) {
static constexpr webui::LocalizedString kLocalizedStrings[] = {
{"bluetoothConnected", IDS_SETTINGS_BLUETOOTH_CONNECTED},
{"bluetoothConnectedWithBattery",
IDS_SETTINGS_BLUETOOTH_CONNECTED_WITH_BATTERY},
{"bluetoothConnecting", IDS_SETTINGS_BLUETOOTH_CONNECTING},
{"bluetoothDeviceListPaired", IDS_SETTINGS_BLUETOOTH_DEVICE_LIST_PAIRED},
{"bluetoothDeviceListUnpaired",
IDS_SETTINGS_BLUETOOTH_DEVICE_LIST_UNPAIRED},
{"bluetoothConnect", IDS_SETTINGS_BLUETOOTH_CONNECT},
{"bluetoothDisconnect", IDS_SETTINGS_BLUETOOTH_DISCONNECT},
{"bluetoothToggleA11yLabel",
IDS_SETTINGS_BLUETOOTH_TOGGLE_ACCESSIBILITY_LABEL},
{"bluetoothExpandA11yLabel",
IDS_SETTINGS_BLUETOOTH_EXPAND_ACCESSIBILITY_LABEL},
{"bluetoothNoDevices", IDS_SETTINGS_BLUETOOTH_NO_DEVICES},
{"bluetoothNoDevicesFound", IDS_SETTINGS_BLUETOOTH_NO_DEVICES_FOUND},
{"bluetoothNotConnected", IDS_SETTINGS_BLUETOOTH_NOT_CONNECTED},
{"bluetoothPageTitle", IDS_SETTINGS_BLUETOOTH},
{"bluetoothPairDevicePageTitle",
IDS_SETTINGS_BLUETOOTH_PAIR_DEVICE_TITLE},
{"bluetoothRemove", IDS_SETTINGS_BLUETOOTH_REMOVE},
{"bluetoothPrimaryUserControlled",
IDS_SETTINGS_BLUETOOTH_PRIMARY_USER_CONTROLLED},
{"bluetoothDeviceType_computer",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_COMPUTER},
{"bluetoothDeviceType_phone",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_PHONE},
{"bluetoothDeviceType_modem",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_MODEM},
{"bluetoothDeviceType_audio",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_AUDIO},
{"bluetoothDeviceType_carAudio",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_CAR_AUDIO},
{"bluetoothDeviceType_video",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_VIDEO},
{"bluetoothDeviceType_peripheral",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_PERIPHERAL},
{"bluetoothDeviceType_joystick",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_JOYSTICK},
{"bluetoothDeviceType_gamepad",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_GAMEPAD},
{"bluetoothDeviceType_keyboard",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_KEYBOARD},
{"bluetoothDeviceType_mouse",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_MOUSE},
{"bluetoothDeviceType_tablet",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_TABLET},
{"bluetoothDeviceType_keyboardMouseCombo",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_KEYBOARD_MOUSE_COMBO},
{"bluetoothDeviceType_unknown",
IDS_BLUETOOTH_ACCESSIBILITY_DEVICE_TYPE_UNKNOWN},
};
AddLocalizedStringsBulk(html_source, kLocalizedStrings);
chromeos::bluetooth_dialog::AddLocalizedStrings(html_source);
}
void AddChromeOSUserStrings(content::WebUIDataSource* html_source, void AddChromeOSUserStrings(content::WebUIDataSource* html_source,
Profile* profile) { Profile* profile) {
user_manager::UserManager* user_manager = user_manager::UserManager::Get(); user_manager::UserManager* user_manager = user_manager::UserManager::Get();
...@@ -2086,6 +2028,8 @@ OsSettingsLocalizedStringsProvider::OsSettingsLocalizedStringsProvider( ...@@ -2086,6 +2028,8 @@ OsSettingsLocalizedStringsProvider::OsSettingsLocalizedStringsProvider(
// TODO(khorimoto): Add providers for the remaining pages. // TODO(khorimoto): Add providers for the remaining pages.
per_page_providers_.push_back( per_page_providers_.push_back(
std::make_unique<InternetStringsProvider>(profile, /*delegate=*/this)); std::make_unique<InternetStringsProvider>(profile, /*delegate=*/this));
per_page_providers_.push_back(
std::make_unique<BluetoothStringsProvider>(profile, /*delegate=*/this));
} }
OsSettingsLocalizedStringsProvider::~OsSettingsLocalizedStringsProvider() = OsSettingsLocalizedStringsProvider::~OsSettingsLocalizedStringsProvider() =
...@@ -2104,7 +2048,6 @@ void OsSettingsLocalizedStringsProvider::AddOsLocalizedStrings( ...@@ -2104,7 +2048,6 @@ void OsSettingsLocalizedStringsProvider::AddOsLocalizedStrings(
AddAndroidAppStrings(html_source); AddAndroidAppStrings(html_source);
AddAppManagementStrings(html_source); AddAppManagementStrings(html_source);
AddAppsStrings(html_source); AddAppsStrings(html_source);
AddBluetoothStrings(html_source);
AddChromeOSUserStrings(html_source, profile); AddChromeOSUserStrings(html_source, profile);
AddCommonStrings(html_source, profile); AddCommonStrings(html_source, profile);
AddCrostiniStrings(html_source, profile); AddCrostiniStrings(html_source, profile);
......
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