[webkit-gtk] Handling the run-file-chooser signal

Mario Sanchez Prada mario.prada at samsung.com
Tue Nov 5 01:22:08 PST 2013


> -----Original Message-----
> [...] 
> I've made some progress - it appears that initially I wasn't waiting
> long enough for the page to load and draw. I am now using a function
> that spins in the event loop for X seconds (which I want anyway to pace
> my interaction with the web servers), and that got things to the point
> where I can "click" on the control and get the run-file-chooser signal
> to fire.

Ah, yes... you need to wait for the web page to load before you can use that
signal, that's right.

> I defined my handler as such:
> 	$view->signal_connect('run-file-chooser' => sub {
> 	  my ($view, $FileChooserRequest) = @_;
> 	  print "Inside run-file-chooser handler\n";
> 	  return('/home/me/test.txt');
> 	});
> I see my text and and this keeps the native file chooser from
> appearing, and doesn't raise any errors -- however I don't see the
> input element update with the file name like I expect. After I send the
> click event I go into GTK events for X seconds loop, so this should not
> be another timing issue.
> I am wondering if I am returning the right thing, or if I'm supposed to
> call a method to set the file list and then return success or failure.
> Looking at the C version of the docs it appears I should return an
> array of file names. Does anyone have any insights?

So, first of all, I'm not a perl guy so I don't know exactly how you are
supposed to use the API in there. However, the code snippet above seems a
bit strange to me, as I don't think you're doing the right thing.

In other words, I don't think returning an string with the path is going to
do anything unless you have something underneath doing some magical
translation, which I see unlikely :)

What you have to do however, is to use the API defined in
WebKitFileChooserRequest, which in the C version is as follows:

  WEBKIT_API const gchar * const *
(WebKitFileChooserRequest *request);

  WEBKIT_API GtkFileFilter *
(WebKitFileChooserRequest *request);

  WEBKIT_API gboolean
(WebKitFileChooserRequest *request);

(WebKitFileChooserRequest *request,
                                                     const gchar * const

  WEBKIT_API const gchar * const *
(WebKitFileChooserRequest *request);

Basically, you probably want to use the webkit_file_chooser_request_get_*()
functions in your callback above to define how you want to show a file
chooser dialog (or whatever other method you want to use to select paths).
Then, once you have selected the interesting paths through that
dialog/whatever, you can tell WebCore that you actually want to "select"
them by using webkit_file_chooser_request_select_files().

You can see a good example of how to use this in
Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp: just search for
webkitWebViewRunFileChooser(), which is the default handler provided by
WebKit2GTK, and fileChooserDialogResponseCallback(), which is the callback
for the used GtkFileChooserDialog, where
webkit_file_chooser_request_select_files() is set.

Of course, you need to translate all this to Perl jargon, but shouldn't be
too hard, I suppose.

Hope this helps,

More information about the webkit-gtk mailing list