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

Side by Side Diff: content/browser/bluetooth/bluetooth_device_chooser_controller.cc

Issue 2304213002: Show device connection and paired status in chooser on Mac (Closed)
Patch Set: added code to handle text identation Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" 5 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <unordered_set> 9 #include <unordered_set>
10 10
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 191 }
192 NOTREACHED(); 192 NOTREACHED();
193 return UMARequestDeviceOutcome::SUCCESS; 193 return UMARequestDeviceOutcome::SUCCESS;
194 } 194 }
195 195
196 } // namespace 196 } // namespace
197 197
198 BluetoothDeviceChooserController::BluetoothDeviceChooserController( 198 BluetoothDeviceChooserController::BluetoothDeviceChooserController(
199 WebBluetoothServiceImpl* web_bluetooth_service, 199 WebBluetoothServiceImpl* web_bluetooth_service,
200 RenderFrameHost* render_frame_host, 200 RenderFrameHost* render_frame_host,
201 device::BluetoothAdapter* adapter) 201 device::BluetoothAdapter* adapter,
202 const BluetoothAllowedDevicesMap& bluetooth_allowed_devices_map,
203 const url::Origin& origin)
202 : adapter_(adapter), 204 : adapter_(adapter),
203 web_bluetooth_service_(web_bluetooth_service), 205 web_bluetooth_service_(web_bluetooth_service),
204 render_frame_host_(render_frame_host), 206 render_frame_host_(render_frame_host),
205 web_contents_(WebContents::FromRenderFrameHost(render_frame_host_)), 207 web_contents_(WebContents::FromRenderFrameHost(render_frame_host_)),
206 discovery_session_timer_( 208 discovery_session_timer_(
207 FROM_HERE, 209 FROM_HERE,
208 // TODO(jyasskin): Add a way for tests to control the dialog 210 // TODO(jyasskin): Add a way for tests to control the dialog
209 // directly, and change this to a reasonable discovery timeout. 211 // directly, and change this to a reasonable discovery timeout.
210 base::TimeDelta::FromSeconds( 212 base::TimeDelta::FromSeconds(
211 use_test_scan_duration_ ? kTestScanDuration : kScanDuration), 213 use_test_scan_duration_ ? kTestScanDuration : kScanDuration),
212 base::Bind(&BluetoothDeviceChooserController::StopDeviceDiscovery, 214 base::Bind(&BluetoothDeviceChooserController::StopDeviceDiscovery,
213 // base::Timer guarantees it won't call back after its 215 // base::Timer guarantees it won't call back after its
214 // destructor starts. 216 // destructor starts.
215 base::Unretained(this)), 217 base::Unretained(this)),
216 /*is_repeating=*/false), 218 /*is_repeating=*/false),
219 bluetooth_allowed_devices_map_(bluetooth_allowed_devices_map),
220 origin_(origin),
217 weak_ptr_factory_(this) { 221 weak_ptr_factory_(this) {
218 CHECK(adapter_); 222 CHECK(adapter_);
219 } 223 }
220 224
221 BluetoothDeviceChooserController::~BluetoothDeviceChooserController() { 225 BluetoothDeviceChooserController::~BluetoothDeviceChooserController() {
222 if (chooser_) { 226 if (chooser_) {
223 DCHECK(!error_callback_.is_null()); 227 DCHECK(!error_callback_.is_null());
224 error_callback_.Run(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED); 228 error_callback_.Run(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED);
225 } 229 }
226 } 230 }
(...skipping 23 matching lines...) Expand all
250 // Check blacklist to reject invalid filters and adjust optional_services. 254 // Check blacklist to reject invalid filters and adjust optional_services.
251 if (BluetoothBlacklist::Get().IsExcluded(options_->filters)) { 255 if (BluetoothBlacklist::Get().IsExcluded(options_->filters)) {
252 RecordRequestDeviceOutcome( 256 RecordRequestDeviceOutcome(
253 UMARequestDeviceOutcome::BLACKLISTED_SERVICE_IN_FILTER); 257 UMARequestDeviceOutcome::BLACKLISTED_SERVICE_IN_FILTER);
254 PostErrorCallback( 258 PostErrorCallback(
255 blink::mojom::WebBluetoothError::REQUEST_DEVICE_WITH_BLACKLISTED_UUID); 259 blink::mojom::WebBluetoothError::REQUEST_DEVICE_WITH_BLACKLISTED_UUID);
256 return; 260 return;
257 } 261 }
258 BluetoothBlacklist::Get().RemoveExcludedUUIDs(options_.get()); 262 BluetoothBlacklist::Get().RemoveExcludedUUIDs(options_.get());
259 263
260 const url::Origin requesting_origin = 264 const url::Origin requesting_origin =
Jeffrey Yasskin 2016/09/14 20:08:36 I think we're assuming that this origin matches th
juncai 2016/09/14 23:13:07 Added WebBluetoothServiceImpl::IsDevicePaired(), s
Jeffrey Yasskin 2016/09/14 23:52:03 Great.
261 render_frame_host_->GetLastCommittedOrigin(); 265 render_frame_host_->GetLastCommittedOrigin();
262 const url::Origin embedding_origin = 266 const url::Origin embedding_origin =
263 web_contents_->GetMainFrame()->GetLastCommittedOrigin(); 267 web_contents_->GetMainFrame()->GetLastCommittedOrigin();
264 268
265 // TODO(crbug.com/518042): Enforce correctly-delegated permissions instead of 269 // TODO(crbug.com/518042): Enforce correctly-delegated permissions instead of
266 // matching origins. When relaxing this, take care to handle non-sandboxed 270 // matching origins. When relaxing this, take care to handle non-sandboxed
267 // unique origins. 271 // unique origins.
268 if (!embedding_origin.IsSameOriginWith(requesting_origin)) { 272 if (!embedding_origin.IsSameOriginWith(requesting_origin)) {
269 PostErrorCallback(blink::mojom::WebBluetoothError:: 273 PostErrorCallback(blink::mojom::WebBluetoothError::
270 REQUEST_DEVICE_FROM_CROSS_ORIGIN_IFRAME); 274 REQUEST_DEVICE_FROM_CROSS_ORIGIN_IFRAME);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 return; 347 return;
344 } 348 }
345 349
346 StartDeviceDiscovery(); 350 StartDeviceDiscovery();
347 } 351 }
348 352
349 void BluetoothDeviceChooserController::AddFilteredDevice( 353 void BluetoothDeviceChooserController::AddFilteredDevice(
350 const device::BluetoothDevice& device) { 354 const device::BluetoothDevice& device) {
351 if (chooser_.get() && MatchesFilters(device, options_->filters)) { 355 if (chooser_.get() && MatchesFilters(device, options_->filters)) {
352 base::Optional<int8_t> rssi = device.GetInquiryRSSI(); 356 base::Optional<int8_t> rssi = device.GetInquiryRSSI();
357 bool is_paired = bluetooth_allowed_devices_map_.GetDeviceId(
358 origin_, device.GetAddress()) != nullptr;
353 chooser_->AddOrUpdateDevice( 359 chooser_->AddOrUpdateDevice(
354 device.GetAddress(), !!device.GetName() /* should_update_name */, 360 device.GetAddress(), !!device.GetName() /* should_update_name */,
355 device.GetNameForDisplay(), 361 device.GetNameForDisplay(), device.IsGattConnected(), is_paired,
356 // TODO(http://crbug.com/543466): Show connection and paired status.
357 false /* is_gatt_connected */, false /* is_paired */,
358 rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1); 362 rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1);
359 } 363 }
360 } 364 }
361 365
362 void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) { 366 void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) {
363 if (!powered && discovery_session_.get()) { 367 if (!powered && discovery_session_.get()) {
364 StopDiscoverySession(std::move(discovery_session_)); 368 StopDiscoverySession(std::move(discovery_session_));
365 } 369 }
366 370
367 if (chooser_.get()) { 371 if (chooser_.get()) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 513
510 void BluetoothDeviceChooserController::PostErrorCallback( 514 void BluetoothDeviceChooserController::PostErrorCallback(
511 blink::mojom::WebBluetoothError error) { 515 blink::mojom::WebBluetoothError error) {
512 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( 516 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
513 FROM_HERE, base::Bind(error_callback_, error))) { 517 FROM_HERE, base::Bind(error_callback_, error))) {
514 LOG(WARNING) << "No TaskRunner."; 518 LOG(WARNING) << "No TaskRunner.";
515 } 519 }
516 } 520 }
517 521
518 } // namespace content 522 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698