1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  *  Copyright © 2017 Gabriel Ivascu <gabrielivascu@gnome.org>
4  *
5  *  This file is part of Epiphany.
6  *
7  *  Epiphany is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  Epiphany is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with Epiphany.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #pragma once
22 
23 #include "ephy-password-record.h"
24 
25 #include <glib-object.h>
26 #include <jsc/jsc.h>
27 #include <libsecret/secret.h>
28 
29 G_BEGIN_DECLS
30 
31 const SecretSchema *ephy_password_manager_get_password_schema (void) G_GNUC_CONST;
32 
33 #define ID_KEY                    "id"
34 #define ORIGIN_KEY                "uri" /* TODO: Rename to "origin". Requires migration. */
35 #define TARGET_ORIGIN_KEY         "target_origin"
36 #define USERNAME_FIELD_KEY        "form_username"
37 #define PASSWORD_FIELD_KEY        "form_password"
38 #define USERNAME_KEY              "username"
39 #define SERVER_TIME_MODIFIED_KEY  "server_time_modified"
40 
41 #define EPHY_FORM_PASSWORD_SCHEMA ephy_password_manager_get_password_schema ()
42 
43 #define EPHY_TYPE_PASSWORD_MANAGER (ephy_password_manager_get_type ())
44 
45 G_DECLARE_FINAL_TYPE (EphyPasswordManager, ephy_password_manager, EPHY, PASSWORD_MANAGER, GObject)
46 
47 typedef void (*EphyPasswordManagerQueryCallback) (GList *records, gpointer user_data);
48 
49 EphyPasswordManager *ephy_password_manager_new                      (void);
50 GList               *ephy_password_manager_get_usernames_for_origin (EphyPasswordManager *self,
51                                                                      const char          *origin);
52 void                 ephy_password_manager_save                     (EphyPasswordManager *self,
53                                                                      const char          *origin,
54                                                                      const char          *target_origin,
55                                                                      const char          *username,
56                                                                      const char          *password,
57                                                                      const char          *username_field,
58                                                                      const char          *password_field,
59                                                                      gboolean             is_new);
60 void                 ephy_password_manager_query                    (EphyPasswordManager              *self,
61                                                                      const char                       *id,
62                                                                      const char                       *origin,
63                                                                      const char                       *target_origin,
64                                                                      const char                       *username,
65                                                                      const char                       *username_field,
66                                                                      const char                       *password_field,
67                                                                      EphyPasswordManagerQueryCallback  callback,
68                                                                      gpointer                          user_data);
69 gboolean             ephy_password_manager_find                     (EphyPasswordManager              *self,
70                                                                      const char                       *origin,
71                                                                      const char                       *target_origin,
72                                                                      const char                       *username,
73                                                                      const char                       *username_field,
74                                                                      const char                       *password_field);
75 void                 ephy_password_manager_forget                    (EphyPasswordManager *self,
76                                                                       const char          *id,
77                                                                       GCancellable        *cancellable,
78                                                                       GAsyncReadyCallback  callback,
79                                                                       gpointer             user_data);
80 gboolean             ephy_password_manager_forget_finish             (EphyPasswordManager  *self,
81                                                                       GAsyncResult         *result,
82                                                                       GError              **error);
83 void                 ephy_password_manager_forget_all                (EphyPasswordManager *self);
84 void                 ephy_password_manager_export_to_js_context      (EphyPasswordManager *self,
85                                                                       JSCContext          *js_context,
86                                                                       JSCValue            *js_namespace);
87 
88 G_END_DECLS
89