~noskcaj/ubuntu/wily/epiphany-browser/merge

« back to all changes in this revision

Viewing changes to src/pdm-dialog.c

  • Committer: Package Import Robot
  • Author(s): Gustavo Noronha Silva
  • Date: 2013-03-20 20:45:41 UTC
  • mto: (120.1.2 experimental) (1.10.1) (105.1.14 sid)
  • mto: This revision was merged to the branch mainline in revision 121.
  • Revision ID: package-import@ubuntu.com-20130320204541-0t2adqjzvpflkni2
Tags: upstream-3.7.91
Import upstream version 3.7.91

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *  Copyright © 2002 Jorn Baayen
4
4
 *  Copyright © 2003 Marco Pesenti Gritti
5
5
 *  Copyright © 2003, 2004 Christian Persch
6
 
 *  Copyright © 2009 Igalia S.L.
 
6
 *  Copyright © 2009-2013 Igalia S.L.
7
7
 *  Copyright © 2009 Holger Hans Peter Freyther
8
8
 *
9
9
 *  This program is free software; you can redistribute it and/or modify
28
28
#include "ephy-shell.h"
29
29
#include "ephy-file-helpers.h"
30
30
#include "ephy-gui.h"
31
 
#include "ephy-state.h"
32
31
#include "ephy-string.h"
33
32
#include "ephy-debug.h"
34
33
#include "ephy-time-helpers.h"
35
34
#include "ephy-embed-single.h"
36
35
#include "ephy-history-service.h"
37
 
#include "ephy-password-info.h"
38
36
 
39
37
#include <gtk/gtk.h>
40
38
#include <glib/gi18n.h>
 
39
#define SECRET_API_SUBJECT_TO_CHANGE
 
40
#include <libsecret/secret.h>
41
41
#include <libsoup/soup.h>
42
42
#ifdef HAVE_WEBKIT2
43
43
#include <webkit2/webkit2.h>
44
44
#else
45
45
#include <webkit/webkit.h>
46
46
#endif
47
 
#include <gnome-keyring.h>
48
 
#include <gnome-keyring-memory.h>
49
47
 
50
48
#include <string.h>
51
49
#include <time.h>
171
169
 
172
170
#ifdef HAVE_WEBKIT2
173
171
static WebKitCookieManager *
174
 
get_cookie_manager ()
 
172
get_cookie_manager (void)
175
173
{
176
174
        WebKitWebContext *web_context;
177
175
 
180
178
}
181
179
#else
182
180
static SoupCookieJar*
183
 
get_cookie_jar ()
 
181
get_cookie_jar (void)
184
182
{
185
183
        SoupSession* session;
186
184
 
210
208
#endif
211
209
 
212
210
static void
213
 
get_info_full_cb (GnomeKeyringResult result,
214
 
                  GnomeKeyringItemInfo *info,
215
 
                  gpointer data)
216
 
{
217
 
        if (result != GNOME_KEYRING_RESULT_OK)
218
 
                return;
219
 
 
220
 
        if (gnome_keyring_item_info_get_type (info) == GNOME_KEYRING_ITEM_NETWORK_PASSWORD)
221
 
                gnome_keyring_item_delete (GNOME_KEYRING_DEFAULT,
222
 
                                           GPOINTER_TO_UINT (data),
223
 
                                           NULL, NULL, NULL);
224
 
}
225
 
 
226
 
static void
227
 
got_network_passwords_list_cb (GnomeKeyringResult result,
228
 
                               GList *list,
229
 
                               gpointer data)
230
 
{
231
 
        GList *l;
232
 
 
233
 
        if (result != GNOME_KEYRING_RESULT_OK)
234
 
                return;
235
 
 
236
 
        for (l = list; l != NULL; l = l->next)
237
 
                gnome_keyring_item_get_info_full (GNOME_KEYRING_DEFAULT,
238
 
                                                  GPOINTER_TO_UINT (l->data),
239
 
                                                  GNOME_KEYRING_ITEM_INFO_BASICS,
240
 
                                                  (GnomeKeyringOperationGetItemInfoCallback) get_info_full_cb,
241
 
                                                  l->data,
242
 
                                                  NULL);
243
 
}
244
 
 
245
 
static void
246
 
_ephy_pdm_delete_all_passwords ()
247
 
{
248
 
        gnome_keyring_list_item_ids (GNOME_KEYRING_DEFAULT,
249
 
                                     got_network_passwords_list_cb,
250
 
                                     NULL, NULL);
 
211
_ephy_pdm_delete_all_passwords (void)
 
212
{
 
213
        GHashTable *attributes;
 
214
 
 
215
        attributes = secret_attributes_build (SECRET_SCHEMA_COMPAT_NETWORK, NULL);
 
216
        secret_service_clear (NULL, SECRET_SCHEMA_COMPAT_NETWORK,
 
217
                              attributes, NULL,
 
218
                              (GAsyncReadyCallback)secret_service_clear_finish,
 
219
                              NULL);
 
220
        g_hash_table_unref (attributes);
251
221
}
252
222
 
253
223
static void
307
277
                {
308
278
                        EphyEmbedShell *shell;
309
279
                        EphyEmbedSingle *single;
 
280
                        WebKitFaviconDatabase *database;
310
281
 
311
282
                        shell = ephy_embed_shell_get_default ();
312
283
 
315
286
                        ephy_embed_single_clear_cache (single);
316
287
 
317
288
#ifdef HAVE_WEBKIT2
318
 
                        /* TODO: Favicons */
 
289
                        database = webkit_web_context_get_favicon_database (webkit_web_context_get_default ());
319
290
#else
320
 
                        webkit_favicon_database_clear (webkit_get_favicon_database ());
 
291
                        database = webkit_get_favicon_database ();
321
292
#endif
 
293
                        webkit_favicon_database_clear (database);
322
294
                }
323
295
        }
324
296
        gtk_widget_destroy (GTK_WIDGET (dialog));
550
522
#ifdef HAVE_WEBKIT2
551
523
                action->remove (action, g_value_get_string (&val));
552
524
#else
553
 
                action->remove (action, g_value_get_boxed (&val));
 
525
                action->remove (action, G_VALUE_HOLDS_OBJECT (&val) ? g_value_get_object (&val) : g_value_get_boxed (&val));
554
526
#endif
555
527
                g_value_unset (&val);
556
528
 
1190
1162
 
1191
1163
/* "Passwords" tab */
1192
1164
static void
1193
 
passwords_data_func_get_item_cb (GnomeKeyringResult result,
1194
 
                                 GnomeKeyringItemInfo *info,
 
1165
passwords_data_func_get_item_cb (SecretItem *item,
 
1166
                                 GAsyncResult *result,
1195
1167
                                 gpointer data)
1196
1168
{
 
1169
        GtkTreeIter iter;
 
1170
        GtkTreePath *path;
 
1171
        GtkTreeModel *model;
 
1172
        GError *error = NULL;
1197
1173
        GtkTreeRowReference *rowref = (GtkTreeRowReference *)data;
1198
1174
 
1199
 
        if (result == GNOME_KEYRING_RESULT_OK) {
1200
 
                GtkTreeIter iter;
1201
 
                GtkTreePath *path;
1202
 
                GtkTreeModel *model;
1203
 
 
1204
 
                if (!gtk_tree_row_reference_valid (rowref))
1205
 
                        return;
1206
 
 
1207
 
                path = gtk_tree_row_reference_get_path (rowref);
1208
 
                model = gtk_tree_row_reference_get_model (rowref);
1209
 
 
1210
 
                if (path != NULL && gtk_tree_model_get_iter (model, &iter, path)) {
1211
 
                        EphyPasswordInfo *epinfo;
1212
 
                        GValue val = {0, };
1213
 
 
1214
 
                        gtk_tree_model_get_value (model, &iter, COL_PASSWORDS_DATA, &val);
1215
 
                        epinfo = g_value_get_boxed (&val);
1216
 
                        epinfo->secret = gnome_keyring_memory_strdup (gnome_keyring_item_info_get_secret (info));
1217
 
 
1218
 
                        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1219
 
                                            COL_PASSWORDS_DATA, epinfo,
1220
 
                                            COL_PASSWORDS_PASSWORD, epinfo->secret, -1);
1221
 
                        g_value_unset (&val);
1222
 
                }
 
1175
        secret_item_load_secret_finish (item, result, &error);
 
1176
        if (error) {
 
1177
                g_warning ("Couldn't load password for site: %s", error->message);
 
1178
                g_error_free (error);
 
1179
                return;
 
1180
        }
 
1181
 
 
1182
        if (!gtk_tree_row_reference_valid (rowref))
 
1183
                return;
 
1184
 
 
1185
        path = gtk_tree_row_reference_get_path (rowref);
 
1186
        model = gtk_tree_row_reference_get_model (rowref);
 
1187
 
 
1188
        if (path != NULL && gtk_tree_model_get_iter (model, &iter, path)) {
 
1189
                SecretValue *secret = secret_item_get_secret (item);
 
1190
                gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 
1191
                                    COL_PASSWORDS_PASSWORD, secret_value_get (secret, NULL),
 
1192
                                    -1);
1223
1193
        }
1224
1194
}
1225
1195
 
1227
1197
passwords_data_func (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
1228
1198
                     GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
1229
1199
{
1230
 
        GValue val = { 0, };
1231
 
        EphyPasswordInfo *info;
 
1200
        SecretItem *item;
 
1201
        SecretValue *value;
1232
1202
 
1233
1203
        if (!gtk_tree_view_column_get_visible (tree_column))
1234
1204
                return;
1235
1205
 
1236
 
        gtk_tree_model_get_value (model, iter, COL_PASSWORDS_DATA, &val);
1237
 
        info = g_value_get_boxed (&val);
 
1206
        gtk_tree_model_get (model, iter, COL_PASSWORDS_DATA, &item, -1);
 
1207
        value = secret_item_get_secret (item);
1238
1208
 
1239
 
        if (info->secret == NULL) {
 
1209
        /* Value has not been loaded yet, do now. */
 
1210
        if (!value) {
1240
1211
                GtkTreePath *path;
1241
1212
                GtkTreeRowReference *rowref;
1242
1213
 
1243
1214
                path = gtk_tree_model_get_path (model, iter);
1244
1215
                rowref = gtk_tree_row_reference_new (model, path);
1245
1216
 
1246
 
                gnome_keyring_item_get_info_full (GNOME_KEYRING_DEFAULT,
1247
 
                                                  info->keyring_id,
1248
 
                                                  GNOME_KEYRING_ITEM_INFO_SECRET,
1249
 
                                                  (GnomeKeyringOperationGetItemInfoCallback) passwords_data_func_get_item_cb,
1250
 
                                                  rowref,
1251
 
                                                  (GDestroyNotify) gtk_tree_row_reference_free);
1252
 
                gtk_tree_path_free (path);
1253
 
        }
1254
 
        g_value_unset (&val);
 
1217
                secret_item_load_secret (item, NULL,
 
1218
                                         (GAsyncReadyCallback)passwords_data_func_get_item_cb,
 
1219
                                         rowref);
 
1220
        } else
 
1221
                secret_value_unref (value);
1255
1222
}
1256
1223
 
1257
1224
static void
1324
1291
                                        G_TYPE_STRING,
1325
1292
                                        G_TYPE_STRING,
1326
1293
                                        G_TYPE_STRING,
1327
 
                                        EPHY_TYPE_PASSWORD_INFO);
 
1294
                                        SECRET_TYPE_ITEM);
1328
1295
 
1329
1296
        gtk_tree_view_set_model (treeview, GTK_TREE_MODEL(liststore));
1330
1297
        gtk_tree_view_set_headers_visible (treeview, TRUE);
1390
1357
}
1391
1358
 
1392
1359
static void
1393
 
pdm_dialog_fill_passwords_list_async_cb (GnomeKeyringResult result,
1394
 
                                         GList *list,
 
1360
pdm_dialog_fill_passwords_list_async_cb (SecretService *service,
 
1361
                                         GAsyncResult *result,
1395
1362
                                         gpointer data)
1396
1363
{
1397
 
        GList *l;
 
1364
        GList *list, *l;
 
1365
        GError *error = NULL;
1398
1366
        PdmActionInfo *info = (PdmActionInfo *)data;
1399
1367
 
1400
 
        if (result != GNOME_KEYRING_RESULT_OK)
 
1368
        list = secret_service_search_finish (service, result, &error);
 
1369
        if (error) {
 
1370
                g_warning ("Couldn't fetch the network passwords: %s",
 
1371
                           error->message);
 
1372
                g_error_free (error);
1401
1373
                return;
 
1374
        }
1402
1375
 
1403
1376
        for (l = list; l != NULL; l = l->next)
1404
1377
                info->add (info, l->data);
1405
1378
 
 
1379
        /* Items are stored in the model, no need to free them. */
 
1380
        g_list_free (list);
 
1381
 
1406
1382
        info->filled = TRUE;
1407
1383
        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (info->model),
1408
1384
                                              COL_PASSWORDS_HOST,
1412
1388
static void
1413
1389
pdm_dialog_fill_passwords_list (PdmActionInfo *info)
1414
1390
{
1415
 
        gnome_keyring_list_item_ids (GNOME_KEYRING_DEFAULT,
1416
 
                                     pdm_dialog_fill_passwords_list_async_cb,
1417
 
                                     info,
1418
 
                                     NULL);
 
1391
        GHashTable *attributes;
 
1392
        attributes = secret_attributes_build (SECRET_SCHEMA_COMPAT_NETWORK, NULL);
 
1393
        secret_service_search (NULL, SECRET_SCHEMA_COMPAT_NETWORK,
 
1394
                               attributes,
 
1395
                               SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK,
 
1396
                               NULL, (GAsyncReadyCallback)pdm_dialog_fill_passwords_list_async_cb,
 
1397
                               info);
1419
1398
}
1420
1399
 
1421
1400
static void
1433
1412
}
1434
1413
 
1435
1414
static void
1436
 
pdm_dialog_password_add_item_attrs_cb (GnomeKeyringResult result,
1437
 
                                       GnomeKeyringAttributeList *attributes,
1438
 
                                       gpointer data)
 
1415
pdm_dialog_password_add (PdmActionInfo *info,
 
1416
                         gpointer data)
1439
1417
{
1440
 
        EphyPasswordInfo *pinfo;
1441
 
        PdmCallBackData *cbdata;
1442
 
        GnomeKeyringAttribute *attribute;
 
1418
        SecretItem *item  = (SecretItem*)data;
 
1419
        GtkTreeIter iter;
1443
1420
        gchar *user, *host, *protocol;
1444
 
        GtkTreeIter iter;
1445
 
        int i;
1446
 
 
1447
 
        if (result != GNOME_KEYRING_RESULT_OK)
1448
 
                return;
1449
 
 
1450
 
        cbdata = (PdmCallBackData *)data;
1451
 
 
1452
 
        user = host = protocol = NULL;
1453
 
        attribute = (GnomeKeyringAttribute *) attributes->data;
1454
 
        for (i = 0; i < attributes->len; ++i) {
1455
 
                if (attribute[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
1456
 
                        if (strcmp (attribute[i].name, "server") == 0)
1457
 
                                host = g_strdup (attribute[i].value.string);
1458
 
                        else if (strcmp (attribute[i].name, "user") == 0)
1459
 
                                user = g_strdup (attribute[i].value.string);
1460
 
                        else if (strcmp (attribute[i].name, "protocol") == 0)
1461
 
                                protocol = attribute[i].value.string;
1462
 
                        }
1463
 
                }
 
1421
        GHashTable *attributes;
 
1422
 
 
1423
        attributes = secret_item_get_attributes (item);
 
1424
 
 
1425
        protocol = g_hash_table_lookup (attributes, "protocol");
1464
1426
        if (!protocol || strncmp("http", protocol, 4) != 0)
1465
1427
                return;
1466
1428
 
1467
 
        pinfo = ephy_password_info_new (cbdata->key);
1468
 
        if (!pinfo)
1469
 
                return;
 
1429
        user = g_hash_table_lookup (attributes, "user");
 
1430
        host = g_hash_table_lookup (attributes, "server");
1470
1431
 
1471
 
        gtk_list_store_append (cbdata->store, &iter);
1472
 
        gtk_list_store_set (cbdata->store, &iter,
 
1432
        gtk_list_store_append (GTK_LIST_STORE (info->model), &iter);
 
1433
        gtk_list_store_set (GTK_LIST_STORE (info->model), &iter,
1473
1434
                            COL_PASSWORDS_HOST, host,
1474
1435
                            COL_PASSWORDS_USER, user,
1475
1436
                            COL_PASSWORDS_PASSWORD, NULL,
1476
 
                            COL_PASSWORDS_DATA, pinfo,
 
1437
                            COL_PASSWORDS_DATA, item,
1477
1438
                            -1);
1478
 
}
1479
 
 
1480
 
static void
1481
 
pdm_dialog_password_add_item_info_cb (GnomeKeyringResult result,
1482
 
                                      GnomeKeyringItemInfo *info,
1483
 
                                      gpointer data)
1484
 
{
1485
 
        if (result != GNOME_KEYRING_RESULT_OK)
1486
 
                return;
1487
 
 
1488
 
        if (gnome_keyring_item_info_get_type (info) == GNOME_KEYRING_ITEM_NETWORK_PASSWORD) {
1489
 
                PdmCallBackData *cbdata = (PdmCallBackData *)data;
1490
 
                gnome_keyring_item_get_attributes (GNOME_KEYRING_DEFAULT,
1491
 
                                                   cbdata->key,
1492
 
                                                   (GnomeKeyringOperationGetAttributesCallback) pdm_dialog_password_add_item_attrs_cb,
1493
 
                                                   g_memdup (cbdata, sizeof (PdmCallBackData)),
1494
 
                                                   (GDestroyNotify) g_free);
1495
 
 
1496
 
        }
1497
 
 
1498
 
}
1499
 
 
1500
 
static void
1501
 
pdm_dialog_password_add (PdmActionInfo *info,
1502
 
                         gpointer data)
1503
 
{
1504
 
        PdmCallBackData *cbdata;
1505
 
        guint key_id = GPOINTER_TO_UINT(data);
1506
 
 
1507
 
        /*
1508
 
         * We have the item id of the password. We will have to check if this
1509
 
         * password entry is of the right type and then can proceed to get the
1510
 
         * the private information. Seahorse is treating every protocol that
1511
 
         * starts with http as Web Access and we will do the same here.
1512
 
         */
1513
 
 
1514
 
        cbdata = g_malloc (sizeof (PdmCallBackData));
1515
 
        cbdata->key = key_id;
1516
 
        cbdata->store = GTK_LIST_STORE (info->model);
1517
 
 
1518
 
        /* Get the type of the key_id */
1519
 
        gnome_keyring_item_get_info_full (GNOME_KEYRING_DEFAULT,
1520
 
                                          key_id,
1521
 
                                          GNOME_KEYRING_ITEM_INFO_BASICS,
1522
 
                                          (GnomeKeyringOperationGetItemInfoCallback) pdm_dialog_password_add_item_info_cb,
1523
 
                                          cbdata,
1524
 
                                          (GDestroyNotify) g_free);
1525
 
}
1526
 
 
1527
 
static void
1528
 
pdm_dialog_password_remove_dummy_cb (GnomeKeyringResult result,
1529
 
                                     gpointer data)
1530
 
{
 
1439
 
 
1440
        g_hash_table_unref (attributes);
1531
1441
}
1532
1442
 
1533
1443
static void
1534
1444
pdm_dialog_password_remove (PdmActionInfo *info,
1535
1445
                            gpointer data)
1536
1446
{
1537
 
        EphyPasswordInfo *pinfo = (EphyPasswordInfo *) data;
 
1447
        SecretItem *item = SECRET_ITEM (data);
1538
1448
 
1539
 
        gnome_keyring_item_delete (GNOME_KEYRING_DEFAULT,
1540
 
                                   pinfo->keyring_id,
1541
 
                                   (GnomeKeyringOperationDoneCallback) pdm_dialog_password_remove_dummy_cb,
1542
 
                                   NULL,
1543
 
                                   NULL);
 
1449
        /* We don't really do anything when the item is deleted, so
 
1450
           just directly call finish(). The method signature fits well
 
1451
           for this. */
 
1452
        secret_item_delete (item, NULL,
 
1453
                            (GAsyncReadyCallback)secret_item_delete_finish, NULL);
1544
1454
}
1545
1455
 
1546
1456
/* common routines */
1608
1518
        PdmDialogPrivate *priv;
1609
1519
        PdmActionInfo *cookies, *passwords;
1610
1520
        GtkWidget *window;
1611
 
        gboolean has_private_profile = 
1612
 
                ephy_embed_shell_get_mode (embed_shell) == EPHY_EMBED_SHELL_MODE_PRIVATE;
1613
 
 
 
1521
        gboolean has_private_profile =
 
1522
                EPHY_EMBED_SHELL_MODE_HAS_PRIVATE_PROFILE (ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()));
1614
1523
 
1615
1524
        priv = dialog->priv = EPHY_PDM_DIALOG_GET_PRIVATE (dialog);
1616
1525
 
1688
1597
        PdmDialog *dialog = EPHY_PDM_DIALOG (object);
1689
1598
        GObject *single;
1690
1599
 
1691
 
        single = ephy_embed_shell_get_embed_single (embed_shell);
 
1600
        single = ephy_embed_shell_get_embed_single (ephy_embed_shell_get_default ());
1692
1601
 
1693
1602
        g_signal_handlers_disconnect_matched
1694
1603
                (single, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, object);