FileChooser hangs and crashes in firefox

Hey all,

I’m using the FileChooser with usenative=true in a browser plugin. Code:

FileChooser dlg("Save As...", File::getSpecialLocation(File::userHomeDirectory), String::empty, true);
if (dlg.browseForFileToSave(true)) 
{
...
}

In IE this seems to work fine, however in Firefox it sometimes hangs after trying a couple of times, usually within 5 tries. When it does hang, the plugin will crash after a minute or so. The save as dialog does appear btw, i just can’t click anything. When I change the usenative to false, it seems to work fine. But i want the native dialog… :slight_smile:

I attached the VS debugger, enabling all exceptions, but nothing was catched.

Anyone with the same problem, or maybe this is a known issue ?

Thanks

edit:

  • This piece of code is called from javascript.
  • Just before this piece of code, MessageManager::isThisTheMessageThread() returns true.

Woah… No, sorry, that’s not going to work.

It’s not safe to run a modal loop in a browser, or even to open any external windows at all, because at any moment the browser may decide to close your plugin down or do some other kind of browser stuff, and if you’re in a modal loop, that’ll screw up the whole stack. In a browser plugin, definitely keep everything inside your own window, and go via javascript for any user-interaction stuff like that.

…in fact, you might want to set JUCE_MODAL_LOOPS_PERMITTED to 0, to make sure that you don’t do anything naughty.

I think u misunderstood - I’m not using a messageloop; i just used MessageManager::isThisTheMessageThread() to test (thought it would tell me whether or not i’m on the main thread).

My browser plugin does not have any gui stuff. Users initiate (via a javascript menu) the save as code. So basicly something like this:

javascript:

m_plugin.Download(…)

And in my plugin:

const var BrowserObject::Download(const var* params, int numParams)
{
...
  FileChooser dlg(title, File::getSpecialLocation(File::userHomeDirectory), String::empty, true);
  if (dlg.browseForFileToSave(true)) 
  {
    ....
  }
}

This I can do right?

No! Like I said, you should avoid anything modal, and browseForFileToSave() is obviously going to go off and run a modal loop!

Well, i cannot do it from javascript… So any other ideas how to let the user choose a file / folder? Also, why is it not hanging/crashing when i use the juce dialog instead of the native one?

Why not use a juce dialog box that’s embedded inside your plugin’s window, and run it non-modally?

I’ve no idea why it’d crash with a native box, but you’ve got to expect that the browser will interact unpredictably with things like that, and avoid them.