| 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" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 78 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 79 ScriptPromise promise = resolver->promise(); | 79 ScriptPromise promise = resolver->promise(); |
| 80 if (!m_deviceManager) { | 80 if (!m_deviceManager) { |
| 81 resolver->reject(DOMException::create(NotSupportedError)); | 81 resolver->reject(DOMException::create(NotSupportedError)); |
| 82 } else { | 82 } else { |
| 83 String errorMessage; | 83 String errorMessage; |
| 84 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { | 84 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { |
| 85 resolver->reject(DOMException::create(SecurityError, errorMessage)); | 85 resolver->reject(DOMException::create(SecurityError, errorMessage)); |
| 86 } else { | 86 } else { |
| 87 m_deviceManagerRequests.insert(resolver); | 87 m_deviceManagerRequests.insert(resolver); |
| 88 m_deviceManager->GetDevices( | 88 m_deviceManager->GetDevices(nullptr, |
| 89 nullptr, convertToBaseCallback(WTF::bind(&USB::onGetDevices, | 89 convertToBaseCallback(WTF::bind( |
| 90 wrapPersistent(this), | 90 &USB::onGetDevices, wrapPersistent(this), |
| 91 wrapPersistent(resolver)))); | 91 wrapPersistent(resolver)))); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 return promise; | 94 return promise; |
| 95 } | 95 } |
| 96 | 96 |
| 97 ScriptPromise USB::requestDevice(ScriptState* scriptState, | 97 ScriptPromise USB::requestDevice(ScriptState* scriptState, |
| 98 const USBDeviceRequestOptions& options) { | 98 const USBDeviceRequestOptions& options) { |
| 99 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 99 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 100 | 100 |
| 101 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 101 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 125 "Must be handling a user gesture to show a permission request.")); | 125 "Must be handling a user gesture to show a permission request.")); |
| 126 } else { | 126 } else { |
| 127 Vector<usb::DeviceFilterPtr> filters; | 127 Vector<usb::DeviceFilterPtr> filters; |
| 128 if (options.hasFilters()) { | 128 if (options.hasFilters()) { |
| 129 filters.reserveCapacity(options.filters().size()); | 129 filters.reserveCapacity(options.filters().size()); |
| 130 for (const auto& filter : options.filters()) | 130 for (const auto& filter : options.filters()) |
| 131 filters.push_back(convertDeviceFilter(filter)); | 131 filters.push_back(convertDeviceFilter(filter)); |
| 132 } | 132 } |
| 133 m_chooserServiceRequests.insert(resolver); | 133 m_chooserServiceRequests.insert(resolver); |
| 134 m_chooserService->GetPermission( | 134 m_chooserService->GetPermission( |
| 135 std::move(filters), convertToBaseCallback(WTF::bind( | 135 std::move(filters), |
| 136 &USB::onGetPermission, wrapPersistent(this), | 136 convertToBaseCallback(WTF::bind(&USB::onGetPermission, |
| 137 wrapPersistent(resolver)))); | 137 wrapPersistent(this), |
| 138 wrapPersistent(resolver)))); |
| 138 } | 139 } |
| 139 return promise; | 140 return promise; |
| 140 } | 141 } |
| 141 | 142 |
| 142 ExecutionContext* USB::getExecutionContext() const { | 143 ExecutionContext* USB::getExecutionContext() const { |
| 143 return ContextLifecycleObserver::getExecutionContext(); | 144 return ContextLifecycleObserver::getExecutionContext(); |
| 144 } | 145 } |
| 145 | 146 |
| 146 const AtomicString& USB::interfaceName() const { | 147 const AtomicString& USB::interfaceName() const { |
| 147 return EventTargetNames::USB; | 148 return EventTargetNames::USB; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 235 |
| 235 DEFINE_TRACE(USB) { | 236 DEFINE_TRACE(USB) { |
| 236 visitor->trace(m_deviceManagerRequests); | 237 visitor->trace(m_deviceManagerRequests); |
| 237 visitor->trace(m_chooserServiceRequests); | 238 visitor->trace(m_chooserServiceRequests); |
| 238 visitor->trace(m_deviceCache); | 239 visitor->trace(m_deviceCache); |
| 239 EventTargetWithInlineData::trace(visitor); | 240 EventTargetWithInlineData::trace(visitor); |
| 240 ContextLifecycleObserver::trace(visitor); | 241 ContextLifecycleObserver::trace(visitor); |
| 241 } | 242 } |
| 242 | 243 |
| 243 } // namespace blink | 244 } // namespace blink |
| OLD | NEW |