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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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. |
105 } | 106 } |
106 | 107 |
107 void UsbChooserBubbleDelegate::Cancel() {} | 108 void UsbChooserBubbleDelegate::Cancel() { |
| 109 if (bubble_reference_) |
| 110 bubble_reference_->CloseBubble(BUBBLE_CLOSE_CANCELED); |
| 111 } |
108 | 112 |
109 void UsbChooserBubbleDelegate::Close() {} | 113 void UsbChooserBubbleDelegate::Close() {} |
110 | 114 |
111 void UsbChooserBubbleDelegate::OnDeviceAdded( | 115 void UsbChooserBubbleDelegate::OnDeviceAdded( |
112 scoped_refptr<device::UsbDevice> device) { | 116 scoped_refptr<device::UsbDevice> device) { |
113 DCHECK(!ContainsValue(devices_, device)); | 117 DCHECK(!ContainsValue(devices_, device)); |
114 if (device::UsbDeviceFilter::MatchesAny(device, filters_) && | 118 if (device::UsbDeviceFilter::MatchesAny(device, filters_) && |
115 FindOriginInDescriptorSet( | 119 FindOriginInDescriptorSet( |
116 device->webusb_allowed_origins(), | 120 device->webusb_allowed_origins(), |
117 render_frame_host_->GetLastCommittedURL().GetOrigin())) { | 121 render_frame_host_->GetLastCommittedURL().GetOrigin())) { |
(...skipping 25 matching lines...) Expand all Loading... |
143 FindOriginInDescriptorSet( | 147 FindOriginInDescriptorSet( |
144 device->webusb_allowed_origins(), | 148 device->webusb_allowed_origins(), |
145 render_frame_host_->GetLastCommittedURL().GetOrigin())) { | 149 render_frame_host_->GetLastCommittedURL().GetOrigin())) { |
146 devices_.push_back(device); | 150 devices_.push_back(device); |
147 devices_names_.push_back(device->product_string()); | 151 devices_names_.push_back(device->product_string()); |
148 } | 152 } |
149 } | 153 } |
150 if (observer()) | 154 if (observer()) |
151 observer()->OnOptionsInitialized(); | 155 observer()->OnOptionsInitialized(); |
152 } | 156 } |
| 157 |
| 158 void UsbChooserBubbleDelegate::set_bubble_reference( |
| 159 BubbleReference bubble_reference) { |
| 160 bubble_reference_ = bubble_reference; |
| 161 } |
OLD | NEW |