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 "config.h" | 5 #include "config.h" |
6 #include "modules/webusb/USB.h" | 6 #include "modules/webusb/USB.h" |
7 | 7 |
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
11 #include "core/dom/DOMException.h" | 11 #include "core/dom/DOMException.h" |
12 #include "core/dom/Document.h" | 12 #include "core/dom/Document.h" |
13 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
14 #include "modules/EventTargetModules.h" | 14 #include "modules/EventTargetModules.h" |
| 15 #include "modules/webusb/USBConnectionEvent.h" |
15 #include "modules/webusb/USBDevice.h" | 16 #include "modules/webusb/USBDevice.h" |
16 #include "modules/webusb/USBDeviceFilter.h" | 17 #include "modules/webusb/USBDeviceFilter.h" |
17 #include "modules/webusb/USBDeviceRequestOptions.h" | 18 #include "modules/webusb/USBDeviceRequestOptions.h" |
18 #include "modules/webusb/USBError.h" | 19 #include "modules/webusb/USBError.h" |
19 #include "public/platform/Platform.h" | 20 #include "public/platform/Platform.h" |
20 #include "public/platform/WebVector.h" | 21 #include "public/platform/WebVector.h" |
21 #include "public/platform/modules/webusb/WebUSBClient.h" | 22 #include "public/platform/modules/webusb/WebUSBClient.h" |
22 #include "public/platform/modules/webusb/WebUSBDeviceFilter.h" | 23 #include "public/platform/modules/webusb/WebUSBDeviceFilter.h" |
23 #include "public/platform/modules/webusb/WebUSBDeviceRequestOptions.h" | 24 #include "public/platform/modules/webusb/WebUSBDeviceRequestOptions.h" |
24 #include "public/platform/modules/webusb/WebUSBError.h" | 25 #include "public/platform/modules/webusb/WebUSBError.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 72 |
72 private: | 73 private: |
73 DeviceArray() = delete; | 74 DeviceArray() = delete; |
74 }; | 75 }; |
75 | 76 |
76 } // namespace | 77 } // namespace |
77 | 78 |
78 USB::USB(LocalFrame& frame) | 79 USB::USB(LocalFrame& frame) |
79 : m_controller(USBController::from(frame)) | 80 : m_controller(USBController::from(frame)) |
80 { | 81 { |
| 82 WebUSBClient* client = m_controller->client(); |
| 83 if (client) |
| 84 client->setObserver(this); |
| 85 } |
| 86 |
| 87 USB::~USB() |
| 88 { |
| 89 WebUSBClient* client = m_controller->client(); |
| 90 if (client) |
| 91 client->setObserver(nullptr); |
81 } | 92 } |
82 | 93 |
83 ScriptPromise USB::getDevices(ScriptState* scriptState) | 94 ScriptPromise USB::getDevices(ScriptState* scriptState) |
84 { | 95 { |
85 WebUSBClient* client = m_controller->client(); | 96 WebUSBClient* client = m_controller->client(); |
86 if (!client) | 97 if (!client) |
87 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 98 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
88 | 99 |
89 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 100 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
90 ScriptPromise promise = resolver->promise(); | 101 ScriptPromise promise = resolver->promise(); |
(...skipping 22 matching lines...) Expand all Loading... |
113 { | 124 { |
114 LocalFrame* frame = m_controller->frame(); | 125 LocalFrame* frame = m_controller->frame(); |
115 return frame ? frame->document() : nullptr; | 126 return frame ? frame->document() : nullptr; |
116 } | 127 } |
117 | 128 |
118 const AtomicString& USB::interfaceName() const | 129 const AtomicString& USB::interfaceName() const |
119 { | 130 { |
120 return EventTargetNames::USB; | 131 return EventTargetNames::USB; |
121 } | 132 } |
122 | 133 |
| 134 void USB::onDeviceConnected(WebPassOwnPtr<WebUSBDevice> device) |
| 135 { |
| 136 dispatchEvent(USBConnectionEvent::create(EventTypeNames::connect, USBDevice:
:create(device.release()))); |
| 137 } |
| 138 |
| 139 void USB::onDeviceDisconnected(WebPassOwnPtr<WebUSBDevice> device) |
| 140 { |
| 141 dispatchEvent(USBConnectionEvent::create(EventTypeNames::disconnect, USBDevi
ce::create(device.release()))); |
| 142 } |
| 143 |
123 DEFINE_TRACE(USB) | 144 DEFINE_TRACE(USB) |
124 { | 145 { |
125 visitor->trace(m_controller); | 146 visitor->trace(m_controller); |
126 RefCountedGarbageCollectedEventTargetWithInlineData<USB>::trace(visitor); | 147 RefCountedGarbageCollectedEventTargetWithInlineData<USB>::trace(visitor); |
127 } | 148 } |
128 | 149 |
129 } // namespace blink | 150 } // namespace blink |
OLD | NEW |