| 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 "modules/webusb/USB.h" | 5 #include "modules/webusb/USB.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
| 10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "device/usb/public/interfaces/device.mojom-blink.h" | 12 #include "device/usb/public/interfaces/device.mojom-blink.h" |
| 13 #include "modules/EventTargetModules.h" | 13 #include "modules/EventTargetModules.h" |
| 14 #include "modules/webusb/USBConnectionEvent.h" | 14 #include "modules/webusb/USBConnectionEvent.h" |
| 15 #include "modules/webusb/USBDevice.h" | 15 #include "modules/webusb/USBDevice.h" |
| 16 #include "modules/webusb/USBDeviceFilter.h" | 16 #include "modules/webusb/USBDeviceFilter.h" |
| 17 #include "modules/webusb/USBDeviceRequestOptions.h" | 17 #include "modules/webusb/USBDeviceRequestOptions.h" |
| 18 #include "platform/UserGestureIndicator.h" | 18 #include "platform/UserGestureIndicator.h" |
| 19 #include "platform/mojo/MojoHelper.h" | 19 #include "platform/mojo/MojoHelper.h" |
| 20 #include "public/platform/ServiceRegistry.h" | 20 #include "public/platform/InterfaceProvider.h" |
| 21 #include "wtf/Functional.h" | 21 #include "wtf/Functional.h" |
| 22 | 22 |
| 23 namespace usb = device::usb::blink; | 23 namespace usb = device::usb::blink; |
| 24 | 24 |
| 25 namespace blink { | 25 namespace blink { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const char kNoServiceError[] = "USB service unavailable."; | 28 const char kNoServiceError[] = "USB service unavailable."; |
| 29 | 29 |
| 30 usb::DeviceFilterPtr convertDeviceFilter(const USBDeviceFilter& filter) | 30 usb::DeviceFilterPtr convertDeviceFilter(const USBDeviceFilter& filter) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 48 return mojoFilter; | 48 return mojoFilter; |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 USB::USB(LocalFrame& frame) | 53 USB::USB(LocalFrame& frame) |
| 54 : ContextLifecycleObserver(frame.document()) | 54 : ContextLifecycleObserver(frame.document()) |
| 55 , m_clientBinding(this) | 55 , m_clientBinding(this) |
| 56 { | 56 { |
| 57 ThreadState::current()->registerPreFinalizer(this); | 57 ThreadState::current()->registerPreFinalizer(this); |
| 58 frame.serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_deviceMana
ger)); | 58 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_deviceManager)); |
| 59 m_deviceManager.set_connection_error_handler(convertToBaseCallback(WTF::bind
(&USB::onDeviceManagerConnectionError, wrapWeakPersistent(this)))); | 59 m_deviceManager.set_connection_error_handler(convertToBaseCallback(WTF::bind
(&USB::onDeviceManagerConnectionError, wrapWeakPersistent(this)))); |
| 60 m_deviceManager->SetClient(m_clientBinding.CreateInterfacePtrAndBind()); | 60 m_deviceManager->SetClient(m_clientBinding.CreateInterfacePtrAndBind()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 USB::~USB() | 63 USB::~USB() |
| 64 { | 64 { |
| 65 // |m_deviceManager| and |m_chooserService| may still be valid but there | 65 // |m_deviceManager| and |m_chooserService| may still be valid but there |
| 66 // should be no more outstanding requests to them because each holds a | 66 // should be no more outstanding requests to them because each holds a |
| 67 // persistent handle to this object. | 67 // persistent handle to this object. |
| 68 DCHECK(m_deviceManagerRequests.isEmpty()); | 68 DCHECK(m_deviceManagerRequests.isEmpty()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 98 { | 98 { |
| 99 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 99 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 100 ScriptPromise promise = resolver->promise(); | 100 ScriptPromise promise = resolver->promise(); |
| 101 | 101 |
| 102 if (!m_chooserService) { | 102 if (!m_chooserService) { |
| 103 LocalFrame* frame = getExecutionContext() ? toDocument(getExecutionConte
xt())->frame() : nullptr; | 103 LocalFrame* frame = getExecutionContext() ? toDocument(getExecutionConte
xt())->frame() : nullptr; |
| 104 if (!frame) { | 104 if (!frame) { |
| 105 resolver->reject(DOMException::create(NotSupportedError)); | 105 resolver->reject(DOMException::create(NotSupportedError)); |
| 106 return promise; | 106 return promise; |
| 107 } | 107 } |
| 108 frame->serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_choos
erService)); | 108 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_chooserServic
e)); |
| 109 m_chooserService.set_connection_error_handler(convertToBaseCallback(WTF:
:bind(&USB::onChooserServiceConnectionError, wrapWeakPersistent(this)))); | 109 m_chooserService.set_connection_error_handler(convertToBaseCallback(WTF:
:bind(&USB::onChooserServiceConnectionError, wrapWeakPersistent(this)))); |
| 110 } | 110 } |
| 111 | 111 |
| 112 String errorMessage; | 112 String errorMessage; |
| 113 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { | 113 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { |
| 114 resolver->reject(DOMException::create(SecurityError, errorMessage)); | 114 resolver->reject(DOMException::create(SecurityError, errorMessage)); |
| 115 } else if (!UserGestureIndicator::consumeUserGesture()) { | 115 } else if (!UserGestureIndicator::consumeUserGesture()) { |
| 116 resolver->reject(DOMException::create(SecurityError, "Must be handling a
user gesture to show a permission request.")); | 116 resolver->reject(DOMException::create(SecurityError, "Must be handling a
user gesture to show a permission request.")); |
| 117 } else { | 117 } else { |
| 118 Vector<usb::DeviceFilterPtr> filters; | 118 Vector<usb::DeviceFilterPtr> filters; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 DEFINE_TRACE(USB) | 227 DEFINE_TRACE(USB) |
| 228 { | 228 { |
| 229 EventTargetWithInlineData::trace(visitor); | 229 EventTargetWithInlineData::trace(visitor); |
| 230 ContextLifecycleObserver::trace(visitor); | 230 ContextLifecycleObserver::trace(visitor); |
| 231 visitor->trace(m_deviceManagerRequests); | 231 visitor->trace(m_deviceManagerRequests); |
| 232 visitor->trace(m_chooserServiceRequests); | 232 visitor->trace(m_chooserServiceRequests); |
| 233 visitor->trace(m_deviceCache); | 233 visitor->trace(m_deviceCache); |
| 234 } | 234 } |
| 235 | 235 |
| 236 } // namespace blink | 236 } // namespace blink |
| OLD | NEW |