Scanning plugin fails to call TWAIN in Firefox 4, Windows.

593 views
Skip to first unread message

kirushik

unread,
Jun 7, 2011, 12:59:48 PM6/7/11
to firebre...@googlegroups.com
I'm trying to develop plugin, which allows visitors of certain portal to scan a document page and upload resulting image on button being clicked.
I've almost achieved the goal, but my plugin fails to open scanner-specific image acquisition dialog when I launch it from Firefox 4, Windows (To be exact - latest version, 4.0.1).

When I call TWAIN-provided scanner selection dialog, everything works, dialog pops up as required, callbacks do their stuff.
When I call TWAIN image acquisition dialog (provided by scanner manufacturer's driver), plugin reports that it
Failed to load Data Source.
DataSource operation failed
RC: TWRC_FAILURE
CC: TWCC_LOWMEMORY

That behavior is documented to occur when calling program
But mysterious thing is that the exact same plugin, started in all other major browsers (Chrome, IE8, Opera and even ) behaves as expected - shows up device-specific scanning dialog.
To add some mystical smoke, I must add that this memory shortage occures only with some of tested scanners, there are scanners whose drivers work fine.

What am I doing wrong?
Are there some memory limitations for plugins in Firefox 4? All
the corresponding process takes no more than 16MB of memory in Chrome during all the manipulations, both for image acquisition, its conversion with statically-linked ImageMagick and upload of the converted image to the server via SOAP call.

How can I solve this?
Tweak something in my code? Mess with firebreath-generated stuff?
Report FF4 bug and pray?

I'll be glad to provide all the required information, code snippets etc.
Firebreath is checked out from repository, version file says
Last Commit Date: Wed, 6 Apr 2011 17:57:12 -0600

Neil Griffiths

unread,
Jun 7, 2011, 1:06:21 PM6/7/11
to firebre...@googlegroups.com
That's IE's protected mode that you're hitting. You'll need to spawn (from your plugin) an external process that your installer sets up to have regular integrity rights which will bring up the TWAIN external dialog.

It's frustrating - but that's IE for you!

I've just noticed there's no example of how to do this on the FB docs, I'll add something when I get a chance. Until then all the information you should need is in here:


Neil

Richard Bateman

unread,
Jun 7, 2011, 2:05:01 PM6/7/11
to firebre...@googlegroups.com

Wait; has Firefox 4 started honoring protected mode?

Richard

Neil Griffiths

unread,
Jun 7, 2011, 2:09:59 PM6/7/11
to firebre...@googlegroups.com
I apologise, I misread what was written originally - when kirushik said major browsers I think I'd assumed they meant everything that wasn't IE and so that's what the problem was with.

Must read messages when I'm not hurrying. :)

Neil

Richard Bateman

unread,
Jun 7, 2011, 2:42:34 PM6/7/11
to firebre...@googlegroups.com
On Jun 7, 2011, at 10:59 AM, kirushik wrote:

I'm trying to develop plugin, which allows visitors of certain portal to scan a document page and upload resulting image on button being clicked.
I've almost achieved the goal, but my plugin fails to open scanner-specific image acquisition dialog when I launch it from Firefox 4, Windows (To be exact - latest version, 4.0.1).

When I call TWAIN-provided scanner selection dialog, everything works, dialog pops up as required, callbacks do their stuff.
When I call TWAIN image acquisition dialog (provided by scanner manufacturer's driver), plugin reports that it
Failed to load Data Source.
DataSource operation failed
RC: TWRC_FAILURE
CC: TWCC_LOWMEMORY

That behavior is documented to occur when calling program
But mysterious thing is that the exact same plugin, started in all other major browsers (Chrome, IE8, Opera and even ) behaves as expected - shows up device-specific scanning dialog.
To add some mystical smoke, I must add that this memory shortage occures only with some of tested scanners, there are scanners whose drivers work fine.

Make sure you're not opening a blocking dialog on the same thread as the plugin runs on -- you don't want to block the UI, particularly on ff4.  It's conceivable (but probably not likely) that this could be part of your problem if you are.

What am I doing wrong?
Are there some memory limitations for plugins in Firefox 4? All
the corresponding process takes no more than 16MB of memory in Chrome during all the manipulations, both for image acquisition, its conversion with statically-linked ImageMagick and upload of the converted image to the server via SOAP call.

There are no such memory limitations that I know of; I have certainly had plugins use far more than 16MB of memory (particularly when I had memory leaks) and have never been shut down by the browser until using in excess of a gigabyte of ram. 

How can I solve this?
Tweak something in my code? Mess with firebreath-generated stuff?
Report FF4 bug and pray?

I really don't know; this is a strange issue. Keep trying different things. One possible option if you can't make it work would be to launch another process to do your TWAIN for you and use some form of IPC between them, though that is annoying.

I'll be glad to provide all the required information, code snippets etc.
Firebreath is checked out from repository, version file says
Last Commit Date: Wed, 6 Apr 2011 17:57:12 -0600


Good luck!

Richard

Richard Bateman

unread,
Mar 7, 2013, 10:25:07 AM3/7/13
to firebre...@googlegroups.com

Have you verified that fb_win isn't NULL at this point? You can't use the window until after AttachedEvent is fired…

Next question, if you're just working on getting the HWND for the browser, why are you not using http://www.firebreath.org/display/documentation/class%20FB%20PluginWindowWin%20getBrowserHWND?

If you just need any HWND (which seems more likely) why are you calling GetAncestor?

Richard

On Mar 7, 2013, at 3:15 , Amruth S <mailto...@gmail.com> wrote:

I'm trying to develop plugin, which allows visitors to scan a document page and upload resulting image on button being clicked.
I am not able get the plugin window handle

FB::PluginWindowWin* w = (FB::PluginWindowWin*)(fb_win);
HWND hWndBrowser = GetAncestor( w->getHWND(), GA_ROOTOWNER );

this crashes my plugin ...
What am i doing wrong

--
 
---
You received this message because you are subscribed to the Google Groups "firebreath-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebreath-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Amruth S

unread,
Mar 8, 2013, 1:18:40 AM3/8/13
to firebre...@googlegroups.com
Thanks for the response..

this is my code snippet:

FB::PluginWindow* pluginWindow = getPlugin()->GetWindow();
    FB::PluginWindowWin* w = (FB::PluginWindowWin*)(pluginWindow);
    HWND hwndBrowser =  w->getBrowserHWND();


fb_win is returning NULL .. How to fire AttachedEvent before this..

Richard Bateman

unread,
Mar 8, 2013, 2:14:53 AM3/8/13
to firebre...@googlegroups.com
Welcome to the fun world of plugin development, where you don't get to decide when the window is available.

You need to wait to do anything you need to do with an HWND until *after* AttachedEvent is called. If you look in your .h file you'll see that you already have (unless you deleted it) an event handler registered for that event.  Use it. =]

Richard

Amruth S

unread,
Mar 8, 2013, 2:38:23 AM3/8/13
to firebre...@googlegroups.com
Thanks for the quick response..

bool Mypluginsample::onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindow *)
{
    // The window is attached; act appropriately
    return false;
}


How to trace this attached event ..
FB_WIN is still NULL..

could you send me sample code snippet.. or the lifecycle

John Dexter

unread,
Mar 8, 2013, 5:04:43 AM3/8/13
to firebre...@googlegroups.com
That's kind of the point Richard makes... there is no nicely defined lifecycle or at least it's different on different browsers and not guaranteed to change on a new version of the same browser.

You have to write your code resilient to this.

Richard Bateman

unread,
Mar 8, 2013, 10:32:14 AM3/8/13
to firebre...@googlegroups.com

I don't know why your window would still be NULL here.  Did you make your plugin invisible with css or set the width=0, height=0? always make it visible and at least 1x1 in size.  1x1 is effectively invisible anyway, but sometimes the browsers don't give you a window when you do things like display: none or visibility: hidden

Richard 

Amruth S

unread,
Mar 11, 2013, 5:44:59 AM3/11/13
to firebre...@googlegroups.com

Hi Richard,

Thanks man.. Now i am getting the handler

bool Myscanplugin::onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindow* win)

{
    // The window is attached; act appropriately
    //return false;

     FB::PluginWindowWin* w = (FB::PluginWindowWin*)(win);
     hwndBrowser =w->getHWND();
  
    return true;
}


I am trying to get this is handle value in the below method...

FB::variant myScannerAPI::echo(const FB::variant& msg)
{
    static int n(0);
    fire_echo("So far, you clicked this many times: ", n++);
    myScanner* ac = new AcsysScanner();
    HWND hwnd = ac->hwndBrowser;
    InitTwain(hwnd);
    // return "foobar";
    return msg;
}

I am getting a different handler value in the hwnd variable ..why?also I cannot access the DSMEntry method with this handler.could you send me the sample snippet.

Regards,
Amruth

Richard Bateman

unread,
Mar 11, 2013, 11:30:17 AM3/11/13
to firebre...@googlegroups.com

If you're telling me that the hwndBrowser variable is getting changed between the time that you set it in onWindowAttached and when you use it in echo then I have no idea how that could happen; it's not a variable on the base class, therefore none of the firebreath code knows about it, therefore only your code could be changing it.

Richard

John Tan

unread,
Mar 11, 2013, 9:32:38 PM3/11/13
to firebre...@googlegroups.com
Which one are you refering to?
 
myScanner* ac = new AcsysScanner();
    HWND hwnd = ac->hwndBrowser;
This one?
 
Seems pretty obvious to me why the hwnd will be different. What happens during the instantiation of AcsysScanner()?
 
One solution is to keep the "hwndBrowser" in hwndBrowser =w->getHWND(); as global.

Richard Bateman

unread,
Mar 11, 2013, 9:52:28 PM3/11/13
to firebre...@googlegroups.com

Heh.  Good point; totally missed that.  Amruth, you don't seem to be passing the hwnd into AcsysScanner, so where would it get it from?

Richardd

Amruth S

unread,
Mar 12, 2013, 1:18:01 AM3/12/13
to firebre...@googlegroups.com

Thanks richard..

Now i am getting the window handle value.. and also Inittwain(twain methods..) is successfully called ...
'll get back to you in my next hurdle..

Amruth S

unread,
Mar 12, 2013, 1:20:13 AM3/12/13
to firebre...@googlegroups.com
Thanks John..

I have kept "hwndBrowser"  as global one..
But I have trouble in getting the value in my JSAPI class in firebreath..

John Tan

unread,
Mar 12, 2013, 8:59:58 PM3/12/13
to firebre...@googlegroups.com
You mean accessing the hwndbrowser from another C/C++ file? Use "extern". Otherwise if it's a global variable, you shouldn't have any problem accessing this variable from any part of the code, assuming that it's initialized first before any part of the code uses it.

Amruth S

unread,
Mar 13, 2013, 9:30:24 AM3/13/13
to firebre...@googlegroups.com
Thanks John I am getting it now ..

I am having trouble in getting the following function
 BOOL WINAPI GetMessage(LPMSG lpMsg,  HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax);

how to invoke this could you guide me with sample snippet..

Amruth S

unread,
Mar 13, 2013, 9:33:55 AM3/13/13
to firebre...@googlegroups.com
I am getting the Scan window  using twain but i could not proceed with scan


I am having trouble in getting the following function
 BOOL WINAPI GetMessage(LPMSG lpMsg,  HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax);

how to invoke this .. any suggestion could you guide me..

Neil Griffiths

unread,
Mar 13, 2013, 12:55:40 PM3/13/13
to firebre...@googlegroups.com
When you get the WindowAttached message, call CreateWindow. You'll want to pass the plugin window handle into the hWndParent parameter. Pass in your new window class that you're going to define that specfies lpfnWndProc pointing to your own message handling function.

Neil
Reply all
Reply to author
Forward
0 new messages