| 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 base::ASCIIToUTF16(base::StringPrintf("%04x", product_id))); | 65 base::ASCIIToUTF16(base::StringPrintf("%04x", product_id))); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 return device_name; | 69 return device_name; |
| 70 } | 70 } |
| 71 | 71 |
| 72 } // namespace | 72 } // namespace |
| 73 | 73 |
| 74 UsbChooserController::UsbChooserController( | 74 UsbChooserController::UsbChooserController( |
| 75 RenderFrameHost* render_frame_host, | 75 content::RenderFrameHost* render_frame_host, |
| 76 mojo::Array<device::usb::DeviceFilterPtr> device_filters, | 76 const std::vector<device::usb::DeviceFilterPtr>& device_filters, |
| 77 const device::usb::ChooserService::GetPermissionCallback& callback) | 77 const device::usb::ChooserService::GetPermissionCallback& callback) |
| 78 : ChooserController(render_frame_host, | 78 : ChooserController(render_frame_host, |
| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 RenderFrameHost* main_frame = | 233 RenderFrameHost* main_frame = |
| 234 WebContents::FromRenderFrameHost(render_frame_host_)->GetMainFrame(); | 234 WebContents::FromRenderFrameHost(render_frame_host_)->GetMainFrame(); |
| 235 if (render_frame_host_ != main_frame) { | 235 if (render_frame_host_ != main_frame) { |
| 236 return device::FindInWebUsbAllowedOrigins( | 236 return device::FindInWebUsbAllowedOrigins( |
| 237 device->webusb_allowed_origins(), | 237 device->webusb_allowed_origins(), |
| 238 render_frame_host_->GetLastCommittedURL().GetOrigin()); | 238 render_frame_host_->GetLastCommittedURL().GetOrigin()); |
| 239 } | 239 } |
| 240 | 240 |
| 241 return true; | 241 return true; |
| 242 } | 242 } |
| OLD | NEW |