| 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 : ContextLifecycleObserver(frame.document()) | 78 : ContextLifecycleObserver(frame.document()) |
| 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->addObserver(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 { |
| 92 // Promptly clears a raw reference from content/ to an on-heap object |
| 93 // so that content/ doesn't access it in a lazy sweeping phase. |
| 87 if (m_client) | 94 if (m_client) |
| 88 m_client->removeObserver(this); | 95 m_client->removeObserver(this); |
| 96 m_client = nullptr; |
| 89 } | 97 } |
| 90 | 98 |
| 91 ScriptPromise USB::getDevices(ScriptState* scriptState) | 99 ScriptPromise USB::getDevices(ScriptState* scriptState) |
| 92 { | 100 { |
| 93 if (!m_client) | 101 if (!m_client) |
| 94 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 102 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
| 95 | 103 |
| 96 String errorMessage; | 104 String errorMessage; |
| 97 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) | 105 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) |
| 98 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); | 106 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 dispatchEvent(USBConnectionEvent::create(EventTypeNames::disconnect, USBDevi
ce::create(adoptPtr(device.release()), getExecutionContext()))); | 161 dispatchEvent(USBConnectionEvent::create(EventTypeNames::disconnect, USBDevi
ce::create(adoptPtr(device.release()), getExecutionContext()))); |
| 154 } | 162 } |
| 155 | 163 |
| 156 DEFINE_TRACE(USB) | 164 DEFINE_TRACE(USB) |
| 157 { | 165 { |
| 158 RefCountedGarbageCollectedEventTargetWithInlineData<USB>::trace(visitor); | 166 RefCountedGarbageCollectedEventTargetWithInlineData<USB>::trace(visitor); |
| 159 ContextLifecycleObserver::trace(visitor); | 167 ContextLifecycleObserver::trace(visitor); |
| 160 } | 168 } |
| 161 | 169 |
| 162 } // namespace blink | 170 } // namespace blink |
| OLD | NEW |