| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/usb/usb_chooser_controller.h" | 5 #include "chrome/browser/usb/usb_chooser_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 return device_name; | 68 return device_name; |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 UsbChooserController::UsbChooserController( | 73 UsbChooserController::UsbChooserController( |
| 74 content::RenderFrameHost* owner, | 74 content::RenderFrameHost* owner, |
| 75 mojo::Array<device::usb::DeviceFilterPtr> device_filters, | 75 const std::vector<device::usb::DeviceFilterPtr>& device_filters, |
| 76 content::RenderFrameHost* render_frame_host, | 76 content::RenderFrameHost* render_frame_host, |
| 77 const device::usb::ChooserService::GetPermissionCallback& callback) | 77 const device::usb::ChooserService::GetPermissionCallback& callback) |
| 78 : ChooserController(owner, | 78 : ChooserController(owner, |
| 79 IDS_USB_DEVICE_CHOOSER_PROMPT_ORIGIN, | 79 IDS_USB_DEVICE_CHOOSER_PROMPT_ORIGIN, |
| 80 IDS_USB_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), | 80 IDS_USB_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), |
| 81 render_frame_host_(render_frame_host), | 81 render_frame_host_(render_frame_host), |
| 82 callback_(callback), | 82 callback_(callback), |
| 83 usb_service_observer_(this), | 83 usb_service_observer_(this), |
| 84 weak_factory_(this) { | 84 weak_factory_(this) { |
| 85 device::UsbService* usb_service = | 85 device::UsbService* usb_service = |
| 86 device::DeviceClient::Get()->GetUsbService(); | 86 device::DeviceClient::Get()->GetUsbService(); |
| 87 if (!usb_service) | 87 if (!usb_service) |
| 88 return; | 88 return; |
| 89 | 89 |
| 90 if (!usb_service_observer_.IsObserving(usb_service)) | 90 if (!usb_service_observer_.IsObserving(usb_service)) |
| 91 usb_service_observer_.Add(usb_service); | 91 usb_service_observer_.Add(usb_service); |
| 92 | 92 |
| 93 if (!device_filters.is_null()) | 93 filters_ = |
| 94 filters_ = device_filters.To<std::vector<device::UsbDeviceFilter>>(); | 94 mojo::ConvertTo<std::vector<device::UsbDeviceFilter>>(device_filters); |
| 95 | 95 |
| 96 usb_service->GetDevices(base::Bind(&UsbChooserController::GotUsbDeviceList, | 96 usb_service->GetDevices(base::Bind(&UsbChooserController::GotUsbDeviceList, |
| 97 weak_factory_.GetWeakPtr())); | 97 weak_factory_.GetWeakPtr())); |
| 98 } | 98 } |
| 99 | 99 |
| 100 UsbChooserController::~UsbChooserController() { | 100 UsbChooserController::~UsbChooserController() { |
| 101 if (!callback_.is_null()) | 101 if (!callback_.is_null()) |
| 102 callback_.Run(nullptr); | 102 callback_.Run(nullptr); |
| 103 } | 103 } |
| 104 | 104 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 bool UsbChooserController::DisplayDevice( | 224 bool UsbChooserController::DisplayDevice( |
| 225 scoped_refptr<device::UsbDevice> device) const { | 225 scoped_refptr<device::UsbDevice> device) const { |
| 226 return device::UsbDeviceFilter::MatchesAny(device, filters_) && | 226 return device::UsbDeviceFilter::MatchesAny(device, filters_) && |
| 227 !UsbBlocklist::Get().IsExcluded(device) && | 227 !UsbBlocklist::Get().IsExcluded(device) && |
| 228 (base::CommandLine::ForCurrentProcess()->HasSwitch( | 228 (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 229 switches::kDisableWebUsbSecurity) || | 229 switches::kDisableWebUsbSecurity) || |
| 230 device::FindInWebUsbAllowedOrigins( | 230 device::FindInWebUsbAllowedOrigins( |
| 231 device->webusb_allowed_origins(), | 231 device->webusb_allowed_origins(), |
| 232 render_frame_host_->GetLastCommittedURL().GetOrigin())); | 232 render_frame_host_->GetLastCommittedURL().GetOrigin())); |
| 233 } | 233 } |
| OLD | NEW |