Commit 0a8c7ee1 authored by James Hollyer's avatar James Hollyer Committed by Commit Bot

Use ChangeMouseLock function from CrossProcessFrameConnector

The FrameConnectorDelegate is supposed to be an interface which
is implemented by an object supplying platform semantics for a child
frame. The recent change(https://crrev.com/c/2071788) failed to
implement the ChangeMouseLock in CrossProcessFrameConnector and
therefore these calls were not getting to the correct place.

I also added the error handler for the rarely hit
PointerLockResult::kUserRejected error.

Bug: 1062702
Change-Id: I9c6aad9bac455b578b39e2aa086732f69f09fe61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2116327
Commit-Queue: James Hollyer <jameshollyer@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarJonathan Ross <jonross@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756517}
parent 1d8f9b48
......@@ -272,6 +272,14 @@ blink::mojom::PointerLockResult CrossProcessFrameConnector::LockMouse(
return blink::mojom::PointerLockResult::kWrongDocument;
}
blink::mojom::PointerLockResult CrossProcessFrameConnector::ChangeMouseLock(
bool request_unadjusted_movement) {
RenderWidgetHostViewBase* root_view = GetRootRenderWidgetHostView();
if (root_view)
return root_view->ChangeMouseLock(request_unadjusted_movement);
return blink::mojom::PointerLockResult::kWrongDocument;
}
void CrossProcessFrameConnector::UnlockMouse() {
RenderWidgetHostViewBase* root_view = GetRootRenderWidgetHostView();
if (root_view)
......
......@@ -98,6 +98,8 @@ class CONTENT_EXPORT CrossProcessFrameConnector
void FocusRootView() override;
blink::mojom::PointerLockResult LockMouse(
bool request_unadjusted_movement) override;
blink::mojom::PointerLockResult ChangeMouseLock(
bool request_unadjusted_movement) override;
void UnlockMouse() override;
void EnableAutoResize(const gfx::Size& min_size,
const gfx::Size& max_size) override;
......
......@@ -773,4 +773,107 @@ IN_PROC_BROWSER_TEST_F(PointerLockBrowserTestWithOptions,
EXPECT_EQ("[6,7,10,11]", EvalJs(root, "JSON.stringify([x,y,mX,mY])"));
}
#endif
#if defined(USE_AURA)
// TODO(https://crbug.com/982379): Remove failure test when fully implemented
#if defined(OS_WIN)
#define MAYBE_ChangeUnadjustedMovementFailure \
DISABLED_ChangeUnadjustedMovementFailure
#else
#define MAYBE_ChangeUnadjustedMovementFailure ChangeUnadjustedMovementFailure
#endif
// Tests that a subsequent request to RequestPointerLock with different
// options inside a Child view gets piped to the proper places and gives
// the proper unsupported error(this option is only supported on Windows
// This was prompted by this bug: https://crbug.com/1062702
IN_PROC_BROWSER_TEST_F(PointerLockBrowserTestWithOptions,
MAYBE_ChangeUnadjustedMovementFailure) {
GURL main_url(embedded_test_server()->GetURL(
"a.com", "/cross_site_iframe_factory.html?a(b)"));
EXPECT_TRUE(NavigateToURL(shell(), main_url));
FrameTreeNode* root = web_contents()->GetFrameTree()->root();
FrameTreeNode* child = root->child_at(0);
RenderWidgetHostViewBase* child_view = static_cast<RenderWidgetHostViewBase*>(
child->current_frame_host()->GetView());
WaitForHitTestData(child->current_frame_host());
// Request a pointer lock on the child frame's body and wait for the promise
// to resolve.
EXPECT_EQ(nullptr, EvalJs(child, "document.body.requestPointerLock()"));
// Child frame should have been granted pointer lock.
EXPECT_EQ(true,
EvalJs(child, "document.pointerLockElement == document.body"));
EXPECT_TRUE(child_view->IsMouseLocked());
EXPECT_FALSE(root->current_frame_host()
->GetView()
->GetIsMouseLockedUnadjustedMovementForTesting());
EXPECT_EQ(child_view->host(), web_contents()->GetMouseLockWidget());
// Request to change pointer lock options and wait for return.
EXPECT_EQ(
"a JavaScript error: \"NotSupportedError: The options asked for in this "
"request are not supported on this platform.\"\n",
EvalJs(child,
"document.body.requestPointerLock({unadjustedMovement:true})")
.error);
// The change errored out but the original lock should still be in place.
EXPECT_TRUE(child_view->IsMouseLocked());
EXPECT_FALSE(root->current_frame_host()
->GetView()
->GetIsMouseLockedUnadjustedMovementForTesting());
EXPECT_EQ(child_view->host(), web_contents()->GetMouseLockWidget());
}
#endif
#if defined(USE_AURA)
#if defined(OS_WIN)
// Tests that a subsequent request to RequestPointerLock with different
// options inside a Child view gets piped to the proper places and updates
// the option(this option is only supported on Windows).
// This was prompted by this bug: https://crbug.com/1062702
IN_PROC_BROWSER_TEST_F(PointerLockBrowserTestWithOptions,
ChangeUnadjustedMovementSuccess) {
GURL main_url(embedded_test_server()->GetURL(
"a.com", "/cross_site_iframe_factory.html?a(b)"));
EXPECT_TRUE(NavigateToURL(shell(), main_url));
FrameTreeNode* root = web_contents()->GetFrameTree()->root();
FrameTreeNode* child = root->child_at(0);
RenderWidgetHostViewBase* child_view = static_cast<RenderWidgetHostViewBase*>(
child->current_frame_host()->GetView());
WaitForHitTestData(child->current_frame_host());
// Request a pointer lock on the child frame's body and wait for the promise
// to resolve.
EXPECT_EQ(nullptr, EvalJs(child, "document.body.requestPointerLock()"));
// Child frame should have been granted pointer lock.
EXPECT_EQ(true,
EvalJs(child, "document.pointerLockElement == document.body"));
EXPECT_TRUE(child_view->IsMouseLocked());
EXPECT_FALSE(root->current_frame_host()
->GetView()
->GetIsMouseLockedUnadjustedMovementForTesting());
EXPECT_EQ(child_view->host(), web_contents()->GetMouseLockWidget());
// Request to change pointer lock options and wait for return.
EXPECT_EQ(
nullptr,
EvalJs(child,
"document.body.requestPointerLock({unadjustedMovement:true})"));
// The new changed lock should now be in place.
EXPECT_TRUE(child_view->IsMouseLocked());
EXPECT_TRUE(root->current_frame_host()
->GetView()
->GetIsMouseLockedUnadjustedMovementForTesting());
EXPECT_EQ(child_view->host(), web_contents()->GetMouseLockWidget());
}
#endif // WIN_OS
#endif // USE_AURA
} // namespace content
......@@ -79,11 +79,13 @@ bool FrameConnectorDelegate::HasFocus() {
blink::mojom::PointerLockResult FrameConnectorDelegate::LockMouse(
bool request_unadjusted_movement) {
NOTREACHED();
return blink::mojom::PointerLockResult::kUnknownError;
}
blink::mojom::PointerLockResult FrameConnectorDelegate::ChangeMouseLock(
bool request_unadjusted_movement) {
NOTREACHED();
return blink::mojom::PointerLockResult::kUnknownError;
}
......
......@@ -186,7 +186,12 @@ DOMException* PointerLockController::ConvertResultToException(
return MakeGarbageCollected<DOMException>(
DOMExceptionCode::kWrongDocumentError,
"The element has been destroyed while making this request.");
default:
case mojom::blink::PointerLockResult::kUserRejected:
return MakeGarbageCollected<DOMException>(
DOMExceptionCode::kSecurityError,
"The user has exited the lock before this request was completed.");
case mojom::blink::PointerLockResult::kSuccess:
case mojom::blink::PointerLockResult::kUnknownError:
return MakeGarbageCollected<DOMException>(
DOMExceptionCode::kUnknownError,
"If you see this error we have a bug. Please report this bug to "
......
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