| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 USB::USB(LocalFrame& frame) | 77 USB::USB(LocalFrame& frame) |
| 78 : LocalFrameLifecycleObserver(&frame) | 78 : LocalFrameLifecycleObserver(&frame) |
| 79 , m_client(USBController::from(frame).client()) | 79 , m_client(USBController::from(frame).client()) |
| 80 { | 80 { |
| 81 if (m_client) | 81 if (m_client) |
| 82 m_client->setObserver(this); | 82 m_client->addObserver(this); |
| 83 } | 83 } |
| 84 | 84 |
| 85 USB::~USB() | 85 USB::~USB() |
| 86 { | 86 { |
| 87 } |
| 88 |
| 89 void USB::dispose() |
| 90 { |
| 87 if (m_client) | 91 if (m_client) |
| 88 m_client->setObserver(nullptr); | 92 m_client->removeObserver(this); |
| 89 } | 93 } |
| 90 | 94 |
| 91 ScriptPromise USB::getDevices(ScriptState* scriptState) | 95 ScriptPromise USB::getDevices(ScriptState* scriptState) |
| 92 { | 96 { |
| 93 if (!m_client) | 97 if (!m_client) |
| 94 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 98 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
| 95 | 99 |
| 96 String errorMessage; | 100 String errorMessage; |
| 97 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) | 101 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) |
| 98 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); | 102 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 136 } |
| 133 | 137 |
| 134 const AtomicString& USB::interfaceName() const | 138 const AtomicString& USB::interfaceName() const |
| 135 { | 139 { |
| 136 return EventTargetNames::USB; | 140 return EventTargetNames::USB; |
| 137 } | 141 } |
| 138 | 142 |
| 139 void USB::willDetachFrameHost() | 143 void USB::willDetachFrameHost() |
| 140 { | 144 { |
| 141 if (m_client) | 145 if (m_client) |
| 142 m_client->setObserver(nullptr); | 146 m_client->removeObserver(this); |
| 143 m_client = nullptr; | 147 m_client = nullptr; |
| 144 } | 148 } |
| 145 | 149 |
| 146 void USB::onDeviceConnected(WebPassOwnPtr<WebUSBDevice> device) | 150 void USB::onDeviceConnected(WebPassOwnPtr<WebUSBDevice> device) |
| 147 { | 151 { |
| 148 dispatchEvent(USBConnectionEvent::create(EventTypeNames::connect, USBDevice:
:create(device.release(), getExecutionContext()))); | 152 dispatchEvent(USBConnectionEvent::create(EventTypeNames::connect, USBDevice:
:create(device.release(), getExecutionContext()))); |
| 149 } | 153 } |
| 150 | 154 |
| 151 void USB::onDeviceDisconnected(WebPassOwnPtr<WebUSBDevice> device) | 155 void USB::onDeviceDisconnected(WebPassOwnPtr<WebUSBDevice> device) |
| 152 { | 156 { |
| 153 dispatchEvent(USBConnectionEvent::create(EventTypeNames::disconnect, USBDevi
ce::create(device.release(), getExecutionContext()))); | 157 dispatchEvent(USBConnectionEvent::create(EventTypeNames::disconnect, USBDevi
ce::create(device.release(), getExecutionContext()))); |
| 154 } | 158 } |
| 155 | 159 |
| 156 DEFINE_TRACE(USB) | 160 DEFINE_TRACE(USB) |
| 157 { | 161 { |
| 158 RefCountedGarbageCollectedEventTargetWithInlineData<USB>::trace(visitor); | 162 RefCountedGarbageCollectedEventTargetWithInlineData<USB>::trace(visitor); |
| 159 LocalFrameLifecycleObserver::trace(visitor); | 163 LocalFrameLifecycleObserver::trace(visitor); |
| 160 } | 164 } |
| 161 | 165 |
| 162 } // namespace blink | 166 } // namespace blink |
| OLD | NEW |