Chromium Code Reviews| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 return devices; | 71 return devices; |
| 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 ThreadState::current()->registerPreFinalizer(this); | |
| 81 if (m_client) | 82 if (m_client) |
| 82 m_client->setObserver(this); | 83 m_client->addObserver(this); |
| 83 } | 84 } |
| 84 | 85 |
| 85 USB::~USB() | 86 USB::~USB() |
| 86 { | 87 { |
| 88 } | |
| 89 | |
| 90 void USB::dispose() | |
| 91 { | |
| 87 if (m_client) | 92 if (m_client) |
| 88 m_client->setObserver(nullptr); | 93 m_client->removeObserver(this); |
|
haraken
2016/04/01 01:36:06
Shall we clear m_client here just in case? Then yo
| |
| 89 } | 94 } |
| 90 | 95 |
| 91 ScriptPromise USB::getDevices(ScriptState* scriptState) | 96 ScriptPromise USB::getDevices(ScriptState* scriptState) |
| 92 { | 97 { |
| 93 if (!m_client) | 98 if (!m_client) |
| 94 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); | 99 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(NotSupportedError)); |
| 95 | 100 |
| 96 String errorMessage; | 101 String errorMessage; |
| 97 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) | 102 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) |
| 98 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(SecurityError, errorMessage)); | 103 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(SecurityError, errorMessage)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 } | 137 } |
| 133 | 138 |
| 134 const AtomicString& USB::interfaceName() const | 139 const AtomicString& USB::interfaceName() const |
| 135 { | 140 { |
| 136 return EventTargetNames::USB; | 141 return EventTargetNames::USB; |
| 137 } | 142 } |
| 138 | 143 |
| 139 void USB::willDetachFrameHost() | 144 void USB::willDetachFrameHost() |
| 140 { | 145 { |
| 141 if (m_client) | 146 if (m_client) |
| 142 m_client->setObserver(nullptr); | 147 m_client->removeObserver(this); |
| 143 m_client = nullptr; | 148 m_client = nullptr; |
| 144 } | 149 } |
| 145 | 150 |
| 146 void USB::onDeviceConnected(WebPassOwnPtr<WebUSBDevice> device) | 151 void USB::onDeviceConnected(WebPassOwnPtr<WebUSBDevice> device) |
| 147 { | 152 { |
| 148 dispatchEvent(USBConnectionEvent::create(EventTypeNames::connect, USBDevice: :create(device.release(), getExecutionContext()))); | 153 dispatchEvent(USBConnectionEvent::create(EventTypeNames::connect, USBDevice: :create(device.release(), getExecutionContext()))); |
| 149 } | 154 } |
| 150 | 155 |
| 151 void USB::onDeviceDisconnected(WebPassOwnPtr<WebUSBDevice> device) | 156 void USB::onDeviceDisconnected(WebPassOwnPtr<WebUSBDevice> device) |
| 152 { | 157 { |
| 153 dispatchEvent(USBConnectionEvent::create(EventTypeNames::disconnect, USBDevi ce::create(device.release(), getExecutionContext()))); | 158 dispatchEvent(USBConnectionEvent::create(EventTypeNames::disconnect, USBDevi ce::create(device.release(), getExecutionContext()))); |
| 154 } | 159 } |
| 155 | 160 |
| 156 DEFINE_TRACE(USB) | 161 DEFINE_TRACE(USB) |
| 157 { | 162 { |
| 158 RefCountedGarbageCollectedEventTargetWithInlineData<USB>::trace(visitor); | 163 RefCountedGarbageCollectedEventTargetWithInlineData<USB>::trace(visitor); |
| 159 LocalFrameLifecycleObserver::trace(visitor); | 164 LocalFrameLifecycleObserver::trace(visitor); |
| 160 } | 165 } |
| 161 | 166 |
| 162 } // namespace blink | 167 } // namespace blink |
| OLD | NEW |