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

nn6eumtr nn6eumtr at gmail.com
Tue Nov 5 06:55:09 PST 2013


Thank you! That pointed me in the right direction. Here is the solution 
for anyone interested.

$view->signal_connect('run-file-chooser' => sub {
   my ($view, $FileChooserRequest) = @_;

   print "Inside run-file-chooser handler\n";

   $FileChooserRequest->select_files(['/home/me/test.txt']);

   return(1); # Required, or native dialog shows
});

On 11/5/2013 4:22 AM, Mario Sanchez Prada wrote:
> Hi,
>
>> -----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 *
>    webkit_file_chooser_request_get_mime_types
> (WebKitFileChooserRequest *request);
>
>    WEBKIT_API GtkFileFilter *
>    webkit_file_chooser_request_get_mime_types_filter
> (WebKitFileChooserRequest *request);
>
>    WEBKIT_API gboolean
>    webkit_file_chooser_request_get_select_multiple
> (WebKitFileChooserRequest *request);
>
>    WEBKIT_API void
>    webkit_file_chooser_request_select_files
> (WebKitFileChooserRequest *request,
>                                                       const gchar * const
> *files);
>
>    WEBKIT_API const gchar * const *
>    webkit_file_chooser_request_get_selected_files
> (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,
> Mario
>
>
>


More information about the webkit-gtk mailing list