Commit 130e81e3 authored by Julian Watson's avatar Julian Watson Committed by Commit Bot

plugin_vm: allow uninstallation when policy is disabled

If the policy is disabled, the user still needs a way to cleanup the vm
from their disk. This change allows them access to the plugin vm subpage
as long as either the policy is enabled, or there is a vm on disk.

Note: It is not enough to simply delete the vm for the user, as the
policy change could be accidental or temporary.

Bug: 1023256
Change-Id: Id1cfae86061c8f7e1a0b771165833e412009edbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2026511
Commit-Queue: Julian Watson <juwa@google.com>
Auto-Submit: Julian Watson <juwa@google.com>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarTimothy Loh <timloh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738029}
parent dfa78fd3
...@@ -30,15 +30,21 @@ ...@@ -30,15 +30,21 @@
</div> </div>
</div> </div>
<template is="dom-if" if="[[prefs.plugin_vm.image_exists.value]]"> <template is="dom-if" if="[[prefs.plugin_vm.image_exists.value]]">
<cr-icon-button class="subpage-arrow" <cr-icon-button id="navigate-to-subpage"
class="subpage-arrow"
aria-label="i18n{pluginVmPageLabel}" aria-label="i18n{pluginVmPageLabel}"
aria-describedby="secondaryText" aria-describedby="secondaryText"
aria-roledescription="$i18n{subpageArrowRoleDescription}"> aria-roledescription="$i18n{subpageArrowRoleDescription}">
</cr-icon-button> </cr-icon-button>
</template> </template>
<template is="dom-if" if="[[!prefs.plugin_vm.image_exists.value]]"> <template is="dom-if" if="[[!prefs.plugin_vm.image_exists.value]]">
<template is="dom-if" if="[[!allowPluginVm_]]" restamp>
<cr-policy-indicator indicator-type="userPolicy">
</cr-policy-indicator>
</template>
<div class="separator"></div> <div class="separator"></div>
<cr-button id="enable" <cr-button id="enable"
disabled="[[!allowPluginVm_]]"
on-click="onEnableClick_" on-click="onEnableClick_"
aria-describedby="secondaryText"> aria-describedby="secondaryText">
$i18n{pluginVmPageEnable} $i18n{pluginVmPageEnable}
......
...@@ -19,6 +19,9 @@ Polymer({ ...@@ -19,6 +19,9 @@ Polymer({
notify: true, notify: true,
}, },
/** @private */
allowPluginVm_: Boolean,
/** @private {!Map<string, string>} */ /** @private {!Map<string, string>} */
focusConfig_: { focusConfig_: {
type: Object, type: Object,
...@@ -35,6 +38,12 @@ Polymer({ ...@@ -35,6 +38,12 @@ Polymer({
}, },
}, },
/** @override */
attached: function() {
this.allowPluginVm_ = loadTimeData.valueExists('allowPluginVm') &&
loadTimeData.getBoolean('allowPluginVm');
},
/** /**
* @param {!Event} event * @param {!Event} event
* @private * @private
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h" #include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h" #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_utils.h"
#include "chrome/browser/chromeos/multidevice_setup/multidevice_setup_client_factory.h" #include "chrome/browser/chromeos/multidevice_setup/multidevice_setup_client_factory.h"
#include "chrome/browser/chromeos/plugin_vm/plugin_vm_pref_names.h"
#include "chrome/browser/chromeos/plugin_vm/plugin_vm_util.h" #include "chrome/browser/chromeos/plugin_vm/plugin_vm_util.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
...@@ -298,7 +299,14 @@ void OSSettingsUI::InitOSWebUIHandlers(content::WebUIDataSource* html_source) { ...@@ -298,7 +299,14 @@ void OSSettingsUI::InitOSWebUIHandlers(content::WebUIDataSource* html_source) {
web_ui()->AddMessageHandler( web_ui()->AddMessageHandler(
std::make_unique<chromeos::settings::WallpaperHandler>(web_ui())); std::make_unique<chromeos::settings::WallpaperHandler>(web_ui()));
if (plugin_vm::IsPluginVmAllowedForProfile(profile)) { // If |!allow_plugin_vm| we still want to |show_plugin_vm| if the VM image is
// on disk, so that users are still able to delete the image at will.
const bool allow_plugin_vm = plugin_vm::IsPluginVmAllowedForProfile(profile);
const bool show_plugin_vm =
allow_plugin_vm ||
profile->GetPrefs()->GetBoolean(plugin_vm::prefs::kPluginVmImageExists);
if (show_plugin_vm) {
web_ui()->AddMessageHandler( web_ui()->AddMessageHandler(
std::make_unique<chromeos::settings::PluginVmHandler>(profile)); std::make_unique<chromeos::settings::PluginVmHandler>(profile));
} }
...@@ -392,8 +400,8 @@ void OSSettingsUI::InitOSWebUIHandlers(content::WebUIDataSource* html_source) { ...@@ -392,8 +400,8 @@ void OSSettingsUI::InitOSWebUIHandlers(content::WebUIDataSource* html_source) {
html_source->AddBoolean( html_source->AddBoolean(
"allowCrostini", crostini::CrostiniFeatures::Get()->IsUIAllowed(profile)); "allowCrostini", crostini::CrostiniFeatures::Get()->IsUIAllowed(profile));
html_source->AddBoolean("showPluginVm", html_source->AddBoolean("allowPluginVm", allow_plugin_vm);
plugin_vm::IsPluginVmAllowedForProfile(profile)); html_source->AddBoolean("showPluginVm", show_plugin_vm);
html_source->AddBoolean("isDemoSession", html_source->AddBoolean("isDemoSession",
chromeos::DemoSession::IsDeviceInDemoMode()); chromeos::DemoSession::IsDeviceInDemoMode());
......
...@@ -53,7 +53,6 @@ suite('PluginVmPage', function() { ...@@ -53,7 +53,6 @@ suite('PluginVmPage', function() {
pluginVmBrowserProxy = new TestPluginVmBrowserProxy(); pluginVmBrowserProxy = new TestPluginVmBrowserProxy();
settings.PluginVmBrowserProxyImpl.instance_ = pluginVmBrowserProxy; settings.PluginVmBrowserProxyImpl.instance_ = pluginVmBrowserProxy;
PolymerTest.clearBody(); PolymerTest.clearBody();
page = document.createElement('settings-plugin-vm-page');
routes = []; routes = [];
...@@ -72,41 +71,55 @@ suite('PluginVmPage', function() { ...@@ -72,41 +71,55 @@ suite('PluginVmPage', function() {
settings.routes = preTestSettingsRoutes; settings.routes = preTestSettingsRoutes;
}); });
test('ImageExistsLink', function() { function setUpPluginVmPage({allowedByPolicy, vmImageExists}) {
page.prefs = { loadTimeData.overrideValues({allowPluginVm: allowedByPolicy});
plugin_vm: {
image_exists: {value: true}, page = document.createElement('settings-plugin-vm-page');
} page.prefs = {plugin_vm: {image_exists: {value: vmImageExists}}};
};
document.body.appendChild(page); document.body.appendChild(page);
Polymer.dom.flush(); Polymer.dom.flush();
}
test('PolicyEnabledAndImageExists', function() {
setUpPluginVmPage({allowedByPolicy: true, vmImageExists: true});
const button = page.$$('cr-icon-button'); assertEquals(page.$$('#enable'), null);
assertTrue(!!button);
assertDeepEquals(routes, []); assertDeepEquals(routes, []);
button.click(); page.$$('#navigate-to-subpage').click();
assertDeepEquals(routes, ['TEST_PLUGIN_VM_DETAILS_ROUTE']); assertDeepEquals(routes, ['TEST_PLUGIN_VM_DETAILS_ROUTE']);
}); });
test('ImageDoesntExist', function() { test('PolicyEnabledAndImageDoesntExist', function() {
page.prefs = { setUpPluginVmPage({allowedByPolicy: true, vmImageExists: false});
plugin_vm: {
image_exists: {value: false},
}
};
document.body.appendChild(page);
Polymer.dom.flush();
const button = page.$$('cr-button'); assertEquals(page.$$('#navigate-to-subpage'), null);
assertTrue(!!button);
assertEquals( assertEquals(
0, pluginVmBrowserProxy.getCallCount('requestPluginVmInstallerView')); 0, pluginVmBrowserProxy.getCallCount('requestPluginVmInstallerView'));
button.click(); page.$$('#enable').click();
assertEquals( assertEquals(
1, pluginVmBrowserProxy.getCallCount('requestPluginVmInstallerView')); 1, pluginVmBrowserProxy.getCallCount('requestPluginVmInstallerView'));
}); });
test('PolicyDisabledAndImageExists', function() {
setUpPluginVmPage({allowedByPolicy: false, vmImageExists: true});
assertEquals(page.$$('#enable'), null);
assertDeepEquals(routes, []);
page.$$('#navigate-to-subpage').click();
assertDeepEquals(routes, ['TEST_PLUGIN_VM_DETAILS_ROUTE']);
});
test('PolicyDisabledAndImageDoesntExist', function() {
setUpPluginVmPage({allowedByPolicy: false, vmImageExists: false});
assertEquals(page.$$('#navigate-to-subpage'), null);
assertTrue(page.$$('#enable').disabled);
});
}); });
suite('Details', function() { suite('Details', function() {
......
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