Commit 2f833e47 authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Commit Bot

Add helper IsEnterpriseManaged() for c/b/ui/webui

Mostly consolidate common pattern of declaring a pointer to the ChromeOS
browser policy connector into a helper function to be called within the
WebUI code.

Simultaneously, support detection for Windows and Apple devices.

Change-Id: Ib92d6e3ae88680cba1ff119bfa00391550a75388
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346936
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796692}
parent 5246cdb2
......@@ -55,7 +55,6 @@
#include "chrome/browser/chromeos/login/users/chrome_user_manager_util.h"
#include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/policy/device_local_account.h"
#include "chrome/browser/chromeos/policy/minimum_version_policy_handler.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
......@@ -73,6 +72,7 @@
#include "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/l10n_util.h"
#include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
......@@ -315,10 +315,8 @@ void SigninScreenHandler::DeclareLocalizedValues(
builder->Add("ownerUserPattern", IDS_LOGIN_POD_OWNER_USER);
builder->Add("removeUser", IDS_LOGIN_POD_REMOVE_USER);
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
builder->Add("disabledAddUserTooltip",
connector->IsEnterpriseManaged()
webui::IsEnterpriseManaged()
? IDS_DISABLED_ADD_USER_TOOLTIP_ENTERPRISE
: IDS_DISABLED_ADD_USER_TOOLTIP);
......@@ -1073,9 +1071,7 @@ void SigninScreenHandler::HandleToggleEnrollmentScreen() {
}
void SigninScreenHandler::HandleToggleKioskEnableScreen() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
if (delegate_ && !connector->IsEnterpriseManaged() &&
if (delegate_ && !webui::IsEnterpriseManaged() &&
KioskAppManager::IsConsumerKioskEnabled() &&
LoginDisplayHost::default_host()) {
delegate_->ShowKioskEnableScreen();
......@@ -1083,9 +1079,7 @@ void SigninScreenHandler::HandleToggleKioskEnableScreen() {
}
void SigninScreenHandler::HandleToggleKioskAutolaunchScreen() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
if (delegate_ && !connector->IsEnterpriseManaged())
if (delegate_ && !webui::IsEnterpriseManaged())
delegate_->ShowKioskAutolaunchScreen();
}
......
......@@ -23,14 +23,6 @@
#include "printing/buildflags/buildflags.h"
#include "ui/base/webui/web_ui_util.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#elif defined(OS_WIN)
#include "base/enterprise_util.h"
#endif
namespace {
content::WebUIDataSource* CreateLocalDiscoveryWarningHTMLSource() {
......@@ -41,18 +33,11 @@ content::WebUIDataSource* CreateLocalDiscoveryWarningHTMLSource() {
source->AddLocalizedString("devicesTitle",
IDS_LOCAL_DISCOVERY_DEVICES_PAGE_TITLE);
bool enterprise_managed = false;
#if defined(OS_CHROMEOS)
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
enterprise_managed = connector->IsEnterpriseManaged();
#elif defined(OS_WIN)
enterprise_managed = base::IsMachineExternallyManaged();
#endif
source->AddLocalizedString(
"cloudPrintDeprecationWarning",
enterprise_managed ? IDS_CLOUD_PRINTING_NOT_SUPPORTED_WARNING_ENTERPRISE
: IDS_CLOUD_PRINTING_NOT_SUPPORTED_WARNING);
webui::IsEnterpriseManaged()
? IDS_CLOUD_PRINTING_NOT_SUPPORTED_WARNING_ENTERPRISE
: IDS_CLOUD_PRINTING_NOT_SUPPORTED_WARNING);
source->DisableDenyXFrameOptions();
......
......@@ -54,6 +54,7 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/ui/webui/management_ui_handler_chromeos.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/grit/chromium_strings.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/proxy/proxy_config_handler.h"
......@@ -187,9 +188,7 @@ bool IsProfileManaged(Profile* profile) {
#if defined(OS_CHROMEOS)
bool IsDeviceManaged() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
return connector->IsEnterpriseManaged();
return webui::IsEnterpriseManaged();
}
#endif // defined(OS_CHROMEOS)
......
......@@ -28,7 +28,6 @@
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/pdf/pdf_extension_util.h"
#include "chrome/browser/printing/background_printing_manager.h"
#include "chrome/browser/printing/print_job_manager.h"
......@@ -70,12 +69,6 @@
#include "ui/web_dialogs/web_dialog_delegate.h"
#include "ui/web_dialogs/web_dialog_ui.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#elif defined(OS_WIN)
#include "base/enterprise_util.h"
#endif
#if !BUILDFLAG(OPTIMIZE_WEBUI)
#include "chrome/browser/ui/webui/managed_ui_handler.h"
#endif
......@@ -379,15 +372,7 @@ void AddPrintPreviewFlags(content::WebUIDataSource* source, Profile* profile) {
source->AddBoolean("useSystemDefaultPrinter", system_default_printer);
#endif
bool enterprise_managed = false;
#if defined(OS_CHROMEOS)
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
enterprise_managed = connector->IsEnterpriseManaged();
#elif defined(OS_WIN)
enterprise_managed = base::IsMachineExternallyManaged();
#endif
source->AddBoolean("isEnterpriseManaged", enterprise_managed);
source->AddBoolean("isEnterpriseManaged", webui::IsEnterpriseManaged());
#if defined(OS_CHROMEOS)
source->AddBoolean(
......
......@@ -27,7 +27,6 @@
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
......@@ -54,7 +53,6 @@
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/tpm_firmware_update.h"
......@@ -63,6 +61,7 @@
#include "chrome/browser/ui/webui/chromeos/image_source.h"
#include "chrome/browser/ui/webui/help/help_utils_chromeos.h"
#include "chrome/browser/ui/webui/help/version_updater_chromeos.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/dbus/power/power_manager_client.h"
......@@ -117,16 +116,9 @@ base::string16 GetAllowedConnectionTypesMessage() {
}
}
// Returns true if the device is enterprise managed, false otherwise.
bool IsEnterpriseManaged() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
return connector->IsEnterpriseManaged();
}
// Returns true if current user can change channel, false otherwise.
bool CanChangeChannel(Profile* profile) {
if (IsEnterpriseManaged()) {
if (webui::IsEnterpriseManaged()) {
bool value = false;
// On a managed machine we delegate this setting to the affiliated users
// only if the policy value is true.
......
......@@ -11,9 +11,8 @@
#if defined(OS_CHROMEOS)
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/tpm_firmware_update.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/user_manager/user_manager.h"
......@@ -104,10 +103,8 @@ void BrowserLifetimeHandler::HandleFactoryReset(
}
// TODO(crbug.com/891905): Centralize powerwash restriction checks.
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
bool allow_powerwash =
!connector->IsEnterpriseManaged() &&
!webui::IsEnterpriseManaged() &&
!user_manager::UserManager::Get()->IsLoggedInAsGuest() &&
!user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser() &&
!user_manager::UserManager::Get()->IsLoggedInAsChildUser();
......
......@@ -4,15 +4,14 @@
#include "chrome/browser/ui/webui/settings/chromeos/about_section.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/i18n/message_formatter.h"
#include "base/no_destructor.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "base/system/sys_info.h"
#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/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/obsolete_system/obsolete_system.h"
#include "chrome/browser/ui/webui/management_ui.h"
#include "chrome/browser/ui/webui/settings/about_handler.h"
......@@ -140,19 +139,6 @@ std::string GetSafetyInfoLink() {
return std::string();
}
// Returns true if the device is enterprise managed, false otherwise.
bool IsEnterpriseManaged() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
return connector->IsEnterpriseManaged();
}
bool IsDeviceManaged() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
return connector->IsEnterpriseManaged();
}
} // namespace
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
......@@ -278,7 +264,7 @@ void AboutSection::AddLoadTimeData(content::WebUIDataSource* html_source) {
if (user_manager::UserManager::IsInitialized()) {
user_manager::UserManager* user_manager = user_manager::UserManager::Get();
if (!IsDeviceManaged() && !user_manager->IsCurrentUserOwner()) {
if (!webui::IsEnterpriseManaged() && !user_manager->IsCurrentUserOwner()) {
html_source->AddString("ownerEmail",
user_manager->GetOwnerAccountId().GetUserEmail());
}
......@@ -315,7 +301,8 @@ void AboutSection::AddLoadTimeData(content::WebUIDataSource* html_source) {
base::ASCIIToUTF16(chrome::kChromeUICrostiniCreditsURL));
html_source->AddString("aboutProductOsWithLinuxLicense",
os_with_linux_license);
html_source->AddBoolean("aboutEnterpriseManaged", IsEnterpriseManaged());
html_source->AddBoolean("aboutEnterpriseManaged",
webui::IsEnterpriseManaged());
html_source->AddBoolean("aboutIsArcEnabled",
arc::IsArcPlayStoreEnabledForProfile(profile()));
html_source->AddBoolean("aboutIsDeveloperMode",
......
......@@ -7,13 +7,10 @@
#include "base/feature_list.h"
#include "base/no_destructor.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/crostini/crostini_disk.h"
#include "chrome/browser/chromeos/crostini/crostini_features.h"
#include "chrome/browser/chromeos/crostini/crostini_pref_names.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/profiles/profile.h"
......@@ -197,9 +194,7 @@ bool IsProfileManaged(Profile* profile) {
}
bool IsDeviceManaged() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
return connector->IsEnterpriseManaged();
return webui::IsEnterpriseManaged();
}
bool IsAdbSideloadingAllowed() {
......
......@@ -6,8 +6,6 @@
#include "base/no_destructor.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_tag_registry.h"
#include "chrome/browser/ui/webui/settings/reset_settings_handler.h"
#include "chrome/browser/ui/webui/webui_util.h"
......@@ -43,9 +41,7 @@ const std::vector<SearchConcept>& GetResetSearchConcepts() {
}
bool IsPowerwashAllowed() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
return !connector->IsEnterpriseManaged() &&
return !webui::IsEnterpriseManaged() &&
!user_manager::UserManager::Get()->IsLoggedInAsGuest() &&
!user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser() &&
!user_manager::UserManager::Get()->IsLoggedInAsChildUser();
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/ui/webui/webui_util.h"
#include "build/build_config.h"
#include "chrome/common/buildflags.h"
#include "content/public/browser/web_ui_data_source.h"
#include "services/network/public/mojom/content_security_policy.mojom.h"
......@@ -11,6 +12,14 @@
#include "ui/resources/grit/webui_resources.h"
#include "ui/resources/grit/webui_resources_map.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#elif defined(OS_WIN) || defined(OS_APPLE)
#include "base/enterprise_util.h"
#endif
namespace webui {
namespace {
......@@ -74,4 +83,16 @@ void AddResourcePathsBulk(content::WebUIDataSource* source,
source->AddResourcePath(resource.name, resource.value);
}
bool IsEnterpriseManaged() {
#if defined(OS_CHROMEOS)
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
return connector->IsEnterpriseManaged();
#elif defined(OS_WIN) || defined(OS_APPLE)
return base::IsMachineExternallyManaged();
#else
return false;
#endif
}
} // namespace webui
......@@ -59,6 +59,11 @@ void AddResourcePathsBulk(content::WebUIDataSource* source,
void AddResourcePathsBulk(content::WebUIDataSource* source,
base::span<const GritResourceMap> resources);
// Returns whether the device is enterprise managed. Note that on Linux, there's
// no good way of detecting whether the device is managed, so always return
// false.
bool IsEnterpriseManaged();
} // namespace webui
#endif // CHROME_BROWSER_UI_WEBUI_WEBUI_UTIL_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