| 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_bubble_delegate.h" | 5 #include "chrome/browser/usb/usb_chooser_bubble_delegate.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/usb/usb_chooser_context.h" | 10 #include "chrome/browser/usb/usb_chooser_context.h" |
| 11 #include "chrome/browser/usb/usb_chooser_context_factory.h" | 11 #include "chrome/browser/usb/usb_chooser_context_factory.h" |
| 12 #include "components/bubble/bubble_controller.h" |
| 12 #include "content/public/browser/render_frame_host.h" | 13 #include "content/public/browser/render_frame_host.h" |
| 13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 14 #include "device/core/device_client.h" | 15 #include "device/core/device_client.h" |
| 15 #include "device/devices_app/usb/type_converters.h" | 16 #include "device/devices_app/usb/type_converters.h" |
| 16 #include "device/usb/usb_device.h" | 17 #include "device/usb/usb_device.h" |
| 17 #include "device/usb/usb_device_filter.h" | 18 #include "device/usb/usb_device_filter.h" |
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 render_frame_host_->GetLastCommittedURL().GetOrigin(), embedding_origin, | 96 render_frame_host_->GetLastCommittedURL().GetOrigin(), embedding_origin, |
| 96 devices_[idx]->guid()); | 97 devices_[idx]->guid()); |
| 97 | 98 |
| 98 device::usb::DeviceInfoPtr device_info_ptr = | 99 device::usb::DeviceInfoPtr device_info_ptr = |
| 99 device::usb::DeviceInfo::From(*devices_[idx]); | 100 device::usb::DeviceInfo::From(*devices_[idx]); |
| 100 callback_.Run(device_info_ptr.Pass()); | 101 callback_.Run(device_info_ptr.Pass()); |
| 101 } else { | 102 } else { |
| 102 callback_.Run(nullptr); | 103 callback_.Run(nullptr); |
| 103 } | 104 } |
| 104 callback_.reset(); // Reset |callback_| so that it is only run once. | 105 callback_.reset(); // Reset |callback_| so that it is only run once. |
| 106 |
| 107 if (bubble_controller_) |
| 108 bubble_controller_->CloseBubble(BUBBLE_CLOSE_ACCEPTED); |
| 105 } | 109 } |
| 106 | 110 |
| 107 void UsbChooserBubbleDelegate::Cancel() {} | 111 void UsbChooserBubbleDelegate::Cancel() { |
| 112 if (bubble_controller_) |
| 113 bubble_controller_->CloseBubble(BUBBLE_CLOSE_CANCELED); |
| 114 } |
| 108 | 115 |
| 109 void UsbChooserBubbleDelegate::Close() {} | 116 void UsbChooserBubbleDelegate::Close() {} |
| 110 | 117 |
| 111 void UsbChooserBubbleDelegate::OnDeviceAdded( | 118 void UsbChooserBubbleDelegate::OnDeviceAdded( |
| 112 scoped_refptr<device::UsbDevice> device) { | 119 scoped_refptr<device::UsbDevice> device) { |
| 113 DCHECK(!ContainsValue(devices_, device)); | 120 DCHECK(!ContainsValue(devices_, device)); |
| 114 if (device::UsbDeviceFilter::MatchesAny(device, filters_) && | 121 if (device::UsbDeviceFilter::MatchesAny(device, filters_) && |
| 115 FindOriginInDescriptorSet( | 122 FindOriginInDescriptorSet( |
| 116 device->webusb_allowed_origins(), | 123 device->webusb_allowed_origins(), |
| 117 render_frame_host_->GetLastCommittedURL().GetOrigin())) { | 124 render_frame_host_->GetLastCommittedURL().GetOrigin())) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 143 FindOriginInDescriptorSet( | 150 FindOriginInDescriptorSet( |
| 144 device->webusb_allowed_origins(), | 151 device->webusb_allowed_origins(), |
| 145 render_frame_host_->GetLastCommittedURL().GetOrigin())) { | 152 render_frame_host_->GetLastCommittedURL().GetOrigin())) { |
| 146 devices_.push_back(device); | 153 devices_.push_back(device); |
| 147 devices_names_.push_back(device->product_string()); | 154 devices_names_.push_back(device->product_string()); |
| 148 } | 155 } |
| 149 } | 156 } |
| 150 if (observer()) | 157 if (observer()) |
| 151 observer()->OnOptionsInitialized(); | 158 observer()->OnOptionsInitialized(); |
| 152 } | 159 } |
| 160 |
| 161 void UsbChooserBubbleDelegate::set_bubble_controller( |
| 162 BubbleReference bubble_controller) { |
| 163 bubble_controller_ = bubble_controller; |
| 164 } |
| OLD | NEW |