4

Edit: In addition to the bounty, we're willing to pay $250 to have this bug fixed in the Firefox/Gecko codebase. Here is a simple test project (Visual Studio 2008 C#) that reproduces the problem.

Edit #2 we're willing to pay $600 to have this bug fixed. See above for sample project that reproduces the problem.

We have a Firefox (Gecko) ActiveX control on our C# Windows Form to display HTML.

When this Firefox ActiveX control is on our form, about 2-3% of our key presses don't make it through. Or rather, a different Windows message is sent:

We hold down the TAB key to tab through 3 regular WinForms text boxes. It will behave correctly 97% of the time. Spy++ tells us WM_KEYDOWN message is sent properly:

normal behavior http://judahhimango.com/images/normaltab.jpg

But randomly, maybe 2-3% of the time, the tab key (or other key) isn't processed right. Spy++ tells us WM_CHAR is being sent instead:

odd behavior http://judahhimango.com/images/screwytab.png

When the odd behavior occurs, either the key is not processed at all, or is processed incorrectly (such as inserting a '\t' character into a textbox that doesn't support tab characters.

This only occurs if the Firefox ActiveX control is on our form.

Our question is: does Firefox/Gecko engine install some kind of keyboard hook that might cause these side effects? Or better yet, how do we fix this problem?

Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212
  • You can look at the Firefox source code, it may be the fastest way to figure out what is going on. You can use their source and symbol servers to debug pretty easily as well (https://developer.mozilla.org/En/Using_the_Mozilla_symbol_server). Also, why aren't you just using the MSHTML-based webbrowser control in your form? – i_am_jorf Jul 10 '09 at 17:13
  • Given that it's not easy to reproduce this error (it happens maybe 3% of the key presses), and given Mozilla is a huge, x-plat codebase, debugging Mozilla to find this bug seems like a daunting task. – Judah Gabriel Himango Jul 10 '09 at 17:33
  • 1
    Regarding MSHTML, we tried that. Its a bug factory. AccessViolationExceptions through bugs in the managed wrapper, COM errors; it was an endless, fruitless battle to make that thing work. – Judah Gabriel Himango Jul 10 '09 at 17:34
  • I've downloaded your sample project but am unable to reproduce the bug. Could you please be more specific regarding the Firefox ActiveX control: Which version do you use exactly? Where did you get it? – Steffen Opel Jul 16 '09 at 00:41
  • We got the ActiveX control from the Firefox codebase, in the mozilla\embedding\browser\activex folder. This is reproducible without the ActiveX. See jasonh's answer below, it's reproducible with the GeckoFX project as well. – Judah Gabriel Himango Jul 16 '09 at 17:14
  • @OP: Did you resolve the problem? Wouldn't it better to inject javascript in the automated page than sending keys? – milous Dec 14 '09 at 17:03
  • We filed a bug with Mozilla's bug tracker, we asked questions in their developer forums, nobody helped us. We ended up isolating the Mozilla control into its own process so that it won't corrupt keys in our main process. PITA, but it was a last resort, short of ditching Gecko. – Judah Gabriel Himango Dec 15 '09 at 16:59
  • It's rare error indeed...are you sure there's no other way of doing it? You could also try, as a last resort, to post that problem on some freelancing websites like rentacoder.com, if you haven't done that yet. As for Mozilla dev forums - well they sure have loads of other bugs and issues to fix... – milous Dec 15 '09 at 20:01
  • Yeah, we tried RentACoder. We had bidders, but then no one delivered. – Judah Gabriel Himango Feb 09 '10 at 03:44

4 Answers4

2

The WM_CHAR message is generated by TranslateMessage call, so a good place to start looking would be the TranslateMessage calls in the Gecko source code.

In the first example code you provided the function is imported only by two libraries - mozctl.dll and xul.dll. Since you claim that the same error happens also with GeckoFX we can take mozctl.dll out of the equation. That leaves us with xul.dll, so given the Gecko source code I would suggest to look into widget\src\windows\nsToolkit.cpp. I am not sure if the code is run if the engine is embedded, but if it is then the library starts a whole new message pump in different thread, which is bound to break.

Unfortunately I can't run or compile the code on my machine (Windows 7 x64 w/o the Mozilla ActiveX control installed), so I can't verify any of this with a debugger. Hope it helps someone to track it down further.

Filip Navara
  • 4,818
  • 1
  • 26
  • 37
1

The root problem is that when Mozilla is embedded in another application, it incorrectly pumps Windows messages when it dispatches internal events. Mozilla uses an event system to coordinate across threads or to schedule deferred processing on a thread (see nsIThread, nsIEventTarget). If you embed a web page with a lot of active XMLHTTPRequests, for example, Mozilla will use its event dispatching interface to dispatch events back to javascript and it will pump windows messages as a side effect. Once Mozilla events are fully dispatched, it goes back to the main event loop.

When Mozilla pumps windows messages, it doesn't include the extra processing done by the application's event loop - IsDialogMessage(), TranslateMessage(), PreTranslateMessage(), or any other pre-processing are skipped when Mozilla gets into this state. Symptoms therefore include tab key presses getting inserted as a character instead of being used for dialog navigation, keyboard hotkeys being sporadically ignored, or custom message pre-processing being sporadically skipped. For example, the Outlook 2007/2010 "Compose" screen sporadically loses keystrokes because it relies on custom message pre-processing to handle keyboard input.

See https://bugzilla.mozilla.org/show_bug.cgi?id=582790 for a patch that addresses the problem.

dmercredi
  • 2,112
  • 11
  • 10
1

I have Snoop Free and PSM Anti-Keylogger. One of them detected firefox trying to install a Keyboard Hook. Mozilla/Firefox file xul.dll attempt at installing at keyboard hook. DENIED.

Kevin
  • 11
  • 1
0

I noticed that you have implemented all of the interoperability yourself. Can you try this with the GeckoFX project and see if you get the same error? I use this project at work and haven't encountered any issues yet.

jasonh
  • 29,297
  • 11
  • 59
  • 61
  • Yep, the same error occurs with GeckoFX. Here's a test project that uses GeckoFX: http://judahhimango.com/GeckoFXError.zip Go to the 2nd tab, focus a text box, hold down the tab key for about 10 seconds. Gecko will randomly cause a \t whitespace character to be inserted into the textbox. – Judah Gabriel Himango Jul 16 '09 at 04:07