[epiphany/wip/forms: 2/2] web-extension: Save password in memory when handling form events
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/forms: 2/2] web-extension: Save password in memory when handling form events
- Date: Wed, 6 Dec 2017 13:56:50 +0000 (UTC)
commit 0fe4603036669127ad432eac338545c1d857a9ed
Author: Exalm <exalm7659 gmail com>
Date: Sun Nov 5 12:38:27 2017 +0500
web-extension: Save password in memory when handling form events
This allows to remember the password even if a website clears
the password field immediately after submitting.
https://bugzilla.gnome.org/show_bug.cgi?id=742573
embed/web-extension/ephy-embed-form-auth.c | 12 ++++++-
embed/web-extension/ephy-embed-form-auth.h | 4 ++-
embed/web-extension/ephy-web-extension.c | 51 +++++++++++++---------------
3 files changed, 38 insertions(+), 29 deletions(-)
---
diff --git a/embed/web-extension/ephy-embed-form-auth.c b/embed/web-extension/ephy-embed-form-auth.c
index dfd236d..dcd02a4 100644
--- a/embed/web-extension/ephy-embed-form-auth.c
+++ b/embed/web-extension/ephy-embed-form-auth.c
@@ -30,6 +30,7 @@ struct _EphyEmbedFormAuth {
WebKitDOMNode *username_node;
WebKitDOMNode *password_node;
char *username;
+ char *password;
gboolean password_updated;
};
@@ -43,6 +44,7 @@ ephy_embed_form_auth_finalize (GObject *object)
if (form_auth->uri)
soup_uri_free (form_auth->uri);
g_free (form_auth->username);
+ g_free (form_auth->password);
g_free (form_auth->target_origin);
g_clear_object (&form_auth->username_node);
g_clear_object (&form_auth->password_node);
@@ -68,7 +70,8 @@ ephy_embed_form_auth_new (WebKitWebPage *web_page,
const char *target_origin,
WebKitDOMNode *username_node,
WebKitDOMNode *password_node,
- const char *username)
+ const char *username,
+ const char *password)
{
EphyEmbedFormAuth *form_auth;
@@ -82,6 +85,7 @@ ephy_embed_form_auth_new (WebKitWebPage *web_page,
form_auth->username_node = username_node;
form_auth->password_node = password_node;
form_auth->username = g_strdup (username);
+ form_auth->password = g_strdup (password);
return form_auth;
}
@@ -122,6 +126,12 @@ ephy_embed_form_auth_get_username (EphyEmbedFormAuth *form_auth)
return form_auth->username;
}
+const char *
+ephy_embed_form_auth_get_password (EphyEmbedFormAuth *form_auth)
+{
+ return form_auth->password;
+}
+
gboolean
ephy_embed_form_auth_get_password_updated (EphyEmbedFormAuth *form_auth)
{
diff --git a/embed/web-extension/ephy-embed-form-auth.h b/embed/web-extension/ephy-embed-form-auth.h
index c3b7e62..002bd2b 100644
--- a/embed/web-extension/ephy-embed-form-auth.h
+++ b/embed/web-extension/ephy-embed-form-auth.h
@@ -34,13 +34,15 @@ EphyEmbedFormAuth *ephy_embed_form_auth_new (WebKitWebPage
const char *target_origin,
WebKitDOMNode *username_node,
WebKitDOMNode *password_node,
- const char *username);
+ const char *username,
+ const char *password);
WebKitDOMNode *ephy_embed_form_auth_get_username_node (EphyEmbedFormAuth *form_auth);
WebKitDOMNode *ephy_embed_form_auth_get_password_node (EphyEmbedFormAuth *form_auth);
const char *ephy_embed_form_auth_get_target_origin (EphyEmbedFormAuth *form_auth);
SoupURI *ephy_embed_form_auth_get_uri (EphyEmbedFormAuth *form_auth);
guint64 ephy_embed_form_auth_get_page_id (EphyEmbedFormAuth *form_auth);
const char *ephy_embed_form_auth_get_username (EphyEmbedFormAuth *form_auth);
+const char *ephy_embed_form_auth_get_password (EphyEmbedFormAuth *form_auth);
gboolean ephy_embed_form_auth_get_password_updated (EphyEmbedFormAuth *form_auth);
void ephy_embed_form_auth_set_password_updated (EphyEmbedFormAuth *form_auth,
gboolean password_updated);
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index 68b1d5c..925355d 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -276,9 +276,9 @@ store_password (EphyEmbedFormAuth *form_auth)
char *uri_str;
char *origin;
char *username_field_name = NULL;
- char *username_field_value = NULL;
char *password_field_name = NULL;
- char *password_field_value = NULL;
+ const char *username = NULL;
+ const char *password = NULL;
const char *target_origin;
gboolean password_updated;
WebKitDOMNode *username_node;
@@ -287,15 +287,16 @@ store_password (EphyEmbedFormAuth *form_auth)
g_assert (extension->password_manager);
username_node = ephy_embed_form_auth_get_username_node (form_auth);
- if (username_node)
+ if (username_node) {
g_object_get (username_node,
"name", &username_field_name,
- "value", &username_field_value,
NULL);
+ username = ephy_embed_form_auth_get_username (form_auth);
+ }
g_object_get (ephy_embed_form_auth_get_password_node (form_auth),
"name", &password_field_name,
- "value", &password_field_value,
NULL);
+ password = ephy_embed_form_auth_get_password (form_auth);
uri = ephy_embed_form_auth_get_uri (form_auth);
uri_str = soup_uri_to_string (uri, FALSE);
@@ -305,8 +306,8 @@ store_password (EphyEmbedFormAuth *form_auth)
ephy_password_manager_save (extension->password_manager,
origin,
target_origin,
- username_field_value,
- password_field_value,
+ username,
+ password,
username_field_name,
password_field_name,
!password_updated);
@@ -314,9 +315,7 @@ store_password (EphyEmbedFormAuth *form_auth)
g_free (uri_str);
g_free (origin);
g_free (username_field_name);
- g_free (username_field_value);
g_free (password_field_name);
- g_free (password_field_value);
}
static void
@@ -391,7 +390,7 @@ should_store_cb (GList *records,
EphyPermission permission;
SoupURI *uri;
char *uri_string;
- char *password_field_value = NULL;
+ const char *password;
char *origin = NULL;
uri = ephy_embed_form_auth_get_uri (form_auth);
@@ -416,26 +415,20 @@ should_store_cb (GList *records,
if (permission == EPHY_PERMISSION_UNDECIDED && ephy_dot_dir_is_web_application ())
permission = EPHY_PERMISSION_PERMIT;
- g_object_get (ephy_embed_form_auth_get_password_node (form_auth),
- "value", &password_field_value, NULL);
- if (password_field_value == NULL || strlen (password_field_value) == 0)
+ password = ephy_embed_form_auth_get_username (form_auth);
+ if (password == NULL || strlen (password) == 0)
goto out;
if (records && records->data) {
EphyPasswordRecord *record = EPHY_PASSWORD_RECORD (records->data);
- WebKitDOMNode *username_node;
- char *username_field_value = NULL;
- const char *username = ephy_password_record_get_username (record);
- const char *password = ephy_password_record_get_password (record);
-
- username_node = ephy_embed_form_auth_get_username_node (form_auth);
- if (username_node)
- g_object_get (username_node, "value", &username_field_value, NULL);
+ const char *stored_username = ephy_password_record_get_username (record);
+ const char *stored_password = ephy_password_record_get_password (record);
+ const char *username = ephy_embed_form_auth_get_username (form_auth);
/* FIXME: We use only the first result, for now; We need to do
* something smarter here */
- if (g_strcmp0 (username, username_field_value) == 0 &&
- g_strcmp0 (password, password_field_value) == 0) {
+ if (g_strcmp0 (stored_username, username) == 0 &&
+ g_strcmp0 (stored_password, password) == 0) {
LOG ("User/password already stored. Not asking about storing.");
} else if (permission == EPHY_PERMISSION_PERMIT) {
LOG ("User/password not yet stored. Storing.");
@@ -447,7 +440,6 @@ should_store_cb (GList *records,
request_decision_on_storing (g_object_ref (form_auth));
}
- g_free (username_field_value);
} else {
LOG ("No result on query; asking whether we should store.");
ephy_embed_form_auth_set_password_updated (form_auth, FALSE);
@@ -455,8 +447,6 @@ should_store_cb (GList *records,
}
out:
- if (password_field_value)
- g_free (password_field_value);
if (origin != NULL)
g_free (origin);
g_free (uri_string);
@@ -477,6 +467,7 @@ on_form_submitted (WebKitWebPage *web_page,
char *username_field_name = NULL;
char *username_field_value = NULL;
char *password_field_name = NULL;
+ char *password_field_value = NULL;
char *uri_str;
char *origin;
char *form_action;
@@ -495,6 +486,9 @@ on_form_submitted (WebKitWebPage *web_page,
"value", &username_field_value,
NULL);
}
+ g_object_get (password_node,
+ "value", &password_field_value,
+ NULL);
form_action = webkit_dom_html_form_element_get_action (dom_form);
if (form_action == NULL)
@@ -506,7 +500,8 @@ on_form_submitted (WebKitWebPage *web_page,
target_origin,
username_node,
password_node,
- username_field_value);
+ username_field_value,
+ password_field_value);
uri = ephy_embed_form_auth_get_uri (form_auth);
soup_uri_set_query (uri, NULL);
@@ -531,6 +526,7 @@ on_form_submitted (WebKitWebPage *web_page,
g_free (username_field_name);
g_free (username_field_value);
g_free (password_field_name);
+ g_free (password_field_value);
g_free (uri_str);
g_free (origin);
@@ -1210,6 +1206,7 @@ web_page_form_controls_associated (WebKitWebPage *web_page,
target_origin,
username_node,
password_node,
+ NULL,
NULL);
/* Plug in the user autocomplete */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]