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

Side by Side Diff: third_party/WebKit/Source/modules/webusb/USB.h

Issue 1850023002: Consume Mojo services directly in Blink's WebUSB implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't do assignments in if statements. Created 4 years, 8 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
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 #ifndef USB_h 5 #ifndef USB_h
6 #define USB_h 6 #define USB_h
7 7
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptWrappable.h" 9 #include "bindings/core/v8/ScriptWrappable.h"
10 #include "core/dom/ContextLifecycleObserver.h" 10 #include "core/dom/ContextLifecycleObserver.h"
11 #include "core/events/EventTarget.h" 11 #include "core/events/EventTarget.h"
12 #include "device/usb/public/interfaces/chooser_service.mojom-wtf.h"
13 #include "device/usb/public/interfaces/device_manager.mojom-wtf.h"
12 #include "platform/heap/Handle.h" 14 #include "platform/heap/Handle.h"
13 #include "public/platform/modules/webusb/WebUSBClient.h"
14 15
15 namespace blink { 16 namespace blink {
16 17
17 class LocalFrame; 18 class LocalFrame;
19 class ScopedScriptPromiseResolver;
18 class ScriptState; 20 class ScriptState;
19 class USBDeviceRequestOptions; 21 class USBDeviceRequestOptions;
20 class WebUSBDevice;
21 22
22 class USB final 23 class USB final
23 : public EventTargetWithInlineData 24 : public EventTargetWithInlineData
24 , public ContextLifecycleObserver 25 , public ContextLifecycleObserver {
25 , public WebUSBClient::Observer {
26 DEFINE_WRAPPERTYPEINFO(); 26 DEFINE_WRAPPERTYPEINFO();
27 USING_GARBAGE_COLLECTED_MIXIN(USB); 27 USING_GARBAGE_COLLECTED_MIXIN(USB);
28 USING_PRE_FINALIZER(USB, dispose);
29 public: 28 public:
30 static USB* create(LocalFrame& frame) 29 static USB* create(LocalFrame& frame)
31 { 30 {
32 return new USB(frame); 31 return new USB(frame);
33 } 32 }
34 33
35 ~USB() override; 34 virtual ~USB();
36 35
37 // USB.idl 36 // USB.idl
38 ScriptPromise getDevices(ScriptState*); 37 ScriptPromise getDevices(ScriptState*);
39 ScriptPromise requestDevice(ScriptState*, const USBDeviceRequestOptions&); 38 ScriptPromise requestDevice(ScriptState*, const USBDeviceRequestOptions&);
40 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); 39 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect);
41 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); 40 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect);
42 41
43 // EventTarget overrides. 42 // EventTarget overrides.
44 ExecutionContext* getExecutionContext() const override; 43 ExecutionContext* getExecutionContext() const override;
45 const AtomicString& interfaceName() const override; 44 const AtomicString& interfaceName() const override;
46 45
47 // ContextLifecycleObserver overrides. 46 // ContextLifecycleObserver overrides.
48 void contextDestroyed() override; 47 void contextDestroyed() override;
49 48
50 // WebUSBClient::Observer overrides. 49 device::usb::wtf::DeviceManager* deviceManager() const { return m_deviceMana ger.get(); }
51 void onDeviceConnected(std::unique_ptr<WebUSBDevice>) override; 50
52 void onDeviceDisconnected(std::unique_ptr<WebUSBDevice>) override; 51 void onGetDevices(ScriptPromiseResolver*, mojo::WTFArray<device::usb::wtf::D eviceInfoPtr>);
52 void onGetPermission(ScriptPromiseResolver*, device::usb::wtf::DeviceInfoPtr );
53 void onDeviceChanges(device::usb::wtf::DeviceChangeNotificationPtr);
53 54
54 DECLARE_VIRTUAL_TRACE(); 55 DECLARE_VIRTUAL_TRACE();
55 56
56 private: 57 private:
57 explicit USB(LocalFrame& frame); 58 explicit USB(LocalFrame& frame);
58 void dispose();
59 59
60 WebUSBClient* m_client; 60 device::usb::wtf::DeviceManagerPtr m_deviceManager;
61 HeapHashSet<Member<ScriptPromiseResolver>> m_deviceManagerRequests;
62 device::usb::wtf::ChooserServicePtr m_chooserService;
63 HeapHashSet<Member<ScriptPromiseResolver>> m_chooserServiceRequests;
61 }; 64 };
62 65
63 } // namespace blink 66 } // namespace blink
64 67
65 #endif // USB_h 68 #endif // USB_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webusb/DEPS ('k') | third_party/WebKit/Source/modules/webusb/USB.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698