fix: pointer lock escape handling (#32369)
This commit is contained in:
parent
841d223b3b
commit
ac1d426c51
4 changed files with 52 additions and 25 deletions
|
@ -1244,6 +1244,9 @@ bool WebContents::PlatformHandleKeyboardEvent(
|
||||||
content::KeyboardEventProcessingResult WebContents::PreHandleKeyboardEvent(
|
content::KeyboardEventProcessingResult WebContents::PreHandleKeyboardEvent(
|
||||||
content::WebContents* source,
|
content::WebContents* source,
|
||||||
const content::NativeWebKeyboardEvent& event) {
|
const content::NativeWebKeyboardEvent& event) {
|
||||||
|
if (exclusive_access_manager_->HandleUserKeyEvent(event))
|
||||||
|
return content::KeyboardEventProcessingResult::HANDLED;
|
||||||
|
|
||||||
if (event.GetType() == blink::WebInputEvent::Type::kRawKeyDown ||
|
if (event.GetType() == blink::WebInputEvent::Type::kRawKeyDown ||
|
||||||
event.GetType() == blink::WebInputEvent::Type::kKeyUp) {
|
event.GetType() == blink::WebInputEvent::Type::kKeyUp) {
|
||||||
bool prevent_default = Emit("before-input-event", event);
|
bool prevent_default = Emit("before-input-event", event);
|
||||||
|
@ -1392,6 +1395,35 @@ void WebContents::FindReply(content::WebContents* web_contents,
|
||||||
Emit("found-in-page", result.GetHandle());
|
Emit("found-in-page", result.GetHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::RequestExclusivePointerAccess(
|
||||||
|
content::WebContents* web_contents,
|
||||||
|
bool user_gesture,
|
||||||
|
bool last_unlocked_by_target,
|
||||||
|
bool allowed) {
|
||||||
|
if (allowed) {
|
||||||
|
exclusive_access_manager_->mouse_lock_controller()->RequestToLockMouse(
|
||||||
|
web_contents, user_gesture, last_unlocked_by_target);
|
||||||
|
} else {
|
||||||
|
web_contents->GotResponseToLockMouseRequest(
|
||||||
|
blink::mojom::PointerLockResult::kPermissionDenied);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebContents::RequestToLockMouse(content::WebContents* web_contents,
|
||||||
|
bool user_gesture,
|
||||||
|
bool last_unlocked_by_target) {
|
||||||
|
auto* permission_helper =
|
||||||
|
WebContentsPermissionHelper::FromWebContents(web_contents);
|
||||||
|
permission_helper->RequestPointerLockPermission(
|
||||||
|
user_gesture, last_unlocked_by_target,
|
||||||
|
base::BindOnce(&WebContents::RequestExclusivePointerAccess,
|
||||||
|
base::Unretained(this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebContents::LostMouseLock() {
|
||||||
|
exclusive_access_manager_->mouse_lock_controller()->LostMouseLock();
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::RequestKeyboardLock(content::WebContents* web_contents,
|
void WebContents::RequestKeyboardLock(content::WebContents* web_contents,
|
||||||
bool esc_key_locked) {
|
bool esc_key_locked) {
|
||||||
exclusive_access_manager_->keyboard_lock_controller()->RequestKeyboardLock(
|
exclusive_access_manager_->keyboard_lock_controller()->RequestKeyboardLock(
|
||||||
|
@ -1424,14 +1456,6 @@ void WebContents::RequestMediaAccessPermission(
|
||||||
permission_helper->RequestMediaAccessPermission(request, std::move(callback));
|
permission_helper->RequestMediaAccessPermission(request, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::RequestToLockMouse(content::WebContents* web_contents,
|
|
||||||
bool user_gesture,
|
|
||||||
bool last_unlocked_by_target) {
|
|
||||||
auto* permission_helper =
|
|
||||||
WebContentsPermissionHelper::FromWebContents(web_contents);
|
|
||||||
permission_helper->RequestPointerLockPermission(user_gesture);
|
|
||||||
}
|
|
||||||
|
|
||||||
content::JavaScriptDialogManager* WebContents::GetJavaScriptDialogManager(
|
content::JavaScriptDialogManager* WebContents::GetJavaScriptDialogManager(
|
||||||
content::WebContents* source) {
|
content::WebContents* source) {
|
||||||
if (!dialog_manager_)
|
if (!dialog_manager_)
|
||||||
|
|
|
@ -556,6 +556,14 @@ class WebContents : public ExclusiveAccessContext,
|
||||||
const gfx::Rect& selection_rect,
|
const gfx::Rect& selection_rect,
|
||||||
int active_match_ordinal,
|
int active_match_ordinal,
|
||||||
bool final_update) override;
|
bool final_update) override;
|
||||||
|
void RequestExclusivePointerAccess(content::WebContents* web_contents,
|
||||||
|
bool user_gesture,
|
||||||
|
bool last_unlocked_by_target,
|
||||||
|
bool allowed);
|
||||||
|
void RequestToLockMouse(content::WebContents* web_contents,
|
||||||
|
bool user_gesture,
|
||||||
|
bool last_unlocked_by_target) override;
|
||||||
|
void LostMouseLock() override;
|
||||||
void RequestKeyboardLock(content::WebContents* web_contents,
|
void RequestKeyboardLock(content::WebContents* web_contents,
|
||||||
bool esc_key_locked) override;
|
bool esc_key_locked) override;
|
||||||
void CancelKeyboardLockRequest(content::WebContents* web_contents) override;
|
void CancelKeyboardLockRequest(content::WebContents* web_contents) override;
|
||||||
|
@ -566,9 +574,6 @@ class WebContents : public ExclusiveAccessContext,
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
const content::MediaStreamRequest& request,
|
const content::MediaStreamRequest& request,
|
||||||
content::MediaResponseCallback callback) override;
|
content::MediaResponseCallback callback) override;
|
||||||
void RequestToLockMouse(content::WebContents* web_contents,
|
|
||||||
bool user_gesture,
|
|
||||||
bool last_unlocked_by_target) override;
|
|
||||||
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
|
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
|
||||||
content::WebContents* source) override;
|
content::WebContents* source) override;
|
||||||
void OnAudioStateChanged(bool audible) override;
|
void OnAudioStateChanged(bool audible) override;
|
||||||
|
|
|
@ -43,17 +43,6 @@ void MediaAccessAllowed(const content::MediaStreamRequest& request,
|
||||||
controller.Deny(blink::mojom::MediaStreamRequestResult::PERMISSION_DENIED);
|
controller.Deny(blink::mojom::MediaStreamRequestResult::PERMISSION_DENIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnPointerLockResponse(content::WebContents* web_contents, bool allowed) {
|
|
||||||
if (web_contents) {
|
|
||||||
if (allowed)
|
|
||||||
web_contents->GotResponseToLockMouseRequest(
|
|
||||||
blink::mojom::PointerLockResult::kSuccess);
|
|
||||||
else
|
|
||||||
web_contents->GotResponseToLockMouseRequest(
|
|
||||||
blink::mojom::PointerLockResult::kPermissionDenied);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnPermissionResponse(base::OnceCallback<void(bool)> callback,
|
void OnPermissionResponse(base::OnceCallback<void(bool)> callback,
|
||||||
blink::mojom::PermissionStatus status) {
|
blink::mojom::PermissionStatus status) {
|
||||||
if (status == blink::mojom::PermissionStatus::GRANTED)
|
if (status == blink::mojom::PermissionStatus::GRANTED)
|
||||||
|
@ -157,10 +146,15 @@ void WebContentsPermissionHelper::RequestWebNotificationPermission(
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContentsPermissionHelper::RequestPointerLockPermission(
|
void WebContentsPermissionHelper::RequestPointerLockPermission(
|
||||||
bool user_gesture) {
|
bool user_gesture,
|
||||||
|
bool last_unlocked_by_target,
|
||||||
|
base::OnceCallback<void(content::WebContents*, bool, bool, bool)>
|
||||||
|
callback) {
|
||||||
RequestPermission(
|
RequestPermission(
|
||||||
static_cast<content::PermissionType>(PermissionType::POINTER_LOCK),
|
static_cast<content::PermissionType>(PermissionType::POINTER_LOCK),
|
||||||
base::BindOnce(&OnPointerLockResponse, web_contents_), user_gesture);
|
base::BindOnce(std::move(callback), web_contents_, user_gesture,
|
||||||
|
last_unlocked_by_target),
|
||||||
|
user_gesture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContentsPermissionHelper::RequestOpenExternalPermission(
|
void WebContentsPermissionHelper::RequestOpenExternalPermission(
|
||||||
|
|
|
@ -36,9 +36,13 @@ class WebContentsPermissionHelper
|
||||||
void RequestFullscreenPermission(base::OnceCallback<void(bool)> callback);
|
void RequestFullscreenPermission(base::OnceCallback<void(bool)> callback);
|
||||||
void RequestMediaAccessPermission(const content::MediaStreamRequest& request,
|
void RequestMediaAccessPermission(const content::MediaStreamRequest& request,
|
||||||
content::MediaResponseCallback callback);
|
content::MediaResponseCallback callback);
|
||||||
|
void RequestPointerLockPermission(
|
||||||
|
bool user_gesture,
|
||||||
|
bool last_unlocked_by_target,
|
||||||
|
base::OnceCallback<void(content::WebContents*, bool, bool, bool)>
|
||||||
|
callback);
|
||||||
void RequestWebNotificationPermission(
|
void RequestWebNotificationPermission(
|
||||||
base::OnceCallback<void(bool)> callback);
|
base::OnceCallback<void(bool)> callback);
|
||||||
void RequestPointerLockPermission(bool user_gesture);
|
|
||||||
void RequestOpenExternalPermission(base::OnceCallback<void(bool)> callback,
|
void RequestOpenExternalPermission(base::OnceCallback<void(bool)> callback,
|
||||||
bool user_gesture,
|
bool user_gesture,
|
||||||
const GURL& url);
|
const GURL& url);
|
||||||
|
|
Loading…
Reference in a new issue