Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: Source/modules/webusb/USB.cpp

Issue 1340523004: Implement USB connection events through the WebUSB client interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Change Member back to PersistentWillBeMember. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/modules/webusb/USB.h ('k') | Source/modules/webusb/USBConnectionEvent.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « Source/modules/webusb/USB.h ('k') | Source/modules/webusb/USBConnectionEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698