25
25
#include " WebFormSubmissionListenerProxy.h"
26
26
#include " WebKitFormSubmissionRequestPrivate.h"
27
27
#include < wtf/glib/GRefPtr.h>
28
+ #include < wtf/glib/GUniquePtr.h>
28
29
#include < wtf/glib/WTFGType.h>
29
30
#include < wtf/text/CString.h>
30
31
@@ -38,15 +39,15 @@ using namespace WebKit;
38
39
* When a form is about to be submitted in a #WebKitWebView, the
39
40
* #WebKitWebView::submit-form signal is emitted. Its request argument
40
41
* contains information about the text fields of the form, that are
41
- * typically used to store login information, returned in a
42
- * #GHashTable by the webkit_form_submission_request_get_text_fields()
43
- * method, and you can finally submit the form with
44
- * webkit_form_submission_request_submit().
45
- *
42
+ * typically used to store login information, returned as lists by
43
+ * webkit_form_submission_request_list_text_fields(). You can submit the
44
+ * form with webkit_form_submission_request_submit().
46
45
*/
47
46
48
47
struct _WebKitFormSubmissionRequestPrivate {
49
48
RefPtr<WebFormSubmissionListenerProxy> listener;
49
+ GRefPtr<GPtrArray> textFieldNames;
50
+ GRefPtr<GPtrArray> textFieldValues;
50
51
GRefPtr<GHashTable> values;
51
52
bool handledRequest;
52
53
};
@@ -74,9 +75,12 @@ WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(const Vector<std:
74
75
{
75
76
WebKitFormSubmissionRequest* request = WEBKIT_FORM_SUBMISSION_REQUEST (g_object_new (WEBKIT_TYPE_FORM_SUBMISSION_REQUEST, nullptr ));
76
77
if (values.size ()) {
77
- request->priv ->values = adoptGRef (g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free));
78
- for (const auto & pair : values)
79
- g_hash_table_insert (request->priv ->values .get (), g_strdup (pair.first .utf8 ().data ()), g_strdup (pair.second .utf8 ().data ()));
78
+ request->priv ->textFieldNames = adoptGRef (g_ptr_array_new_full (values.size (), g_free));
79
+ request->priv ->textFieldValues = adoptGRef (g_ptr_array_new_full (values.size (), g_free));
80
+ for (size_t i = 0 ; i < values.size (); i++) {
81
+ g_ptr_array_add (request->priv ->textFieldNames .get (), g_strdup (values[i].first .utf8 ().data ()));
82
+ g_ptr_array_add (request->priv ->textFieldValues .get (), g_strdup (values[i].second .utf8 ().data ()));
83
+ }
80
84
}
81
85
request->priv ->listener = WTFMove (listener);
82
86
return request;
@@ -87,18 +91,62 @@ WebKitFormSubmissionRequest* webkitFormSubmissionRequestCreate(const Vector<std:
87
91
* @request: a #WebKitFormSubmissionRequest
88
92
*
89
93
* Get a #GHashTable with the values of the text fields contained in the form
90
- * associated to @request.
94
+ * associated to @request. Note that fields will be missing if the form
95
+ * contains multiple text input elements with the same name, so this
96
+ * function does not reliably return all text fields.
97
+ *
98
+ * Returns: (allow-none) (transfer none): a #GHashTable with the form
99
+ * text fields, or %NULL if the form doesn't contain text fields.
91
100
*
92
- * Returns: (transfer none): a #GHashTable with the form text fields, or %NULL if the
93
- * form doesn't contain text fields.
101
+ * Deprecated: 2.20. Use webkit_form_submission_request_list_text_fields() instead.
94
102
*/
95
103
GHashTable* webkit_form_submission_request_get_text_fields (WebKitFormSubmissionRequest* request)
96
104
{
97
105
g_return_val_if_fail (WEBKIT_IS_FORM_SUBMISSION_REQUEST (request), nullptr );
98
106
107
+ if (!request->priv ->values && request->priv ->textFieldNames ->len ) {
108
+ request->priv ->values = adoptGRef (g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free));
109
+ for (unsigned i = 0 ; i < request->priv ->textFieldNames ->len ; i++) {
110
+ GUniquePtr<char > name (g_strdup (static_cast <char *>(request->priv ->textFieldNames ->pdata [i])));
111
+ GUniquePtr<char > value (g_strdup (static_cast <char *>(request->priv ->textFieldValues ->pdata [i])));
112
+ g_hash_table_insert (request->priv ->values .get (), name.release (), value.release ());
113
+ }
114
+ }
115
+
99
116
return request->priv ->values .get ();
100
117
}
101
118
119
+ /* *
120
+ * webkit_form_submission_request_list_text_fields:
121
+ * @request: a #WebKitFormSubmissionRequest
122
+ * @field_names: (out) (optional) (element-type utf8) (transfer none):
123
+ * names of the text fields in the form
124
+ * @field_values: (out) (optional) (element-type utf8) (transfer none):
125
+ * values of the text fields in the form
126
+ *
127
+ * Get lists with the names and values of the text fields contained in
128
+ * the form associated to @request. Note that names and values may be
129
+ * %NULL.
130
+ *
131
+ * If this function returns %FALSE, then both @field_names and
132
+ * @field_values will be empty.
133
+ *
134
+ * Returns: %TRUE if the form contains text fields, or %FALSE otherwise
135
+ *
136
+ * Since: 2.20
137
+ */
138
+ gboolean webkit_form_submission_request_list_text_fields (WebKitFormSubmissionRequest* request, GPtrArray** fieldNames, GPtrArray** fieldValues)
139
+ {
140
+ g_return_val_if_fail (WEBKIT_IS_FORM_SUBMISSION_REQUEST (request), FALSE );
141
+
142
+ if (fieldNames)
143
+ *fieldNames = request->priv ->textFieldNames .get ();
144
+ if (fieldValues)
145
+ *fieldValues = request->priv ->textFieldValues .get ();
146
+
147
+ return !!request->priv ->textFieldNames ->len ;
148
+ }
149
+
102
150
/* *
103
151
* webkit_form_submission_request_submit:
104
152
* @request: a #WebKitFormSubmissionRequest
0 commit comments