Closed Bug 680326 Opened 13 years ago Closed 6 years ago

Add XPCOM observers for device connection/disconnection

Categories

(Core :: DOM: Device Interfaces, defect)

All
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: kael, Unassigned)

References

Details

Attachments

(1 file, 2 obsolete files)

Device connection/disconnection notifications from the operating system (WM_DEVICECHANGE on windows) should be exposed as XPCOM observer events, so that subsystems (like the Joystick API and WebUSB) can respond to them by intelligently rescanning the available devices.
This patch should add the necessary observer notifications. Not sure how to write a test. Still trying to get it working with the current Joystick API patches.
We discussed this on IRC, but for posterity:
I tested this patch, and plugging/unplugging any of my game controllers doesn't produce any notifications. With some printf debugging, I found that I only get DBT_DEVNODES_CHANGED messages, not DBT_DEVICEARRIVAL / DBT_DEVICEREMOVECOMPLETE.
Keywords: dev-doc-needed
Updated to respond to DBT_DEVNODES_CHANGED as well since there are cases (like syncing a wireless XBox 360 controller) that don't produce the normal attached/removed notifications.

Also replaced the two different observer notifications with a single 'devices-changed' notification.
Attachment #554958 - Attachment is obsolete: true
I integrated support for this into my patches in bug 604039, and it works great. We'll have to work on getting this landed!
I emailed Kevin, and he's not working on this anymore. This patch updates his fix to work after bug 503879 removed the window messaging from nsToolkit.cpp, and moved it to nsWindow.cpp.
Assignee: kevin.gadd → jon
Attachment #563893 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #579755 - Flags: review?(ted.mielczarek)
Comment on attachment 579755 [details] [diff] [review]
Updated after bug 503879 was landed

Sorry, I should have redirected this earlier. I'm not a Windows widget peer, so I'll redirect this to jimm.
Attachment #579755 - Flags: review?(ted.mielczarek) → review?(jmathies)
Comment on attachment 579755 [details] [diff] [review]
Updated after bug 503879 was landed

> +      const uint DBT_DEVICEARRIVAL        = 0x8000;
> +      const uint DBT_DEVICEREMOVECOMPLETE = 0x8004;
> +      const uint DBT_DEVNODES_CHANGED     = 0x7;

There's no need for this, just include <dbt.h>

> @@ -4641,16 +4641,37 @@ bool nsWindow::ProcessMessage(UINT msg, WPARAM &wParam, LPARAM &lParam, ..
>     case WM_DEVICECHANGE:

By placing this in our main window procedure, which is used by every window we create, this observer event will fire multiple time on the same device state change. With two windows open I counted a total of seven DBT_DEVICEARRIVAL events for one usb stick being plugged in.

I'd suggest you either tie this to a unique window (the hidden message window managed by nsAppShell.cpp would probably do) or do something similar to what we do for WM_POWERBROADCAST events where we track the current state and only only fire the observer when necessary. Not sure how to handle that for multiple devices though, so going with the message window might be the simplest approach.
Attachment #579755 - Flags: review?(jmathies) → review-
Hm. The original version of this patch (in attachment 563893 [details] [diff] [review]), was using nsToolkit::WindowProc, but apparently that got removed as part of bug 503879.
Neil: since you removed the code that this patch originally touched, could you offer a suggestion as to what we should do to update this patch?
Assignee: jon → nobody
Status: ASSIGNED → NEW
This isn't really valid for gecko's device handling anymore. Marking incomplete.
Status: NEW → RESOLVED
Closed: 6 years ago
Component: General → DOM: Device Interfaces
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: