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

Side by Side Diff: content/renderer/usb/web_usb_device_impl.cc

Issue 1693433003: webusb: Reject the promise if the device is already open. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | device/usb/mojo/device_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/renderer/usb/web_usb_device_impl.h" 5 #include "content/renderer/usb/web_usb_device_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "content/child/mojo/type_converters.h" 12 #include "content/child/mojo/type_converters.h"
13 #include "content/child/scoped_web_callbacks.h" 13 #include "content/child/scoped_web_callbacks.h"
14 #include "content/renderer/usb/type_converters.h" 14 #include "content/renderer/usb/type_converters.h"
15 #include "mojo/shell/public/cpp/connect.h" 15 #include "mojo/shell/public/cpp/connect.h"
16 #include "mojo/shell/public/interfaces/shell.mojom.h" 16 #include "mojo/shell/public/interfaces/shell.mojom.h"
17 #include "third_party/WebKit/public/platform/WebVector.h" 17 #include "third_party/WebKit/public/platform/WebVector.h"
18 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceInfo.h" 18 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBDeviceInfo.h"
19 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBTransferInfo.h " 19 #include "third_party/WebKit/public/platform/modules/webusb/WebUSBTransferInfo.h "
20 20
21 namespace content { 21 namespace content {
22 22
23 namespace { 23 namespace {
24 24
25 const char kClaimInterfaceFailed[] = "Unable to claim interface."; 25 const char kClaimInterfaceFailed[] = "Unable to claim interface.";
26 const char kClearHaltFailed[] = "Unable to clear endpoint."; 26 const char kClearHaltFailed[] = "Unable to clear endpoint.";
27 const char kDeviceAlreadyOpen[] = "Device has already been opened.";
27 const char kDeviceNoAccess[] = "Access denied."; 28 const char kDeviceNoAccess[] = "Access denied.";
28 const char kDeviceNotConfigured[] = "Device not configured."; 29 const char kDeviceNotConfigured[] = "Device not configured.";
29 const char kDeviceUnavailable[] = "Device unavailable."; 30 const char kDeviceUnavailable[] = "Device unavailable.";
30 const char kDeviceResetFailed[] = "Unable to reset the device."; 31 const char kDeviceResetFailed[] = "Unable to reset the device.";
31 const char kReleaseInterfaceFailed[] = "Unable to release interface."; 32 const char kReleaseInterfaceFailed[] = "Unable to release interface.";
32 const char kSetConfigurationFailed[] = "Unable to set device configuration."; 33 const char kSetConfigurationFailed[] = "Unable to set device configuration.";
33 const char kSetInterfaceFailed[] = "Unable to set device interface."; 34 const char kSetInterfaceFailed[] = "Unable to set device interface.";
34 const char kTransferFailed[] = "Transfer failed."; 35 const char kTransferFailed[] = "Transfer failed.";
35 36
36 // Generic default rejection handler for any WebUSB callbacks type. Assumes 37 // Generic default rejection handler for any WebUSB callbacks type. Assumes
(...skipping 30 matching lines...) Expand all
67 auto scoped_callbacks = callbacks.PassCallbacks(); 68 auto scoped_callbacks = callbacks.PassCallbacks();
68 switch(error) { 69 switch(error) {
69 case device::usb::OpenDeviceError::OK: 70 case device::usb::OpenDeviceError::OK:
70 scoped_callbacks->onSuccess(); 71 scoped_callbacks->onSuccess();
71 break; 72 break;
72 case device::usb::OpenDeviceError::ACCESS_DENIED: 73 case device::usb::OpenDeviceError::ACCESS_DENIED:
73 scoped_callbacks->onError(blink::WebUSBError( 74 scoped_callbacks->onError(blink::WebUSBError(
74 blink::WebUSBError::Error::Security, 75 blink::WebUSBError::Error::Security,
75 base::ASCIIToUTF16(kDeviceNoAccess))); 76 base::ASCIIToUTF16(kDeviceNoAccess)));
76 break; 77 break;
78 case device::usb::OpenDeviceError::ALREADY_OPEN:
79 scoped_callbacks->onError(blink::WebUSBError(
80 blink::WebUSBError::Error::InvalidState,
81 base::ASCIIToUTF16(kDeviceAlreadyOpen)));
82 break;
77 default: 83 default:
78 NOTREACHED(); 84 NOTREACHED();
79 } 85 }
80 } 86 }
81 87
82 void OnDeviceClosed( 88 void OnDeviceClosed(
83 ScopedWebCallbacks<blink::WebUSBDeviceCloseCallbacks> callbacks) { 89 ScopedWebCallbacks<blink::WebUSBDeviceCloseCallbacks> callbacks) {
84 callbacks.PassCallbacks()->onSuccess(); 90 callbacks.PassCallbacks()->onSuccess();
85 } 91 }
86 92
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 401 }
396 402
397 void WebUSBDeviceImpl::reset(blink::WebUSBDeviceResetCallbacks* callbacks) { 403 void WebUSBDeviceImpl::reset(blink::WebUSBDeviceResetCallbacks* callbacks) {
398 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks); 404 auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks);
399 device_->Reset(base::Bind(&HandlePassFailDeviceOperation, 405 device_->Reset(base::Bind(&HandlePassFailDeviceOperation,
400 base::Passed(&scoped_callbacks), 406 base::Passed(&scoped_callbacks),
401 kDeviceResetFailed)); 407 kDeviceResetFailed));
402 } 408 }
403 409
404 } // namespace content 410 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | device/usb/mojo/device_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698