Changeset 115627 in webkit


Ignore:
Timestamp:
Apr 30, 2012 6:49:12 AM (12 years ago)
Author:
mario@webkit.org
Message:

[GTK] Implement WebUIClient's runOpenPanel in WebKit2GTK+
https://bugs.webkit.org/show_bug.cgi?id=78491

Reviewed by Martin Robinson.

Add a new public class to the API, WebKitFileChooserRequest, to be
emitted along with a new WebKitWebView::run-file-chooser signal to
let client applications to provide their own file chooser dialog
when the use interacts with HTML Input elements of type 'file'.

  • GNUmakefile.am: Added new source files and headers.
  • UIProcess/API/gtk/WebKitFileChooserRequest.cpp: Added.

(_WebKitFileChooserRequestPrivate):
(webkit_file_chooser_request_init):
(webkitFileChooserRequestFinalize):
(webkitFileChooserRequestGetProperty):
(webkit_file_chooser_request_class_init):
(webkitFileChooserRequestCreate):
(webkit_file_chooser_request_get_mime_types):
(webkit_file_chooser_request_get_mime_types_filter):
(webkit_file_chooser_request_get_select_multiple):
(webkit_file_chooser_request_select_files):
(webkit_file_chooser_request_get_selected_files):
(webkit_file_chooser_request_cancel):

  • UIProcess/API/gtk/WebKitFileChooserRequest.h: Added.

(_WebKitFileChooserRequest):
(_WebKitFileChooserRequestClass):

  • UIProcess/API/gtk/WebKitFileChooserRequestPrivate.h: Added,

containing the prototype of webkitFileChooserRequestCreate.

Provide private API to make a file chooser request from the
WebView, and provide a default handler for it.

  • UIProcess/API/gtk/WebKitWebView.cpp:

(fileChooserDialogResponseCallback): Handler for the 'response'
signal for the GtkFileChooserDialog used in the default
handler. It will call to webkit_file_chooser_request_select_files
or webkit_file_chooser_request_cancel as needed.
(webkitWebViewRunFileChooser): Default handler for the new
'run-file-chooser' signal. It will create a GtkFileChooserDialog,
connect to the 'response' signal and show it.
(webkit_web_view_class_init): Connect the 'run-file-chooser'
signal to the default handler, webkitWebViewRunFileChooser.
(webkitWebViewRunFileChooserRequest):

  • UIProcess/API/gtk/WebKitWebView.h:

(_WebKitWebViewClass): Added prototype for the handler of the new
'run-file-chooser' signal.

  • UIProcess/API/gtk/WebKitWebViewPrivate.h: Added prototype for

private new function webkitWebViewRunFileChooserRequest.

Provide an implementation for runOpenPanel in WebKitUIClient.

  • UIProcess/API/gtk/WebKitUIClient.cpp:

(runOpenPanel): New, implements runOpenPanel by creating an
instance of WebKitFileChooserRequest and asking the WebView to
emit the 'run-file-chooser' signal with it.
(attachUIClientToView): Reference the new runOpenPanel function.

Added the new publich header to the main header.

  • UIProcess/API/gtk/webkit2.h: Added WebKitFileChooserRequest.h.

New unit tests for the new WebKitFileChooserRequest API. Also,
extended the WebViewTest class to allow simulating mouse clicks.

  • UIProcess/API/gtk/tests/TestWebKitWebView.cpp:

(checkMimeTypeForFilter): New, checks whether a GtkFileFilter
filters a given MIME type, as specified by RFC 2046.
(testWebViewFileChooserRequest): New unit test.
(beforeAll): Add the new unit test as an UIClientTest.

  • UIProcess/API/gtk/tests/WebViewTest.cpp:

(WebViewTest::clickMouseButton): New public function to simulate a
mouse click through GdkEvents, as the combination of a 'press' and
a 'release' event. Used from the new unit test to simulate the
user pressing in the button rendered for a HTML Input element.
(WebViewTest::executeMouseButtonEvent): New private function to
simulate a mouse event through GdkEvents.

  • UIProcess/API/gtk/tests/WebViewTest.h:

Updated documentation related files with the new API.

  • UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Added new API.
  • UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Added new section.
  • UIProcess/API/gtk/docs/webkit2gtk.types: Added get_type function.
Location:
trunk/Source/WebKit2
Files:
3 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r115559 r115627  
     12012-04-30  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        [GTK] Implement WebUIClient's runOpenPanel in WebKit2GTK+
     4        https://bugs.webkit.org/show_bug.cgi?id=78491
     5
     6        Reviewed by Martin Robinson.
     7
     8        Add a new public class to the API, WebKitFileChooserRequest, to be
     9        emitted along with a new WebKitWebView::run-file-chooser signal to
     10        let client applications to provide their own file chooser dialog
     11        when the use interacts with HTML Input elements of type 'file'.
     12
     13        * GNUmakefile.am: Added new source files and headers.
     14        * UIProcess/API/gtk/WebKitFileChooserRequest.cpp: Added.
     15        (_WebKitFileChooserRequestPrivate):
     16        (webkit_file_chooser_request_init):
     17        (webkitFileChooserRequestFinalize):
     18        (webkitFileChooserRequestGetProperty):
     19        (webkit_file_chooser_request_class_init):
     20        (webkitFileChooserRequestCreate):
     21        (webkit_file_chooser_request_get_mime_types):
     22        (webkit_file_chooser_request_get_mime_types_filter):
     23        (webkit_file_chooser_request_get_select_multiple):
     24        (webkit_file_chooser_request_select_files):
     25        (webkit_file_chooser_request_get_selected_files):
     26        (webkit_file_chooser_request_cancel):
     27        * UIProcess/API/gtk/WebKitFileChooserRequest.h: Added.
     28        (_WebKitFileChooserRequest):
     29        (_WebKitFileChooserRequestClass):
     30        * UIProcess/API/gtk/WebKitFileChooserRequestPrivate.h: Added,
     31        containing the prototype of webkitFileChooserRequestCreate.
     32
     33        Provide private API to make a file chooser request from the
     34        WebView, and provide a default handler for it.
     35
     36        * UIProcess/API/gtk/WebKitWebView.cpp:
     37        (fileChooserDialogResponseCallback): Handler for the 'response'
     38        signal for the GtkFileChooserDialog used in the default
     39        handler. It will call to webkit_file_chooser_request_select_files
     40        or webkit_file_chooser_request_cancel as needed.
     41        (webkitWebViewRunFileChooser): Default handler for the new
     42        'run-file-chooser' signal. It will create a GtkFileChooserDialog,
     43        connect to the 'response' signal and show it.
     44        (webkit_web_view_class_init): Connect the 'run-file-chooser'
     45        signal to the default handler, webkitWebViewRunFileChooser.
     46        (webkitWebViewRunFileChooserRequest):
     47        * UIProcess/API/gtk/WebKitWebView.h:
     48        (_WebKitWebViewClass): Added prototype for the handler of the new
     49        'run-file-chooser' signal.
     50        * UIProcess/API/gtk/WebKitWebViewPrivate.h: Added prototype for
     51        private new function webkitWebViewRunFileChooserRequest.
     52
     53        Provide an implementation for runOpenPanel in WebKitUIClient.
     54
     55        * UIProcess/API/gtk/WebKitUIClient.cpp:
     56        (runOpenPanel): New, implements runOpenPanel by creating an
     57        instance of WebKitFileChooserRequest and asking the WebView to
     58        emit the 'run-file-chooser' signal with it.
     59        (attachUIClientToView): Reference the new runOpenPanel function.
     60
     61        Added the new publich header to the main header.
     62
     63        * UIProcess/API/gtk/webkit2.h: Added WebKitFileChooserRequest.h.
     64
     65        New unit tests for the new WebKitFileChooserRequest API. Also,
     66        extended the WebViewTest class to allow simulating mouse clicks.
     67
     68        * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
     69        (checkMimeTypeForFilter): New, checks whether a GtkFileFilter
     70        filters a given MIME type, as specified by RFC 2046.
     71        (testWebViewFileChooserRequest): New unit test.
     72        (beforeAll): Add the new unit test as an UIClientTest.
     73
     74        * UIProcess/API/gtk/tests/WebViewTest.cpp:
     75        (WebViewTest::clickMouseButton): New public function to simulate a
     76        mouse click through GdkEvents, as the combination of a 'press' and
     77        a 'release' event. Used from the new unit test to simulate the
     78        user pressing in the button rendered for a HTML Input element.
     79        (WebViewTest::executeMouseButtonEvent): New private function to
     80        simulate a mouse event through GdkEvents.
     81        * UIProcess/API/gtk/tests/WebViewTest.h:
     82
     83        Updated documentation related files with the new API.
     84
     85        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Added new API.
     86        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Added new section.
     87        * UIProcess/API/gtk/docs/webkit2gtk.types: Added get_type function.
     88
    1892012-04-28  Yury Semikhatsky  <yurys@chromium.org>
    290
  • trunk/Source/WebKit2/GNUmakefile.am

    r115411 r115627  
    9797        $(WebKit2)/UIProcess/API/gtk/WebKitEditingCommands.h \
    9898        $(WebKit2)/UIProcess/API/gtk/WebKitError.h \
     99        $(WebKit2)/UIProcess/API/gtk/WebKitFileChooserRequest.h \
    99100        $(WebKit2)/UIProcess/API/gtk/WebKitFindController.h \
    100101        $(WebKit2)/UIProcess/API/gtk/WebKitHitTestResult.h \
     
    578579        Source/WebKit2/UIProcess/API/gtk/WebKitError.h \
    579580        Source/WebKit2/UIProcess/API/gtk/WebKitError.cpp \
     581        Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.cpp \
     582        Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequest.h \
     583        Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequestPrivate.h \
    580584        Source/WebKit2/UIProcess/API/gtk/WebKitFullscreenClient.cpp \
    581585        Source/WebKit2/UIProcess/API/gtk/WebKitFullscreenClient.h \
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp

    r107947 r115627  
    2121#include "WebKitUIClient.h"
    2222
     23#include "WebKitFileChooserRequestPrivate.h"
    2324#include "WebKitPrivate.h"
    2425#include "WebKitWebViewBasePrivate.h"
     
    2728#include "WebPageProxy.h"
    2829#include <WebCore/GtkUtilities.h>
     30#include <wtf/gobject/GRefPtr.h>
    2931
    3032using namespace WebKit;
     
    137139}
    138140
     141static void runOpenPanel(WKPageRef page, WKFrameRef frame, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener, const void *clientInfo)
     142{
     143    GRefPtr<WebKitFileChooserRequest> request = adoptGRef(webkitFileChooserRequestCreate(parameters, listener));
     144    webkitWebViewRunFileChooserRequest(WEBKIT_WEB_VIEW(clientInfo), request.get());
     145}
     146
    139147void attachUIClientToView(WebKitWebView* webView)
    140148{
     
    170178        0, // pageDidScroll
    171179        0, // exceededDatabaseQuota
    172         0, // runOpenPanel
     180        runOpenPanel,
    173181        0, // decidePolicyForGeolocationPermissionRequest
    174182        0, // headerHeight
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r114719 r115627  
    7575    LEAVE_FULLSCREEN,
    7676
     77    RUN_FILE_CHOOSER,
     78
    7779    LAST_SIGNAL
    7880};
     
    207209}
    208210
     211static void fileChooserDialogResponseCallback(GtkDialog* dialog, gint responseID, WebKitFileChooserRequest* request)
     212{
     213    GRefPtr<WebKitFileChooserRequest> adoptedRequest = adoptGRef(request);
     214    if (responseID == GTK_RESPONSE_ACCEPT) {
     215        GOwnPtr<GSList> filesList(gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog)));
     216        GRefPtr<GPtrArray> filesArray = adoptGRef(g_ptr_array_new());
     217        for (GSList* file = filesList.get(); file; file = g_slist_next(file))
     218            g_ptr_array_add(filesArray.get(), file->data);
     219        g_ptr_array_add(filesArray.get(), 0);
     220        webkit_file_chooser_request_select_files(adoptedRequest.get(), reinterpret_cast<const gchar* const*>(filesArray->pdata));
     221    } else
     222        webkit_file_chooser_request_cancel(adoptedRequest.get());
     223
     224    gtk_widget_destroy(GTK_WIDGET(dialog));
     225}
     226
     227static gboolean webkitWebViewRunFileChooser(WebKitWebView* webView, WebKitFileChooserRequest* request)
     228{
     229    GtkWidget* toplevel = gtk_widget_get_toplevel(GTK_WIDGET(webView));
     230    if (!widgetIsOnscreenToplevelWindow(toplevel))
     231        toplevel = 0;
     232
     233    gboolean allowsMultipleSelection = webkit_file_chooser_request_get_select_multiple(request);
     234    GtkWidget* dialog = gtk_file_chooser_dialog_new(allowsMultipleSelection ? _("Select Files") : _("Select File"),
     235                                                    toplevel ? GTK_WINDOW(toplevel) : 0,
     236                                                    GTK_FILE_CHOOSER_ACTION_OPEN,
     237                                                    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
     238                                                    GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
     239                                                    NULL);
     240
     241    if (GtkFileFilter* filter = webkit_file_chooser_request_get_mime_types_filter(request))
     242        gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
     243    gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), allowsMultipleSelection);
     244
     245    if (const gchar* const* selectedFiles = webkit_file_chooser_request_get_selected_files(request))
     246        gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(dialog), selectedFiles[0]);
     247
     248    g_signal_connect(dialog, "response", G_CALLBACK(fileChooserDialogResponseCallback), g_object_ref(request));
     249    gtk_widget_show(dialog);
     250
     251    return TRUE;
     252}
     253
    209254static void webkitWebViewConstructed(GObject* object)
    210255{
     
    314359    webViewClass->script_dialog = webkitWebViewScriptDialog;
    315360    webViewClass->decide_policy = webkitWebViewDecidePolicy;
     361    webViewClass->run_file_chooser = webkitWebViewRunFileChooser;
    316362
    317363    g_type_class_add_private(webViewClass, sizeof(WebKitWebViewPrivate));
     
    758804                     webkit_marshal_BOOLEAN__VOID,
    759805                     G_TYPE_BOOLEAN, 0);
     806     /**
     807     * WebKitWebView::run-file-chooser:
     808     * @web_view: the #WebKitWebView on which the signal is emitted
     809     * @request: a #WebKitFileChooserRequest
     810     *
     811     * This signal is emitted when the user interacts with a &lt;input
     812     * type='file' /&gt; HTML element, requesting from WebKit to show
     813     * a dialog to select one or more files to be uploaded. To let the
     814     * application know the details of the file chooser, as well as to
     815     * allow the client application to either cancel the request or
     816     * perform an actual selection of files, the signal will pass an
     817     * instance of the #WebKitFileChooserRequest in the @request
     818     * argument.
     819     *
     820     * The default signal handler will asynchronously run a regular
     821     * #GtkFileChooserDialog for the user to interact with.
     822     *
     823     * Returns: %TRUE to stop other handlers from being invoked for the event.
     824     *   %FALSE to propagate the event further.
     825     *
     826     */
     827    signals[RUN_FILE_CHOOSER] =
     828        g_signal_new("run-file-chooser",
     829                     G_TYPE_FROM_CLASS(webViewClass),
     830                     G_SIGNAL_RUN_LAST,
     831                     G_STRUCT_OFFSET(WebKitWebViewClass, run_file_chooser),
     832                     g_signal_accumulator_true_handled, 0 /* accumulator data */,
     833                     webkit_marshal_BOOLEAN__OBJECT,
     834                     G_TYPE_BOOLEAN, 1, /* number of parameters */
     835                     WEBKIT_TYPE_FILE_CHOOSER_REQUEST);
    760836}
    761837
     
    9831059    g_signal_emit(webView, signals[LEAVE_FULLSCREEN], 0, &returnValue);
    9841060    return !returnValue;
     1061}
     1062
     1063void webkitWebViewRunFileChooserRequest(WebKitWebView* webView, WebKitFileChooserRequest* request)
     1064{
     1065    gboolean returnValue;
     1066    g_signal_emit(webView, signals[RUN_FILE_CHOOSER], 0, request, &returnValue);
    9851067}
    9861068
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h

    r113697 r115627  
    3232#include <webkit2/WebKitBackForwardList.h>
    3333#include <webkit2/WebKitDefines.h>
     34#include <webkit2/WebKitFileChooserRequest.h>
    3435#include <webkit2/WebKitFindController.h>
    3536#include <webkit2/WebKitHitTestResult.h>
    3637#include <webkit2/WebKitJavascriptResult.h>
     38#include <webkit2/WebKitPolicyDecision.h>
    3739#include <webkit2/WebKitScriptDialog.h>
    3840#include <webkit2/WebKitSettings.h>
     
    4244#include <webkit2/WebKitWebViewBase.h>
    4345#include <webkit2/WebKitWindowProperties.h>
    44 #include <webkit2/WebKitPolicyDecision.h>
    4546
    4647G_BEGIN_DECLS
     
    152153    gboolean   (* enter_fullscreen)      (WebKitWebView             *web_view);
    153154    gboolean   (* leave_fullscreen)      (WebKitWebView             *web_view);
     155    gboolean   (* run_file_chooser)      (WebKitWebView             *web_view,
     156                                          WebKitFileChooserRequest  *request);
    154157
    155158    /* Padding for future expansion */
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h

    r113697 r115627  
    4747void webkitWebViewPrintFrame(WebKitWebView*, WKFrameRef);
    4848void webkitWebViewResourceLoadStarted(WebKitWebView*, WKFrameRef, uint64_t resourceIdentifier, WebKitURIRequest*, bool isMainResource);
     49void webkitWebViewRunFileChooserRequest(WebKitWebView*, WebKitFileChooserRequest*);
    4950WebKitWebResource* webkitWebViewGetLoadingWebResource(WebKitWebView*, uint64_t resourceIdentifier);
    5051void webkitWebViewRemoveLoadingWebResource(WebKitWebView*, uint64_t resourceIdentifier);
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml

    r113870 r115627  
    2929    <xi:include href="xml/WebKitWebResource.xml"/>
    3030    <xi:include href="xml/WebKitError.xml"/>
     31    <xi:include href="xml/WebKitFileChooserRequest.xml"/>
    3132    <xi:include href="xml/WebKitFindController.xml"/>
    3233    <xi:include href="xml/WebKitCookieManager.xml"/>
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r113870 r115627  
    522522
    523523<SECTION>
     524<FILE>WebKitFileChooserRequest</FILE>
     525WebKitFileChooserRequest
     526webkit_file_chooser_request_get_mime_types
     527webkit_file_chooser_request_get_mime_types_filter
     528webkit_file_chooser_request_get_select_multiple
     529webkit_file_chooser_request_select_files
     530webkit_file_chooser_request_get_selected_files
     531webkit_file_chooser_request_cancel
     532
     533<SUBSECTION Standard>
     534WebKitFileChooserRequestClass
     535WEBKIT_TYPE_FILE_CHOOSER_REQUEST
     536WEBKIT_FILE_CHOOSER_REQUEST
     537WEBKIT_IS_FILE_CHOOSER_REQUEST
     538WEBKIT_FILE_CHOOSER_REQUEST_CLASS
     539WEBKIT_IS_FILE_CHOOSER_REQUEST_CLASS
     540WEBKIT_FILE_CHOOSER_REQUEST_GET_CLASS
     541
     542<SUBSECTION Private>
     543WebKitFileChooserRequestPrivate
     544webkit_file_chooser_request_get_type
     545</SECTION>
     546
     547<SECTION>
    524548<FILE>WebKitFindController</FILE>
    525549WebKitFindController
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types

    r113870 r115627  
    1010webkit_window_properties_get_type
    1111webkit_download_get_type
     12webkit_file_chooser_request_get_type
    1213webkit_find_controller_get_type
    1314webkit_script_dialog_get_type
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp

    r113697 r115627  
    333333}
    334334
     335static gboolean checkMimeTypeForFilter(GtkFileFilter* filter, const gchar* mimeType)
     336{
     337    GtkFileFilterInfo filterInfo;
     338    filterInfo.contains = GTK_FILE_FILTER_MIME_TYPE;
     339    filterInfo.mime_type = mimeType;
     340    return gtk_file_filter_filter(filter, &filterInfo);
     341}
     342
    335343static void testWebViewJavaScriptDialogs(UIClientTest* test, gconstpointer)
    336344{
     
    513521}
    514522
     523class FileChooserTest: public UIClientTest {
     524public:
     525    MAKE_GLIB_TEST_FIXTURE(FileChooserTest);
     526
     527    FileChooserTest()
     528    {
     529        g_signal_connect(m_webView, "run-file-chooser", G_CALLBACK(runFileChooserCallback), this);
     530    }
     531
     532    static gboolean runFileChooserCallback(WebKitWebView*, WebKitFileChooserRequest* request, FileChooserTest* test)
     533    {
     534        test->runFileChooser(request);
     535        return TRUE;
     536    }
     537
     538    void runFileChooser(WebKitFileChooserRequest* request)
     539    {
     540        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request));
     541        m_fileChooserRequest = request;
     542        g_main_loop_quit(m_mainLoop);
     543    }
     544
     545    WebKitFileChooserRequest* clickMouseButtonAndWaitForFileChooserRequest(int x, int y)
     546    {
     547        clickMouseButton(x, y);
     548        g_main_loop_run(m_mainLoop);
     549        return m_fileChooserRequest.get();
     550    }
     551
     552private:
     553    GRefPtr<WebKitFileChooserRequest> m_fileChooserRequest;
     554};
     555
     556static void testWebViewFileChooserRequest(FileChooserTest* test, gconstpointer)
     557{
     558    test->showInWindowAndWaitUntilMapped();
     559    static const char* fileChooserHTMLFormat = "<html><body><input style='position:absolute;left:0;top:0;margin:0;padding:0' type='file' %s/></body></html>";
     560
     561    // Multiple selections not allowed, no MIME filtering.
     562    GOwnPtr<char> simpleFileUploadHTML(g_strdup_printf(fileChooserHTMLFormat, ""));
     563    test->loadHtml(simpleFileUploadHTML.get(), 0);
     564    test->waitUntilLoadFinished();
     565    WebKitFileChooserRequest* fileChooserRequest = test->clickMouseButtonAndWaitForFileChooserRequest(5, 5);
     566    g_assert(!webkit_file_chooser_request_get_select_multiple(fileChooserRequest));
     567
     568    const gchar* const* mimeTypes = webkit_file_chooser_request_get_mime_types(fileChooserRequest);
     569    g_assert(!mimeTypes);
     570    GtkFileFilter* filter = webkit_file_chooser_request_get_mime_types_filter(fileChooserRequest);
     571    g_assert(!filter);
     572    const gchar* const* selectedFiles = webkit_file_chooser_request_get_selected_files(fileChooserRequest);
     573    g_assert(!selectedFiles);
     574    webkit_file_chooser_request_cancel(fileChooserRequest);
     575
     576    // Multiple selections allowed, no MIME filtering, some pre-selected files.
     577    GOwnPtr<char> multipleSelectionFileUploadHTML(g_strdup_printf(fileChooserHTMLFormat, "multiple"));
     578    test->loadHtml(multipleSelectionFileUploadHTML.get(), 0);
     579    test->waitUntilLoadFinished();
     580    fileChooserRequest = test->clickMouseButtonAndWaitForFileChooserRequest(5, 5);
     581    g_assert(webkit_file_chooser_request_get_select_multiple(fileChooserRequest));
     582
     583    mimeTypes = webkit_file_chooser_request_get_mime_types(fileChooserRequest);
     584    g_assert(!mimeTypes);
     585    filter = webkit_file_chooser_request_get_mime_types_filter(fileChooserRequest);
     586    g_assert(!filter);
     587    selectedFiles = webkit_file_chooser_request_get_selected_files(fileChooserRequest);
     588    g_assert(!selectedFiles);
     589
     590    // Select some files.
     591    const gchar* filesToSelect[4] = { "/foo", "/foo/bar", "/foo/bar/baz", 0 };
     592    webkit_file_chooser_request_select_files(fileChooserRequest, filesToSelect);
     593
     594    // Check the files that have been just selected.
     595    selectedFiles = webkit_file_chooser_request_get_selected_files(fileChooserRequest);
     596    g_assert(selectedFiles);
     597    g_assert_cmpstr(selectedFiles[0], ==, "/foo");
     598    g_assert_cmpstr(selectedFiles[1], ==, "/foo/bar");
     599    g_assert_cmpstr(selectedFiles[2], ==, "/foo/bar/baz");
     600    g_assert(!selectedFiles[3]);
     601
     602    // Perform another request to check if the list of files selected
     603    // in the previous step appears now as part of the new request.
     604    fileChooserRequest = test->clickMouseButtonAndWaitForFileChooserRequest(5, 5);
     605    selectedFiles = webkit_file_chooser_request_get_selected_files(fileChooserRequest);
     606    g_assert(selectedFiles);
     607    g_assert_cmpstr(selectedFiles[0], ==, "/foo");
     608    g_assert_cmpstr(selectedFiles[1], ==, "/foo/bar");
     609    g_assert_cmpstr(selectedFiles[2], ==, "/foo/bar/baz");
     610    g_assert(!selectedFiles[3]);
     611    webkit_file_chooser_request_cancel(fileChooserRequest);
     612
     613    // Multiple selections not allowed, only accept images, audio and video files..
     614    GOwnPtr<char> mimeFilteredFileUploadHTML(g_strdup_printf(fileChooserHTMLFormat, "accept='audio/*,video/*,image/*'"));
     615    test->loadHtml(mimeFilteredFileUploadHTML.get(), 0);
     616    test->waitUntilLoadFinished();
     617    fileChooserRequest = test->clickMouseButtonAndWaitForFileChooserRequest(5, 5);
     618    g_assert(!webkit_file_chooser_request_get_select_multiple(fileChooserRequest));
     619
     620    mimeTypes = webkit_file_chooser_request_get_mime_types(fileChooserRequest);
     621    g_assert(mimeTypes);
     622    g_assert_cmpstr(mimeTypes[0], ==, "audio/*");
     623    g_assert_cmpstr(mimeTypes[1], ==, "video/*");
     624    g_assert_cmpstr(mimeTypes[2], ==, "image/*");
     625    g_assert(!mimeTypes[3]);
     626
     627    filter = webkit_file_chooser_request_get_mime_types_filter(fileChooserRequest);
     628    g_assert(GTK_IS_FILE_FILTER(filter));
     629    g_assert(checkMimeTypeForFilter(filter, "audio/*"));
     630    g_assert(checkMimeTypeForFilter(filter, "video/*"));
     631    g_assert(checkMimeTypeForFilter(filter, "image/*"));
     632
     633    selectedFiles = webkit_file_chooser_request_get_selected_files(fileChooserRequest);
     634    g_assert(!selectedFiles);
     635    webkit_file_chooser_request_cancel(fileChooserRequest);
     636}
     637
    515638class FullScreenClientTest: public WebViewTest {
    516639public:
     
    596719    WebViewTest::add("WebKitWebView", "zoom-level", testWebViewZoomLevel);
    597720    WebViewTest::add("WebKitWebView", "run-javascript", testWebViewRunJavaScript);
     721    FileChooserTest::add("WebKitWebView", "file-chooser-request", testWebViewFileChooserRequest);
    598722    FullScreenClientTest::add("WebKitWebView", "fullscreen", testWebViewFullScreen);
    599723}
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp

    r113697 r115627  
    199199}
    200200
     201void WebViewTest::clickMouseButton(int x, int y, unsigned int button, unsigned int mouseModifiers)
     202{
     203    doMouseButtonEvent(GDK_BUTTON_PRESS, x, y, button, mouseModifiers);
     204    doMouseButtonEvent(GDK_BUTTON_RELEASE, x, y, button, mouseModifiers);
     205}
     206
    201207void WebViewTest::keyStroke(unsigned int keyVal, unsigned int keyModifiers)
    202208{
     
    225231}
    226232
     233void WebViewTest::doMouseButtonEvent(GdkEventType eventType, int x, int y, unsigned int button, unsigned int mouseModifiers)
     234{
     235    g_assert(m_parentWindow);
     236    GtkWidget* viewWidget = GTK_WIDGET(m_webView);
     237    g_assert(gtk_widget_get_realized(viewWidget));
     238
     239    GOwnPtr<GdkEvent> event(gdk_event_new(eventType));
     240    event->button.window = gtk_widget_get_window(viewWidget);
     241    g_object_ref(event->button.window);
     242
     243    event->button.time = GDK_CURRENT_TIME;
     244    event->button.x = x;
     245    event->button.y = y;
     246    event->button.axes = 0;
     247    event->button.state = mouseModifiers;
     248    event->button.button = button;
     249
     250    event->button.device = gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(viewWidget)));
     251
     252    int xRoot, yRoot;
     253    gdk_window_get_root_coords(gtk_widget_get_window(viewWidget), x, y, &xRoot, &yRoot);
     254    event->button.x_root = xRoot;
     255    event->button.y_root = yRoot;
     256    gtk_main_do_event(event.get());
     257}
     258
    227259static void runJavaScriptReadyCallback(GObject*, GAsyncResult* result, WebViewTest* test)
    228260{
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h

    r113697 r115627  
    4848
    4949    void mouseMoveTo(int x, int y, unsigned int mouseModifiers = 0);
     50    void clickMouseButton(int x, int y, unsigned int button = 1, unsigned int mouseModifiers = 0);
    5051    void keyStroke(unsigned int keyVal, unsigned int keyModifiers = 0);
    5152
     
    6667    WebKitJavascriptResult* m_javascriptResult;
    6768    GError** m_javascriptError;
     69
     70private:
     71    void doMouseButtonEvent(GdkEventType, int, int, unsigned int, unsigned int);
    6872};
    6973
  • trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h

    r113870 r115627  
    3232#include <webkit2/WebKitEnumTypes.h>
    3333#include <webkit2/WebKitError.h>
     34#include <webkit2/WebKitFileChooserRequest.h>
    3435#include <webkit2/WebKitFindController.h>
    3536#include <webkit2/WebKitHitTestResult.h>
     
    4243#include <webkit2/WebKitWebContext.h>
    4344#include <webkit2/WebKitWebResource.h>
     45#include <webkit2/WebKitWebView.h>
    4446#include <webkit2/WebKitWebViewBase.h>
    45 #include <webkit2/WebKitWebView.h>
    4647#include <webkit2/WebKitWindowProperties.h>
    4748
Note: See TracChangeset for help on using the changeset viewer.