Commit 471524ed authored by Renee Wright's avatar Renee Wright Committed by Commit Bot

Show icon in settings when Crostini enforced off

When crostini is disallowed by hardware, Chrome flags, etc, we do not
want to show the Linux row in Chrome Settings. If it is not disallowed
by these factors but it is enforced off by the enterprise policy then
we want to show the Linux row, but disable the "turn on" button and
show a policy indicator icon in the row. This change implements that
behavior.

Change-Id: I8d4367a3e9e732e308ae166855dc91ac1d8ef52b
Reviewed-on: https://chromium-review.googlesource.com/c/1322338Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarNicholas Verne <nverne@chromium.org>
Commit-Queue: Renée Wright <rjwright@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613015}
parent e99d5a1d
......@@ -38,8 +38,8 @@ constexpr char kCrostiniAppLaunchHistogram[] = "Crostini.AppLaunch";
constexpr char kCrostiniAppNamePrefix[] = "_crostini_";
constexpr int64_t kDelayBeforeSpinnerMs = 400;
// If true then override IsCrostiniUIAllowedForProfile and related methods to
// turn on Crostini.
// If true then override IsCrostiniUIAllowedForProfile and related methods
// to turn on Crostini.
bool g_crostini_ui_allowed_for_testing = false;
// These values are persisted to logs. Entries should not be renumbered and
......@@ -207,15 +207,7 @@ class IconLoadWaiter : public CrostiniAppIcon::Observer {
base::OnceCallback<void(const std::vector<gfx::ImageSkia>&)> callback_;
};
} // namespace
namespace crostini {
void SetCrostiniUIAllowedForTesting(bool enabled) {
g_crostini_ui_allowed_for_testing = enabled;
}
bool IsCrostiniAllowedForProfile(Profile* profile) {
bool IsCrostiniAllowedForProfileImpl(Profile* profile) {
if (g_crostini_ui_allowed_for_testing) {
return true;
}
......@@ -225,13 +217,10 @@ bool IsCrostiniAllowedForProfile(Profile* profile) {
chromeos::ProfileHelper::IsLockScreenAppProfile(profile)) {
return false;
}
if (!profile->GetPrefs()->GetBoolean(
crostini::prefs::kUserCrostiniAllowedByPolicy)) {
return false;
}
const user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
if (!user->IsAffiliated() && !IsUnaffiliatedCrostiniAllowedByPolicy()) {
if (!user->IsAffiliated() &&
!crostini::IsUnaffiliatedCrostiniAllowedByPolicy()) {
return false;
}
if (!crostini::CrostiniManager::IsDevKvmPresent()) {
......@@ -243,7 +232,23 @@ bool IsCrostiniAllowedForProfile(Profile* profile) {
base::FeatureList::IsEnabled(features::kCrostini);
}
bool IsCrostiniUIAllowedForProfile(Profile* profile) {
} // namespace
namespace crostini {
void SetCrostiniUIAllowedForTesting(bool enabled) {
g_crostini_ui_allowed_for_testing = enabled;
}
bool IsCrostiniAllowedForProfile(Profile* profile) {
if (!profile->GetPrefs()->GetBoolean(
crostini::prefs::kUserCrostiniAllowedByPolicy)) {
return false;
}
return IsCrostiniAllowedForProfileImpl(profile);
}
bool IsCrostiniUIAllowedForProfile(Profile* profile, bool check_policy) {
if (g_crostini_ui_allowed_for_testing) {
return true;
}
......@@ -251,8 +256,13 @@ bool IsCrostiniUIAllowedForProfile(Profile* profile) {
return false;
}
return IsCrostiniAllowedForProfile(profile) &&
base::FeatureList::IsEnabled(features::kExperimentalCrostiniUI);
if (!base::FeatureList::IsEnabled(features::kExperimentalCrostiniUI)) {
return false;
}
if (check_policy) {
return IsCrostiniAllowedForProfile(profile);
}
return IsCrostiniAllowedForProfileImpl(profile);
}
bool IsCrostiniEnabled(Profile* profile) {
......
......@@ -33,9 +33,12 @@ void SetCrostiniUIAllowedForTesting(bool enabled);
// or it is in the flow to set up managed account creation.
bool IsCrostiniAllowedForProfile(Profile* profile);
// Returns true if crostini UI can be shown. Implies crostini is allowed to
// run.
bool IsCrostiniUIAllowedForProfile(Profile* profile);
// When |check_policy| is true, returns true if fully interactive crostini UI
// may be shown. Implies crostini is allowed to run.
// When check_policy is false, returns true if crostini UI is not forbidden by
// hardware, flags, etc, even if it is forbidden by the enterprise policy. The
// UI uses this to indicate that crostini is available but disabled by policy.
bool IsCrostiniUIAllowedForProfile(Profile* profile, bool check_policy = true);
// Returns whether if Crostini has been enabled, i.e. the user has launched it
// at least once and not deleted it.
......
......@@ -200,7 +200,8 @@
<template is="dom-if" if="[[showCrostini]]" restamp>
<settings-section page-title="$i18n{crostiniPageTitle}"
section="crostini">
<settings-crostini-page prefs="{{prefs}}">
<settings-crostini-page prefs="{{prefs}}"
allow-crostini="[[allowCrostini_]]">
</settings-crostini-page>
</settings-section>
</template>
......
......@@ -23,6 +23,8 @@ Polymer({
showCrostini: Boolean,
allowCrostini_: Boolean,
showMultidevice: Boolean,
havePlayStoreApp: Boolean,
......@@ -109,6 +111,9 @@ Polymer({
attached: function() {
this.currentRoute_ = settings.getCurrentRoute();
this.allowCrostini_ = loadTimeData.valueExists('allowCrostini') &&
loadTimeData.getBoolean('allowCrostini');
this.addWebUIListener('change-password-visibility', visibility => {
this.showChangePassword = visibility;
});
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/policy/cr_policy_pref_indicator.html">
<link rel="import" href="chrome://resources/cr_elements/policy/cr_policy_indicator.html">
<link rel="import" href="chrome://resources/html/i18n_behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/neon-animation/neon-animatable.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
......@@ -29,9 +29,10 @@
inner-h-t-m-l="[[i18nAdvanced('crostiniSubtext')]]">
</div>
</div>
<cr-policy-pref-indicator pref="[[prefs.crostini.enabled]]"
icon-aria-label="$i18n{crostiniPageTitle}">
</cr-policy-pref-indicator>
<template is="dom-if" if="[[!allowCrostini]]" restamp>
<cr-policy-indicator indicator-type="userPolicy">
</cr-policy-indicator>
</template>
<template is="dom-if" if="[[prefs.crostini.enabled.value]]">
<paper-icon-button-light class="subpage-arrow">
<button aria-label="$i18n{crostiniPageTitle}"
......@@ -41,7 +42,9 @@
</template>
<template is="dom-if" if="[[!prefs.crostini.enabled.value]]">
<div class="separator"></div>
<paper-button id="enable" on-click="onEnableTap_"
<paper-button id="enable"
disabled="[[!allowCrostini]]"
on-click="onEnableTap_"
aria-label="$i18n{crostiniPageTitle}"
aria-describedby="secondaryText">
$i18n{crostiniEnable}
......
......@@ -205,7 +205,8 @@ MdSettingsUI::MdSettingsUI(content::WebUI* web_ui)
}
AddSettingsPageUIHandler(
std::make_unique<chromeos::settings::ChangePictureHandler>());
if (crostini::IsCrostiniUIAllowedForProfile(profile)) {
if (crostini::IsCrostiniUIAllowedForProfile(profile,
false /* check_policy */)) {
AddSettingsPageUIHandler(
std::make_unique<chromeos::settings::CrostiniHandler>(profile));
}
......@@ -336,6 +337,10 @@ MdSettingsUI::MdSettingsUI(content::WebUI* web_ui)
ash::stylus_utils::HasInternalStylus());
html_source->AddBoolean("showCrostini",
crostini::IsCrostiniUIAllowedForProfile(
profile, false /* check_policy */));
html_source->AddBoolean("allowCrostini",
crostini::IsCrostiniUIAllowedForProfile(profile));
html_source->AddBoolean("isDemoSession",
......
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