Commit d02b27dd authored by Matt Reynolds's avatar Matt Reynolds Committed by Commit Bot

Avoid crash when checking gamepad user activation

The Gamepad API may be invoked after the frame has been detached, in
which case GetPage() and GetFrame() will be null. If the Gamepad API
was uninitialized before the frame was detached, the gamepads_ buffer
may also be null.

This CL adds more null checks to the user activation check to ensure
we do not try to access the page after it has been detached.

BUG=852517

Change-Id: I4d8152a9a16a027719d31150bd1b7687fdf991a0
Reviewed-on: https://chromium-review.googlesource.com/1101926Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567737}
parent bda25618
...@@ -65,12 +65,14 @@ void HasGamepadConnectionChanged(const String& old_id, ...@@ -65,12 +65,14 @@ void HasGamepadConnectionChanged(const String& old_id,
*gamepad_lost = id_changed || (old_connected && !new_connected); *gamepad_lost = id_changed || (old_connected && !new_connected);
} }
bool HasUserActivation(GamepadList& gamepads) { bool HasUserActivation(GamepadList* gamepads) {
if (!gamepads)
return false;
// A button press counts as a user activation if the button's value is greater // A button press counts as a user activation if the button's value is greater
// than the activation threshold. A threshold is used so that analog buttons // than the activation threshold. A threshold is used so that analog buttons
// or triggers do not generate an activation from a light touch. // or triggers do not generate an activation from a light touch.
for (size_t pad_index = 0; pad_index < gamepads.length(); ++pad_index) { for (size_t pad_index = 0; pad_index < gamepads->length(); ++pad_index) {
Gamepad* pad = gamepads.item(pad_index); Gamepad* pad = gamepads->item(pad_index);
if (pad) { if (pad) {
const GamepadButtonVector& buttons = pad->buttons(); const GamepadButtonVector& buttons = pad->buttons();
for (size_t i = 0; i < buttons.size(); ++i) { for (size_t i = 0; i < buttons.size(); ++i) {
...@@ -204,9 +206,10 @@ GamepadList* NavigatorGamepad::Gamepads() { ...@@ -204,9 +206,10 @@ GamepadList* NavigatorGamepad::Gamepads() {
SampleAndCheckConnectedGamepads(); SampleAndCheckConnectedGamepads();
// Allow gamepad button presses to qualify as user activations. // Allow gamepad button presses to qualify as user activations if the page is
if (RuntimeEnabledFeatures::UserActivationV2Enabled() && // visible.
GetPage()->IsPageVisible() && HasUserActivation(*gamepads_)) { if (RuntimeEnabledFeatures::UserActivationV2Enabled() && GetFrame() &&
GetPage() && GetPage()->IsPageVisible() && HasUserActivation(gamepads_)) {
Frame::NotifyUserActivation(GetFrame(), UserGestureToken::kNewGesture); Frame::NotifyUserActivation(GetFrame(), UserGestureToken::kNewGesture);
} }
......
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