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 deb626df075cda1a08b08e8fc27ee6164cdd1dbf..0a032bee84082e4d44124e2a6ebcd3e35e0153fc 100644 |
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
@@ -24,6 +24,8 @@ |
#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/chooser_permission_manager.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/browser/web_contents_delegate.h" |
#include "device/bluetooth/bluetooth_adapter.h" |
@@ -340,11 +342,13 @@ struct BluetoothDispatcherHost::RequestDeviceSession { |
public: |
RequestDeviceSession(int thread_id, |
int request_id, |
+ content::WebContents* web_contents, |
url::Origin origin, |
const std::vector<BluetoothScanFilter>& filters, |
const std::vector<BluetoothUUID>& optional_services) |
: thread_id(thread_id), |
request_id(request_id), |
+ web_contents(web_contents), |
origin(origin), |
filters(filters), |
optional_services(optional_services) {} |
@@ -371,6 +375,7 @@ struct BluetoothDispatcherHost::RequestDeviceSession { |
const int thread_id; |
const int request_id; |
+ content::WebContents* web_contents; |
const url::Origin origin; |
const std::vector<BluetoothScanFilter> filters; |
const std::vector<BluetoothUUID> optional_services; |
@@ -658,18 +663,20 @@ void BluetoothDispatcherHost::OnRequestDevice( |
return; |
} |
+ WebContents* web_contents = |
+ WebContents::FromRenderFrameHost(render_frame_host); |
+ |
// 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); |
+ thread_id, request_id, web_contents, |
+ render_frame_host->GetLastCommittedOrigin(), filters, optional_services); |
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 (web_contents) { |
if (WebContentsDelegate* delegate = web_contents->GetDelegate()) { |
session->chooser = delegate->RunBluetoothChooser( |
web_contents, chooser_event_handler, |
@@ -1193,6 +1200,14 @@ void BluetoothDispatcherHost::FinishClosingChooser( |
for (BluetoothUUID uuid : device->GetUUIDs()) |
VLOG(1) << "\t" << uuid.canonical_value(); |
+ GURL embedding_origin = |
ortuno
2016/01/19 21:09:31
Can you add a TODO that points to an issue to chan
juncai
2016/01/19 22:21:37
Modified ChooserPermissionManager to take url::Ori
|
+ session->web_contents->GetMainFrame()->GetLastCommittedURL().GetOrigin(); |
ortuno
2016/01/19 21:09:31
Could the WebContents object be deleted before Fin
juncai
2016/01/19 22:21:37
store chooser_permission_manager pointer instead o
|
+ BrowserContext* browser_context = session->web_contents->GetBrowserContext(); |
+ ChooserPermissionManager* chooser_permission_manager = |
+ browser_context->GetChooserPermissionManager(); |
+ chooser_permission_manager->GrantPermission(GURL(session->origin.Serialize()), |
+ embedding_origin, device_id); |
+ |
const std::string& device_id_for_origin = allowed_devices_map_.AddDevice( |
session->origin, device->GetAddress(), session->filters, |
session->optional_services); |