Commit e7965a77 authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

Stop using WebContents::GetMainFrame in chrome/browser/bluetooth.

Use RenderFrameHost::GetMainFrame instead to always get the correct main
frame — as frame might have navigated away, WebContents::GetMainFrame can return
a completely different frame.

BUG=1061899

Change-Id: I319602ee64482cfe0dfc002c797c6dc0e80ec003
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2153110Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Alexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759899}
parent 73e177e7
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chrome/browser/bluetooth/bluetooth_chooser_context.h" #include "chrome/browser/bluetooth/bluetooth_chooser_context.h"
#include "chrome/browser/bluetooth/bluetooth_chooser_context_factory.h" #include "chrome/browser/bluetooth/bluetooth_chooser_context_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_device.h"
#include "device/bluetooth/public/cpp/bluetooth_uuid.h" #include "device/bluetooth/public/cpp/bluetooth_uuid.h"
...@@ -23,9 +24,9 @@ using device::BluetoothUUID; ...@@ -23,9 +24,9 @@ using device::BluetoothUUID;
namespace { namespace {
BluetoothChooserContext* GetBluetoothChooserContext(WebContents* web_contents) { BluetoothChooserContext* GetBluetoothChooserContext(RenderFrameHost* frame) {
auto* profile = auto* profile = Profile::FromBrowserContext(
Profile::FromBrowserContext(web_contents->GetBrowserContext()); WebContents::FromRenderFrameHost(frame)->GetBrowserContext());
return BluetoothChooserContextFactory::GetForProfile(profile); return BluetoothChooserContextFactory::GetForProfile(profile);
} }
...@@ -38,86 +39,68 @@ ChromeBluetoothDelegate::~ChromeBluetoothDelegate() = default; ...@@ -38,86 +39,68 @@ ChromeBluetoothDelegate::~ChromeBluetoothDelegate() = default;
WebBluetoothDeviceId ChromeBluetoothDelegate::GetWebBluetoothDeviceId( WebBluetoothDeviceId ChromeBluetoothDelegate::GetWebBluetoothDeviceId(
RenderFrameHost* frame, RenderFrameHost* frame,
const std::string& device_address) { const std::string& device_address) {
auto* web_contents = WebContents::FromRenderFrameHost(frame); return GetBluetoothChooserContext(frame)->GetWebBluetoothDeviceId(
return GetBluetoothChooserContext(web_contents) frame->GetLastCommittedOrigin(),
->GetWebBluetoothDeviceId( frame->GetMainFrame()->GetLastCommittedOrigin(), device_address);
frame->GetLastCommittedOrigin(),
web_contents->GetMainFrame()->GetLastCommittedOrigin(),
device_address);
} }
std::string ChromeBluetoothDelegate::GetDeviceAddress( std::string ChromeBluetoothDelegate::GetDeviceAddress(
RenderFrameHost* frame, RenderFrameHost* frame,
const WebBluetoothDeviceId& device_id) { const WebBluetoothDeviceId& device_id) {
auto* web_contents = WebContents::FromRenderFrameHost(frame); return GetBluetoothChooserContext(frame)->GetDeviceAddress(
return GetBluetoothChooserContext(web_contents) frame->GetLastCommittedOrigin(),
->GetDeviceAddress(frame->GetLastCommittedOrigin(), frame->GetMainFrame()->GetLastCommittedOrigin(), device_id);
web_contents->GetMainFrame()->GetLastCommittedOrigin(),
device_id);
} }
WebBluetoothDeviceId ChromeBluetoothDelegate::AddScannedDevice( WebBluetoothDeviceId ChromeBluetoothDelegate::AddScannedDevice(
RenderFrameHost* frame, RenderFrameHost* frame,
const std::string& device_address) { const std::string& device_address) {
auto* web_contents = WebContents::FromRenderFrameHost(frame); return GetBluetoothChooserContext(frame)->AddScannedDevice(
return GetBluetoothChooserContext(web_contents) frame->GetLastCommittedOrigin(),
->AddScannedDevice(frame->GetLastCommittedOrigin(), frame->GetMainFrame()->GetLastCommittedOrigin(), device_address);
web_contents->GetMainFrame()->GetLastCommittedOrigin(),
device_address);
} }
WebBluetoothDeviceId ChromeBluetoothDelegate::GrantServiceAccessPermission( WebBluetoothDeviceId ChromeBluetoothDelegate::GrantServiceAccessPermission(
RenderFrameHost* frame, RenderFrameHost* frame,
const device::BluetoothDevice* device, const device::BluetoothDevice* device,
const blink::mojom::WebBluetoothRequestDeviceOptions* options) { const blink::mojom::WebBluetoothRequestDeviceOptions* options) {
auto* web_contents = WebContents::FromRenderFrameHost(frame); return GetBluetoothChooserContext(frame)->GrantServiceAccessPermission(
return GetBluetoothChooserContext(web_contents) frame->GetLastCommittedOrigin(),
->GrantServiceAccessPermission( frame->GetMainFrame()->GetLastCommittedOrigin(), device, options);
frame->GetLastCommittedOrigin(),
web_contents->GetMainFrame()->GetLastCommittedOrigin(), device,
options);
} }
bool ChromeBluetoothDelegate::HasDevicePermission( bool ChromeBluetoothDelegate::HasDevicePermission(
RenderFrameHost* frame, RenderFrameHost* frame,
const WebBluetoothDeviceId& device_id) { const WebBluetoothDeviceId& device_id) {
auto* web_contents = WebContents::FromRenderFrameHost(frame); return GetBluetoothChooserContext(frame)->HasDevicePermission(
return GetBluetoothChooserContext(web_contents) frame->GetLastCommittedOrigin(),
->HasDevicePermission( frame->GetMainFrame()->GetLastCommittedOrigin(), device_id);
frame->GetLastCommittedOrigin(),
web_contents->GetMainFrame()->GetLastCommittedOrigin(), device_id);
} }
bool ChromeBluetoothDelegate::IsAllowedToAccessService( bool ChromeBluetoothDelegate::IsAllowedToAccessService(
RenderFrameHost* frame, RenderFrameHost* frame,
const WebBluetoothDeviceId& device_id, const WebBluetoothDeviceId& device_id,
const BluetoothUUID& service) { const BluetoothUUID& service) {
auto* web_contents = WebContents::FromRenderFrameHost(frame); return GetBluetoothChooserContext(frame)->IsAllowedToAccessService(
return GetBluetoothChooserContext(web_contents) frame->GetLastCommittedOrigin(),
->IsAllowedToAccessService( frame->GetMainFrame()->GetLastCommittedOrigin(), device_id, service);
frame->GetLastCommittedOrigin(),
web_contents->GetMainFrame()->GetLastCommittedOrigin(), device_id,
service);
} }
bool ChromeBluetoothDelegate::IsAllowedToAccessAtLeastOneService( bool ChromeBluetoothDelegate::IsAllowedToAccessAtLeastOneService(
RenderFrameHost* frame, RenderFrameHost* frame,
const WebBluetoothDeviceId& device_id) { const WebBluetoothDeviceId& device_id) {
auto* web_contents = WebContents::FromRenderFrameHost(frame); return GetBluetoothChooserContext(frame)->IsAllowedToAccessAtLeastOneService(
return GetBluetoothChooserContext(web_contents) frame->GetLastCommittedOrigin(),
->IsAllowedToAccessAtLeastOneService( frame->GetMainFrame()->GetLastCommittedOrigin(), device_id);
frame->GetLastCommittedOrigin(),
web_contents->GetMainFrame()->GetLastCommittedOrigin(), device_id);
} }
std::vector<blink::mojom::WebBluetoothDevicePtr> std::vector<blink::mojom::WebBluetoothDevicePtr>
ChromeBluetoothDelegate::GetPermittedDevices(content::RenderFrameHost* frame) { ChromeBluetoothDelegate::GetPermittedDevices(content::RenderFrameHost* frame) {
auto* web_contents = WebContents::FromRenderFrameHost(frame); auto* context = GetBluetoothChooserContext(frame);
auto* context = GetBluetoothChooserContext(web_contents);
std::vector<std::unique_ptr<permissions::ChooserContextBase::Object>> std::vector<std::unique_ptr<permissions::ChooserContextBase::Object>>
objects = context->GetGrantedObjects( objects = context->GetGrantedObjects(
frame->GetLastCommittedOrigin(), frame->GetLastCommittedOrigin(),
web_contents->GetMainFrame()->GetLastCommittedOrigin()); frame->GetMainFrame()->GetLastCommittedOrigin());
std::vector<blink::mojom::WebBluetoothDevicePtr> permitted_devices; std::vector<blink::mojom::WebBluetoothDevicePtr> permitted_devices;
for (const auto& object : objects) { for (const auto& object : objects) {
......
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