| 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 content::RenderFrameHost* render_frame_host, | 75 RenderFrameHost* render_frame_host, |
| 76 const std::vector<device::usb::DeviceFilterPtr>& device_filters, | 76 const std::vector<device::UsbDeviceFilter>& 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 filters_(device_filters), |
| 84 weak_factory_(this) { | 85 weak_factory_(this) { |
| 85 device::UsbService* usb_service = | 86 device::UsbService* usb_service = |
| 86 device::DeviceClient::Get()->GetUsbService(); | 87 device::DeviceClient::Get()->GetUsbService(); |
| 87 if (!usb_service) | 88 if (!usb_service) |
| 88 return; | 89 return; |
| 89 | 90 |
| 90 if (!usb_service_observer_.IsObserving(usb_service)) | 91 if (!usb_service_observer_.IsObserving(usb_service)) |
| 91 usb_service_observer_.Add(usb_service); | 92 usb_service_observer_.Add(usb_service); |
| 92 | 93 |
| 93 filters_ = | |
| 94 mojo::ConvertTo<std::vector<device::UsbDeviceFilter>>(device_filters); | |
| 95 | |
| 96 usb_service->GetDevices(base::Bind(&UsbChooserController::GotUsbDeviceList, | 94 usb_service->GetDevices(base::Bind(&UsbChooserController::GotUsbDeviceList, |
| 97 weak_factory_.GetWeakPtr())); | 95 weak_factory_.GetWeakPtr())); |
| 98 } | 96 } |
| 99 | 97 |
| 100 UsbChooserController::~UsbChooserController() { | 98 UsbChooserController::~UsbChooserController() { |
| 101 if (!callback_.is_null()) | 99 if (!callback_.is_null()) |
| 102 callback_.Run(nullptr); | 100 callback_.Run(nullptr); |
| 103 } | 101 } |
| 104 | 102 |
| 105 base::string16 UsbChooserController::GetNoOptionsText() const { | 103 base::string16 UsbChooserController::GetNoOptionsText() const { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 RenderFrameHost* main_frame = | 231 RenderFrameHost* main_frame = |
| 234 WebContents::FromRenderFrameHost(render_frame_host_)->GetMainFrame(); | 232 WebContents::FromRenderFrameHost(render_frame_host_)->GetMainFrame(); |
| 235 if (render_frame_host_ != main_frame) { | 233 if (render_frame_host_ != main_frame) { |
| 236 return device::FindInWebUsbAllowedOrigins( | 234 return device::FindInWebUsbAllowedOrigins( |
| 237 device->webusb_allowed_origins(), | 235 device->webusb_allowed_origins(), |
| 238 render_frame_host_->GetLastCommittedURL().GetOrigin()); | 236 render_frame_host_->GetLastCommittedURL().GetOrigin()); |
| 239 } | 237 } |
| 240 | 238 |
| 241 return true; | 239 return true; |
| 242 } | 240 } |
| OLD | NEW |