summaryrefslogtreecommitdiff
path: root/Source/WebKit/gtk/webkit
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-06-25 13:35:59 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-06-25 13:35:59 +0200
commit79ad030d505ccf79cf10aa9f8189ca3e2f61f6f4 (patch)
tree0287b1a69d84492c901e8bc820e635e7133809a0 /Source/WebKit/gtk/webkit
parent682ab87480e7757346802ce7f54cfdbdfeb2339e (diff)
downloadqtwebkit-79ad030d505ccf79cf10aa9f8189ca3e2f61f6f4.tar.gz
Imported WebKit commit c4b613825abd39ac739a47d7b4410468fcef66dc (http://svn.webkit.org/repository/webkit/trunk@121147)
New snapshot that includes Win32 debug build fix (use SVGAllInOne)
Diffstat (limited to 'Source/WebKit/gtk/webkit')
-rw-r--r--Source/WebKit/gtk/webkit/webkit.h1
-rw-r--r--Source/WebKit/gtk/webkit/webkitfilechooserrequest.cpp367
-rw-r--r--Source/WebKit/gtk/webkit/webkitfilechooserrequest.h71
-rw-r--r--Source/WebKit/gtk/webkit/webkitfilechooserrequestprivate.h30
-rw-r--r--Source/WebKit/gtk/webkit/webkitwebview.cpp86
-rw-r--r--Source/WebKit/gtk/webkit/webkitwebview.h6
-rw-r--r--Source/WebKit/gtk/webkit/webkitwebviewprivate.h2
7 files changed, 560 insertions, 3 deletions
diff --git a/Source/WebKit/gtk/webkit/webkit.h b/Source/WebKit/gtk/webkit/webkit.h
index c7e95e8ed..aa7b93dbd 100644
--- a/Source/WebKit/gtk/webkit/webkit.h
+++ b/Source/WebKit/gtk/webkit/webkit.h
@@ -28,6 +28,7 @@
#include <webkit/webkitdownload.h>
#include <webkit/webkitenumtypes.h>
#include <webkit/webkitfavicondatabase.h>
+#include <webkit/webkitfilechooserrequest.h>
#include <webkit/webkitgeolocationpolicydecision.h>
#include <webkit/webkitglobals.h>
#include <webkit/webkithittestresult.h>
diff --git a/Source/WebKit/gtk/webkit/webkitfilechooserrequest.cpp b/Source/WebKit/gtk/webkit/webkitfilechooserrequest.cpp
new file mode 100644
index 000000000..c1373ed49
--- /dev/null
+++ b/Source/WebKit/gtk/webkit/webkitfilechooserrequest.cpp
@@ -0,0 +1,367 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "webkitfilechooserrequest.h"
+
+#include "FileChooser.h"
+#include "FileSystem.h"
+#include "webkitfilechooserrequestprivate.h"
+#include "webkitglobalsprivate.h"
+#include <glib/gi18n-lib.h>
+#include <wtf/gobject/GOwnPtr.h>
+#include <wtf/gobject/GRefPtr.h>
+#include <wtf/text/CString.h>
+
+using namespace WebCore;
+
+/**
+ * SECTION:webkitfilechooserrequest
+ * @Short_description: A request to open a file chooser
+ * @Title: WebKitFileChooserRequest
+ * @See_also: #WebKitWebView
+ *
+ * Whenever the user interacts with an &lt;input type='file' /&gt;
+ * HTML element, WebKit will need to show a dialog to choose one or
+ * more files to be uploaded to the server along with the rest of the
+ * form data. For that to happen in a general way, instead of just
+ * opening a #GtkFileChooserDialog (which might be not desirable in
+ * some cases, such as when an embedding applications prefers to use
+ * its own file chooser dialog), WebKit will fire the
+ * #WebKitWebView::run-file-chooser signal with a
+ * #WebKitFileChooserRequest object, which will allow the client
+ * application to specify the files to be selected, to inspect the
+ * details of the request (e.g. if multiple selection should be
+ * allowed) and to cancel the request, in case nothing was selected.
+ *
+ * In case the client application does not wish to handle this signal,
+ * WebKit will provide a default handler which will asynchronously run
+ * a regular #GtkFileChooserDialog for the user to interact with.
+ */
+G_DEFINE_TYPE(WebKitFileChooserRequest, webkit_file_chooser_request, G_TYPE_OBJECT)
+
+struct _WebKitFileChooserRequestPrivate {
+ RefPtr<FileChooser> chooser;
+ GRefPtr<GtkFileFilter> filter;
+ GRefPtr<GPtrArray> mimeTypes;
+ GRefPtr<GPtrArray> selectedFiles;
+};
+
+enum {
+ PROP_0,
+ PROP_FILTER,
+ PROP_MIME_TYPES,
+ PROP_SELECT_MULTIPLE,
+ PROP_SELECTED_FILES,
+};
+
+static void webkit_file_chooser_request_init(WebKitFileChooserRequest* request)
+{
+ request->priv = G_TYPE_INSTANCE_GET_PRIVATE(request, WEBKIT_TYPE_FILE_CHOOSER_REQUEST, WebKitFileChooserRequestPrivate);
+ new (request->priv) WebKitFileChooserRequestPrivate();
+}
+
+static void webkit_file_chooser_request_finalize(GObject* object)
+{
+ WebKitFileChooserRequest* request = WEBKIT_FILE_CHOOSER_REQUEST(object);
+
+ request->priv->~WebKitFileChooserRequestPrivate();
+ G_OBJECT_CLASS(webkit_file_chooser_request_parent_class)->finalize(object);
+}
+
+static void webkit_file_chooser_request_get_property(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
+{
+ WebKitFileChooserRequest* request = WEBKIT_FILE_CHOOSER_REQUEST(object);
+ switch (propId) {
+ case PROP_FILTER:
+ g_value_set_object(value, webkit_file_chooser_request_get_mime_types_filter(request));
+ break;
+ case PROP_MIME_TYPES:
+ g_value_set_boxed(value, webkit_file_chooser_request_get_mime_types(request));
+ break;
+ case PROP_SELECT_MULTIPLE:
+ g_value_set_boolean(value, webkit_file_chooser_request_get_select_multiple(request));
+ break;
+ case PROP_SELECTED_FILES:
+ g_value_set_boxed(value, webkit_file_chooser_request_get_selected_files(request));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
+ break;
+ }
+}
+
+static void webkit_file_chooser_request_class_init(WebKitFileChooserRequestClass* requestClass)
+{
+ GObjectClass* objectClass = G_OBJECT_CLASS(requestClass);
+ objectClass->finalize = webkit_file_chooser_request_finalize;
+ objectClass->get_property = webkit_file_chooser_request_get_property;
+ g_type_class_add_private(requestClass, sizeof(WebKitFileChooserRequestPrivate));
+
+ /**
+ * WebKitFileChooserRequest:filter:
+ *
+ * The filter currently associated with the request. See
+ * webkit_file_chooser_request_get_mime_types_filter() for more
+ * details.
+ *
+ * Since: 1.10
+ */
+ g_object_class_install_property(objectClass,
+ PROP_FILTER,
+ g_param_spec_object("filter",
+ _("MIME types filter"),
+ _("The filter currently associated with the request"),
+ GTK_TYPE_FILE_FILTER,
+ WEBKIT_PARAM_READABLE));
+ /**
+ * WebKitFileChooserRequest:mime-types:
+ *
+ * A %NULL-terminated array of strings containing the list of MIME
+ * types the file chooser dialog should handle. See
+ * webkit_file_chooser_request_get_mime_types() for more details.
+ *
+ * Since: 1.10
+ */
+ g_object_class_install_property(objectClass,
+ PROP_MIME_TYPES,
+ g_param_spec_boxed("mime-types",
+ _("MIME types"),
+ _("The list of MIME types associated with the request"),
+ G_TYPE_STRV,
+ WEBKIT_PARAM_READABLE)); /**
+ * WebKitFileChooserRequest:select-multiple:
+ *
+ * Whether the file chooser should allow selecting multiple
+ * files. See
+ * webkit_file_chooser_request_get_select_multiple() for
+ * more details.
+ *
+ * Since: 1.10
+ */
+ g_object_class_install_property(objectClass,
+ PROP_SELECT_MULTIPLE,
+ g_param_spec_boolean("select-multiple",
+ _("Select multiple files"),
+ _("Whether the file chooser should allow selecting multiple files"),
+ FALSE,
+ WEBKIT_PARAM_READABLE));
+ /**
+ * WebKitFileChooserRequest:selected-files:
+ *
+ * A %NULL-terminated array of strings containing the list of
+ * selected files associated to the current request. See
+ * webkit_file_chooser_request_get_selected_files() for more details.
+ *
+ * Since: 1.10
+ */
+ g_object_class_install_property(objectClass,
+ PROP_SELECTED_FILES,
+ g_param_spec_boxed("selected-files",
+ _("Selected files"),
+ _("The list of selected files associated with the request"),
+ G_TYPE_STRV,
+ WEBKIT_PARAM_READABLE));
+}
+
+WebKitFileChooserRequest* webkit_file_chooser_request_create(PassRefPtr<FileChooser> chooser)
+{
+ WebKitFileChooserRequest* request = WEBKIT_FILE_CHOOSER_REQUEST(g_object_new(WEBKIT_TYPE_FILE_CHOOSER_REQUEST, NULL));
+ request->priv->chooser = chooser;
+ return request;
+}
+
+/**
+ * webkit_file_chooser_request_get_mime_types:
+ * @request: a #WebKitFileChooserRequest
+ *
+ * Get the list of MIME types the file chooser dialog should handle,
+ * in the format specified in RFC 2046 for "media types". Its contents
+ * depend on the value of the 'accept' attribute for HTML input
+ * elements. This function should normally be called before presenting
+ * the file chooser dialog to the user, to decide whether to allow the
+ * user to select multiple files at once or only one.
+ *
+ * Returns: (array zero-terminated=1) (transfer none): a
+ * %NULL-terminated array of strings if a list of accepted MIME types
+ * is defined or %NULL otherwise, meaning that any MIME type should be
+ * accepted. This array and its contents are owned by WebKitGTK+ and
+ * should not be modified or freed.
+ *
+ * Since: 1.10
+ */
+const gchar* const* webkit_file_chooser_request_get_mime_types(WebKitFileChooserRequest* request)
+{
+ g_return_val_if_fail(WEBKIT_IS_FILE_CHOOSER_REQUEST(request), 0);
+ if (request->priv->mimeTypes)
+ return reinterpret_cast<gchar**>(request->priv->mimeTypes->pdata);
+
+ FileChooserSettings settings = request->priv->chooser->settings();
+ size_t numOfMimeTypes = settings.acceptMIMETypes.size();
+ if (!numOfMimeTypes)
+ return 0;
+
+ request->priv->mimeTypes = adoptGRef(g_ptr_array_new_with_free_func(g_free));
+ for (size_t i = 0; i < numOfMimeTypes; ++i) {
+ String mimeTypeString = settings.acceptMIMETypes[i];
+ if (mimeTypeString.isEmpty())
+ continue;
+ g_ptr_array_add(request->priv->mimeTypes.get(), g_strdup(mimeTypeString.utf8().data()));
+ }
+ g_ptr_array_add(request->priv->mimeTypes.get(), 0);
+
+ return reinterpret_cast<gchar**>(request->priv->mimeTypes->pdata);
+}
+
+/**
+ * webkit_file_chooser_request_get_mime_types_filter:
+ * @request: a #WebKitFileChooserRequest
+ *
+ * Get the filter currently associated with the request, ready to be
+ * used by #GtkFileChooser. This function should normally be called
+ * before presenting the file chooser dialog to the user, to decide
+ * whether to apply a filter so the user would not be allowed to
+ * select files with other MIME types.
+ *
+ * See webkit_file_chooser_request_get_mime_types() if you are
+ * interested in getting the list of accepted MIME types.
+ *
+ * Returns: (transfer none): a #GtkFileFilter if a list of accepted
+ * MIME types is defined or %NULL otherwise. The returned object is
+ * owned by WebKitGTK+ should not be modified or freed.
+ *
+ * Since: 1.10
+ */
+GtkFileFilter* webkit_file_chooser_request_get_mime_types_filter(WebKitFileChooserRequest* request)
+{
+ g_return_val_if_fail(WEBKIT_IS_FILE_CHOOSER_REQUEST(request), 0);
+ if (request->priv->filter)
+ return request->priv->filter.get();
+
+ FileChooserSettings settings = request->priv->chooser->settings();
+ size_t numOfMimeTypes = settings.acceptMIMETypes.size();
+ if (!numOfMimeTypes)
+ return 0;
+
+ // Do not use adoptGRef here, since we want to sink the floating
+ // reference for the new instance of GtkFileFilter, so we make
+ // sure we keep the ownership during the lifetime of the request.
+ request->priv->filter = gtk_file_filter_new();
+ for (size_t i = 0; i < numOfMimeTypes; ++i) {
+ String mimeTypeString = settings.acceptMIMETypes[i];
+ if (mimeTypeString.isEmpty())
+ continue;
+ gtk_file_filter_add_mime_type(request->priv->filter.get(), mimeTypeString.utf8().data());
+ }
+
+ return request->priv->filter.get();
+}
+
+/**
+ * webkit_file_chooser_request_get_select_multiple:
+ * @request: a #WebKitFileChooserRequest
+ *
+ * Determine whether the file chooser associated to this
+ * #WebKitFileChooserRequest should allow selecting multiple files,
+ * which depends on the HTML input element having a 'multiple'
+ * attribute defined.
+ *
+ * Returns: %TRUE if the file chooser should allow selecting multiple files or %FALSE otherwise.
+ *
+ * Since: 1.10
+ */
+gboolean webkit_file_chooser_request_get_select_multiple(WebKitFileChooserRequest* request)
+{
+ g_return_val_if_fail(WEBKIT_IS_FILE_CHOOSER_REQUEST(request), FALSE);
+ return request->priv->chooser->settings().allowsMultipleFiles;
+}
+
+/**
+ * webkit_file_chooser_request_select_files:
+ * @request: a #WebKitFileChooserRequest
+ * @files: (array zero-terminated=1) (transfer none): a
+ * %NULL-terminated array of strings, containing paths to local files.
+ *
+ * Ask WebKit to select local files for upload and complete the
+ * request.
+ *
+ * Since: 1.10
+ */
+void webkit_file_chooser_request_select_files(WebKitFileChooserRequest* request, const gchar* const* files)
+{
+ g_return_if_fail(WEBKIT_IS_FILE_CHOOSER_REQUEST(request));
+ g_return_if_fail(files);
+
+ Vector<String> names;
+ GRefPtr<GPtrArray> selectedFiles = adoptGRef(g_ptr_array_new_with_free_func(g_free));
+
+ for (int i = 0; files[i]; i++) {
+ names.append(filenameToString(files[i]));
+ g_ptr_array_add(selectedFiles.get(), g_strdup(files[i]));
+ }
+
+ g_ptr_array_add(selectedFiles.get(), 0);
+ request->priv->chooser->chooseFiles(names);
+ request->priv->selectedFiles = selectedFiles;
+}
+
+/**
+ * webkit_file_chooser_request_get_selected_files:
+ * @request: a #WebKitFileChooserRequest
+ *
+ * Get the list of selected files currently associated to the
+ * request. Initially, the return value of this method contains any
+ * files selected in previous file chooser requests for this HTML
+ * input element. Once webkit_file_chooser_request_select_files, the
+ * value will reflect whatever files are given.
+ *
+ * This function should normally be called only before presenting the
+ * file chooser dialog to the user, to decide whether to perform some
+ * extra action, like pre-selecting the files from a previous request.
+ *
+ * Returns: (array zero-terminated=1) (transfer none): a
+ * %NULL-terminated array of strings if there are selected files
+ * associated with the request or %NULL otherwise. This array and its
+ * contents are owned by WebKitGTK+ and should not be modified or
+ * freed.
+ *
+ * Since: 1.10
+ */
+const gchar* const* webkit_file_chooser_request_get_selected_files(WebKitFileChooserRequest* request)
+{
+ g_return_val_if_fail(WEBKIT_IS_FILE_CHOOSER_REQUEST(request), 0);
+ if (request->priv->selectedFiles)
+ return reinterpret_cast<gchar**>(request->priv->selectedFiles->pdata);
+
+ FileChooserSettings settings = request->priv->chooser->settings();
+ size_t numOfFiles = settings.selectedFiles.size();
+ if (!numOfFiles)
+ return 0;
+
+ request->priv->selectedFiles = adoptGRef(g_ptr_array_new_with_free_func(g_free));
+ for (size_t i = 0; i < numOfFiles; ++i) {
+ if (settings.selectedFiles[i].isEmpty())
+ continue;
+ CString filename = fileSystemRepresentation(settings.selectedFiles[i]);
+ g_ptr_array_add(request->priv->selectedFiles.get(), g_strdup(filename.data()));
+ }
+ g_ptr_array_add(request->priv->selectedFiles.get(), 0);
+
+ return reinterpret_cast<gchar**>(request->priv->selectedFiles->pdata);
+}
diff --git a/Source/WebKit/gtk/webkit/webkitfilechooserrequest.h b/Source/WebKit/gtk/webkit/webkitfilechooserrequest.h
new file mode 100644
index 000000000..dea94c860
--- /dev/null
+++ b/Source/WebKit/gtk/webkit/webkitfilechooserrequest.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef webkitfilechooserrequest_h
+#define webkitfilechooserrequest_h
+
+#include <gtk/gtk.h>
+#include <webkit/webkitdefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_FILE_CHOOSER_REQUEST (webkit_file_chooser_request_get_type())
+#define WEBKIT_FILE_CHOOSER_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_FILE_CHOOSER_REQUEST, WebKitFileChooserRequest))
+#define WEBKIT_FILE_CHOOSER_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_FILE_CHOOSER_REQUEST, WebKitFileChooserRequestClass))
+#define WEBKIT_IS_FILE_CHOOSER_REQUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_FILE_CHOOSER_REQUEST))
+#define WEBKIT_IS_FILE_CHOOSER_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_FILE_CHOOSER_REQUEST))
+#define WEBKIT_FILE_CHOOSER_REQUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_FILE_CHOOSER_REQUEST, WebKitFileChooserRequestClass))
+
+typedef struct _WebKitFileChooserRequest WebKitFileChooserRequest;
+typedef struct _WebKitFileChooserRequestClass WebKitFileChooserRequestClass;
+typedef struct _WebKitFileChooserRequestPrivate WebKitFileChooserRequestPrivate;
+
+struct _WebKitFileChooserRequest {
+ GObject parent;
+
+ /*< private >*/
+ WebKitFileChooserRequestPrivate *priv;
+};
+
+struct _WebKitFileChooserRequestClass {
+ GObjectClass parent_class;
+};
+
+WEBKIT_API GType
+webkit_file_chooser_request_get_type (void);
+
+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);
+
+G_END_DECLS
+
+#endif
diff --git a/Source/WebKit/gtk/webkit/webkitfilechooserrequestprivate.h b/Source/WebKit/gtk/webkit/webkitfilechooserrequestprivate.h
new file mode 100644
index 000000000..a41cc79f6
--- /dev/null
+++ b/Source/WebKit/gtk/webkit/webkitfilechooserrequestprivate.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef webkitfilechooserrequestprivate_h
+#define webkitfilechooserrequestprivate_h
+
+#include "FileChooser.h"
+#include "webkitfilechooserrequest.h"
+
+using namespace WebCore;
+
+WebKitFileChooserRequest* webkit_file_chooser_request_create(PassRefPtr<FileChooser> chooser);
+
+#endif
diff --git a/Source/WebKit/gtk/webkit/webkitwebview.cpp b/Source/WebKit/gtk/webkit/webkitwebview.cpp
index 00625cdef..aac487f23 100644
--- a/Source/WebKit/gtk/webkit/webkitwebview.cpp
+++ b/Source/WebKit/gtk/webkit/webkitwebview.cpp
@@ -216,6 +216,7 @@ enum {
ENTERING_FULLSCREEN,
LEAVING_FULLSCREEN,
CONTEXT_MENU,
+ RUN_FILE_CHOOSER,
LAST_SIGNAL
};
@@ -1294,6 +1295,48 @@ static gboolean webkit_web_view_real_leaving_fullscreen(WebKitWebView* webView)
return FALSE;
}
+static void fileChooserDialogResponseCallback(GtkDialog* dialog, gint responseID, WebKitFileChooserRequest* request)
+{
+ GRefPtr<WebKitFileChooserRequest> adoptedRequest = adoptGRef(request);
+ if (responseID == GTK_RESPONSE_ACCEPT) {
+ GOwnPtr<GSList> filesList(gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog)));
+ GRefPtr<GPtrArray> filesArray = adoptGRef(g_ptr_array_new());
+ for (GSList* file = filesList.get(); file; file = g_slist_next(file))
+ g_ptr_array_add(filesArray.get(), file->data);
+ g_ptr_array_add(filesArray.get(), 0);
+ webkit_file_chooser_request_select_files(adoptedRequest.get(), reinterpret_cast<const gchar* const*>(filesArray->pdata));
+ }
+
+ gtk_widget_destroy(GTK_WIDGET(dialog));
+}
+
+static gboolean webkitWebViewRealRunFileChooser(WebKitWebView* webView, WebKitFileChooserRequest* request)
+{
+ GtkWidget* toplevel = gtk_widget_get_toplevel(GTK_WIDGET(webView));
+ if (!widgetIsOnscreenToplevelWindow(toplevel))
+ toplevel = 0;
+
+ gboolean allowsMultipleSelection = webkit_file_chooser_request_get_select_multiple(request);
+ GtkWidget* dialog = gtk_file_chooser_dialog_new(allowsMultipleSelection ? _("Select Files") : _("Select File"),
+ toplevel ? GTK_WINDOW(toplevel) : 0,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ if (GtkFileFilter* filter = webkit_file_chooser_request_get_mime_types_filter(request))
+ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
+ gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), allowsMultipleSelection);
+
+ if (const gchar* const* selectedFiles = webkit_file_chooser_request_get_selected_files(request))
+ gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(dialog), selectedFiles[0]);
+
+ g_signal_connect(dialog, "response", G_CALLBACK(fileChooserDialogResponseCallback), g_object_ref(request));
+ gtk_widget_show(dialog);
+
+ return TRUE;
+}
+
static void webkit_web_view_dispose(GObject* object)
{
WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
@@ -2547,6 +2590,42 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
G_TYPE_NONE, 1,
WEBKIT_TYPE_WEB_FRAME);
+ /**
+ * WebKitWebView::run-file-chooser:
+ * @web_view: the #WebKitWebView on which the signal is emitted
+ * @request: a #WebKitFileChooserRequest
+ *
+ * This signal is emitted when the user interacts with a &lt;input
+ * type='file' /&gt; HTML element, requesting from WebKit to show
+ * a dialog to select one or more files to be uploaded. To let the
+ * application know the details of the file chooser, as well as to
+ * allow the client application to either cancel the request or
+ * perform an actual selection of files, the signal will pass an
+ * instance of the #WebKitFileChooserRequest in the @request
+ * argument.
+ *
+ * The default signal handler will asynchronously run a regular
+ * #GtkFileChooserDialog for the user to interact with.
+ *
+ * If this signal is to be handled asynchronously, you must
+ * call g_object_ref() on the @request, and return %TRUE to indicate
+ * that the request is being handled. When you are ready to complete the
+ * request, call webkit_file_chooser_request_select_files().
+ *
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * %FALSE to propagate the event further.
+ *
+ */
+ webkit_web_view_signals[RUN_FILE_CHOOSER] =
+ g_signal_new("run-file-chooser",
+ G_TYPE_FROM_CLASS(webViewClass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(WebKitWebViewClass, run_file_chooser),
+ g_signal_accumulator_true_handled, 0 /* accumulator data */,
+ webkit_marshal_BOOLEAN__OBJECT,
+ G_TYPE_BOOLEAN, 1, /* number of parameters */
+ WEBKIT_TYPE_FILE_CHOOSER_REQUEST);
+
webkit_web_view_signals[SHOULD_BEGIN_EDITING] = g_signal_new("should-begin-editing",
G_TYPE_FROM_CLASS(webViewClass), static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
G_STRUCT_OFFSET(WebKitWebViewClass, should_allow_editing_action), g_signal_accumulator_first_wins, 0,
@@ -2856,6 +2935,7 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
webViewClass->should_allow_editing_action = webkit_web_view_real_should_allow_editing_action;
webViewClass->entering_fullscreen = webkit_web_view_real_entering_fullscreen;
webViewClass->leaving_fullscreen = webkit_web_view_real_leaving_fullscreen;
+ webViewClass->run_file_chooser = webkitWebViewRealRunFileChooser;
GObjectClass* objectClass = G_OBJECT_CLASS(webViewClass);
objectClass->dispose = webkit_web_view_dispose;
@@ -3610,6 +3690,12 @@ GtkWidget* webkit_web_view_new(void)
return GTK_WIDGET(webView);
}
+void webkitWebViewRunFileChooserRequest(WebKitWebView* webView, WebKitFileChooserRequest* request)
+{
+ gboolean returnValue;
+ g_signal_emit(webView, webkit_web_view_signals[RUN_FILE_CHOOSER], 0, request, &returnValue);
+}
+
// for internal use only
void webkit_web_view_notify_ready(WebKitWebView* webView)
{
diff --git a/Source/WebKit/gtk/webkit/webkitwebview.h b/Source/WebKit/gtk/webkit/webkitwebview.h
index dc578d5fa..87c197acf 100644
--- a/Source/WebKit/gtk/webkit/webkitwebview.h
+++ b/Source/WebKit/gtk/webkit/webkitwebview.h
@@ -28,6 +28,7 @@
#include <webkit/webkitdefines.h>
#include <webkit/webkitdom.h>
+#include <webkit/webkitfilechooserrequest.h>
#include <webkit/webkitwebbackforwardlist.h>
#include <webkit/webkitwebframe.h>
#include <webkit/webkitwebhistoryitem.h>
@@ -178,9 +179,8 @@ struct _WebKitWebViewClass {
gboolean (* should_allow_editing_action) (WebKitWebView *web_view);
gboolean (* entering_fullscreen) (WebKitWebView *web_view);
gboolean (* leaving_fullscreen) (WebKitWebView *web_view);
-
- /* Padding for future expansion */
- void (*_webkit_reserved0) (void);
+ gboolean (* run_file_chooser) (WebKitWebView *web_view,
+ WebKitFileChooserRequest *request);
};
WEBKIT_API GType
diff --git a/Source/WebKit/gtk/webkit/webkitwebviewprivate.h b/Source/WebKit/gtk/webkit/webkitwebviewprivate.h
index a0f7fa677..72a8dbc05 100644
--- a/Source/WebKit/gtk/webkit/webkitwebviewprivate.h
+++ b/Source/WebKit/gtk/webkit/webkitwebviewprivate.h
@@ -137,6 +137,8 @@ GtkMenu* webkit_web_view_get_context_menu(WebKitWebView*);
void webViewEnterFullscreen(WebKitWebView* webView, WebCore::Node*);
void webViewExitFullscreen(WebKitWebView* webView);
+void webkitWebViewRunFileChooserRequest(WebKitWebView*, WebKitFileChooserRequest*);
+
#if ENABLE(ICONDATABASE)
void webkitWebViewRegisterForIconNotification(WebKitWebView*, bool shouldRegister);
void webkitWebViewIconLoaded(WebKitFaviconDatabase*, const char* frameURI, WebKitWebView*);