ephy-security-popover.c 22.9 KB
Newer Older
1
2
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
3
 *  Copyright © 2014, 2015 Igalia S.L.
4
 *
Michael Catanzaro's avatar
Michael Catanzaro committed
5
6
7
 *  This file is part of Epiphany.
 *
 *  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
Michael Catanzaro's avatar
Michael Catanzaro committed
9
10
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
11
 *
Michael Catanzaro's avatar
Michael Catanzaro committed
12
 *  Epiphany is distributed in the hope that it will be useful,
13
14
15
16
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
Michael Catanzaro's avatar
Michael Catanzaro committed
18
 *  along with Epiphany.  If not, see <http://www.gnu.org/licenses/>.
19
20
21
 */

#include "config.h"
22
#include "ephy-security-popover.h"
23
24
25
26

#include <glib/gi18n.h>

#include "ephy-certificate-dialog.h"
27
#include "ephy-embed-shell.h"
28
#include "ephy-lib-type-builtins.h"
29
30
31
#include "ephy-permissions-manager.h"
#include "ephy-settings.h"
#include "ephy-uri-helpers.h"
32
33

/**
34
35
 * SECTION:ephy-security-popover
 * @short_description: A popover to show basic TLS connection information
36
 *
37
38
39
 * #EphySecurityPopover shows basic information about a TLS connection
 * and allows opening #EphyCertificateDialog for more detailed information. It
 * can also be used to show that a connection does not use TLS at all.
40
41
 */

Michael Catanzaro's avatar
Michael Catanzaro committed
42
enum {
43
44
45
46
47
  PROP_0,
  PROP_ADDRESS,
  PROP_CERTIFICATE,
  PROP_SECURITY_LEVEL,
  PROP_TLS_ERRORS,
48
  LAST_PROP
49
50
};

51
52
static GParamSpec *obj_properties[LAST_PROP];

Michael Catanzaro's avatar
Michael Catanzaro committed
53
struct _EphySecurityPopover {
54
  GtkPopover parent_instance;
55
56
  char *address;
  char *hostname;
57
  guint permission_pos;
58
59
60
  GtkWidget *lock_image;
  GtkWidget *host_label;
  GtkWidget *security_label;
61
62
63
64
65
66
  GtkWidget *ad_combobox;
  GtkWidget *notification_combobox;
  GtkWidget *save_password_combobox;
  GtkWidget *access_location_combobox;
  GtkWidget *access_microphone_combobox;
  GtkWidget *access_webcam_combobox;
67
  GtkWidget *autoplay_combobox;
68
  GtkWidget *grid;
69
70
  GTlsCertificate *certificate;
  GTlsCertificateFlags tls_errors;
71
  EphySecurityLevel security_level;
72
73
};

74
G_DEFINE_TYPE (EphySecurityPopover, ephy_security_popover, GTK_TYPE_POPOVER)
75

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
static void
set_permission_ads_combobox_state (EphyPermissionsManager *permissions_manager,
                                   gint                    permission_id,
                                   gchar                  *origin,
                                   GtkWidget              *widget)
{
  GSettings *web_settings = ephy_settings_get (EPHY_PREFS_WEB_SCHEMA);
  EphyPermission permission;

  permission = ephy_permissions_manager_get_permission (permissions_manager,
                                                        permission_id,
                                                        origin);

  switch (permission) {
    case EPHY_PERMISSION_UNDECIDED:
      gtk_combo_box_set_active (GTK_COMBO_BOX (widget),
                                g_settings_get_boolean (web_settings, EPHY_PREFS_WEB_ENABLE_ADBLOCK));
      break;
    case EPHY_PERMISSION_DENY:
      gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 1);
      break;
    case EPHY_PERMISSION_PERMIT:
      gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
      break;
  }
}

static void
set_permission_combobox_state (EphyPermissionsManager *permissions_manager,
                               gint                    permission_id,
                               gchar                  *origin,
                               GtkWidget              *widget)
{
  EphyPermission permission;

  permission = ephy_permissions_manager_get_permission (permissions_manager,
                                                        permission_id,
                                                        origin);

  switch (permission) {
    case EPHY_PERMISSION_PERMIT:
      gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
      break;
    case EPHY_PERMISSION_DENY:
      gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 1);
      break;
    case EPHY_PERMISSION_UNDECIDED:
      gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 2);
      break;
  }
}

128
static void
129
ephy_security_popover_set_address (EphySecurityPopover *popover,
Michael Catanzaro's avatar
Michael Catanzaro committed
130
                                   const char          *address)
131
{
132
  EphyPermissionsManager *permissions_manager;
133
  g_autoptr (GUri) uri = NULL;
134
  g_autofree gchar *origin = NULL;
135
  g_autofree gchar *uri_text = NULL;
136

137
138
  uri = g_uri_parse (address, G_URI_FLAGS_NONE, NULL);
  uri_text = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>", g_uri_get_host (uri));
139
  /* Label when clicking the lock icon on a secure page. %s is the website's hostname. */
140
  gtk_label_set_markup (GTK_LABEL (popover->host_label), uri_text);
141

142
  popover->address = g_strdup (address);
143
  popover->hostname = g_strdup (g_uri_get_host (uri));
144
145
146
147
148
149

  origin = ephy_uri_to_security_origin (address);
  if (!origin)
    return;

  permissions_manager = ephy_embed_shell_get_permissions_manager (ephy_embed_shell_get_default ());
150
151
152
153
154
155
  set_permission_ads_combobox_state (permissions_manager, EPHY_PERMISSION_TYPE_SHOW_ADS, origin, popover->ad_combobox);
  set_permission_combobox_state (permissions_manager, EPHY_PERMISSION_TYPE_SHOW_NOTIFICATIONS, origin, popover->notification_combobox);
  set_permission_combobox_state (permissions_manager, EPHY_PERMISSION_TYPE_SAVE_PASSWORD, origin, popover->save_password_combobox);
  set_permission_combobox_state (permissions_manager, EPHY_PERMISSION_TYPE_ACCESS_LOCATION, origin, popover->access_location_combobox);
  set_permission_combobox_state (permissions_manager, EPHY_PERMISSION_TYPE_ACCESS_MICROPHONE, origin, popover->access_microphone_combobox);
  set_permission_combobox_state (permissions_manager, EPHY_PERMISSION_TYPE_ACCESS_WEBCAM, origin, popover->access_webcam_combobox);
156
  set_permission_combobox_state (permissions_manager, EPHY_PERMISSION_TYPE_AUTOPLAY_POLICY, origin, popover->autoplay_combobox);
157
158
159
}

static void
160
ephy_security_popover_set_certificate (EphySecurityPopover *popover,
Michael Catanzaro's avatar
Michael Catanzaro committed
161
                                       GTlsCertificate     *certificate)
162
{
163
  if (certificate)
164
    popover->certificate = g_object_ref (certificate);
165
166
167
}

static void
168
ephy_security_popover_set_security_level (EphySecurityPopover *popover,
Michael Catanzaro's avatar
Michael Catanzaro committed
169
                                          EphySecurityLevel    security_level)
170
171
{
  GIcon *icon;
172
173
  g_autofree gchar *address_text = NULL;
  g_autofree gchar *label_text = NULL;
174

175
  popover->security_level = security_level;
176

177
  address_text = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>", popover->hostname);
178
  gtk_label_set_markup (GTK_LABEL (popover->host_label), address_text);
179
180

  switch (security_level) {
Michael Catanzaro's avatar
Michael Catanzaro committed
181
182
183
184
185
186
187
188
189
    case EPHY_SECURITY_LEVEL_UNACCEPTABLE_CERTIFICATE:
      /* Label in certificate popover when site is untrusted. %s is a URL. */
      label_text = g_strdup_printf (_("This web site’s digital identification is not trusted. "
                                      "You may have connected to an attacker pretending to be %s."),
                                    address_text);
      gtk_label_set_markup (GTK_LABEL (popover->security_label), label_text);
      break;
    case EPHY_SECURITY_LEVEL_NO_SECURITY:
      /* Label in certificate popover when site uses HTTP. %s is a URL. */
190
191
      label_text = g_strdup_printf (_("This site has no security. An attacker could see any information "
                                      "you send, or control the content that you see."));
Michael Catanzaro's avatar
Michael Catanzaro committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
      gtk_label_set_markup (GTK_LABEL (popover->security_label), label_text);
      break;
    case EPHY_SECURITY_LEVEL_MIXED_CONTENT:
      gtk_label_set_text (GTK_LABEL (popover->security_label),
                          /* Label in certificate popover when site sends mixed content. */
                          _("This web site did not properly secure your connection."));
      break;
    case EPHY_SECURITY_LEVEL_STRONG_SECURITY:
      gtk_label_set_text (GTK_LABEL (popover->security_label),
                          /* Label in certificate popover on secure sites. */
                          _("Your connection seems to be secure."));
      break;
    case EPHY_SECURITY_LEVEL_TO_BE_DETERMINED:
    case EPHY_SECURITY_LEVEL_LOCAL_PAGE:
    default:
      g_assert_not_reached ();
208
209
210
  }

  icon = g_themed_icon_new_with_default_fallbacks (ephy_security_level_to_icon_name (security_level));
211
  gtk_image_set_from_gicon (GTK_IMAGE (popover->lock_image), icon, GTK_ICON_SIZE_BUTTON);
212

213
214
215
  g_object_unref (icon);
}

216
217
static void
certificate_button_clicked_cb (GtkButton *button,
Michael Catanzaro's avatar
Michael Catanzaro committed
218
                               gpointer   user_data)
219
{
220
  EphySecurityPopover *popover = EPHY_SECURITY_POPOVER (user_data);
221
222
223
  GtkWidget *dialog;

  dialog = ephy_certificate_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (popover))),
224
225
226
227
                                        popover->address,
                                        popover->certificate,
                                        popover->tls_errors,
                                        popover->security_level);
228
229
230
231
232
  gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
  g_signal_connect (dialog, "response",
                    G_CALLBACK (gtk_widget_destroy),
                    NULL);

233
  gtk_popover_popdown (GTK_POPOVER (popover));
234
235
236
237
  gtk_widget_show (dialog);
}

static void
238
ephy_security_popover_constructed (GObject *object)
239
{
240
  EphySecurityPopover *popover = EPHY_SECURITY_POPOVER (object);
241
242
  GtkWidget *certificate_button;

243
  G_OBJECT_CLASS (ephy_security_popover_parent_class)->constructed (object);
244

245
  if (!popover->certificate)
246
247
248
    return;

  certificate_button = gtk_button_new_with_mnemonic (_("_View Certificate…"));
249
  gtk_widget_set_halign (certificate_button, GTK_ALIGN_END);
250
251
252
253
254
255
256
  gtk_widget_set_margin_top (certificate_button, 5);
  gtk_widget_set_receives_default (certificate_button, FALSE);
  gtk_widget_show (certificate_button);
  g_signal_connect (certificate_button, "clicked",
                    G_CALLBACK (certificate_button_clicked_cb),
                    popover);

257
  gtk_grid_attach (GTK_GRID (popover->grid), certificate_button, 1, 2, 1, 1);
258
259
}

260
static void
261
ephy_security_popover_dispose (GObject *object)
262
{
263
  EphySecurityPopover *popover = EPHY_SECURITY_POPOVER (object);
264

265
  g_clear_object (&popover->certificate);
266

267
  G_OBJECT_CLASS (ephy_security_popover_parent_class)->dispose (object);
268
269
270
}

static void
271
ephy_security_popover_finalize (GObject *object)
272
{
273
  EphySecurityPopover *popover = EPHY_SECURITY_POPOVER (object);
274

275
276
  g_free (popover->address);
  g_free (popover->hostname);
277

278
  G_OBJECT_CLASS (ephy_security_popover_parent_class)->finalize (object);
279
280
281
}

static void
Michael Catanzaro's avatar
Michael Catanzaro committed
282
283
ephy_security_popover_set_property (GObject      *object,
                                    guint         prop_id,
284
                                    const GValue *value,
Michael Catanzaro's avatar
Michael Catanzaro committed
285
                                    GParamSpec   *pspec)
286
{
287
  EphySecurityPopover *popover = EPHY_SECURITY_POPOVER (object);
288
289

  switch (prop_id) {
Michael Catanzaro's avatar
Michael Catanzaro committed
290
291
292
293
294
295
296
297
298
299
300
301
302
303
    case PROP_ADDRESS:
      ephy_security_popover_set_address (popover, g_value_get_string (value));
      break;
    case PROP_CERTIFICATE:
      ephy_security_popover_set_certificate (popover, g_value_get_object (value));
      break;
    case PROP_SECURITY_LEVEL:
      ephy_security_popover_set_security_level (popover, g_value_get_enum (value));
      break;
    case PROP_TLS_ERRORS:
      popover->tls_errors = g_value_get_flags (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
304
305
306
307
  }
}

static void
308
ephy_security_popover_get_preferred_width (GtkWidget *widget,
Michael Catanzaro's avatar
Michael Catanzaro committed
309
310
                                           gint      *minimum_width,
                                           gint      *natural_width)
311
{
312
  GTK_WIDGET_CLASS (ephy_security_popover_parent_class)->get_preferred_width (widget,
Michael Catanzaro's avatar
Michael Catanzaro committed
313
314
                                                                              minimum_width,
                                                                              natural_width);
315

316
317
  if (*natural_width > 360)
    *natural_width = MAX (360, *minimum_width);
318
319
320
}

static void
321
ephy_security_popover_class_init (EphySecurityPopoverClass *klass)
322
323
324
325
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

326
327
328
329
  object_class->constructed = ephy_security_popover_constructed;
  object_class->dispose = ephy_security_popover_dispose;
  object_class->finalize = ephy_security_popover_finalize;
  object_class->set_property = ephy_security_popover_set_property;
330

331
  widget_class->get_preferred_width = ephy_security_popover_get_preferred_width;
332
333

  /**
334
   * EphySecurityPopover:address:
335
336
337
   *
   * The address of the website.
   */
338
339
340
341
342
343
  obj_properties[PROP_ADDRESS] =
    g_param_spec_string ("address",
                         "Address",
                         "The address of the website",
                         NULL,
                         G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
344
345

  /**
346
   * EphySecurityPopover:certificate:
347
348
349
   *
   * The certificate of the website.
   */
350
351
352
353
354
355
  obj_properties[PROP_CERTIFICATE] =
    g_param_spec_object ("certificate",
                         "Certificate",
                         "The certificate of the website, if HTTPS",
                         G_TYPE_TLS_CERTIFICATE,
                         G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
356
357

  /**
358
   * EphySecurityPopover:tls-errors:
359
360
361
   *
   * Indicates issues with the security of the website.
   */
362
363
364
365
366
367
368
  obj_properties[PROP_TLS_ERRORS] =
    g_param_spec_flags ("tls-errors",
                        "TLS Errors",
                        "Issues with the security of the website, if HTTPS",
                        G_TYPE_TLS_CERTIFICATE_FLAGS,
                        0,
                        G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
369
370

  /**
371
   * EphySecurityPopover:security-level:
372
373
374
   *
   * The state of the lock displayed in the address bar.
   */
375
376
377
378
379
380
381
382
383
  obj_properties[PROP_SECURITY_LEVEL] =
    g_param_spec_enum ("security-level",
                       "Security Level",
                       "Determines what type of information to display",
                       EPHY_TYPE_SECURITY_LEVEL,
                       EPHY_SECURITY_LEVEL_TO_BE_DETERMINED,
                       G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
384
385
}

386
static gboolean
387
on_ad_combobox_changed (GtkComboBox         *widget,
388
389
390
391
392
                        EphySecurityPopover *popover)
{
  GSettings *web_settings = ephy_settings_get (EPHY_PREFS_WEB_SCHEMA);
  EphyPermissionsManager *permissions_manager;
  EphyPermission permission = EPHY_PERMISSION_UNDECIDED;
393
  gboolean global_flag = g_settings_get_boolean (web_settings, EPHY_PREFS_WEB_ENABLE_ADBLOCK);
394
  g_autofree gchar *origin = NULL;
395
  gboolean state = gtk_combo_box_get_active (widget) == 1;
396
397
398
399
400
401
402
403

  origin = ephy_uri_to_security_origin (popover->address);
  if (!origin)
    return FALSE;

  permissions_manager = ephy_embed_shell_get_permissions_manager (ephy_embed_shell_get_default ());

  if (global_flag != state)
404
    permission = state ? EPHY_PERMISSION_DENY : EPHY_PERMISSION_PERMIT;
405
406
407
408
409
410
411
412
413

  ephy_permissions_manager_set_permission (permissions_manager,
                                           EPHY_PERMISSION_TYPE_SHOW_ADS,
                                           origin,
                                           permission);

  return FALSE;
}

414
static void
415
416
417
handle_permission_combobox_changed (EphySecurityPopover *popover,
                                    gint                 action,
                                    EphyPermissionType   permission_type)
418
{
419
420
421
422
423
424
425
426
427
428
429
  EphyPermissionsManager *permissions_manager;
  EphyPermission permission;
  g_autofree gchar *origin = NULL;

  origin = ephy_uri_to_security_origin (popover->address);
  if (!origin)
    return;

  permissions_manager = ephy_embed_shell_get_permissions_manager (ephy_embed_shell_get_default ());

  switch (action) {
430
431
432
433
434
435
436
437
438
439
    case 0:
      permission = EPHY_PERMISSION_PERMIT;
      break;
    default:
    case 1:
      permission = EPHY_PERMISSION_DENY;
      break;
    case 2:
      permission = EPHY_PERMISSION_UNDECIDED;
      break;
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
  }

  ephy_permissions_manager_set_permission (permissions_manager,
                                           permission_type,
                                           origin,
                                           permission);
}

static void
on_notification_combobox_changed (GtkComboBox         *box,
                                  EphySecurityPopover *popover)
{
  handle_permission_combobox_changed (popover, gtk_combo_box_get_active (box), EPHY_PERMISSION_TYPE_SHOW_NOTIFICATIONS);
}

static void
on_save_password_combobox_changed (GtkComboBox         *box,
                                   EphySecurityPopover *popover)
{
  handle_permission_combobox_changed (popover, gtk_combo_box_get_active (box), EPHY_PERMISSION_TYPE_SAVE_PASSWORD);
}

static void
on_access_location_combobox_changed (GtkComboBox         *box,
                                     EphySecurityPopover *popover)
{
  handle_permission_combobox_changed (popover, gtk_combo_box_get_active (box), EPHY_PERMISSION_TYPE_ACCESS_LOCATION);
}

static void
on_access_microphone_combobox_changed (GtkComboBox         *box,
                                       EphySecurityPopover *popover)
{
  handle_permission_combobox_changed (popover, gtk_combo_box_get_active (box), EPHY_PERMISSION_TYPE_ACCESS_MICROPHONE);
}

static void
on_access_webcam_combobox_changed (GtkComboBox         *box,
                                   EphySecurityPopover *popover)
{
  handle_permission_combobox_changed (popover, gtk_combo_box_get_active (box), EPHY_PERMISSION_TYPE_ACCESS_WEBCAM);
}

483
484
485
486
487
488
489
static void
on_autoplay_policy_combobox_changed (GtkComboBox         *box,
                                     EphySecurityPopover *popover)
{
  handle_permission_combobox_changed (popover, gtk_combo_box_get_active (box), EPHY_PERMISSION_TYPE_AUTOPLAY_POLICY);
}

490
491
492
493
static GtkWidget *
add_permission_combobox (EphySecurityPopover *popover,
                         const gchar         *name,
                         gpointer             callback,
494
495
496
                         GtkSizeGroup        *size_group,
                         gboolean             no_ask,
                         const gchar         *third_option_name)
497
498
{
  GtkWidget *widget;
499
  GtkWidget *hbox;
500
501
  GtkWidget *tmp;

502
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
503
504
505
506
  gtk_grid_attach (GTK_GRID (popover->grid), hbox, 0, popover->permission_pos++, 2, 1);

  tmp = gtk_label_new (name);
  gtk_label_set_xalign (GTK_LABEL (tmp), 0.0);
507
508
  gtk_widget_set_hexpand (tmp, TRUE);
  gtk_box_pack_start (GTK_BOX (hbox), tmp, FALSE, TRUE, 0);
509
510

  widget = gtk_combo_box_text_new ();
511
512
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), _("Allow"));
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), _("Deny"));
513

514
515
516
517
  if (!no_ask) {
    const gchar *name = third_option_name == NULL ? _("Ask") : third_option_name;
    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), _(name));
  }
518

519
  gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, TRUE, 0);
520
  g_signal_connect (widget, "changed", G_CALLBACK (callback), popover);
521
  gtk_size_group_add_widget (size_group, widget);
522
523
524
525
526
527
528
529

  return widget;
}

static void
ephy_security_popover_init (EphySecurityPopover *popover)
{
  GtkWidget *permissions;
530
  GtkWidget *box;
531
  g_autoptr (GtkSizeGroup) combo_box_size_group = NULL;
532
  g_autofree char *label = g_strdup_printf ("<b>%s</b>", _("Permissions"));
533

534
  popover->grid = gtk_grid_new ();
535
536
  gtk_grid_set_column_spacing (GTK_GRID (popover->grid), 12);
  gtk_grid_set_row_spacing (GTK_GRID (popover->grid), 6);
537
538
539
540
  gtk_widget_set_margin_top (popover->grid, 10);
  gtk_widget_set_margin_bottom (popover->grid, 10);
  gtk_widget_set_margin_start (popover->grid, 10);
  gtk_widget_set_margin_end (popover->grid, 10);
541

542
543
544
  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  gtk_widget_set_halign (box, GTK_ALIGN_CENTER);

545
  popover->lock_image = gtk_image_new ();
546
  gtk_box_pack_start (GTK_BOX (box), popover->lock_image, FALSE, TRUE, 0);
547

548
  popover->host_label = gtk_label_new (NULL);
549
550
551
  gtk_label_set_line_wrap (GTK_LABEL (popover->host_label), TRUE);
  gtk_label_set_line_wrap_mode (GTK_LABEL (popover->host_label), PANGO_WRAP_WORD_CHAR);
  gtk_label_set_xalign (GTK_LABEL (popover->host_label), 0.0);
552
  gtk_box_pack_start (GTK_BOX (box), popover->host_label, FALSE, TRUE, 0);
553

554
555
  popover->security_label = gtk_label_new (NULL);
  gtk_label_set_line_wrap (GTK_LABEL (popover->security_label), TRUE);
556
  gtk_label_set_xalign (GTK_LABEL (popover->security_label), 0.0);
557

558
559
  gtk_grid_attach (GTK_GRID (popover->grid), box, 0, 0, 2, 1);
  gtk_grid_attach (GTK_GRID (popover->grid), popover->security_label, 0, 1, 2, 1);
560

561
562
563
  gtk_grid_attach (GTK_GRID (popover->grid), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL), 0, 3, 2, 1);

  /* Permissions */
564
565
566
567
568
569
  permissions = gtk_label_new (NULL);
  gtk_label_set_markup (GTK_LABEL (permissions), label);
  gtk_label_set_xalign (GTK_LABEL (permissions), 0.0);
  gtk_grid_attach (GTK_GRID (popover->grid), permissions, 0, 4, 2, 1);

  popover->permission_pos = 5;
570
571
572
573
574
575
576
577
  combo_box_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);

  popover->ad_combobox = add_permission_combobox (popover, _("Advertisements"), on_ad_combobox_changed, combo_box_size_group, TRUE, NULL);
  popover->notification_combobox = add_permission_combobox (popover, _("Notifications"), on_notification_combobox_changed, combo_box_size_group, FALSE, NULL);
  popover->save_password_combobox = add_permission_combobox (popover, _("Password saving"), on_save_password_combobox_changed, combo_box_size_group, FALSE, NULL);
  popover->access_location_combobox = add_permission_combobox (popover, _("Location access"), on_access_location_combobox_changed, combo_box_size_group, FALSE, NULL);
  popover->access_microphone_combobox = add_permission_combobox (popover, _("Microphone access"), on_access_microphone_combobox_changed, combo_box_size_group, FALSE, NULL);
  popover->access_webcam_combobox = add_permission_combobox (popover, _("Webcam access"), on_access_webcam_combobox_changed, combo_box_size_group, FALSE, NULL);
578
  popover->autoplay_combobox = add_permission_combobox (popover, _("Media autoplay"), on_autoplay_policy_combobox_changed, combo_box_size_group, FALSE, _("Without Sound"));
579

580
581
  gtk_container_add (GTK_CONTAINER (popover), popover->grid);
  gtk_widget_show_all (popover->grid);
582
583
}

584
585
586
587
588
589
GtkWidget *
ephy_security_popover_new (GtkWidget            *relative_to,
                           const char           *address,
                           GTlsCertificate      *certificate,
                           GTlsCertificateFlags  tls_errors,
                           EphySecurityLevel     security_level)
590
{
Michael Catanzaro's avatar
Michael Catanzaro committed
591
  g_assert (address != NULL);
592

593
  return GTK_WIDGET (g_object_new (EPHY_TYPE_SECURITY_POPOVER,
594
595
596
597
598
599
600
                                   "address", address,
                                   "certificate", certificate,
                                   "relative-to", relative_to,
                                   "security-level", security_level,
                                   "tls-errors", tls_errors,
                                   NULL));
}