| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/usb/usb_chooser_context.h" | 15 #include "chrome/browser/usb/usb_chooser_context.h" |
| 15 #include "chrome/browser/usb/usb_chooser_context_factory.h" | 16 #include "chrome/browser/usb/usb_chooser_context_factory.h" |
| 17 #include "chrome/common/url_constants.h" |
| 16 #include "components/bubble/bubble_controller.h" | 18 #include "components/bubble/bubble_controller.h" |
| 17 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 19 #include "device/core/device_client.h" | 21 #include "device/core/device_client.h" |
| 20 #include "device/usb/mojo/type_converters.h" | 22 #include "device/usb/mojo/type_converters.h" |
| 21 #include "device/usb/usb_device.h" | 23 #include "device/usb/usb_device.h" |
| 22 #include "device/usb/usb_device_filter.h" | 24 #include "device/usb/usb_device_filter.h" |
| 23 #include "url/gurl.h" | |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // Reasons the chooser may be closed. These are used in histograms so do not | 28 // Reasons the chooser may be closed. These are used in histograms so do not |
| 28 // remove/reorder entries. Only add at the end just before | 29 // remove/reorder entries. Only add at the end just before |
| 29 // WEBUSB_CHOOSER_CLOSED_MAX. Also remember to update the enum listing in | 30 // WEBUSB_CHOOSER_CLOSED_MAX. Also remember to update the enum listing in |
| 30 // tools/metrics/histograms/histograms.xml. | 31 // tools/metrics/histograms/histograms.xml. |
| 31 enum WebUsbChooserClosed { | 32 enum WebUsbChooserClosed { |
| 32 // The user cancelled the permission prompt without selecting a device. | 33 // The user cancelled the permission prompt without selecting a device. |
| 33 WEBUSB_CHOOSER_CLOSED_CANCELLED = 0, | 34 WEBUSB_CHOOSER_CLOSED_CANCELLED = 0, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 if (device::UsbDeviceFilter::MatchesAny(device, filters_) && | 155 if (device::UsbDeviceFilter::MatchesAny(device, filters_) && |
| 155 FindInAllowedOrigins( | 156 FindInAllowedOrigins( |
| 156 device->webusb_allowed_origins(), | 157 device->webusb_allowed_origins(), |
| 157 render_frame_host_->GetLastCommittedURL().GetOrigin())) { | 158 render_frame_host_->GetLastCommittedURL().GetOrigin())) { |
| 158 devices_.push_back(std::make_pair(device, device->product_string())); | 159 devices_.push_back(std::make_pair(device, device->product_string())); |
| 159 if (observer()) | 160 if (observer()) |
| 160 observer()->OnOptionAdded(devices_.size() - 1); | 161 observer()->OnOptionAdded(devices_.size() - 1); |
| 161 } | 162 } |
| 162 } | 163 } |
| 163 | 164 |
| 165 base::string16 UsbChooserBubbleDelegate::GetHelpCenterUrl() const { |
| 166 return base::ASCIIToUTF16(chrome::kChooserUsbOverviewURL); |
| 167 } |
| 168 |
| 169 base::string16 UsbChooserBubbleDelegate::GetOptionDescription() const { |
| 170 return base::ASCIIToUTF16("device"); |
| 171 } |
| 172 |
| 164 void UsbChooserBubbleDelegate::OnDeviceRemoved( | 173 void UsbChooserBubbleDelegate::OnDeviceRemoved( |
| 165 scoped_refptr<device::UsbDevice> device) { | 174 scoped_refptr<device::UsbDevice> device) { |
| 166 for (auto it = devices_.begin(); it != devices_.end(); ++it) { | 175 for (auto it = devices_.begin(); it != devices_.end(); ++it) { |
| 167 if (it->first == device) { | 176 if (it->first == device) { |
| 168 size_t index = it - devices_.begin(); | 177 size_t index = it - devices_.begin(); |
| 169 devices_.erase(it); | 178 devices_.erase(it); |
| 170 if (observer()) | 179 if (observer()) |
| 171 observer()->OnOptionRemoved(index); | 180 observer()->OnOptionRemoved(index); |
| 172 return; | 181 return; |
| 173 } | 182 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 187 } | 196 } |
| 188 } | 197 } |
| 189 if (observer()) | 198 if (observer()) |
| 190 observer()->OnOptionsInitialized(); | 199 observer()->OnOptionsInitialized(); |
| 191 } | 200 } |
| 192 | 201 |
| 193 void UsbChooserBubbleDelegate::set_bubble_controller( | 202 void UsbChooserBubbleDelegate::set_bubble_controller( |
| 194 BubbleReference bubble_controller) { | 203 BubbleReference bubble_controller) { |
| 195 bubble_controller_ = bubble_controller; | 204 bubble_controller_ = bubble_controller; |
| 196 } | 205 } |
| OLD | NEW |