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/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 if (m_client) | 87 if (m_client) |
88 m_client->setObserver(nullptr); | 88 m_client->setObserver(nullptr); |
89 } | 89 } |
90 | 90 |
91 ScriptPromise USB::getDevices(ScriptState* scriptState) | 91 ScriptPromise USB::getDevices(ScriptState* scriptState) |
92 { | 92 { |
93 if (!m_client) | 93 if (!m_client) |
94 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 94 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
95 | 95 |
96 String errorMessage; | 96 String errorMessage; |
97 if (!scriptState->executionContext()->isSecureContext(errorMessage)) | 97 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) |
98 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); | 98 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); |
99 | 99 |
100 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 100 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
101 ScriptPromise promise = resolver->promise(); | 101 ScriptPromise promise = resolver->promise(); |
102 m_client->getDevices(new CallbackPromiseAdapter<DeviceArray, USBError>(resol
ver)); | 102 m_client->getDevices(new CallbackPromiseAdapter<DeviceArray, USBError>(resol
ver)); |
103 | 103 |
104 return promise; | 104 return promise; |
105 } | 105 } |
106 | 106 |
107 ScriptPromise USB::requestDevice(ScriptState* scriptState, const USBDeviceReques
tOptions& options) | 107 ScriptPromise USB::requestDevice(ScriptState* scriptState, const USBDeviceReques
tOptions& options) |
108 { | 108 { |
109 if (!m_client) | 109 if (!m_client) |
110 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 110 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
111 | 111 |
112 String errorMessage; | 112 String errorMessage; |
113 if (!scriptState->executionContext()->isSecureContext(errorMessage)) | 113 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) |
114 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); | 114 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); |
115 | 115 |
116 if (!UserGestureIndicator::consumeUserGesture()) | 116 if (!UserGestureIndicator::consumeUserGesture()) |
117 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "Must be handling a user gesture to show a permission requ
est.")); | 117 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "Must be handling a user gesture to show a permission requ
est.")); |
118 | 118 |
119 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 119 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
120 ScriptPromise promise = resolver->promise(); | 120 ScriptPromise promise = resolver->promise(); |
121 | 121 |
122 WebUSBDeviceRequestOptions webOptions; | 122 WebUSBDeviceRequestOptions webOptions; |
123 convertDeviceRequestOptions(options, &webOptions); | 123 convertDeviceRequestOptions(options, &webOptions); |
124 m_client->requestDevice(webOptions, new CallbackPromiseAdapter<USBDevice, US
BError>(resolver)); | 124 m_client->requestDevice(webOptions, new CallbackPromiseAdapter<USBDevice, US
BError>(resolver)); |
125 | 125 |
126 return promise; | 126 return promise; |
127 } | 127 } |
128 | 128 |
129 ExecutionContext* USB::executionContext() const | 129 ExecutionContext* USB::getExecutionContext() const |
130 { | 130 { |
131 return frame() ? frame()->document() : nullptr; | 131 return frame() ? frame()->document() : nullptr; |
132 } | 132 } |
133 | 133 |
134 const AtomicString& USB::interfaceName() const | 134 const AtomicString& USB::interfaceName() const |
135 { | 135 { |
136 return EventTargetNames::USB; | 136 return EventTargetNames::USB; |
137 } | 137 } |
138 | 138 |
139 void USB::willDetachFrameHost() | 139 void USB::willDetachFrameHost() |
(...skipping 13 matching lines...) Expand all Loading... |
153 dispatchEvent(USBConnectionEvent::create(EventTypeNames::disconnect, USBDevi
ce::create(device.release()))); | 153 dispatchEvent(USBConnectionEvent::create(EventTypeNames::disconnect, USBDevi
ce::create(device.release()))); |
154 } | 154 } |
155 | 155 |
156 DEFINE_TRACE(USB) | 156 DEFINE_TRACE(USB) |
157 { | 157 { |
158 RefCountedGarbageCollectedEventTargetWithInlineData<USB>::trace(visitor); | 158 RefCountedGarbageCollectedEventTargetWithInlineData<USB>::trace(visitor); |
159 LocalFrameLifecycleObserver::trace(visitor); | 159 LocalFrameLifecycleObserver::trace(visitor); |
160 } | 160 } |
161 | 161 |
162 } // namespace blink | 162 } // namespace blink |
OLD | NEW |