Commit a9f4d599 authored by Callistus's avatar Callistus Committed by Commit Bot

Implemented logic to provide feature flags for the Help App.

- For some of the flags, I've extended HelpAppUIDelegate to contain
logic that depends on code in "chrome/".
- Moved existing code to obtain board name, customization id and
version to HelpAppUIDelegate.


Bug: b/140150028
Change-Id: Ie2cbbdacf84692724a69c2b106f703ceadeb7a74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2073438
Commit-Queue: Callistus Tan <callistus@google.com>
Auto-Submit: Callistus Tan <callistus@google.com>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748539}
parent bf3194ad
......@@ -63,6 +63,7 @@ source_set("chromeos") {
"//apps",
"//ash",
"//ash/public/cpp",
"//ash/public/mojom",
"//ash/system/message_center/arc",
"//build:branding_buildflags",
"//chrome/app:command_ids",
......@@ -220,6 +221,7 @@ source_set("chromeos") {
"//components/policy/core/common",
"//components/policy/core/common:common_constants",
"//components/pref_registry",
"//components/prefs",
"//components/printing/common:mojo_interfaces",
"//components/proxy_config",
"//components/quirks",
......
......@@ -4,9 +4,21 @@
#include "chrome/browser/chromeos/web_applications/chrome_help_app_ui_delegate.h"
#include "ash/public/cpp/assistant/assistant_state.h"
#include "ash/public/cpp/tablet_mode.h"
#include "ash/public/mojom/assistant_state_controller.mojom.h"
#include "base/system/sys_info.h"
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/assistant/assistant_util.h"
#include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chromeos/components/help_app_ui/url_constants.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "chromeos/system/statistics_provider.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/events/devices/device_data_manager.h"
#include "url/gurl.h"
ChromeHelpAppUIDelegate::ChromeHelpAppUIDelegate(content::WebUI* web_ui)
......@@ -25,3 +37,47 @@ base::Optional<std::string> ChromeHelpAppUIDelegate::OpenFeedbackDialog() {
std::string() /* category_tag */, std::string() /* extra_diagnostics */);
return base::nullopt;
}
void ChromeHelpAppUIDelegate::PopulateLoadTimeData(
content::WebUIDataSource* source) {
// Add strings that can be pulled in.
source->AddString("boardName", base::SysInfo::GetLsbReleaseBoard());
source->AddString("chromeOSVersion", base::SysInfo::OperatingSystemVersion());
std::string customization_id;
chromeos::system::StatisticsProvider* provider =
chromeos::system::StatisticsProvider::GetInstance();
// Customization id does not exist for browser tests, but it is fine for this
// to be an empty string.
provider->GetMachineStatistic(chromeos::system::kCustomizationIdKey,
&customization_id);
source->AddString("customizationId", customization_id);
Profile* profile = Profile::FromWebUI(web_ui_);
PrefService* pref_service = profile->GetPrefs();
// Checks if any of the MultiDevice features (e.g. Instant Tethering,
// Messages, Smart Lock) is allowed on this device.
source->AddBoolean(
"multiDeviceFeaturesAllowed",
chromeos::multidevice_setup::AreAnyMultiDeviceFeaturesAllowed(
pref_service));
source->AddBoolean("tabletMode", ash::TabletMode::Get()->InTabletMode());
// Checks if there are active touch screens.
source->AddBoolean(
"hasTouchScreen",
ui::DeviceDataManager::GetInstance()->GetTouchscreenDevices().empty());
// Checks if the Google Assistant is allowed on this device by going through
// policies.
ash::mojom::AssistantAllowedState assistant_allowed_state =
assistant::IsAssistantAllowedForProfile(profile);
source->AddBoolean(
"assistantAllowed",
assistant_allowed_state == ash::mojom::AssistantAllowedState::ALLOWED);
source->AddBoolean(
"assistantEnabled",
ash::AssistantState::Get()->settings_enabled().value_or(false));
source->AddBoolean("playStoreEnabled",
arc::IsArcPlayStoreEnabledForProfile(profile));
source->AddBoolean("pinEnabled",
chromeos::quick_unlock::IsPinEnabled(pref_service));
}
......@@ -25,6 +25,7 @@ class ChromeHelpAppUIDelegate : public HelpAppUIDelegate {
// HelpAppUIDelegate:
base::Optional<std::string> OpenFeedbackDialog() override;
void PopulateLoadTimeData(content::WebUIDataSource* source) override;
private:
content::WebUI* web_ui_; // Owns |this|.
......
......@@ -51,7 +51,8 @@ HelpAppUI::HelpAppUI(content::WebUI* web_ui,
host_source->OverrideContentSecurityPolicyChildSrc(csp);
content::WebUIDataSource* untrusted_source =
CreateHelpAppUntrustedDataSource();
CreateHelpAppUntrustedDataSource(delegate_.get());
content::WebUIDataSource::Add(browser_context, untrusted_source);
// Add ability to request chrome-untrusted: URLs.
......
......@@ -9,6 +9,10 @@
#include "base/optional.h"
namespace content {
class WebUIDataSource;
}
// A delegate which exposes browser functionality from //chrome to the help app
// ui page handler.
class HelpAppUIDelegate {
......@@ -19,6 +23,10 @@ class HelpAppUIDelegate {
// Returns an optional error message if unable to open the dialog or nothing
// if the dialog was determined to have opened successfully.
virtual base::Optional<std::string> OpenFeedbackDialog() = 0;
// Takes a WebUIDataSource, and adds device flags (e.g. board name) and
// feature flags (e.g. Google Assistant).
virtual void PopulateLoadTimeData(content::WebUIDataSource* source) = 0;
};
#endif // CHROMEOS_COMPONENTS_HELP_APP_UI_HELP_APP_UI_DELEGATE_H_
......@@ -4,19 +4,19 @@
#include "chromeos/components/help_app_ui/help_app_untrusted_ui.h"
#include "base/system/sys_info.h"
#include "chromeos/components/help_app_ui/help_app_ui_delegate.h"
#include "chromeos/components/help_app_ui/url_constants.h"
#include "chromeos/grit/chromeos_help_app_bundle_resources.h"
#include "chromeos/grit/chromeos_help_app_bundle_resources_map.h"
#include "chromeos/grit/chromeos_help_app_resources.h"
#include "chromeos/system/statistics_provider.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/resources/grit/webui_resources.h"
namespace chromeos {
// static
content::WebUIDataSource* CreateHelpAppUntrustedDataSource() {
content::WebUIDataSource* CreateHelpAppUntrustedDataSource(
HelpAppUIDelegate* delegate) {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(kChromeUIHelpAppUntrustedURL);
source->AddResourcePath("app.html", IDR_HELP_APP_APP_HTML);
......@@ -29,17 +29,10 @@ content::WebUIDataSource* CreateHelpAppUntrustedDataSource() {
kChromeosHelpAppBundleResources[i].value);
}
// Add strings that can be pulled in.
source->AddString("boardName", base::SysInfo::GetLsbReleaseBoard());
source->AddString("chromeOSVersion", base::SysInfo::OperatingSystemVersion());
std::string customization_id;
chromeos::system::StatisticsProvider* provider =
chromeos::system::StatisticsProvider::GetInstance();
provider->GetMachineStatistic(chromeos::system::kCustomizationIdKey,
&customization_id);
source->AddString("customizationId", customization_id);
source->UseStringsJs();
// Add device and feature flags.
delegate->PopulateLoadTimeData(source);
source->UseStringsJs();
source->AddFrameAncestor(GURL(kChromeUIHelpAppURL));
return source;
}
......
......@@ -9,9 +9,12 @@ namespace content {
class WebUIDataSource;
}
class HelpAppUIDelegate;
namespace chromeos {
// The data source creation for chrome-untrusted://help-app.
content::WebUIDataSource* CreateHelpAppUntrustedDataSource();
content::WebUIDataSource* CreateHelpAppUntrustedDataSource(
HelpAppUIDelegate* delegate);
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_HELP_APP_UI_HELP_APP_UNTRUSTED_UI_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