Skip to content

Commit

Permalink
webhid: Migrate HidDelegate to use BrowserContext and Origin
Browse files Browse the repository at this point in the history
This is a temporary fix for  https://chromium-review.googlesource.com/c/chromium/src/+/3611967 to get the build compiling, but we need to either patch around  https://chromium-review.googlesource.com/c/chromium/src/+/3611967 or move our device permissioning to BrowserContext
  • Loading branch information
jkleinsc authored and codebytere committed Jun 3, 2022
1 parent 014c4b9 commit 322e968
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions shell/browser/hid/electron_hid_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ std::unique_ptr<content::HidChooser> ElectronHidDelegate::RunChooser(
AddControllerForFrame(render_frame_host, std::move(filters),
std::move(exclusion_filters), std::move(callback));

render_frame_host_id_ = render_frame_host->GetGlobalId();

// Return a nullptr because the return value isn't used for anything, eg
// there is no mechanism to cancel navigator.hid.requestDevice(). The return
// value is simply used in Chromium to cleanup the chooser UI once the serial
Expand All @@ -59,8 +61,9 @@ std::unique_ptr<content::HidChooser> ElectronHidDelegate::RunChooser(
bool ElectronHidDelegate::CanRequestDevicePermission(
content::BrowserContext* browser_context,
const url::Origin& origin) {
auto* rfh = content::RenderFrameHost::FromID(render_frame_host_id_);
auto* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
content::WebContents::FromRenderFrameHost(rfh);
auto* permission_helper =
WebContentsPermissionHelper::FromWebContents(web_contents);
return permission_helper->CheckHIDAccessPermission(
Expand All @@ -71,16 +74,18 @@ bool ElectronHidDelegate::HasDevicePermission(
content::BrowserContext* browser_context,
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device) {
auto* rfh = content::RenderFrameHost::FromID(render_frame_host_id_);
return GetChooserContext(browser_context)
->HasDevicePermission(origin, device);
->HasDevicePermission(origin, device, rfh);
}

void ElectronHidDelegate::RevokeDevicePermission(
content::BrowserContext* browser_context,
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device) {
auto* rfh = content::RenderFrameHost::FromID(render_frame_host_id_);
return GetChooserContext(browser_context)
->RevokeDevicePermission(origin, device);
->RevokeDevicePermission(origin, device, rfh);
}

device::mojom::HidManager* ElectronHidDelegate::GetHidManager(
Expand Down
2 changes: 2 additions & 0 deletions shell/browser/hid/electron_hid_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class ElectronHidDelegate : public content::HidDelegate,
std::unique_ptr<HidChooserController>>
controller_map_;

content::GlobalRenderFrameHostId render_frame_host_id_;

base::WeakPtrFactory<ElectronHidDelegate> weak_factory_{this};
};

Expand Down

0 comments on commit 322e968

Please sign in to comment.