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/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 mojoFilter->has_protocol_code = filter.hasProtocolCode(); | 46 mojoFilter->has_protocol_code = filter.hasProtocolCode(); |
47 if (mojoFilter->has_protocol_code) | 47 if (mojoFilter->has_protocol_code) |
48 mojoFilter->protocol_code = filter.protocolCode(); | 48 mojoFilter->protocol_code = filter.protocolCode(); |
49 return mojoFilter; | 49 return mojoFilter; |
50 } | 50 } |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 USB::USB(LocalFrame& frame) | 54 USB::USB(LocalFrame& frame) |
55 : ContextLifecycleObserver(frame.document()), m_clientBinding(this) { | 55 : ContextLifecycleObserver(frame.document()), m_clientBinding(this) { |
56 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_deviceManager)); | 56 frame.interfaceProvider()->getInterface(mojo::MakeRequest(&m_deviceManager)); |
57 m_deviceManager.set_connection_error_handler(convertToBaseCallback(WTF::bind( | 57 m_deviceManager.set_connection_error_handler(convertToBaseCallback(WTF::bind( |
58 &USB::onDeviceManagerConnectionError, wrapWeakPersistent(this)))); | 58 &USB::onDeviceManagerConnectionError, wrapWeakPersistent(this)))); |
59 m_deviceManager->SetClient(m_clientBinding.CreateInterfacePtrAndBind()); | 59 m_deviceManager->SetClient(m_clientBinding.CreateInterfacePtrAndBind()); |
60 } | 60 } |
61 | 61 |
62 USB::~USB() { | 62 USB::~USB() { |
63 // |m_deviceManager| and |m_chooserService| may still be valid but there | 63 // |m_deviceManager| and |m_chooserService| may still be valid but there |
64 // should be no more outstanding requests to them because each holds a | 64 // should be no more outstanding requests to them because each holds a |
65 // persistent handle to this object. | 65 // persistent handle to this object. |
66 DCHECK(m_deviceManagerRequests.isEmpty()); | 66 DCHECK(m_deviceManagerRequests.isEmpty()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 ScriptPromise promise = resolver->promise(); | 105 ScriptPromise promise = resolver->promise(); |
106 | 106 |
107 if (!m_chooserService) { | 107 if (!m_chooserService) { |
108 LocalFrame* frame = executionContext->isDocument() | 108 LocalFrame* frame = executionContext->isDocument() |
109 ? toDocument(executionContext)->frame() | 109 ? toDocument(executionContext)->frame() |
110 : nullptr; | 110 : nullptr; |
111 if (!frame) { | 111 if (!frame) { |
112 resolver->reject(DOMException::create(NotSupportedError)); | 112 resolver->reject(DOMException::create(NotSupportedError)); |
113 return promise; | 113 return promise; |
114 } | 114 } |
115 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_chooserService)); | 115 frame->interfaceProvider()->getInterface( |
| 116 mojo::MakeRequest(&m_chooserService)); |
116 m_chooserService.set_connection_error_handler( | 117 m_chooserService.set_connection_error_handler( |
117 convertToBaseCallback(WTF::bind(&USB::onChooserServiceConnectionError, | 118 convertToBaseCallback(WTF::bind(&USB::onChooserServiceConnectionError, |
118 wrapWeakPersistent(this)))); | 119 wrapWeakPersistent(this)))); |
119 } | 120 } |
120 | 121 |
121 String errorMessage; | 122 String errorMessage; |
122 if (!executionContext->isSecureContext(errorMessage)) { | 123 if (!executionContext->isSecureContext(errorMessage)) { |
123 resolver->reject(DOMException::create(SecurityError, errorMessage)); | 124 resolver->reject(DOMException::create(SecurityError, errorMessage)); |
124 } else if (!UserGestureIndicator::consumeUserGesture()) { | 125 } else if (!UserGestureIndicator::consumeUserGesture()) { |
125 resolver->reject(DOMException::create( | 126 resolver->reject(DOMException::create( |
(...skipping 28 matching lines...) Expand all Loading... |
154 m_deviceManagerRequests.clear(); | 155 m_deviceManagerRequests.clear(); |
155 m_chooserService.reset(); | 156 m_chooserService.reset(); |
156 m_chooserServiceRequests.clear(); | 157 m_chooserServiceRequests.clear(); |
157 } | 158 } |
158 | 159 |
159 USBDevice* USB::getOrCreateDevice(usb::DeviceInfoPtr deviceInfo) { | 160 USBDevice* USB::getOrCreateDevice(usb::DeviceInfoPtr deviceInfo) { |
160 USBDevice* device = m_deviceCache.get(deviceInfo->guid); | 161 USBDevice* device = m_deviceCache.get(deviceInfo->guid); |
161 if (!device) { | 162 if (!device) { |
162 String guid = deviceInfo->guid; | 163 String guid = deviceInfo->guid; |
163 usb::DevicePtr pipe; | 164 usb::DevicePtr pipe; |
164 m_deviceManager->GetDevice(guid, mojo::GetProxy(&pipe)); | 165 m_deviceManager->GetDevice(guid, mojo::MakeRequest(&pipe)); |
165 device = USBDevice::create(std::move(deviceInfo), std::move(pipe), | 166 device = USBDevice::create(std::move(deviceInfo), std::move(pipe), |
166 getExecutionContext()); | 167 getExecutionContext()); |
167 m_deviceCache.add(guid, device); | 168 m_deviceCache.add(guid, device); |
168 } | 169 } |
169 return device; | 170 return device; |
170 } | 171 } |
171 | 172 |
172 void USB::onGetDevices(ScriptPromiseResolver* resolver, | 173 void USB::onGetDevices(ScriptPromiseResolver* resolver, |
173 Vector<usb::DeviceInfoPtr> deviceInfos) { | 174 Vector<usb::DeviceInfoPtr> deviceInfos) { |
174 auto requestEntry = m_deviceManagerRequests.find(resolver); | 175 auto requestEntry = m_deviceManagerRequests.find(resolver); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 247 |
247 DEFINE_TRACE(USB) { | 248 DEFINE_TRACE(USB) { |
248 EventTargetWithInlineData::trace(visitor); | 249 EventTargetWithInlineData::trace(visitor); |
249 ContextLifecycleObserver::trace(visitor); | 250 ContextLifecycleObserver::trace(visitor); |
250 visitor->trace(m_deviceManagerRequests); | 251 visitor->trace(m_deviceManagerRequests); |
251 visitor->trace(m_chooserServiceRequests); | 252 visitor->trace(m_chooserServiceRequests); |
252 visitor->trace(m_deviceCache); | 253 visitor->trace(m_deviceCache); |
253 } | 254 } |
254 | 255 |
255 } // namespace blink | 256 } // namespace blink |
OLD | NEW |