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

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

Issue 2394423002: bluetooth: Rename blink::mojom::WebBluetoothError (Closed)
Patch Set: bluetooth: Rename blink::mojom::WebBluetoothError Created 4 years, 2 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 // destructor starts. 218 // destructor starts.
219 base::Unretained(this)), 219 base::Unretained(this)),
220 /*is_repeating=*/false), 220 /*is_repeating=*/false),
221 weak_ptr_factory_(this) { 221 weak_ptr_factory_(this) {
222 CHECK(adapter_); 222 CHECK(adapter_);
223 } 223 }
224 224
225 BluetoothDeviceChooserController::~BluetoothDeviceChooserController() { 225 BluetoothDeviceChooserController::~BluetoothDeviceChooserController() {
226 if (chooser_) { 226 if (chooser_) {
227 DCHECK(!error_callback_.is_null()); 227 DCHECK(!error_callback_.is_null());
228 error_callback_.Run(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED); 228 error_callback_.Run(blink::mojom::WebBluetoothResult::CHOOSER_CANCELLED);
229 } 229 }
230 } 230 }
231 231
232 void BluetoothDeviceChooserController::GetDevice( 232 void BluetoothDeviceChooserController::GetDevice(
233 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, 233 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options,
234 const SuccessCallback& success_callback, 234 const SuccessCallback& success_callback,
235 const ErrorCallback& error_callback) { 235 const ErrorCallback& error_callback) {
236 DCHECK_CURRENTLY_ON(BrowserThread::UI); 236 DCHECK_CURRENTLY_ON(BrowserThread::UI);
237 237
238 // GetDevice should only be called once. 238 // GetDevice should only be called once.
(...skipping 10 matching lines...) Expand all
249 return; 249 return;
250 } 250 }
251 options_ = std::move(options); 251 options_ = std::move(options);
252 LogRequestDeviceOptions(options_); 252 LogRequestDeviceOptions(options_);
253 253
254 // Check blacklist to reject invalid filters and adjust optional_services. 254 // Check blacklist to reject invalid filters and adjust optional_services.
255 if (BluetoothBlacklist::Get().IsExcluded(options_->filters)) { 255 if (BluetoothBlacklist::Get().IsExcluded(options_->filters)) {
256 RecordRequestDeviceOutcome( 256 RecordRequestDeviceOutcome(
257 UMARequestDeviceOutcome::BLACKLISTED_SERVICE_IN_FILTER); 257 UMARequestDeviceOutcome::BLACKLISTED_SERVICE_IN_FILTER);
258 PostErrorCallback( 258 PostErrorCallback(
259 blink::mojom::WebBluetoothError::REQUEST_DEVICE_WITH_BLACKLISTED_UUID); 259 blink::mojom::WebBluetoothResult::REQUEST_DEVICE_WITH_BLACKLISTED_UUID);
260 return; 260 return;
261 } 261 }
262 BluetoothBlacklist::Get().RemoveExcludedUUIDs(options_.get()); 262 BluetoothBlacklist::Get().RemoveExcludedUUIDs(options_.get());
263 263
264 const url::Origin requesting_origin = 264 const url::Origin requesting_origin =
265 render_frame_host_->GetLastCommittedOrigin(); 265 render_frame_host_->GetLastCommittedOrigin();
266 const url::Origin embedding_origin = 266 const url::Origin embedding_origin =
267 web_contents_->GetMainFrame()->GetLastCommittedOrigin(); 267 web_contents_->GetMainFrame()->GetLastCommittedOrigin();
268 268
269 // TODO(crbug.com/518042): Enforce correctly-delegated permissions instead of 269 // TODO(crbug.com/518042): Enforce correctly-delegated permissions instead of
270 // matching origins. When relaxing this, take care to handle non-sandboxed 270 // matching origins. When relaxing this, take care to handle non-sandboxed
271 // unique origins. 271 // unique origins.
272 if (!embedding_origin.IsSameOriginWith(requesting_origin)) { 272 if (!embedding_origin.IsSameOriginWith(requesting_origin)) {
273 PostErrorCallback(blink::mojom::WebBluetoothError:: 273 PostErrorCallback(blink::mojom::WebBluetoothResult::
274 REQUEST_DEVICE_FROM_CROSS_ORIGIN_IFRAME); 274 REQUEST_DEVICE_FROM_CROSS_ORIGIN_IFRAME);
275 return; 275 return;
276 } 276 }
277 // The above also excludes unique origins, which are not even same-origin with 277 // The above also excludes unique origins, which are not even same-origin with
278 // themselves. 278 // themselves.
279 DCHECK(!requesting_origin.unique()); 279 DCHECK(!requesting_origin.unique());
280 280
281 if (!adapter_->IsPresent()) { 281 if (!adapter_->IsPresent()) {
282 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice."; 282 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice.";
283 RecordRequestDeviceOutcome( 283 RecordRequestDeviceOutcome(
284 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT); 284 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT);
285 PostErrorCallback(blink::mojom::WebBluetoothError::NO_BLUETOOTH_ADAPTER); 285 PostErrorCallback(blink::mojom::WebBluetoothResult::NO_BLUETOOTH_ADAPTER);
286 return; 286 return;
287 } 287 }
288 288
289 switch (GetContentClient()->browser()->AllowWebBluetooth( 289 switch (GetContentClient()->browser()->AllowWebBluetooth(
290 web_contents_->GetBrowserContext(), requesting_origin, 290 web_contents_->GetBrowserContext(), requesting_origin,
291 embedding_origin)) { 291 embedding_origin)) {
292 case ContentBrowserClient::AllowWebBluetoothResult::BLOCK_POLICY: { 292 case ContentBrowserClient::AllowWebBluetoothResult::BLOCK_POLICY: {
293 RecordRequestDeviceOutcome( 293 RecordRequestDeviceOutcome(
294 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_POLICY_DISABLED); 294 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_POLICY_DISABLED);
295 PostErrorCallback(blink::mojom::WebBluetoothError:: 295 PostErrorCallback(blink::mojom::WebBluetoothResult::
296 CHOOSER_NOT_SHOWN_API_LOCALLY_DISABLED); 296 CHOOSER_NOT_SHOWN_API_LOCALLY_DISABLED);
297 return; 297 return;
298 } 298 }
299 case ContentBrowserClient::AllowWebBluetoothResult:: 299 case ContentBrowserClient::AllowWebBluetoothResult::
300 BLOCK_GLOBALLY_DISABLED: { 300 BLOCK_GLOBALLY_DISABLED: {
301 // Log to the developer console. 301 // Log to the developer console.
302 web_contents_->GetMainFrame()->AddMessageToConsole( 302 web_contents_->GetMainFrame()->AddMessageToConsole(
303 content::CONSOLE_MESSAGE_LEVEL_LOG, 303 content::CONSOLE_MESSAGE_LEVEL_LOG,
304 "Bluetooth permission has been blocked."); 304 "Bluetooth permission has been blocked.");
305 // Block requests. 305 // Block requests.
306 RecordRequestDeviceOutcome( 306 RecordRequestDeviceOutcome(
307 UMARequestDeviceOutcome::BLUETOOTH_GLOBALLY_DISABLED); 307 UMARequestDeviceOutcome::BLUETOOTH_GLOBALLY_DISABLED);
308 PostErrorCallback(blink::mojom::WebBluetoothError:: 308 PostErrorCallback(blink::mojom::WebBluetoothResult::
309 CHOOSER_NOT_SHOWN_API_GLOBALLY_DISABLED); 309 CHOOSER_NOT_SHOWN_API_GLOBALLY_DISABLED);
310 return; 310 return;
311 } 311 }
312 case ContentBrowserClient::AllowWebBluetoothResult::ALLOW: 312 case ContentBrowserClient::AllowWebBluetoothResult::ALLOW:
313 break; 313 break;
314 } 314 }
315 315
316 BluetoothChooser::EventHandler chooser_event_handler = 316 BluetoothChooser::EventHandler chooser_event_handler =
317 base::Bind(&BluetoothDeviceChooserController::OnBluetoothChooserEvent, 317 base::Bind(&BluetoothDeviceChooserController::OnBluetoothChooserEvent,
318 base::Unretained(this)); 318 base::Unretained(this));
319 319
320 if (WebContentsDelegate* delegate = web_contents_->GetDelegate()) { 320 if (WebContentsDelegate* delegate = web_contents_->GetDelegate()) {
321 chooser_ = delegate->RunBluetoothChooser(render_frame_host_, 321 chooser_ = delegate->RunBluetoothChooser(render_frame_host_,
322 chooser_event_handler); 322 chooser_event_handler);
323 } 323 }
324 324
325 if (!chooser_.get()) { 325 if (!chooser_.get()) {
326 PostErrorCallback( 326 PostErrorCallback(
327 blink::mojom::WebBluetoothError::WEB_BLUETOOTH_NOT_SUPPORTED); 327 blink::mojom::WebBluetoothResult::WEB_BLUETOOTH_NOT_SUPPORTED);
328 return; 328 return;
329 } 329 }
330 330
331 if (!chooser_->CanAskForScanningPermission()) { 331 if (!chooser_->CanAskForScanningPermission()) {
332 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; 332 VLOG(1) << "Closing immediately because Chooser cannot obtain permission.";
333 OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION, 333 OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION,
334 "" /* device_address */); 334 "" /* device_address */);
335 return; 335 return;
336 } 336 }
337 337
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 463
464 switch (event) { 464 switch (event) {
465 case BluetoothChooser::Event::RESCAN: 465 case BluetoothChooser::Event::RESCAN:
466 PopulateConnectedDevices(); 466 PopulateConnectedDevices();
467 DCHECK(chooser_); 467 DCHECK(chooser_);
468 StartDeviceDiscovery(); 468 StartDeviceDiscovery();
469 // No need to close the chooser so we return. 469 // No need to close the chooser so we return.
470 return; 470 return;
471 case BluetoothChooser::Event::DENIED_PERMISSION: 471 case BluetoothChooser::Event::DENIED_PERMISSION:
472 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); 472 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
473 PostErrorCallback(blink::mojom::WebBluetoothError:: 473 PostErrorCallback(blink::mojom::WebBluetoothResult::
474 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN); 474 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN);
475 break; 475 break;
476 case BluetoothChooser::Event::CANCELLED: 476 case BluetoothChooser::Event::CANCELLED:
477 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); 477 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
478 PostErrorCallback(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED); 478 PostErrorCallback(blink::mojom::WebBluetoothResult::CHOOSER_CANCELLED);
479 break; 479 break;
480 case BluetoothChooser::Event::SHOW_OVERVIEW_HELP: 480 case BluetoothChooser::Event::SHOW_OVERVIEW_HELP:
481 VLOG(1) << "Overview Help link pressed."; 481 VLOG(1) << "Overview Help link pressed.";
482 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); 482 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
483 PostErrorCallback(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED); 483 PostErrorCallback(blink::mojom::WebBluetoothResult::CHOOSER_CANCELLED);
484 break; 484 break;
485 case BluetoothChooser::Event::SHOW_ADAPTER_OFF_HELP: 485 case BluetoothChooser::Event::SHOW_ADAPTER_OFF_HELP:
486 VLOG(1) << "Adapter Off Help link pressed."; 486 VLOG(1) << "Adapter Off Help link pressed.";
487 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); 487 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
488 PostErrorCallback(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED); 488 PostErrorCallback(blink::mojom::WebBluetoothResult::CHOOSER_CANCELLED);
489 break; 489 break;
490 case BluetoothChooser::Event::SHOW_NEED_LOCATION_HELP: 490 case BluetoothChooser::Event::SHOW_NEED_LOCATION_HELP:
491 VLOG(1) << "Need Location Help link pressed."; 491 VLOG(1) << "Need Location Help link pressed.";
492 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event)); 492 RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
493 PostErrorCallback(blink::mojom::WebBluetoothError::CHOOSER_CANCELLED); 493 PostErrorCallback(blink::mojom::WebBluetoothResult::CHOOSER_CANCELLED);
494 break; 494 break;
495 case BluetoothChooser::Event::SELECTED: 495 case BluetoothChooser::Event::SELECTED:
496 PostSuccessCallback(device_address); 496 PostSuccessCallback(device_address);
497 break; 497 break;
498 } 498 }
499 // Close chooser. 499 // Close chooser.
500 chooser_.reset(); 500 chooser_.reset();
501 } 501 }
502 502
503 void BluetoothDeviceChooserController::PostSuccessCallback( 503 void BluetoothDeviceChooserController::PostSuccessCallback(
504 const std::string& device_address) { 504 const std::string& device_address) {
505 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( 505 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
506 FROM_HERE, 506 FROM_HERE,
507 base::Bind(success_callback_, base::Passed(std::move(options_)), 507 base::Bind(success_callback_, base::Passed(std::move(options_)),
508 device_address))) { 508 device_address))) {
509 LOG(WARNING) << "No TaskRunner."; 509 LOG(WARNING) << "No TaskRunner.";
510 } 510 }
511 } 511 }
512 512
513 void BluetoothDeviceChooserController::PostErrorCallback( 513 void BluetoothDeviceChooserController::PostErrorCallback(
514 blink::mojom::WebBluetoothError error) { 514 blink::mojom::WebBluetoothResult error) {
515 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( 515 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
516 FROM_HERE, base::Bind(error_callback_, error))) { 516 FROM_HERE, base::Bind(error_callback_, error))) {
517 LOG(WARNING) << "No TaskRunner."; 517 LOG(WARNING) << "No TaskRunner.";
518 } 518 }
519 } 519 }
520 520
521 } // namespace content 521 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/bluetooth_device_chooser_controller.h ('k') | content/browser/bluetooth/cache_query_result.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698