Skip to content

Commit

Permalink
Add device policy: Kiosk Virtual Keyboard Layout.
Browse files Browse the repository at this point in the history
BUG=376900

Review URL: https://codereview.chromium.org/320223002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278317 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rsadam@chromium.org committed Jun 19, 2014
1 parent 75bf76c commit 7a22697
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 7 deletions.
5 changes: 5 additions & 0 deletions chrome/browser/chromeos/preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ void Preferences::RegisterProfilePrefs(
prefs::kTouchHudProjectionEnabled,
false,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);

registry->RegisterBooleanPref(
prefs::kTouchVirtualKeyboardEnabled,
false,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}

void Preferences::InitUserPrefs(PrefServiceSyncable* prefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
{ key::kKeyboardDefaultToFunctionKeys,
prefs::kLanguageSendFunctionKeys,
base::Value::TYPE_BOOLEAN },
{ key::kTouchVirtualKeyboardEnabled,
prefs::kTouchVirtualKeyboardEnabled,
base::Value::TYPE_BOOLEAN },
#endif // defined(OS_CHROMEOS)

#if !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
Expand Down
38 changes: 37 additions & 1 deletion chrome/browser/policy/policy_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/screenshot_taker.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "ui/keyboard/keyboard_util.h"
#endif

#if !defined(OS_MACOSX)
Expand Down Expand Up @@ -2418,7 +2419,7 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, ScreenMagnifierTypeFull) {
EXPECT_TRUE(magnification_manager->IsMagnifierEnabled());
}

IN_PROC_BROWSER_TEST_F(PolicyTest, VirtualKeyboardEnabled) {
IN_PROC_BROWSER_TEST_F(PolicyTest, AccessibilityVirtualKeyboardEnabled) {
// Verifies that the on-screen keyboard accessibility feature can be
// controlled through policy.
chromeos::AccessibilityManager* accessibility_manager =
Expand All @@ -2441,6 +2442,41 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, VirtualKeyboardEnabled) {
EXPECT_FALSE(accessibility_manager->IsVirtualKeyboardEnabled());
}

IN_PROC_BROWSER_TEST_F(PolicyTest, VirtualKeyboardEnabled) {
// Verify keyboard disabled by default.
EXPECT_FALSE(keyboard::IsKeyboardEnabled());
// Verify keyboard can be toggled by default.
keyboard::SetTouchKeyboardEnabled(true);
EXPECT_TRUE(keyboard::IsKeyboardEnabled());
keyboard::SetTouchKeyboardEnabled(false);
EXPECT_FALSE(keyboard::IsKeyboardEnabled());

// Verify enabling the policy takes effect immediately and that that user
// cannot disable the keyboard..
PolicyMap policies;
policies.Set(key::kTouchVirtualKeyboardEnabled,
POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER,
base::Value::CreateBooleanValue(true),
NULL);
UpdateProviderPolicy(policies);
EXPECT_TRUE(keyboard::IsKeyboardEnabled());
keyboard::SetTouchKeyboardEnabled(false);
EXPECT_TRUE(keyboard::IsKeyboardEnabled());

// Verify that disabling the policy takes effect immediately and that the user
// cannot enable the keyboard.
policies.Set(key::kTouchVirtualKeyboardEnabled,
POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER,
base::Value::CreateBooleanValue(false),
NULL);
UpdateProviderPolicy(policies);
EXPECT_FALSE(keyboard::IsKeyboardEnabled());
keyboard::SetTouchKeyboardEnabled(true);
EXPECT_FALSE(keyboard::IsKeyboardEnabled());
}

#endif

namespace {
Expand Down
27 changes: 27 additions & 0 deletions chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ void ChromeLauncherController::Init() {
if (ash::Shell::HasInstance()) {
SetShelfAutoHideBehaviorFromPrefs();
SetShelfAlignmentFromPrefs();
#if defined(OS_CHROMEOS)
SetVirtualKeyboardBehaviorFromPrefs();
#endif // defined(OS_CHROMEOS)
PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_);
if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() ||
!prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal)->
Expand Down Expand Up @@ -1128,6 +1131,9 @@ void ChromeLauncherController::ActiveUserChanged(
SetShelfAlignmentFromPrefs();
SetShelfAutoHideBehaviorFromPrefs();
SetShelfBehaviorsFromPrefs();
#if defined(OS_CHROMEOS)
SetVirtualKeyboardBehaviorFromPrefs();
#endif // defined(OS_CHROMEOS)
// Restore the order of running, but unpinned applications for the activated
// user.
RestoreUnpinnedRunningApplicationOrder(user_email);
Expand Down Expand Up @@ -1710,6 +1716,21 @@ void ChromeLauncherController::SetShelfBehaviorsFromPrefs() {
SetShelfAlignmentFromPrefs();
}

#if defined(OS_CHROMEOS)
void ChromeLauncherController::SetVirtualKeyboardBehaviorFromPrefs() {
const PrefService* service = profile_->GetPrefs();
if (!service->HasPrefPath(prefs::kTouchVirtualKeyboardEnabled)) {
keyboard::SetKeyboardShowOverride(keyboard::KEYBOARD_SHOW_OVERRIDE_NONE);
} else {
const bool enabled = service->GetBoolean(
prefs::kTouchVirtualKeyboardEnabled);
keyboard::SetKeyboardShowOverride(
enabled ? keyboard::KEYBOARD_SHOW_OVERRIDE_ENABLED
: keyboard::KEYBOARD_SHOW_OVERRIDE_DISABLED);
}
}
#endif // defined(OS_CHROMEOS)

ash::ShelfItemStatus ChromeLauncherController::GetAppState(
const::std::string& app_id) {
ash::ShelfItemStatus status = ash::STATUS_CLOSED;
Expand Down Expand Up @@ -2030,6 +2051,12 @@ void ChromeLauncherController::AttachProfile(Profile* profile) {
prefs::kShelfPreferences,
base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs,
base::Unretained(this)));
#if defined(OS_CHROMEOS)
pref_change_registrar_.Add(
prefs::kTouchVirtualKeyboardEnabled,
base::Bind(&ChromeLauncherController::SetVirtualKeyboardBehaviorFromPrefs,
base::Unretained(this)));
#endif // defined(OS_CHROMEOS)
}

void ChromeLauncherController::ReleaseProfile() {
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/ui/ash/launcher/chrome_launcher_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ class ChromeLauncherController : public ash::ShelfDelegate,
// Sets both of auto-hide behavior and alignment from prefs.
void SetShelfBehaviorsFromPrefs();

#if defined(OS_CHROMEOS)
// Sets whether the virtual keyboard is enabled from prefs.
void SetVirtualKeyboardBehaviorFromPrefs();
#endif // defined(OS_CHROMEOS)

// Returns the shelf item status for the given |app_id|, which can be either
// STATUS_ACTIVE (if the app is active), STATUS_RUNNING (if there is such an
// app) or STATUS_CLOSED.
Expand Down
4 changes: 4 additions & 0 deletions chrome/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,10 @@ const char kCurrentWallpaperAppName[] = "wallpaper.app.name";
// List of mounted file systems via the File System Provider API. Used to
// restore them after a reboot.
const char kFileSystemProviderMounted[] = "file_system_provider.mounted";

// A boolean pref set to true if the virtual keyboard should be enabled.
const char kTouchVirtualKeyboardEnabled[] = "ui.touch_virtual_keyboard_enabled";

#endif // defined(OS_CHROMEOS)

// The disabled messages in IPC logging.
Expand Down
1 change: 1 addition & 0 deletions chrome/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ extern const char kSAMLLastGAIASignInTime[];
extern const char kTimeOnOobe[];
extern const char kCurrentWallpaperAppName[];
extern const char kFileSystemProviderMounted[];
extern const char kTouchVirtualKeyboardEnabled[];
#endif // defined(OS_CHROMEOS)
extern const char kIpcDisabledMessages[];
extern const char kShowHomeButton[];
Expand Down
8 changes: 8 additions & 0 deletions chrome/test/data/policy/policy_test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,14 @@
]
},

"TouchVirtualKeyboardEnabled": {
"os": ["chromeos"],
"test_policy": { "TouchVirtualKeyboardEnabled": false },
"pref_mappings": [
{ "pref": "ui.touch_virtual_keyboard_enabled" }
]
},

"----- Chrome OS device policies ---------------------------------------": {},

"DevicePolicyRefreshRate": {
Expand Down
24 changes: 23 additions & 1 deletion components/policy/resources/policy_templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
# persistent IDs for all fields (but not for groups!) are needed. These are
# specified by the 'id' keys of each policy. NEVER CHANGE EXISTING IDs,
# because doing so would break the deployed wire format!
# For your editing convenience: highest ID currently used: 268
# For your editing convenience: highest ID currently used: 269
#
# Placeholders:
# The following placeholder strings are automatically substituted:
Expand Down Expand Up @@ -4695,6 +4695,28 @@

If this policy is not set, the device will default to a 24 hour clock format.''',
},
{
'name': 'TouchVirtualKeyboardEnabled',
'type': 'main',
'schema': { 'type': 'boolean' },
'supported_on': ['chrome_os:37-' ],
'features': {
'dynamic_refresh': True,
'per_profile': True
},
'example_value': False,
'id': 269,
'caption': '''Enable virtual keyboard''',
'desc': '''This policy configures enabling the virtual keyboard as an input device on ChromeOS. Users cannot override this policy.

If the policy is set to true, the on-screen virtual keyboard will always be enabled.

If set to false, the on-screen virtual keyboard will always be disabled.

If you set this policy, users cannot change or override it. However, users will still be able to enable/disable an accessibility on-screen keyboard which takes precedence over the virtual keyboard controlled by this policy. See the |VirtualKeyboardEnabled| policy for controlling the accessibility on-screen keyboard.

If this policy is left unset, the on-screen keyboard is disabled initially but can be enabled by the user anytime. Heuristic rules may also be used to decide when to display the keyboard.''',
},
{
'name': 'ShowLogoutButtonInTray',
'type': 'main',
Expand Down
1 change: 1 addition & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35506,6 +35506,7 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<int value="266" label="Block developer mode"/>
<int value="267" label="Show the apps shortcut in the bookmark bar"/>
<int value="268" label="Register protocol handlers"/>
<int value="269" label="Enable virtual keyboard"/>
</enum>

<enum name="EnterprisePolicyInvalidations" type="int">
Expand Down
24 changes: 19 additions & 5 deletions ui/keyboard/keyboard_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ bool g_touch_keyboard_enabled = false;
keyboard::KeyboardOverscrolOverride g_keyboard_overscroll_override =
keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE;

keyboard::KeyboardShowOverride g_keyboard_show_override =
keyboard::KEYBOARD_SHOW_OVERRIDE_NONE;

} // namespace

namespace keyboard {
Expand Down Expand Up @@ -97,11 +100,18 @@ std::string GetKeyboardLayout() {
}

bool IsKeyboardEnabled() {
return g_accessibility_keyboard_enabled ||
CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableVirtualKeyboard) ||
IsKeyboardUsabilityExperimentEnabled() ||
g_touch_keyboard_enabled;
// Accessibility setting prioritized over policy setting.
if (g_accessibility_keyboard_enabled)
return true;
// Policy strictly disables showing a virtual keyboard.
if (g_keyboard_show_override == keyboard::KEYBOARD_SHOW_OVERRIDE_DISABLED)
return false;
// Check if any of the flags are enabled.
return CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableVirtualKeyboard) ||
IsKeyboardUsabilityExperimentEnabled() ||
g_touch_keyboard_enabled ||
(g_keyboard_show_override == keyboard::KEYBOARD_SHOW_OVERRIDE_ENABLED);
}

bool IsKeyboardUsabilityExperimentEnabled() {
Expand Down Expand Up @@ -136,6 +146,10 @@ void SetKeyboardOverscrollOverride(KeyboardOverscrolOverride override) {
g_keyboard_overscroll_override = override;
}

void SetKeyboardShowOverride(KeyboardShowOverride override) {
g_keyboard_show_override = override;
}

bool IsInputViewEnabled() {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableInputView))
return true;
Expand Down
10 changes: 10 additions & 0 deletions ui/keyboard/keyboard_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ enum KeyboardOverscrolOverride {
KEYBOARD_OVERSCROLL_OVERRIDE_NONE,
};

// An enumeration of keyboard policy settings.
enum KeyboardShowOverride {
KEYBOARD_SHOW_OVERRIDE_DISABLED = 0,
KEYBOARD_SHOW_OVERRIDE_ENABLED,
KEYBOARD_SHOW_OVERRIDE_NONE,
};

// Gets the default keyboard bounds from |window_bounds|.
KEYBOARD_EXPORT gfx::Rect DefaultKeyboardBoundsFromWindowBounds(
const gfx::Rect& window_bounds);
Expand Down Expand Up @@ -82,6 +89,9 @@ KEYBOARD_EXPORT bool IsKeyboardOverscrollEnabled();
KEYBOARD_EXPORT void SetKeyboardOverscrollOverride(
KeyboardOverscrolOverride override);

// Sets policy override on whether to show the keyboard.
KEYBOARD_EXPORT void SetKeyboardShowOverride(KeyboardShowOverride override);

// Returns true if an IME extension can specify a custom input view for the
// virtual keyboard window.
KEYBOARD_EXPORT bool IsInputViewEnabled();
Expand Down

0 comments on commit 7a22697

Please sign in to comment.