Commit 8cbbc19f authored by Joe Downing's avatar Joe Downing Committed by Commit Bot

[KeyboardLock] Adding a SystemKeyboardLock feature

This feature controls whether the low-level keyboard hook is enabled
when keyboard lock is requested.  I wanted to separate browser and
system level keyboard lock functionality as I get closer to launching
the blink api for keyboard lock.  This will allow us to release
browser-level keyboard lock w/o the system hooks if needed and will
also give us the ability to target a finch kill switch for the
system-level functionality if needed.

BUG=680809

Change-Id: I2d522046c90fd8776bfb1d9c53978f2c41e1c7cc
Reviewed-on: https://chromium-review.googlesource.com/1046154Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Joe Downing <joedow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558367}
parent 1ecb4827
......@@ -2255,6 +2255,9 @@ const FeatureEntry kFeatureEntries[] = {
{"keyboard-lock-api", flag_descriptions::kKeyboardLockApiName,
flag_descriptions::kKeyboardLockApiDescription, kOsDesktop,
FEATURE_VALUE_TYPE(features::kKeyboardLockAPI)},
{"system-keyboard-lock", flag_descriptions::kSystemKeyboardLockName,
flag_descriptions::kSystemKeyboardLockDescription, kOsDesktop,
FEATURE_VALUE_TYPE(features::kSystemKeyboardLock)},
{"experimental-keyboard-lock-ui",
flag_descriptions::kExperimentalKeyboardLockUiName,
flag_descriptions::kExperimentalKeyboardLockUiDescription, kOsDesktop,
......
......@@ -1593,6 +1593,12 @@ const char kSyncSandboxName[] = "Use Chrome Sync sandbox";
const char kSyncSandboxDescription[] =
"Connects to the testing server for Chrome Sync.";
const char kSystemKeyboardLockName[] = "Experimental system keyboard lock";
const char kSystemKeyboardLockDescription[] =
"Enables websites to use the keyboard.lock() API to intercept system "
"keyboard shortcuts and have the events routed directly to the website "
"when in fullscreen mode.";
const char kTabAudioMutingName[] = "Tab audio muting UI control";
const char kTabAudioMutingDescription[] =
"When enabled, the audio indicators in the tab strip double as tab audio "
......
......@@ -964,6 +964,9 @@ extern const char kStopLoadingInBackgroundDescription[];
extern const char kStopNonTimersInBackgroundName[];
extern const char kStopNonTimersInBackgroundDescription[];
extern const char kSystemKeyboardLockName[];
extern const char kSystemKeyboardLockDescription[];
extern const char kTLS13VariantName[];
extern const char kTLS13VariantDescription[];
extern const char kTLS13VariantDisabled[];
......
......@@ -26489,6 +26489,7 @@ from previous Chrome versions.
<int value="-1946522787" label="VrCustomTabBrowsing:disabled"/>
<int value="-1945524394" label="EnableBackgroundBlur:disabled"/>
<int value="-1943507605" label="enable-new-video-renderer"/>
<int value="-1943313820" label="SystemKeyboardLock:disabled"/>
<int value="-1941852572" label="floating-virtual-keyboard"/>
<int value="-1940806558" label="enable-syncfs-directory-operation"/>
<int value="-1940377152" label="MacRTL:enabled"/>
......@@ -27775,6 +27776,7 @@ from previous Chrome versions.
<int value="986796748" label="AccountConsistency:enabled"/>
<int value="988981463" label="ImageCaptureAPI:enabled"/>
<int value="989062160" label="ModuleScriptsImportMetaUrl:enabled"/>
<int value="996701528" label="SystemKeyboardLock:enabled"/>
<int value="996797157" label="V8ContextSnapshot:enabled"/>
<int value="1000587036" label="OfflinePagesDescriptiveFailStatus:disabled"/>
<int value="1000706989" label="AutomaticTabDiscarding:disabled"/>
......@@ -70,6 +70,7 @@ jumbo_component("aura") {
"mus/window_tree_host_mus_delegate.h",
"mus/window_tree_host_mus_init_params.h",
"scoped_keyboard_hook.h",
"scoped_simple_keyboard_hook.h",
"scoped_window_targeter.h",
"window.h",
"window_delegate.h",
......@@ -134,6 +135,7 @@ jumbo_component("aura") {
"mus/window_tree_host_mus.cc",
"mus/window_tree_host_mus_init_params.cc",
"scoped_keyboard_hook.cc",
"scoped_simple_keyboard_hook.cc",
"scoped_window_targeter.cc",
"window.cc",
"window_event_dispatcher.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/aura/scoped_simple_keyboard_hook.h"
#include <utility>
#include "base/stl_util.h"
#include "ui/events/keycodes/dom/dom_code.h"
namespace aura {
ScopedSimpleKeyboardHook::ScopedSimpleKeyboardHook(
base::Optional<base::flat_set<ui::DomCode>> dom_codes)
: dom_codes_(std::move(dom_codes)) {}
ScopedSimpleKeyboardHook::~ScopedSimpleKeyboardHook() = default;
bool ScopedSimpleKeyboardHook::IsKeyLocked(ui::DomCode dom_code) {
if (dom_code == ui::DomCode::NONE)
return false;
return !dom_codes_ || base::ContainsKey(dom_codes_.value(), dom_code);
}
} // namespace aura
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_AURA_SCOPED_SIMPLE_KEYBOARD_HOOK_H_
#define UI_AURA_SCOPED_SIMPLE_KEYBOARD_HOOK_H_
#include "base/containers/flat_set.h"
#include "base/macros.h"
#include "base/optional.h"
#include "ui/aura/scoped_keyboard_hook.h"
namespace ui {
enum class DomCode;
}
namespace aura {
// This subclass of ScopedKeyboardHook will not set up a system-level keyboard
// hook or call into any WindowTreeHost methods for lock state or cleanup.
// It allows for disabling system-level keyboard lock functionality while
// continuing to support browser-level keyboard lock.
// TODO(joedow): Remove this class after 'system-keyboard-lock' is removed.
class ScopedSimpleKeyboardHook : public ScopedKeyboardHook {
public:
explicit ScopedSimpleKeyboardHook(
base::Optional<base::flat_set<ui::DomCode>> dom_codes);
~ScopedSimpleKeyboardHook() override;
// ScopedKeyboardHook override.
bool IsKeyLocked(ui::DomCode dom_code) override;
private:
base::Optional<base::flat_set<ui::DomCode>> dom_codes_;
DISALLOW_COPY_AND_ASSIGN(ScopedSimpleKeyboardHook);
};
} // namespace aura
#endif // UI_AURA_SCOPED_SIMPLE_KEYBOARD_HOOK_H_
......@@ -5,6 +5,7 @@
#include "ui/aura/window_tree_host.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
......@@ -13,6 +14,7 @@
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/env.h"
#include "ui/aura/scoped_keyboard_hook.h"
#include "ui/aura/scoped_simple_keyboard_hook.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_port.h"
......@@ -21,6 +23,7 @@
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_factory.h"
#include "ui/base/layout.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/view_prop.h"
#include "ui/compositor/compositor_switches.h"
#include "ui/compositor/dip_util.h"
......@@ -274,8 +277,12 @@ void WindowTreeHost::Hide() {
}
std::unique_ptr<ScopedKeyboardHook> WindowTreeHost::CaptureSystemKeyEvents(
base::Optional<base::flat_set<ui::DomCode>> codes) {
if (CaptureSystemKeyEventsImpl(std::move(codes)))
base::Optional<base::flat_set<ui::DomCode>> dom_codes) {
// TODO(joedow): Remove the simple hook class/logic once this flag is removed.
if (!base::FeatureList::IsEnabled(features::kSystemKeyboardLock))
return std::make_unique<ScopedSimpleKeyboardHook>(std::move(dom_codes));
if (CaptureSystemKeyEventsImpl(std::move(dom_codes)))
return std::make_unique<ScopedKeyboardHook>(weak_factory_.GetWeakPtr());
return nullptr;
}
......
......@@ -42,6 +42,10 @@ const base::Feature kSecondaryUiMd = {"SecondaryUiMd",
#endif
};
// Allows system keyboard event capture when |features::kKeyboardLockApi| is on.
const base::Feature kSystemKeyboardLock{"SystemKeyboardLock",
base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kTouchableAppContextMenu = {
"EnableTouchableAppContextMenu", base::FEATURE_DISABLED_BY_DEFAULT};
......
......@@ -19,6 +19,7 @@ UI_BASE_EXPORT extern const base::Feature
kEnableFullscreenHandwritingVirtualKeyboard;
UI_BASE_EXPORT extern const base::Feature kEnableStylusVirtualKeyboard;
UI_BASE_EXPORT extern const base::Feature kSecondaryUiMd;
UI_BASE_EXPORT extern const base::Feature kSystemKeyboardLock;
UI_BASE_EXPORT extern const base::Feature kTouchableAppContextMenu;
UI_BASE_EXPORT extern const base::Feature kUiCompositorScrollWithLayers;
......
......@@ -573,6 +573,7 @@ bool DesktopWindowTreeHostWin::CaptureSystemKeyEventsImpl(
std::move(dom_codes), GetAcceleratedWidget(),
base::BindRepeating(&DesktopWindowTreeHostWin::HandleKeyEvent,
base::Unretained(this)));
return keyboard_hook_ != nullptr;
}
......
......@@ -1311,6 +1311,7 @@ bool DesktopWindowTreeHostX11::CaptureSystemKeyEventsImpl(
std::move(dom_codes), GetAcceleratedWidget(),
base::BindRepeating(&DesktopWindowTreeHostX11::DispatchKeyEvent,
base::Unretained(this)));
return keyboard_hook_ != nullptr;
}
......
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