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

Unified Diff: content/renderer/usb/web_usb_device_impl.cc

Issue 1521803002: Match WebUSB errors more closely to the specificiation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « content/renderer/usb/web_usb_client_impl.cc ('k') | third_party/WebKit/Source/modules/webusb/USBError.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/usb/web_usb_device_impl.cc
diff --git a/content/renderer/usb/web_usb_device_impl.cc b/content/renderer/usb/web_usb_device_impl.cc
index beeec4f7e15920de3b4075846251e12dab8cefe1..0b6ccb95c2c6375f148aa88f6a7ba428147d5472 100644
--- a/content/renderer/usb/web_usb_device_impl.cc
+++ b/content/renderer/usb/web_usb_device_impl.cc
@@ -41,17 +41,9 @@ void RejectWithError(const blink::WebUSBError& error,
}
template <typename CallbacksType>
-void RejectWithDeviceError(const std::string& message,
- scoped_ptr<CallbacksType> callbacks) {
- RejectWithError(blink::WebUSBError(blink::WebUSBError::Error::Device,
- base::UTF8ToUTF16(message)),
- callbacks.Pass());
-}
-
-template <typename CallbacksType>
void RejectWithTransferError(scoped_ptr<CallbacksType> callbacks) {
- RejectWithError(blink::WebUSBError(blink::WebUSBError::Error::Transfer,
- base::UTF8ToUTF16(kTransferFailed)),
+ RejectWithError(blink::WebUSBError(blink::WebUSBError::Error::Network,
+ base::ASCIIToUTF16(kTransferFailed)),
callbacks.Pass());
}
@@ -63,8 +55,8 @@ ScopedWebCallbacks<CallbacksType> MakeScopedUSBCallbacks(
return make_scoped_web_callbacks(
callbacks,
base::Bind(&RejectWithError<CallbacksType>,
- blink::WebUSBError(blink::WebUSBError::Error::Device,
- base::UTF8ToUTF16(kDeviceUnavailable))));
+ blink::WebUSBError(blink::WebUSBError::Error::NotFound,
+ base::ASCIIToUTF16(kDeviceUnavailable))));
}
void OnOpenDevice(
@@ -77,8 +69,8 @@ void OnOpenDevice(
break;
case device::usb::OPEN_DEVICE_ERROR_ACCESS_DENIED:
scoped_callbacks->onError(blink::WebUSBError(
- blink::WebUSBError::Error::Device,
- base::UTF8ToUTF16(kDeviceNoAccess)));
+ blink::WebUSBError::Error::Security,
+ base::ASCIIToUTF16(kDeviceNoAccess)));
break;
default:
NOTREACHED();
@@ -94,10 +86,13 @@ void OnGetConfiguration(
ScopedWebCallbacks<blink::WebUSBDeviceGetConfigurationCallbacks> callbacks,
uint8_t configuration_value) {
auto scoped_callbacks = callbacks.PassCallbacks();
- if (configuration_value == 0)
- RejectWithDeviceError(kDeviceNotConfigured, scoped_callbacks.Pass());
- else
+ if (configuration_value == 0) {
+ RejectWithError(blink::WebUSBError(blink::WebUSBError::Error::NotFound,
+ kDeviceNotConfigured),
+ scoped_callbacks.Pass());
+ } else {
scoped_callbacks->onSuccess(configuration_value);
+ }
}
void HandlePassFailDeviceOperation(
@@ -106,10 +101,13 @@ void HandlePassFailDeviceOperation(
const std::string& failure_message,
bool success) {
auto scoped_callbacks = callbacks.PassCallbacks();
- if (success)
+ if (success) {
scoped_callbacks->onSuccess();
- else
- RejectWithDeviceError(failure_message, scoped_callbacks.Pass());
+ } else {
+ RejectWithError(blink::WebUSBError(blink::WebUSBError::Error::Network,
+ base::ASCIIToUTF16(failure_message)),
+ scoped_callbacks.Pass());
+ }
}
void OnTransferIn(
« no previous file with comments | « content/renderer/usb/web_usb_client_impl.cc ('k') | third_party/WebKit/Source/modules/webusb/USBError.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698