[epiphany] password-manager: Handle security origins only (no more URIs)



commit 3960972797cc09fbe3e608f57231d77e040f0566
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date:   Sun Aug 27 00:11:06 2017 +0300

    password-manager: Handle security origins only (no more URIs)
    
    Change the API of EphyPasswordManager to handle security origins only,
    thus clearing possible confusions about whether to call functions with
    URIs or origins. Also fix bad variable naming: "hostname" -> "origin".
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786818

 embed/web-extension/ephy-web-extension.c     |   22 ++++-
 lib/sync/ephy-password-manager.c             |  127 ++++++++++++--------------
 lib/sync/ephy-password-manager.h             |   12 +-
 lib/sync/ephy-password-record.c              |   49 ++++++----
 lib/sync/ephy-password-record.h              |    4 +-
 src/passwords-dialog.c                       |    2 +-
 src/profile-migrator/ephy-profile-migrator.c |   35 ++++----
 7 files changed, 130 insertions(+), 121 deletions(-)
---
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index 753e89f..93be7ad 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -266,6 +266,7 @@ store_password (EphyEmbedFormAuth *form_auth)
 {
   SoupURI *uri;
   char *uri_str;
+  char *origin;
   char *target_origin;
   char *username_field_name = NULL;
   char *username_field_value = NULL;
@@ -290,10 +291,11 @@ store_password (EphyEmbedFormAuth *form_auth)
 
   uri = ephy_embed_form_auth_get_uri (form_auth);
   uri_str = soup_uri_to_string (uri, FALSE);
+  origin = ephy_uri_to_security_origin (uri_str);
   target_origin = ephy_embed_form_auth_get_target_origin (form_auth);
   password_updated = ephy_embed_form_auth_get_password_updated (form_auth);
   ephy_password_manager_save (extension->password_manager,
-                              uri_str,
+                              origin,
                               target_origin,
                               username_field_value,
                               password_field_value,
@@ -302,6 +304,7 @@ store_password (EphyEmbedFormAuth *form_auth)
                               !password_updated);
 
   g_free (uri_str);
+  g_free (origin);
   g_free (target_origin);
   g_free (username_field_name);
   g_free (username_field_value);
@@ -469,6 +472,7 @@ form_submitted_cb (WebKitDOMHTMLFormElement *dom_form,
   char *username_field_value = NULL;
   char *password_field_name = NULL;
   char *uri_str;
+  char *origin;
   char *form_action;
 
   if (!extension->password_manager)
@@ -504,10 +508,11 @@ form_submitted_cb (WebKitDOMHTMLFormElement *dom_form,
     g_object_get (username_node, "name", &username_field_name, NULL);
   g_object_get (password_node, "name", &password_field_name, NULL);
   uri_str = soup_uri_to_string (uri, FALSE);
+  origin = ephy_uri_to_security_origin (uri_str);
 
   ephy_password_manager_query (extension->password_manager,
                                NULL,
-                               uri_str,
+                               origin,
                                target_origin,
                                username_field_value,
                                username_field_name,
@@ -521,6 +526,7 @@ form_submitted_cb (WebKitDOMHTMLFormElement *dom_form,
   g_free (username_field_value);
   g_free (password_field_name);
   g_free (uri_str);
+  g_free (origin);
 
   return TRUE;
 }
@@ -563,6 +569,7 @@ pre_fill_form (EphyEmbedFormAuth *form_auth)
 {
   SoupURI *uri;
   char *uri_str;
+  char *origin;
   char *target_origin;
   char *username = NULL;
   char *username_field_name = NULL;
@@ -579,7 +586,6 @@ pre_fill_form (EphyEmbedFormAuth *form_auth)
   if (!extension->password_manager)
     return;
 
-  uri_str = soup_uri_to_string (uri, FALSE);
   username_node = ephy_embed_form_auth_get_username_node (form_auth);
   if (username_node) {
     g_object_get (username_node, "name", &username_field_name, NULL);
@@ -593,11 +599,13 @@ pre_fill_form (EphyEmbedFormAuth *form_auth)
   if (username != NULL && g_str_equal (username, ""))
     g_clear_pointer (&username, g_free);
 
+  uri_str = soup_uri_to_string (uri, FALSE);
+  origin = ephy_uri_to_security_origin (uri_str);
   target_origin = ephy_embed_form_auth_get_target_origin (form_auth);
 
   ephy_password_manager_query (extension->password_manager,
                                NULL,
-                               uri_str,
+                               origin,
                                target_origin,
                                username,
                                username_field_name,
@@ -606,6 +614,7 @@ pre_fill_form (EphyEmbedFormAuth *form_auth)
                                form_auth);
 
   g_free (uri_str);
+  g_free (origin);
   g_free (target_origin);
   g_free (username);
   g_free (username_field_name);
@@ -1152,6 +1161,7 @@ web_page_form_controls_associated (WebKitWebPage    *web_page,
       EphyEmbedFormAuth *form_auth;
       GList *cached_users;
       const char *uri;
+      char *origin;
       char *form_action;
       char *target_origin;
 
@@ -1180,7 +1190,8 @@ web_page_form_controls_associated (WebKitWebPage    *web_page,
       }
 
       /* Plug in the user autocomplete */
-      cached_users = ephy_password_manager_get_cached_users_for_uri (extension->password_manager, uri);
+      origin = ephy_uri_to_security_origin (uri);
+      cached_users = ephy_password_manager_get_cached_users (extension->password_manager, origin);
 
       if (cached_users && cached_users->next && username_node) {
         LOG ("More than 1 password saved, hooking menu for choosing which on focus");
@@ -1207,6 +1218,7 @@ web_page_form_controls_associated (WebKitWebPage    *web_page,
 
       pre_fill_form (form_auth);
 
+      g_free (origin);
       g_free (form_action);
       g_free (target_origin);
       g_object_weak_ref (G_OBJECT (form), form_destroyed_cb, form_auth);
diff --git a/lib/sync/ephy-password-manager.c b/lib/sync/ephy-password-manager.c
index a025c0e..fa1cd52 100644
--- a/lib/sync/ephy-password-manager.c
+++ b/lib/sync/ephy-password-manager.c
@@ -25,7 +25,6 @@
 #include "ephy-settings.h"
 #include "ephy-sync-utils.h"
 #include "ephy-synchronizable-manager.h"
-#include "ephy-uri-helpers.h"
 
 #include <glib/gi18n.h>
 #include <stdio.h>
@@ -37,7 +36,7 @@ ephy_password_manager_get_password_schema (void)
     "org.epiphany.FormPassword", SECRET_SCHEMA_NONE,
     {
       { ID_KEY, SECRET_SCHEMA_ATTRIBUTE_STRING },
-      { HOSTNAME_KEY, SECRET_SCHEMA_ATTRIBUTE_STRING },
+      { ORIGIN_KEY, SECRET_SCHEMA_ATTRIBUTE_STRING },
       { TARGET_ORIGIN_KEY, SECRET_SCHEMA_ATTRIBUTE_STRING },
       { USERNAME_FIELD_KEY, SECRET_SCHEMA_ATTRIBUTE_STRING },
       { PASSWORD_FIELD_KEY, SECRET_SCHEMA_ATTRIBUTE_STRING },
@@ -184,7 +183,7 @@ replace_record_async_data_free (ReplaceRecordAsyncData *data)
 
 static GHashTable *
 get_attributes_table (const char *id,
-                      const char *uri,
+                      const char *origin,
                       const char *target_origin,
                       const char *username,
                       const char *username_field,
@@ -197,14 +196,14 @@ get_attributes_table (const char *id,
     g_hash_table_insert (attributes,
                          g_strdup (ID_KEY),
                          g_strdup (id));
-  if (uri)
+  if (origin)
     g_hash_table_insert (attributes,
-                         g_strdup (HOSTNAME_KEY),
-                         ephy_uri_to_security_origin (uri));
+                         g_strdup (ORIGIN_KEY),
+                         g_strdup (origin));
   if (target_origin)
     g_hash_table_insert (attributes,
                          g_strdup (TARGET_ORIGIN_KEY),
-                         ephy_uri_to_security_origin (target_origin));
+                         g_strdup (target_origin));
   if (username)
     g_hash_table_insert (attributes,
                          g_strdup (USERNAME_KEY),
@@ -242,7 +241,7 @@ ephy_password_manager_cache_clear (EphyPasswordManager *self)
 
 static void
 ephy_password_manager_cache_remove (EphyPasswordManager *self,
-                                    const char          *hostname,
+                                    const char          *origin,
                                     const char          *username)
 {
   GList *usernames;
@@ -251,23 +250,23 @@ ephy_password_manager_cache_remove (EphyPasswordManager *self,
   g_assert (EPHY_IS_PASSWORD_MANAGER (self));
   g_assert (self->cache);
 
-  if (!hostname || !username)
+  if (!origin || !username)
     return;
 
-  usernames = g_hash_table_lookup (self->cache, hostname);
+  usernames = g_hash_table_lookup (self->cache, origin);
   if (usernames) {
     for (GList *l = usernames; l && l->data; l = l->next) {
       if (g_strcmp0 (username, l->data))
         new_usernames = g_list_prepend (new_usernames, g_strdup (l->data));
     }
-    g_hash_table_replace (self->cache, g_strdup (hostname), new_usernames);
+    g_hash_table_replace (self->cache, g_strdup (origin), new_usernames);
     g_list_free_full (usernames, g_free);
   }
 }
 
 static void
 ephy_password_manager_cache_add (EphyPasswordManager *self,
-                                 const char          *hostname,
+                                 const char          *origin,
                                  const char          *username)
 {
   GList *usernames;
@@ -275,16 +274,16 @@ ephy_password_manager_cache_add (EphyPasswordManager *self,
   g_assert (EPHY_IS_PASSWORD_MANAGER (self));
   g_assert (self->cache);
 
-  if (!hostname || !username)
+  if (!origin || !username)
     return;
 
-  usernames = g_hash_table_lookup (self->cache, hostname);
+  usernames = g_hash_table_lookup (self->cache, origin);
   for (GList *l = usernames; l && l->data; l = l->next) {
     if (!g_strcmp0 (username, l->data))
       return;
   }
   usernames = g_list_prepend (usernames, g_strdup (username));
-  g_hash_table_replace (self->cache, g_strdup (hostname), usernames);
+  g_hash_table_replace (self->cache, g_strdup (origin), usernames);
 }
 
 static void
@@ -295,10 +294,10 @@ populate_cache_cb (GList    *records,
 
   for (GList *l = records; l && l->data; l = l->next) {
     EphyPasswordRecord *record = EPHY_PASSWORD_RECORD (l->data);
-    const char *hostname = ephy_password_record_get_hostname (record);
+    const char *origin = ephy_password_record_get_origin (record);
     const char *username = ephy_password_record_get_username (record);
 
-    ephy_password_manager_cache_add (self, hostname, username);
+    ephy_password_manager_cache_add (self, origin, username);
   }
 
   g_list_free_full (records, g_object_unref);
@@ -341,20 +340,13 @@ ephy_password_manager_new (void)
 }
 
 GList *
-ephy_password_manager_get_cached_users_for_uri (EphyPasswordManager *self,
-                                                const char          *uri)
+ephy_password_manager_get_cached_users (EphyPasswordManager *self,
+                                        const char          *origin)
 {
-  GList *list;
-  char *hostname;
-
   g_return_val_if_fail (EPHY_IS_PASSWORD_MANAGER (self), NULL);
-  g_return_val_if_fail (uri, NULL);
-
-  hostname = ephy_uri_to_security_origin (uri);
-  list = g_hash_table_lookup (self->cache, hostname);
-  g_free (hostname);
+  g_return_val_if_fail (origin, NULL);
 
-  return list;
+  return g_hash_table_lookup (self->cache, origin);
 }
 
 static void
@@ -381,7 +373,7 @@ store_internal (const char          *password,
 {
   SecretValue *value;
   GTask *task;
-  const char *hostname;
+  const char *origin;
   const char *username;
   char *label;
 
@@ -390,22 +382,22 @@ store_internal (const char          *password,
 
   task = g_task_new (NULL, NULL, callback, user_data);
   value = secret_value_new (password, -1, "text/plain");
-  hostname = g_hash_table_lookup (attributes, HOSTNAME_KEY);
+  origin = g_hash_table_lookup (attributes, ORIGIN_KEY);
   username = g_hash_table_lookup (attributes, USERNAME_KEY);
 
   if (username) {
     /* Translators: The first %s is the username and the second one is the
      * security origin where this is happening. Example: gnome gmail com and
      * https://mail.google.com. */
-    label = g_strdup_printf (_("Password for %s in a form in %s"), username, hostname);
+    label = g_strdup_printf (_("Password for %s in a form in %s"), username, origin);
   } else {
     /* Translators: The %s is the security origin where this is happening.
      * Example: https://mail.google.com. */
-    label = g_strdup_printf (_("Password in a form in %s"), hostname);
+    label = g_strdup_printf (_("Password in a form in %s"), origin);
   }
 
   LOG ("Storing password record for (%s, %s, %s, %s)",
-       hostname, username,
+       origin, username,
        (char *)g_hash_table_lookup (attributes, USERNAME_FIELD_KEY),
        (char *)g_hash_table_lookup (attributes, PASSWORD_FIELD_KEY));
 
@@ -424,16 +416,16 @@ ephy_password_manager_store_record (EphyPasswordManager *self,
                                     EphyPasswordRecord  *record)
 {
   GHashTable *attributes;
-  const char *hostname;
+  const char *origin;
   const char *username;
 
   g_assert (EPHY_IS_PASSWORD_MANAGER (self));
   g_assert (EPHY_IS_PASSWORD_RECORD (record));
 
-  hostname = ephy_password_record_get_hostname (record);
+  origin = ephy_password_record_get_origin (record);
   username = ephy_password_record_get_username (record);
   attributes = get_attributes_table (ephy_password_record_get_id (record),
-                                     hostname,
+                                     origin,
                                      ephy_password_record_get_target_origin (record),
                                      username,
                                      ephy_password_record_get_username_field (record),
@@ -441,7 +433,7 @@ ephy_password_manager_store_record (EphyPasswordManager *self,
                                      ephy_synchronizable_get_server_time_modified (EPHY_SYNCHRONIZABLE 
(record)));
   store_internal (ephy_password_record_get_password (record), attributes, NULL, NULL);
 
-  ephy_password_manager_cache_add (self, hostname, username);
+  ephy_password_manager_cache_add (self, origin, username);
 
   g_hash_table_unref (attributes);
 }
@@ -467,7 +459,7 @@ update_password_cb (GList    *records,
 
 void
 ephy_password_manager_save (EphyPasswordManager *self,
-                            const char          *uri,
+                            const char          *origin,
                             const char          *target_origin,
                             const char          *username,
                             const char          *password,
@@ -476,13 +468,12 @@ ephy_password_manager_save (EphyPasswordManager *self,
                             gboolean             is_new)
 {
   EphyPasswordRecord *record;
-  char *hostname;
   char *uuid;
   char *id;
   gint64 timestamp;
 
   g_return_if_fail (EPHY_IS_PASSWORD_MANAGER (self));
-  g_return_if_fail (uri);
+  g_return_if_fail (origin);
   g_return_if_fail (target_origin);
   g_return_if_fail (password);
   g_return_if_fail (!username_field || username);
@@ -490,9 +481,9 @@ ephy_password_manager_save (EphyPasswordManager *self,
 
   if (!is_new) {
     LOG ("Updating password for (%s, %s, %s, %s, %s)",
-         uri, target_origin, username, username_field, password_field);
+         origin, target_origin, username, username_field, password_field);
     ephy_password_manager_query (self, NULL,
-                                 uri, target_origin, username,
+                                 origin, target_origin, username,
                                  username_field, password_field,
                                  update_password_cb,
                                  update_password_async_data_new (self, password));
@@ -502,15 +493,13 @@ ephy_password_manager_save (EphyPasswordManager *self,
   uuid = g_uuid_string_random ();
   id = g_strdup_printf ("{%s}", uuid);
   timestamp = g_get_real_time () / 1000;
-  hostname = ephy_uri_to_security_origin (uri);
-  record = ephy_password_record_new (id, hostname, target_origin,
+  record = ephy_password_record_new (id, origin, target_origin,
                                      username, password,
                                      username_field, password_field,
                                      timestamp, timestamp);
   ephy_password_manager_store_record (self, record);
   g_signal_emit_by_name (self, "synchronizable-modified", record, FALSE);
 
-  g_free (hostname);
   g_free (uuid);
   g_free (id);
   g_object_unref (record);
@@ -537,7 +526,7 @@ secret_service_search_cb (SecretService  *service,
     GHashTable *attributes = secret_item_get_attributes (item);
     SecretValue *value = secret_item_get_secret (item);
     const char *id = g_hash_table_lookup (attributes, ID_KEY);
-    const char *hostname = g_hash_table_lookup (attributes, HOSTNAME_KEY);
+    const char *origin = g_hash_table_lookup (attributes, ORIGIN_KEY);
     const char *target_origin = g_hash_table_lookup (attributes, TARGET_ORIGIN_KEY);
     const char *username = g_hash_table_lookup (attributes, USERNAME_KEY);
     const char *username_field = g_hash_table_lookup (attributes, USERNAME_FIELD_KEY);
@@ -548,14 +537,14 @@ secret_service_search_cb (SecretService  *service,
     EphyPasswordRecord *record;
 
     LOG ("Found password record for (%s, %s, %s, %s, %s)",
-         hostname, target_origin, username, username_field, password_field);
+         origin, target_origin, username, username_field, password_field);
 
-    if (!id || !hostname || !target_origin || !password_field || !timestamp) {
+    if (!id || !origin || !target_origin || !password_field || !timestamp) {
       LOG ("Password record is corrupted, skipping it...");
       goto next;
     }
 
-    record = ephy_password_record_new (id, hostname, target_origin,
+    record = ephy_password_record_new (id, origin, target_origin,
                                        username, password,
                                        username_field, password_field,
                                        secret_item_get_created (item) * 1000,
@@ -580,7 +569,7 @@ out:
 void
 ephy_password_manager_query (EphyPasswordManager              *self,
                              const char                       *id,
-                             const char                       *uri,
+                             const char                       *origin,
                              const char                       *target_origin,
                              const char                       *username,
                              const char                       *username_field,
@@ -594,9 +583,9 @@ ephy_password_manager_query (EphyPasswordManager              *self,
   g_return_if_fail (EPHY_IS_PASSWORD_MANAGER (self));
 
   LOG ("Querying password records for (%s, %s, %s, %s)",
-       uri, username, username_field, password_field);
+       origin, username, username_field, password_field);
 
-  attributes = get_attributes_table (id, uri, target_origin, username,
+  attributes = get_attributes_table (id, origin, target_origin, username,
                                      username_field, password_field, -1);
   data = query_async_data_new (callback, user_data);
 
@@ -612,7 +601,7 @@ ephy_password_manager_query (EphyPasswordManager              *self,
 }
 
 void
-ephy_password_manager_store_raw (const char          *uri,
+ephy_password_manager_store_raw (const char          *origin,
                                  const char          *username,
                                  const char          *password,
                                  const char          *username_field,
@@ -622,12 +611,12 @@ ephy_password_manager_store_raw (const char          *uri,
 {
   GHashTable *attributes;
 
-  g_return_if_fail (uri);
+  g_return_if_fail (origin);
   g_return_if_fail (password);
   g_return_if_fail (!username_field || username);
   g_return_if_fail (!password_field || password);
 
-  attributes = get_attributes_table (NULL, uri, uri, username,
+  attributes = get_attributes_table (NULL, origin, origin, username,
                                      username_field, password_field, -1);
   store_internal (password, attributes, callback, user_data);
 
@@ -676,7 +665,7 @@ ephy_password_manager_forget_record (EphyPasswordManager *self,
   g_assert (EPHY_IS_PASSWORD_RECORD (record));
 
   attributes = get_attributes_table (ephy_password_record_get_id (record),
-                                     ephy_password_record_get_hostname (record),
+                                     ephy_password_record_get_origin (record),
                                      ephy_password_record_get_target_origin (record),
                                      ephy_password_record_get_username (record),
                                      ephy_password_record_get_username_field (record),
@@ -684,7 +673,7 @@ ephy_password_manager_forget_record (EphyPasswordManager *self,
                                      -1);
 
   LOG ("Forgetting password record for (%s, %s, %s, %s, %s)",
-       ephy_password_record_get_hostname (record),
+       ephy_password_record_get_origin (record),
        ephy_password_record_get_target_origin (record),
        ephy_password_record_get_username (record),
        ephy_password_record_get_username_field (record),
@@ -695,7 +684,7 @@ ephy_password_manager_forget_record (EphyPasswordManager *self,
                         replacement ? replace_record_async_data_new (self, replacement) : NULL);
 
   ephy_password_manager_cache_remove (self,
-                                      ephy_password_record_get_hostname (record),
+                                      ephy_password_record_get_origin (record),
                                       ephy_password_record_get_username (record));
   g_hash_table_unref (attributes);
 }
@@ -876,7 +865,7 @@ get_record_by_id (GList      *records,
 
 static EphyPasswordRecord *
 get_record_by_parameters (GList      *records,
-                          const char *hostname,
+                          const char *origin,
                           const char *target_origin,
                           const char *username,
                           const char *username_field,
@@ -884,7 +873,7 @@ get_record_by_parameters (GList      *records,
 {
   for (GList *l = records; l && l->data; l = l->next) {
     if (!g_strcmp0 (ephy_password_record_get_username (l->data), username) &&
-        !g_strcmp0 (ephy_password_record_get_hostname (l->data), hostname) &&
+        !g_strcmp0 (ephy_password_record_get_origin (l->data), origin) &&
         !g_strcmp0 (ephy_password_record_get_target_origin (l->data), target_origin) &&
         !g_strcmp0 (ephy_password_record_get_username_field (l->data), username_field) &&
         !g_strcmp0 (ephy_password_record_get_password_field (l->data), password_field))
@@ -918,7 +907,7 @@ ephy_password_manager_handle_initial_merge (EphyPasswordManager *self,
   GHashTable *dont_upload;
   GList *to_upload = NULL;
   const char *remote_id;
-  const char *remote_hostname;
+  const char *remote_origin;
   const char *remote_target_origin;
   const char *remote_username;
   const char *remote_password;
@@ -932,7 +921,7 @@ ephy_password_manager_handle_initial_merge (EphyPasswordManager *self,
   g_assert (EPHY_IS_PASSWORD_MANAGER (self));
 
   /* A saved password record is uniquely identified by its ID or by its tuple
-   * of (hostname, username, username field, password field). When importing
+   * of (origin, username, username field, password field). When importing
    * password records from server, we may encounter duplicates either by ID
    * or by mentioned tuple. We start from the assumption that same ID means
    * same tuple but same tuple does not necessarily mean same ID. This is what
@@ -942,7 +931,7 @@ ephy_password_manager_handle_initial_merge (EphyPasswordManager *self,
 
   for (GList *l = remote_records; l && l->data; l = l->next) {
     remote_id = ephy_password_record_get_id (l->data);
-    remote_hostname = ephy_password_record_get_hostname (l->data);
+    remote_origin = ephy_password_record_get_origin (l->data);
     remote_target_origin = ephy_password_record_get_target_origin (l->data);
     remote_username = ephy_password_record_get_username (l->data);
     remote_password = ephy_password_record_get_password (l->data);
@@ -976,7 +965,7 @@ ephy_password_manager_handle_initial_merge (EphyPasswordManager *self,
       }
     } else {
       record = get_record_by_parameters (local_records,
-                                         remote_hostname,
+                                         remote_origin,
                                          remote_target_origin,
                                          remote_username,
                                          remote_username_field,
@@ -994,8 +983,8 @@ ephy_password_manager_handle_initial_merge (EphyPasswordManager *self,
         }
       } else {
         record = get_record_by_parameters (local_records,
-                                           remote_hostname,
-                                           remote_hostname,
+                                           remote_origin,
+                                           remote_origin,
                                            remote_username,
                                            remote_username_field,
                                            remote_password_field);
@@ -1034,7 +1023,7 @@ ephy_password_manager_handle_regular_merge (EphyPasswordManager  *self,
   EphyPasswordRecord *record;
   GList *to_upload = NULL;
   const char *remote_id;
-  const char *remote_hostname;
+  const char *remote_origin;
   const char *remote_target_origin;
   const char *remote_username;
   const char *remote_username_field;
@@ -1056,7 +1045,7 @@ ephy_password_manager_handle_regular_merge (EphyPasswordManager  *self,
   /* See comment in ephy_password_manager_handle_initial_merge. */
   for (GList *l = updated_records; l && l->data; l = l->next) {
     remote_id = ephy_password_record_get_id (l->data);
-    remote_hostname = ephy_password_record_get_hostname (l->data);
+    remote_origin = ephy_password_record_get_origin (l->data);
     remote_target_origin = ephy_password_record_get_target_origin (l->data);
     remote_username = ephy_password_record_get_username (l->data);
     remote_username_field = ephy_password_record_get_username_field (l->data);
@@ -1069,7 +1058,7 @@ ephy_password_manager_handle_regular_merge (EphyPasswordManager  *self,
       ephy_password_manager_forget_record (self, record, l->data);
     } else {
       record = get_record_by_parameters (*local_records,
-                                         remote_hostname,
+                                         remote_origin,
                                          remote_target_origin,
                                          remote_username,
                                          remote_username_field,
diff --git a/lib/sync/ephy-password-manager.h b/lib/sync/ephy-password-manager.h
index 598350a..b6fe346 100644
--- a/lib/sync/ephy-password-manager.h
+++ b/lib/sync/ephy-password-manager.h
@@ -30,7 +30,7 @@ G_BEGIN_DECLS
 const SecretSchema *ephy_password_manager_get_password_schema (void) G_GNUC_CONST;
 
 #define ID_KEY                    "id"
-#define HOSTNAME_KEY              "uri"
+#define ORIGIN_KEY                "uri" /* TODO: Rename to "origin". Requires migration. */
 #define TARGET_ORIGIN_KEY         "target_origin"
 #define USERNAME_FIELD_KEY        "form_username"
 #define PASSWORD_FIELD_KEY        "form_password"
@@ -46,10 +46,10 @@ G_DECLARE_FINAL_TYPE (EphyPasswordManager, ephy_password_manager, EPHY, PASSWORD
 typedef void (*EphyPasswordManagerQueryCallback) (GList *records, gpointer user_data);
 
 EphyPasswordManager *ephy_password_manager_new                      (void);
-GList               *ephy_password_manager_get_cached_users_for_uri (EphyPasswordManager *self,
-                                                                     const char          *uri);
+GList               *ephy_password_manager_get_cached_users         (EphyPasswordManager *self,
+                                                                     const char          *origin);
 void                 ephy_password_manager_save                     (EphyPasswordManager *self,
-                                                                     const char          *uri,
+                                                                     const char          *origin,
                                                                      const char          *target_origin,
                                                                      const char          *username,
                                                                      const char          *password,
@@ -58,7 +58,7 @@ void                 ephy_password_manager_save                     (EphyPasswor
                                                                      gboolean             is_new);
 void                 ephy_password_manager_query                    (EphyPasswordManager              *self,
                                                                      const char                       *id,
-                                                                     const char                       *uri,
+                                                                     const char                       
*origin,
                                                                      const char                       
*target_origin,
                                                                      const char                       
*username,
                                                                      const char                       
*username_field,
@@ -70,7 +70,7 @@ void                 ephy_password_manager_forget                    (EphyPasswo
 void                 ephy_password_manager_forget_all                (EphyPasswordManager *self);
 /* Note: Below functions are deprecated and should not be used in newly written code.
  * The only reason they still exist is that the profile migrator expects them. */
-void                 ephy_password_manager_store_raw                 (const char          *uri,
+void                 ephy_password_manager_store_raw                 (const char          *origin,
                                                                       const char          *username,
                                                                       const char          *password,
                                                                       const char          *username_field,
diff --git a/lib/sync/ephy-password-record.c b/lib/sync/ephy-password-record.c
index 21b94ff..4c7e731 100644
--- a/lib/sync/ephy-password-record.c
+++ b/lib/sync/ephy-password-record.c
@@ -27,7 +27,7 @@ struct _EphyPasswordRecord {
   GObject parent_instance;
 
   char    *id;
-  char    *hostname;
+  char    *origin;
   char    *target_origin;
   char    *username;
   char    *password;
@@ -51,7 +51,7 @@ G_DEFINE_TYPE_WITH_CODE (EphyPasswordRecord, ephy_password_record, G_TYPE_OBJECT
 enum {
   PROP_0,
   PROP_ID,                    /* Firefox Sync */
-  PROP_HOSTNAME,              /* Epiphany && Firefox Sync */
+  PROP_ORIGIN,                /* Epiphany && Firefox Sync */
   PROP_TARGET_ORIGIN,         /* Epiphany && Firefox Sync */
   PROP_USERNAME,              /* Epiphany && Firefox Sync */
   PROP_PASSWORD,              /* Epiphany && Firefox Sync */
@@ -77,9 +77,9 @@ ephy_password_record_set_property (GObject      *object,
       g_free (self->id);
       self->id = g_strdup (g_value_get_string (value));
       break;
-    case PROP_HOSTNAME:
-      g_free (self->hostname);
-      self->hostname = g_strdup (g_value_get_string (value));
+    case PROP_ORIGIN:
+      g_free (self->origin);
+      self->origin = g_strdup (g_value_get_string (value));
       break;
     case PROP_TARGET_ORIGIN:
       g_free (self->target_origin);
@@ -124,8 +124,8 @@ ephy_password_record_get_property (GObject    *object,
     case PROP_ID:
       g_value_set_string (value, self->id);
       break;
-    case PROP_HOSTNAME:
-      g_value_set_string (value, self->hostname);
+    case PROP_ORIGIN:
+      g_value_set_string (value, self->origin);
       break;
     case PROP_TARGET_ORIGIN:
       g_value_set_string (value, self->target_origin);
@@ -159,7 +159,7 @@ ephy_password_record_finalize (GObject *object)
   EphyPasswordRecord *self = EPHY_PASSWORD_RECORD (object);
 
   g_free (self->id);
-  g_free (self->hostname);
+  g_free (self->origin);
   g_free (self->target_origin);
   g_free (self->username);
   g_free (self->password);
@@ -179,27 +179,34 @@ ephy_password_record_class_init (EphyPasswordRecordClass *klass)
   object_class->finalize = ephy_password_record_finalize;
 
   /* The property names must match Firefox password object structure, see
-   * https://mozilla-services.readthedocs.io/en/latest/sync/objectformats.html#passwords */
+   * https://mozilla-services.readthedocs.io/en/latest/sync/objectformats.html#passwords
+   */
   obj_properties[PROP_ID] =
     g_param_spec_string ("id",
                          "Id",
                          "Id of the password record",
                          "Default id",
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
-  obj_properties[PROP_HOSTNAME] =
+  /* Origin matches hostname field from Firefox.
+   * Despite its name, it's actually a security origin (scheme + host + port), so call it appropriately, see
+   * 
https://dxr.mozilla.org/mozilla-central/rev/892c8916ba32b7733e06bfbfdd4083ffae3ca028/toolkit/components/passwordmgr/LoginManagerContent.jsm#922
+   * 
https://dxr.mozilla.org/mozilla-central/rev/892c8916ba32b7733e06bfbfdd4083ffae3ca028/toolkit/components/passwordmgr/LoginManagerContent.jsm#1380
+   */
+  obj_properties[PROP_ORIGIN] =
     g_param_spec_string ("hostname",
-                         "Hostname",
-                         "Hostname url that password is applicable at",
-                         "Default hostname",
+                         "Security origin",
+                         "Security origin of the URI that password is applicable at",
+                         "Default security origin",
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
   /* Target origin matches formSubmitURL field from Firefox.
-   * Despite its name, it's actually an origin, so call it appropriately, see
-   * 
https://dxr.mozilla.org/mozilla-central/rev/892c8916ba32b7733e06bfbfdd4083ffae3ca028/toolkit/components/passwordmgr/LoginManagerContent.jsm#928
 */
+   * Despite its name, it's actually a security origin, so call it appropriately, see
+   * 
https://dxr.mozilla.org/mozilla-central/rev/892c8916ba32b7733e06bfbfdd4083ffae3ca028/toolkit/components/passwordmgr/LoginManagerContent.jsm#928
+   */
   obj_properties[PROP_TARGET_ORIGIN] =
     g_param_spec_string ("formSubmitURL",
                          "Target origin",
-                         "The target origin of the URI where that password is applicable at",
-                         "Default target origin URI",
+                         "The target origin of the URI that password is applicable at",
+                         "Default target origin",
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
   obj_properties[PROP_USERNAME] =
     g_param_spec_string ("username",
@@ -252,7 +259,7 @@ ephy_password_record_init (EphyPasswordRecord *self)
 
 EphyPasswordRecord *
 ephy_password_record_new (const char *id,
-                          const char *hostname,
+                          const char *origin,
                           const char *target_origin,
                           const char *username,
                           const char *password,
@@ -263,7 +270,7 @@ ephy_password_record_new (const char *id,
 {
   return EPHY_PASSWORD_RECORD (g_object_new (EPHY_TYPE_PASSWORD_RECORD,
                                              "id", id,
-                                             "hostname", hostname,
+                                             "hostname", origin,
                                              "formSubmitURL", target_origin,
                                              "username", username,
                                              "password", password,
@@ -283,11 +290,11 @@ ephy_password_record_get_id (EphyPasswordRecord *self)
 }
 
 const char *
-ephy_password_record_get_hostname (EphyPasswordRecord *self)
+ephy_password_record_get_origin (EphyPasswordRecord *self)
 {
   g_return_val_if_fail (EPHY_IS_PASSWORD_RECORD (self), NULL);
 
-  return self->hostname;
+  return self->origin;
 }
 
 const char *
diff --git a/lib/sync/ephy-password-record.h b/lib/sync/ephy-password-record.h
index 3364359..548fe07 100644
--- a/lib/sync/ephy-password-record.h
+++ b/lib/sync/ephy-password-record.h
@@ -29,7 +29,7 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (EphyPasswordRecord, ephy_password_record, EPHY, PASSWORD_RECORD, GObject)
 
 EphyPasswordRecord *ephy_password_record_new                        (const char *id,
-                                                                     const char *hostname,
+                                                                     const char *origin,
                                                                      const char *target_origin,
                                                                      const char *username,
                                                                      const char *password,
@@ -38,7 +38,7 @@ EphyPasswordRecord *ephy_password_record_new                        (const char
                                                                      guint64     time_created,
                                                                      guint64     time_password_changed);
 const char         *ephy_password_record_get_id                     (EphyPasswordRecord *self);
-const char         *ephy_password_record_get_hostname               (EphyPasswordRecord *self);
+const char         *ephy_password_record_get_origin                 (EphyPasswordRecord *self);
 const char         *ephy_password_record_get_target_origin          (EphyPasswordRecord *self);
 const char         *ephy_password_record_get_username               (EphyPasswordRecord *self);
 const char         *ephy_password_record_get_password               (EphyPasswordRecord *self);
diff --git a/src/passwords-dialog.c b/src/passwords-dialog.c
index 9d7cf8a..a6cc4a1 100644
--- a/src/passwords-dialog.c
+++ b/src/passwords-dialog.c
@@ -416,7 +416,7 @@ populate_model_cb (GList    *records,
     gtk_list_store_insert_with_values (GTK_LIST_STORE (dialog->liststore),
                                        &iter,
                                        -1,
-                                       COL_PASSWORDS_ORIGIN, ephy_password_record_get_hostname (record),
+                                       COL_PASSWORDS_ORIGIN, ephy_password_record_get_origin (record),
                                        COL_PASSWORDS_USER, ephy_password_record_get_username (record),
                                        COL_PASSWORDS_PASSWORD, ephy_password_record_get_password (record),
                                        COL_PASSWORDS_INVISIBLE, "●●●●●●●●",
diff --git a/src/profile-migrator/ephy-profile-migrator.c b/src/profile-migrator/ephy-profile-migrator.c
index d7fa4f0..a408d6a 100644
--- a/src/profile-migrator/ephy-profile-migrator.c
+++ b/src/profile-migrator/ephy-profile-migrator.c
@@ -313,7 +313,7 @@ load_collection_items_cb (SecretCollection *collection,
   GList *l;
   GHashTable *attributes, *t;
   const char *server, *username, *username_field, *password_field, *password;
-  char *actual_server;
+  char *origin;
   SoupURI *uri;
   GError *error = NULL;
   GList *items;
@@ -344,18 +344,18 @@ load_collection_items_cb (SecretCollection *collection,
       username_field = g_hash_table_lookup (t, USERNAME_FIELD_KEY);
       password_field = g_hash_table_lookup (t, PASSWORD_FIELD_KEY);
       soup_uri_set_query (uri, NULL);
-      actual_server = soup_uri_to_string (uri, FALSE);
+      origin = soup_uri_to_string (uri, FALSE);
       secret_item_load_secret_sync (item, NULL, NULL);
       secret = secret_item_get_secret (item);
       password = secret_value_get (secret, NULL);
-      ephy_password_manager_store_raw (actual_server,
+      ephy_password_manager_store_raw (origin,
                                        username,
                                        password,
                                        username_field,
                                        password_field,
                                        (GAsyncReadyCallback)store_form_auth_data_cb,
                                        g_hash_table_ref (attributes));
-      g_free (actual_server);
+      g_free (origin);
       secret_value_unref (secret);
       g_hash_table_unref (t);
       soup_uri_free (uri);
@@ -443,7 +443,7 @@ migrate_insecure_password (SecretItem *item)
   const char *original_uri;
 
   attributes = secret_item_get_attributes (item);
-  original_uri = g_hash_table_lookup (attributes, HOSTNAME_KEY);
+  original_uri = g_hash_table_lookup (attributes, ORIGIN_KEY);
   original_origin = webkit_security_origin_new_for_uri (original_uri);
   if (original_origin == NULL) {
     g_warning ("Failed to convert URI %s to a security origin, insecure password will not be migrated", 
original_uri);
@@ -462,7 +462,7 @@ migrate_insecure_password (SecretItem *item)
     new_uri = webkit_security_origin_to_string (new_origin);
     webkit_security_origin_unref (new_origin);
 
-    g_hash_table_replace (attributes, g_strdup (HOSTNAME_KEY), new_uri);
+    g_hash_table_replace (attributes, g_strdup (ORIGIN_KEY), new_uri);
     secret_item_set_attributes_sync (item, EPHY_FORM_PASSWORD_SCHEMA, attributes, NULL, &error);
     if (error != NULL) {
       g_warning ("Failed to convert URI %s to https://, insecure password will not be migrated: %s", 
original_uri, error->message);
@@ -1037,7 +1037,7 @@ migrate_passwords_to_firefox_sync_passwords (void)
     SecretItem *item = (SecretItem *)l->data;
     SecretValue *value = secret_item_get_secret (item);
     GHashTable *attrs = secret_item_get_attributes (item);
-    const char *hostname = g_hash_table_lookup (attrs, HOSTNAME_KEY);
+    const char *origin = g_hash_table_lookup (attrs, ORIGIN_KEY);
     const char *username = g_hash_table_lookup (attrs, USERNAME_KEY);
     char *uuid = g_uuid_string_random ();
     char *label;
@@ -1046,9 +1046,9 @@ migrate_passwords_to_firefox_sync_passwords (void)
     g_hash_table_insert (attrs, g_strdup (SERVER_TIME_MODIFIED_KEY), g_strdup ("0"));
 
     if (username)
-      label = g_strdup_printf ("Password for %s in a form in %s", username, hostname);
+      label = g_strdup_printf ("Password for %s in a form in %s", username, origin);
     else
-      label = g_strdup_printf ("Password in a form in %s", hostname);
+      label = g_strdup_printf ("Password in a form in %s", origin);
     secret_service_store_sync (NULL, EPHY_FORM_PASSWORD_SCHEMA,
                                attrs, NULL, label,
                                value, NULL, &error);
@@ -1135,7 +1135,7 @@ migrate_passwords_add_target_origin (void)
   /* Similar to Firefox Sync and the insecure passwords migrations.
    * This is also a migration that runs once, and not for each profile
    * Adds target_origin field to all existing records,
-   * with the same value as hostname
+   * with the same value as origin.
    */
   default_profile_migration_version = ephy_profile_utils_get_migration_version_for_profile_dir 
(ephy_default_dot_dir ());
   if (default_profile_migration_version >= EPHY_TARGET_ORIGIN_MIGRATION_VERSION)
@@ -1161,21 +1161,22 @@ migrate_passwords_add_target_origin (void)
     SecretItem *item = (SecretItem *)l->data;
     SecretValue *value = secret_item_get_secret (item);
     GHashTable *attrs = secret_item_get_attributes (item);
-    const char *hostname = g_hash_table_lookup (attrs, HOSTNAME_KEY);
+    const char *origin = g_hash_table_lookup (attrs, ORIGIN_KEY);
     const char *username = g_hash_table_lookup (attrs, USERNAME_KEY);
     const char *target_origin = g_hash_table_lookup (attrs, TARGET_ORIGIN_KEY);
     char *label;
 
-    // In most cases target_origin has the same value as hostname
-    // We don't have a way of figuring out the correct value retroactively,
-    // so just use the hostname value
+    /* In most cases target_origin has the same value as origin
+     * We don't have a way of figuring out the correct value retroactively,
+     * so just use the origin value.
+    */
     if (target_origin == NULL)
-      g_hash_table_insert (attrs, g_strdup (TARGET_ORIGIN_KEY), g_strdup (hostname));
+      g_hash_table_insert (attrs, g_strdup (TARGET_ORIGIN_KEY), g_strdup (origin));
 
     if (username)
-      label = g_strdup_printf ("Password for %s in a form in %s", username, hostname);
+      label = g_strdup_printf ("Password for %s in a form in %s", username, origin);
     else
-      label = g_strdup_printf ("Password in a form in %s", hostname);
+      label = g_strdup_printf ("Password in a form in %s", origin);
     secret_service_store_sync (NULL, EPHY_FORM_PASSWORD_SCHEMA,
                                attrs, NULL, label,
                                value, NULL, &error);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]