aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2013-03-09 20:04:02 +0800
committerCarlos Garcia Campos <carlosgc@gnome.org>2013-03-12 17:01:29 +0800
commit78b70aa84bb94f5097d40ffbb461aefcbbaeb979 (patch)
tree244512bedc4d496536ba5b0b1cee0048872edc3d /lib
parentcc3fa5ae4c8edac523c3800fbebff37b5eac33bf (diff)
downloadgsoc2013-epiphany-78b70aa84bb94f5097d40ffbb461aefcbbaeb979.tar
gsoc2013-epiphany-78b70aa84bb94f5097d40ffbb461aefcbbaeb979.tar.gz
gsoc2013-epiphany-78b70aa84bb94f5097d40ffbb461aefcbbaeb979.tar.bz2
gsoc2013-epiphany-78b70aa84bb94f5097d40ffbb461aefcbbaeb979.tar.lz
gsoc2013-epiphany-78b70aa84bb94f5097d40ffbb461aefcbbaeb979.tar.xz
gsoc2013-epiphany-78b70aa84bb94f5097d40ffbb461aefcbbaeb979.tar.zst
gsoc2013-epiphany-78b70aa84bb94f5097d40ffbb461aefcbbaeb979.zip
Move find_username_and_password_elements to ephy-web-dom-utils
Renamed as ephy_web_dom_utils_find_form_auth_elements(). Also fixed possible memory leaks in case of multiple auth input fields found. It now returns a boolean indicating whther form auth elements were found.
Diffstat (limited to 'lib')
-rw-r--r--lib/ephy-web-dom-utils.c72
-rw-r--r--lib/ephy-web-dom-utils.h11
2 files changed, 71 insertions, 12 deletions
diff --git a/lib/ephy-web-dom-utils.c b/lib/ephy-web-dom-utils.c
index 375a7be60..1224c5621 100644
--- a/lib/ephy-web-dom-utils.c
+++ b/lib/ephy-web-dom-utils.c
@@ -23,12 +23,6 @@
#include "ephy-web-dom-utils.h"
#include <libsoup/soup.h>
-#ifdef HAVE_WEBKIT2
-#include <webkit2/webkit2.h>
-#include <webkit2/webkit-web-extension.h>
-#else
-#include <webkit/webkit.h>
-#endif
/**
* ephy_web_dom_utils_has_modified_forms:
@@ -354,3 +348,69 @@ ephy_web_dom_utils_get_best_icon (WebKitDOMDocument *document,
return ret;
}
+
+gboolean
+ephy_web_dom_utils_find_form_auth_elements (WebKitDOMHTMLFormElement *form,
+ WebKitDOMNode **username,
+ WebKitDOMNode **password)
+{
+ WebKitDOMHTMLCollection *elements;
+ WebKitDOMNode *username_node = NULL;
+ WebKitDOMNode *password_node = NULL;
+ guint i, n_elements;
+ gboolean found_auth_elements = FALSE;
+
+ elements = webkit_dom_html_form_element_get_elements (form);
+ n_elements = webkit_dom_html_collection_get_length (elements);
+
+ for (i = 0; i < n_elements; i++) {
+ WebKitDOMNode *element;
+ char *element_type;
+
+ element = webkit_dom_html_collection_item (elements, i);
+ if (!WEBKIT_DOM_IS_HTML_INPUT_ELEMENT (element))
+ continue;
+
+ g_object_get (element, "type", &element_type, NULL);
+
+ if (g_str_equal (element_type, "text") || g_str_equal (element_type, "email")) {
+ /* We found more than one inputs of type text; we won't be saving here. */
+ if (username_node) {
+ g_free (element_type);
+ found_auth_elements = FALSE;
+ break;
+ }
+
+ username_node = g_object_ref (element);
+ found_auth_elements = TRUE;
+ } else if (g_str_equal (element_type, "password")) {
+ /* We found more than one inputs of type password; we won't be saving here. */
+ if (password_node) {
+ g_free (element_type);
+ found_auth_elements = FALSE;
+ break;
+ }
+
+ password_node = g_object_ref (element);
+ found_auth_elements = TRUE;
+ }
+
+ g_free (element_type);
+ }
+
+ g_object_unref(elements);
+
+ if (found_auth_elements && username_node && password_node) {
+ *username = username_node;
+ *password = password_node;
+
+ return TRUE;
+ }
+
+ if (username_node)
+ g_object_unref (username_node);
+ if (password_node)
+ g_object_unref (password_node);
+
+ return FALSE;
+}
diff --git a/lib/ephy-web-dom-utils.h b/lib/ephy-web-dom-utils.h
index a998d4a17..aa052d26e 100644
--- a/lib/ephy-web-dom-utils.h
+++ b/lib/ephy-web-dom-utils.h
@@ -24,12 +24,7 @@
#ifndef EPHY_WEB_DOM_UTILS_H
#define EPHY_WEB_DOM_UTILS_H
-#ifdef HAVE_WEBKIT2
-#include <webkit2/webkit2.h>
-#include <webkit2/webkit-web-extension.h>
-#else
-#include <webkit/webkit.h>
-#endif
+#include <webkitdom/webkitdom.h>
G_BEGIN_DECLS
@@ -42,6 +37,10 @@ gboolean ephy_web_dom_utils_get_best_icon (WebKitDOMDocument *document,
char **uri_out,
char **color_out);
+gboolean ephy_web_dom_utils_find_form_auth_elements (WebKitDOMHTMLFormElement *form,
+ WebKitDOMNode **username,
+ WebKitDOMNode **password);
+
G_END_DECLS
#endif