Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Unified Diff: content/browser/bluetooth/bluetooth_dispatcher_host.cc

Issue 1706503002: Add enterprise policy to turn off Bluetooth. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Sync Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/bluetooth/bluetooth_dispatcher_host.cc
diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
index e5b96d93df90afdb7f89ceea2fdcf5350cc6cea2..504d1163a87880a580454c359dddaa9ecf077977 100644
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
@@ -25,6 +25,9 @@
#include "content/browser/bluetooth/first_device_bluetooth_chooser.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/common/bluetooth/bluetooth_messages.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/permission_manager.h"
+#include "content/public/browser/permission_type.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "device/bluetooth/bluetooth_adapter.h"
@@ -1024,18 +1027,25 @@ void BluetoothDispatcherHost::OnRequestDeviceImpl(
RenderFrameHostImpl* render_frame_host =
RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
+ WebContents* web_contents =
+ WebContents::FromRenderFrameHost(render_frame_host);
- if (!render_frame_host) {
- DLOG(WARNING)
- << "Got a requestDevice IPC without a matching RenderFrameHost: "
- << render_process_id_ << ", " << frame_routing_id;
+ if (!render_frame_host || !web_contents) {
+ DLOG(WARNING) << "Got a requestDevice IPC without a matching "
+ << "RenderFrameHost or WebContents: " << render_process_id_
+ << ", " << frame_routing_id;
RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME);
Send(new BluetoothMsg_RequestDeviceError(
thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame));
return;
}
- if (render_frame_host->GetLastCommittedOrigin().unique()) {
+ const url::Origin requesting_origin =
+ render_frame_host->GetLastCommittedOrigin();
+ const url::Origin embedding_origin =
+ web_contents->GetMainFrame()->GetLastCommittedOrigin();
+
+ if (requesting_origin.unique()) {
VLOG(1) << "Request device with unique origin.";
Send(new BluetoothMsg_RequestDeviceError(
thread_id, request_id,
@@ -1061,22 +1071,32 @@ void BluetoothDispatcherHost::OnRequestDeviceImpl(
return;
}
+ if (web_contents->GetBrowserContext()
+ ->GetPermissionManager()
+ ->GetPermissionStatus(PermissionType::BLUETOOTH_GUARD,
+ GURL(requesting_origin.Serialize()),
+ GURL(embedding_origin.Serialize())) !=
+ PermissionStatus::ASK) {
+ RecordRequestDeviceOutcome(
+ UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_GLOBALLY_DISABLED);
+ Send(new BluetoothMsg_RequestDeviceError(
+ thread_id, request_id, WebBluetoothError::ChooserDisabled));
+ return;
+ }
+
// Create storage for the information that backs the chooser, and show the
// chooser.
- RequestDeviceSession* const session = new RequestDeviceSession(
- thread_id, request_id, render_frame_host->GetLastCommittedOrigin(),
- filters, optional_services_blacklist_filtered);
+ RequestDeviceSession* const session =
+ new RequestDeviceSession(thread_id, request_id, requesting_origin,
+ filters, optional_services_blacklist_filtered);
int chooser_id = request_device_sessions_.Add(session);
BluetoothChooser::EventHandler chooser_event_handler =
base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent,
weak_ptr_on_ui_thread_, chooser_id);
- if (WebContents* web_contents =
- WebContents::FromRenderFrameHost(render_frame_host)) {
- if (WebContentsDelegate* delegate = web_contents->GetDelegate()) {
- session->chooser = delegate->RunBluetoothChooser(render_frame_host,
- chooser_event_handler);
- }
+ if (WebContentsDelegate* delegate = web_contents->GetDelegate()) {
+ session->chooser =
+ delegate->RunBluetoothChooser(render_frame_host, chooser_event_handler);
}
if (!session->chooser) {
LOG(WARNING)

Powered by Google App Engine
This is Rietveld 408576698