Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Unified Diff: chrome/browser/usb/usb_chooser_controller.cc

Issue 2539593002: Fix blank names issue for navigator.usb.requestDevice (Closed)
Patch Set: fix blank names issue for navigator.usb.requestDevice Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/usb/usb_chooser_controller.cc
diff --git a/chrome/browser/usb/usb_chooser_controller.cc b/chrome/browser/usb/usb_chooser_controller.cc
index 1e4b0ed9ad461463fdd8307c88ee6d9150d9d292..c5fcfffb9a5cd5eafdafe4f7403585b9597f5080 100644
--- a/chrome/browser/usb/usb_chooser_controller.cc
+++ b/chrome/browser/usb/usb_chooser_controller.cc
@@ -9,6 +9,8 @@
#include "base/bind.h"
#include "base/command_line.h"
+#include "base/strings/stringprintf.h"
+#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/net/referrer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
@@ -27,6 +29,7 @@
#include "device/usb/mojo/type_converters.h"
#include "device/usb/usb_device.h"
#include "device/usb/usb_device_filter.h"
+#include "device/usb/usb_ids.h"
#include "device/usb/webusb_descriptors.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
@@ -40,6 +43,30 @@ Browser* GetBrowser() {
return browser_displayer.browser();
}
+base::string16 GetDeviceName(scoped_refptr<device::UsbDevice> device) {
+ base::string16 device_name = device->product_string();
+ if (device_name.empty()) {
+ uint16_t vendor_id = device->vendor_id();
+ uint16_t product_id = device->product_id();
+ if (const char* product_name =
+ device::UsbIds::GetProductName(vendor_id, product_id)) {
+ device_name = base::UTF8ToUTF16(product_name);
+ } else if (const char* vendor_name =
+ device::UsbIds::GetVendorName(vendor_id)) {
+ device_name = l10n_util::GetStringFUTF16(
+ IDS_DEVICE_CHOOSER_DEVICE_NAME_UNKNOWN_DEVICE_WITH_VENDOR_NAME,
+ base::UTF8ToUTF16(vendor_name));
+ } else {
+ device_name = l10n_util::GetStringFUTF16(
+ IDS_DEVICE_CHOOSER_DEVICE_NAME_UNKNOWN_DEVICE_WITH_VENDOR_ID_AND_PRODUCT_ID,
+ base::ASCIIToUTF16(base::StringPrintf("%04x", vendor_id)),
+ base::ASCIIToUTF16(base::StringPrintf("%04x", product_id)));
+ }
+ }
+
+ return device_name;
+}
+
} // namespace
UsbChooserController::UsbChooserController(
@@ -154,7 +181,7 @@ void UsbChooserController::OpenHelpCenterUrl() const {
void UsbChooserController::OnDeviceAdded(
scoped_refptr<device::UsbDevice> device) {
if (DisplayDevice(device)) {
- const base::string16& device_name = device->product_string();
+ base::string16 device_name = GetDeviceName(device);
devices_.push_back(std::make_pair(device, device_name));
++device_name_map_[device_name];
if (view())
@@ -184,7 +211,7 @@ void UsbChooserController::GotUsbDeviceList(
const std::vector<scoped_refptr<device::UsbDevice>>& devices) {
for (const auto& device : devices) {
if (DisplayDevice(device)) {
- const base::string16& device_name = device->product_string();
+ base::string16 device_name = GetDeviceName(device);
devices_.push_back(std::make_pair(device, device_name));
++device_name_map_[device_name];
}
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698