Commit 38d3363a authored by reillyg@chromium.org's avatar reillyg@chromium.org

Add onconnect and ondisconnect events to navigator.usb.

This patch updates USB.idl to add these two events, making it an
EventTarget. WebUSBClient still needs to be updated to support
delivering these events to Blink.

BUG=492204

Review URL: https://codereview.chromium.org/1291753004

git-svn-id: svn://svn.chromium.org/blink/trunk@200912 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent a01198fe
......@@ -53,6 +53,8 @@ PASS window.cached_navigator_serviceWorker.oncontrollerchange is null
PASS window.cached_navigator_serviceWorker.onmessage is null
PASS window.cached_navigator_services.onclose is null
PASS window.cached_navigator_services.onmessage is null
PASS window.cached_navigator_usb.onconnect is null
PASS window.cached_navigator_usb.ondisconnect is null
PASS window.cached_performance.onframetimingbufferfull is null
PASS window.cached_performance.onresourcetimingbufferfull is null
PASS window.cached_performance.onwebkitresourcetimingbufferfull is null
......
......@@ -53,6 +53,8 @@ PASS window.cached_navigator_serviceWorker.oncontrollerchange is null
PASS window.cached_navigator_serviceWorker.onmessage is null
PASS window.cached_navigator_services.onclose is null
PASS window.cached_navigator_services.onmessage is null
PASS window.cached_navigator_usb.onconnect is null
PASS window.cached_navigator_usb.ondisconnect is null
PASS window.cached_performance.onframetimingbufferfull is null
PASS window.cached_performance.onresourcetimingbufferfull is null
PASS window.cached_performance.onwebkitresourcetimingbufferfull is null
......
......@@ -53,6 +53,8 @@ PASS window.cached_navigator_serviceWorker.oncontrollerchange is null
PASS window.cached_navigator_serviceWorker.onmessage is null
PASS window.cached_navigator_services.onclose is null
PASS window.cached_navigator_services.onmessage is null
PASS window.cached_navigator_usb.onconnect is null
PASS window.cached_navigator_usb.ondisconnect is null
PASS window.cached_performance.onframetimingbufferfull is null
PASS window.cached_performance.onresourcetimingbufferfull is null
PASS window.cached_performance.onwebkitresourcetimingbufferfull is null
......
......@@ -61,6 +61,8 @@ PASS oldChildWindow.navigator.serviceWorker.oncontrollerchange is newChildWindow
PASS oldChildWindow.navigator.serviceWorker.onmessage is newChildWindow.navigator.serviceWorker.onmessage
PASS oldChildWindow.navigator.services.onclose is newChildWindow.navigator.services.onclose
PASS oldChildWindow.navigator.services.onmessage is newChildWindow.navigator.services.onmessage
PASS oldChildWindow.navigator.usb.onconnect is newChildWindow.navigator.usb.onconnect
PASS oldChildWindow.navigator.usb.ondisconnect is newChildWindow.navigator.usb.ondisconnect
PASS oldChildWindow.navigator.userAgent is newChildWindow.navigator.userAgent
PASS oldChildWindow.navigator.vendor is newChildWindow.navigator.vendor
PASS oldChildWindow.navigator.vendorSub is newChildWindow.navigator.vendorSub
......
......@@ -61,6 +61,8 @@ FAIL childWindow.navigator.serviceWorker.oncontrollerchange should be null. Thre
FAIL childWindow.navigator.serviceWorker.onmessage should be null. Threw exception TypeError: Cannot read property 'onmessage' of null
PASS childWindow.navigator.services.onclose is null
PASS childWindow.navigator.services.onmessage is null
FAIL childWindow.navigator.usb.onconnect should be null. Threw exception TypeError: Cannot read property 'onconnect' of null
FAIL childWindow.navigator.usb.ondisconnect should be null. Threw exception TypeError: Cannot read property 'ondisconnect' of null
PASS childWindow.navigator.userAgent is ''
PASS childWindow.navigator.vendor is window.navigator.vendor
PASS childWindow.navigator.vendorSub is ''
......
......@@ -60,6 +60,8 @@ FAIL childWindow.navigator.serviceWorker.oncontrollerchange should be null. Thre
FAIL childWindow.navigator.serviceWorker.onmessage should be null. Threw exception TypeError: Cannot read property 'onmessage' of null
PASS childWindow.navigator.services.onclose is null
PASS childWindow.navigator.services.onmessage is null
FAIL childWindow.navigator.usb.onconnect should be null. Threw exception TypeError: Cannot read property 'onconnect' of null
FAIL childWindow.navigator.usb.ondisconnect should be null. Threw exception TypeError: Cannot read property 'ondisconnect' of null
PASS childWindow.navigator.userAgent is ''
PASS childWindow.navigator.vendor is window.navigator.vendor
PASS childWindow.navigator.vendorSub is ''
......
......@@ -40,3 +40,4 @@ modules/webmidi/MIDIAccess
modules/webmidi/MIDIInput
modules/webmidi/MIDIPort
modules/websockets/WebSocket ImplementedAs=DOMWebSocket
modules/webusb/USB
......@@ -11,6 +11,7 @@
#include "core/dom/DOMException.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
#include "modules/EventTargetModules.h"
#include "modules/webusb/USBDevice.h"
#include "modules/webusb/USBDeviceFilter.h"
#include "modules/webusb/USBDeviceRequestOptions.h"
......@@ -108,9 +109,21 @@ ScriptPromise USB::requestDevice(ScriptState* scriptState, const USBDeviceReques
return promise;
}
ExecutionContext* USB::executionContext() const
{
LocalFrame* frame = m_controller->frame();
return frame ? frame->document() : nullptr;
}
const AtomicString& USB::interfaceName() const
{
return EventTargetNames::USB;
}
DEFINE_TRACE(USB)
{
visitor->trace(m_controller);
RefCountedGarbageCollectedEventTargetWithInlineData<USB>::trace(visitor);
}
} // namespace blink
......@@ -7,6 +7,7 @@
#include "bindings/core/v8/ScriptPromise.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/events/EventTarget.h"
#include "modules/webusb/USBController.h"
#include "platform/heap/Handle.h"
......@@ -17,9 +18,10 @@ class ScriptState;
class USBDeviceRequestOptions;
class USB final
: public GarbageCollectedFinalized<USB>
, public ScriptWrappable {
: public RefCountedGarbageCollectedEventTargetWithInlineData<USB> {
DEFINE_WRAPPERTYPEINFO();
REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(USB);
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(USB);
public:
static USB* create(LocalFrame& frame)
{
......@@ -28,8 +30,15 @@ public:
explicit USB(LocalFrame& frame);
// USB.idl
ScriptPromise getDevices(ScriptState*);
ScriptPromise requestDevice(ScriptState*, const USBDeviceRequestOptions&);
DEFINE_ATTRIBUTE_EVENT_LISTENER(connect);
DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect);
// EventTarget overrides.
ExecutionContext* executionContext() const override;
const AtomicString& interfaceName() const override;
DECLARE_VIRTUAL_TRACE();
......
......@@ -8,7 +8,9 @@
GarbageCollected,
NoInterfaceObject,
RuntimeEnabled=WebUSB,
] interface USB {
] interface USB : EventTarget {
attribute EventHandler onconnect;
attribute EventHandler ondisconnect;
[CallWith=ScriptState] Promise<sequence<USBDevice>> getDevices();
[CallWith=ScriptState] Promise<sequence<USBDevice>> requestDevice(USBDeviceRequestOptions options);
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment