Use Promise with RequestPointerLock calls
The Pointer Lock API used to use an even based system. However, that
is an outdated system and the events do not give an reason in failures.
This change introduces a Promise to the call that adds reasons if the
request is rejected.
Bug: 1042289
Change-Id: I4c8cacac3db5d9dc8d2f3a09c663c2dfb5bdf89e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2069199
Commit-Queue: James Hollyer <[email protected]>
Reviewed-by: Kinuko Yasuda <[email protected]>
Reviewed-by: Kentaro Hara <[email protected]>
Reviewed-by: Yuki Shiino <[email protected]>
Cr-Commit-Position: refs/heads/master@{#748810}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index d4e730ce..7a6b4e8 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -640,7 +640,8 @@
}
if (mouse_lock_widget_)
- mouse_lock_widget_->RejectMouseLockOrUnlockIfNecessary();
+ mouse_lock_widget_->RejectMouseLockOrUnlockIfNecessary(
+ blink::mojom::PointerLockResult::kElementDestroyed);
for (FrameTreeNode* node : frame_tree_.Nodes()) {
// Delete all RFHs pending shutdown, which will lead the corresponding RVHs
@@ -2734,7 +2735,8 @@
for (WebContentsImpl* current = this; current;
current = current->GetOuterWebContents()) {
if (current->mouse_lock_widget_) {
- render_widget_host->GotResponseToLockMouseRequest(false);
+ render_widget_host->GotResponseToLockMouseRequest(
+ blink::mojom::PointerLockResult::kAlreadyLocked);
return;
}
}
@@ -2742,7 +2744,8 @@
if (privileged) {
DCHECK(!GetOuterWebContents());
mouse_lock_widget_ = render_widget_host;
- render_widget_host->GotResponseToLockMouseRequest(true);
+ render_widget_host->GotResponseToLockMouseRequest(
+ blink::mojom::PointerLockResult::kSuccess);
return;
}
@@ -2763,7 +2766,8 @@
delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
} else {
- render_widget_host->GotResponseToLockMouseRequest(false);
+ render_widget_host->GotResponseToLockMouseRequest(
+ blink::mojom::PointerLockResult::kWrongDocument);
}
}
@@ -4226,15 +4230,16 @@
return IsBeingCaptured() ? preferred_size_for_capture_ : preferred_size_;
}
-bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
+bool WebContentsImpl::GotResponseToLockMouseRequest(
+ blink::mojom::PointerLockResult result) {
if (mouse_lock_widget_) {
if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) {
return mouse_lock_widget_->delegate()
->GetAsWebContents()
- ->GotResponseToLockMouseRequest(allowed);
+ ->GotResponseToLockMouseRequest(result);
}
- if (mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
+ if (mouse_lock_widget_->GotResponseToLockMouseRequest(result))
return true;
}
@@ -4246,6 +4251,12 @@
return false;
}
+void WebContentsImpl::GotLockMousePermissionResponse(bool allowed) {
+ GotResponseToLockMouseRequest(
+ allowed ? blink::mojom::PointerLockResult::kSuccess
+ : blink::mojom::PointerLockResult::kPermissionDenied);
+}
+
bool WebContentsImpl::GotResponseToKeyboardLockRequest(bool allowed) {
if (!keyboard_lock_widget_)
return false;
@@ -4370,7 +4381,8 @@
void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
// Clean up related state and initiate the fullscreen exit.
- GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
+ GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary(
+ blink::mojom::PointerLockResult::kUserRejected);
ExitFullscreenMode(will_cause_resize);
}