Commit 85309cdc authored by Matt Reynolds's avatar Matt Reynolds Committed by Commit Bot

[webhid] Avoid DCHECK when revoking device permission

content::HidService incorrectly decrements the active frame
count when revoking a permission for a device with no open
connections. This CL changes the behavior so the active frame
count is only decremented if a connection was closed as a
result of revoking the permission.

BUG=1137031

Change-Id: I686d1e11193991c8e5ddeb7a90d50c77b848fe53
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2463997
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Auto-Submit: Matt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815893}
parent 15b72101
...@@ -183,22 +183,25 @@ void HidService::OnPermissionRevoked(const url::Origin& requesting_origin, ...@@ -183,22 +183,25 @@ void HidService::OnPermissionRevoked(const url::Origin& requesting_origin,
WebContents* web_contents = WebContents* web_contents =
WebContents::FromRenderFrameHost(render_frame_host()); WebContents::FromRenderFrameHost(render_frame_host());
base::EraseIf(watcher_ids_, [&](const auto& watcher_entry) { size_t watchers_removed =
const auto* device_info = base::EraseIf(watcher_ids_, [&](const auto& watcher_entry) {
delegate->GetDeviceInfo(web_contents, watcher_entry.first); const auto* device_info =
if (!device_info) delegate->GetDeviceInfo(web_contents, watcher_entry.first);
return true; if (!device_info)
return true;
if (delegate->HasDevicePermission(web_contents, origin(), *device_info)) {
return false; if (delegate->HasDevicePermission(web_contents, origin(),
} *device_info)) {
return false;
watchers_.Remove(watcher_entry.second); }
return true;
}); watchers_.Remove(watcher_entry.second);
return true;
});
// If needed decrement the active frame count. // If needed decrement the active frame count.
OnWatcherRemoved(false /* cleanup_watcher_ids */); if (watchers_removed)
OnWatcherRemoved(/*cleanup_watcher_ids=*/false);
} }
void HidService::FinishGetDevices( void HidService::FinishGetDevices(
......
...@@ -388,4 +388,19 @@ TEST_F(HidServiceTest, RevokeDevicePermission) { ...@@ -388,4 +388,19 @@ TEST_F(HidServiceTest, RevokeDevicePermission) {
EXPECT_FALSE(connection.is_connected()); EXPECT_FALSE(connection.is_connected());
} }
TEST_F(HidServiceTest, RevokeDevicePermissionWithoutConnection) {
NavigateAndCommit(GURL(kTestUrl));
mojo::Remote<blink::mojom::HidService> service;
contents()->GetMainFrame()->GetHidService(
service.BindNewPipeAndPassReceiver());
// Simulate user revoking permission.
url::Origin origin = url::Origin::Create(GURL(kTestUrl));
hid_delegate().OnPermissionRevoked(origin, origin);
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(contents()->IsConnectedToHidDevice());
}
} // namespace content } // namespace content
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