[epiphany] Merge EphyWebViewSecurityLevel and EphyLocationLockState



commit d8ec235316724ba778e5e4eece2b479ed7da163a
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Thu Jul 10 21:24:05 2014 -0500

    Merge EphyWebViewSecurityLevel and EphyLocationLockState
    
    EphyWebViewSecurityLevel has lots of unused members. Once they're
    removed, they correspond one-to-one with EphyLocationLockState. Merge
    these so we don't have to convert between two identical enums.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=666808

 embed/ephy-web-view.c             |   25 +++++++++--------
 embed/ephy-web-view.h             |   16 +++--------
 lib/Makefile.am                   |    3 +-
 lib/ephy-security-levels.h        |   42 ++++++++++++++++++++++++++++
 lib/widgets/ephy-location-entry.c |   55 +++++++++++++++++++------------------
 lib/widgets/ephy-location-entry.h |   13 +++------
 src/ephy-title-box.c              |   14 +++++-----
 src/ephy-title-box.h              |    4 +-
 src/ephy-window.c                 |   30 ++++++--------------
 9 files changed, 111 insertions(+), 91 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 1c0e342..c9442dd 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -37,6 +37,7 @@
 #include "ephy-file-monitor.h"
 #include "ephy-form-auth-data.h"
 #include "ephy-history-service.h"
+#include "ephy-lib-type-builtins.h"
 #include "ephy-prefs.h"
 #include "ephy-settings.h"
 #include "ephy-snapshot-service.h"
@@ -65,7 +66,7 @@
 #define EPHY_PAGE_TEMPLATE_ERROR         "/org/gnome/epiphany/page-templates/error.html"
 
 struct _EphyWebViewPrivate {
-  EphyWebViewSecurityLevel security_level;
+  EphySecurityLevel security_level;
   EphyWebViewDocumentType document_type;
   EphyWebViewNavigationFlags nav_flags;
 
@@ -974,15 +975,15 @@ ephy_web_view_class_init (EphyWebViewClass *klass)
 /**
  * EphyWebView:security-level:
  *
- * One of #EphyWebViewSecurityLevel, determining view's current security level.
+ * One of #EphySecurityLevel, determining view's current security level.
  **/
   g_object_class_install_property (gobject_class,
                                    PROP_SECURITY,
                                    g_param_spec_enum ("security-level",
                                                       "Security Level",
                                                       "The view's security level",
-                                                      EPHY_TYPE_WEB_VIEW_SECURITY_LEVEL,
-                                                      EPHY_WEB_VIEW_STATE_IS_UNKNOWN,
+                                                      EPHY_TYPE_SECURITY_LEVEL,
+                                                      EPHY_SECURITY_LEVEL_NO_SECURITY,
                                                       G_PARAM_READABLE | G_PARAM_STATIC_NAME | 
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
 
 /**
@@ -1600,7 +1601,7 @@ load_changed_cb (WebKitWebView *web_view,
     break;
   case WEBKIT_LOAD_COMMITTED: {
     const char* uri;
-    EphyWebViewSecurityLevel security_level = EPHY_WEB_VIEW_STATE_IS_UNKNOWN;
+    EphySecurityLevel security_level = EPHY_SECURITY_LEVEL_NO_SECURITY;
 
     priv->ever_committed = TRUE;
 
@@ -1618,7 +1619,7 @@ load_changed_cb (WebKitWebView *web_view,
       if (webkit_web_view_get_tls_info (web_view, &priv->certificate, &priv->tls_errors)) {
         g_object_ref (priv->certificate);
         security_level = priv->tls_errors == 0 ?
-          EPHY_WEB_VIEW_STATE_IS_SECURE_HIGH : EPHY_WEB_VIEW_STATE_IS_BROKEN;
+          EPHY_SECURITY_LEVEL_STRONG_SECURITY : EPHY_SECURITY_LEVEL_BROKEN_SECURITY;
       }
 
       ephy_web_view_set_security_level (EPHY_WEB_VIEW (web_view), security_level);
@@ -2031,7 +2032,7 @@ load_failed_with_tls_error_cb (WebKitWebView *web_view,
   priv->certificate = g_object_ref (certificate);
   priv->tls_errors = errors;
   priv->tls_error_page_host = g_strdup (host);
-  ephy_web_view_set_security_level (EPHY_WEB_VIEW (web_view), EPHY_WEB_VIEW_STATE_IS_BROKEN);
+  ephy_web_view_set_security_level (EPHY_WEB_VIEW (web_view), EPHY_SECURITY_LEVEL_BROKEN_SECURITY);
   ephy_web_view_load_error_page (EPHY_WEB_VIEW (web_view),
                                  webkit_web_view_get_uri (web_view),
                                  EPHY_WEB_VIEW_ERROR_INVALID_TLS_CERTIFICATE, NULL);
@@ -2088,7 +2089,7 @@ ephy_web_view_init (EphyWebView *web_view)
   priv->is_blank = TRUE;
   priv->ever_committed = FALSE;
   priv->document_type = EPHY_WEB_VIEW_DOCUMENT_HTML;
-  priv->security_level = EPHY_WEB_VIEW_STATE_IS_UNKNOWN;
+  priv->security_level = EPHY_SECURITY_LEVEL_NO_SECURITY;
 
   priv->file_monitor = ephy_file_monitor_new (web_view);
 
@@ -2473,13 +2474,13 @@ ephy_web_view_set_link_message (EphyWebView *view,
 /**
  * ephy_web_view_set_security_level:
  * @view: an #EphyWebView
- * @level: the new #EphyWebViewSecurityLevel for @view
+ * @level: the new #EphySecurityLevel for @view
  *
  * Sets @view's security-level property to @level.
  **/
 void
 ephy_web_view_set_security_level (EphyWebView *view,
-                                  EphyWebViewSecurityLevel level)
+                                  EphySecurityLevel level)
 {
   EphyWebViewPrivate *priv = view->priv;
 
@@ -2759,13 +2760,13 @@ ephy_web_view_get_web_app_title_finish (EphyWebView *view,
  * @certificate: (out) (transfer none): return value of TLS certificate
  * @errors: (out): return value of TLS errors
  *
- * Fetches the #EphyWebViewSecurityLevel and a #GTlsCertificate associated
+ * Fetches the #EphySecurityLevel and a #GTlsCertificate associated
  * with @view and a #GTlsCertificateFlags showing what problems, if any,
  * have been found with that certificate.
  **/
 void
 ephy_web_view_get_security_level (EphyWebView *view,
-                                  EphyWebViewSecurityLevel *level,
+                                  EphySecurityLevel *level,
                                   GTlsCertificate **certificate,
                                   GTlsCertificateFlags *errors)
 {
diff --git a/embed/ephy-web-view.h b/embed/ephy-web-view.h
index fa4bfff..2530bf7 100644
--- a/embed/ephy-web-view.h
+++ b/embed/ephy-web-view.h
@@ -29,6 +29,8 @@
 
 #include <webkit2/webkit2.h>
 
+#include "ephy-security-levels.h"
+
 G_BEGIN_DECLS
 
 #define EPHY_TYPE_WEB_VIEW         (ephy_web_view_get_type ())
@@ -50,16 +52,6 @@ typedef enum
 
 typedef enum
 {
-  EPHY_WEB_VIEW_STATE_IS_UNKNOWN,
-  EPHY_WEB_VIEW_STATE_IS_INSECURE,
-  EPHY_WEB_VIEW_STATE_IS_BROKEN,
-  EPHY_WEB_VIEW_STATE_IS_SECURE_LOW,
-  EPHY_WEB_VIEW_STATE_IS_SECURE_MED,
-  EPHY_WEB_VIEW_STATE_IS_SECURE_HIGH
-} EphyWebViewSecurityLevel;
-
-typedef enum
-{
   EPHY_WEB_VIEW_DOCUMENT_HTML,
   EPHY_WEB_VIEW_DOCUMENT_XML,
   EPHY_WEB_VIEW_DOCUMENT_IMAGE,
@@ -130,7 +122,7 @@ const char *               ephy_web_view_get_link_message         (EphyWebView
 void                       ephy_web_view_set_link_message         (EphyWebView               *view,
                                                                    const char                *link_message);
 void                       ephy_web_view_set_security_level       (EphyWebView               *view,
-                                                                   EphyWebViewSecurityLevel   level);
+                                                                   EphySecurityLevel          level);
 const char *               ephy_web_view_get_typed_address        (EphyWebView               *view);
 void                       ephy_web_view_set_typed_address        (EphyWebView               *view,
                                                                    const char                *address);
@@ -144,7 +136,7 @@ gboolean                  ephy_web_view_has_modified_forms_finish (EphyWebView
                                                                    GAsyncResult              *result,
                                                                    GError                   **error);
 void                       ephy_web_view_get_security_level       (EphyWebView               *view,
-                                                                   EphyWebViewSecurityLevel  *level,
+                                                                   EphySecurityLevel         *level,
                                                                    GTlsCertificate          **certificate,
                                                                    GTlsCertificateFlags      *errors);
 void                       ephy_web_view_print                    (EphyWebView               *view);
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 717a42b..e3695d1 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -30,7 +30,8 @@ NOINST_H_FILES = \
 
 TYPES_H_FILES = \
        ephy-initial-state.h                    \
-       ephy-node.h
+       ephy-node.h                             \
+       ephy-security-levels.h
 
 INST_H_FILES = \
        ephy-dialog.h                           \
diff --git a/lib/ephy-security-levels.h b/lib/ephy-security-levels.h
new file mode 100644
index 0000000..759120b
--- /dev/null
+++ b/lib/ephy-security-levels.h
@@ -0,0 +1,42 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 ts=2 sts=2 et: */
+/*
+ *  Copyright © 2014 Igalia S.L.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  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
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#if !defined (__EPHY_EPIPHANY_H_INSIDE__) && !defined (EPIPHANY_COMPILATION)
+#error "Only <epiphany/epiphany.h> can be included directly."
+#endif
+
+#ifndef EPHY_SECURITY_LEVELS_H
+#define EPHY_SECURITY_LEVELS_H
+
+#include "glib.h"
+
+G_BEGIN_DECLS
+
+typedef enum
+{
+  EPHY_SECURITY_LEVEL_NO_SECURITY,
+  EPHY_SECURITY_LEVEL_BROKEN_SECURITY,
+  EPHY_SECURITY_LEVEL_STRONG_SECURITY,
+} EphySecurityLevel;
+
+G_END_DECLS
+
+#endif
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 1d055a4..3e739e8 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -29,6 +29,7 @@
 #include "ephy-debug.h"
 #include "ephy-dnd.h"
 #include "ephy-gui.h"
+#include "ephy-lib-type-builtins.h"
 #include "ephy-signal-accumulator.h"
 
 #include <libsoup/soup.h>
@@ -110,7 +111,7 @@ enum
        PROP_0,
        PROP_LOCATION,
        PROP_FAVICON,
-       PROP_LOCK_STATE,
+       PROP_SECURITY_LEVEL,
        PROP_SHOW_LOCK,
        PROP_SHOW_FAVICON
 };
@@ -145,9 +146,9 @@ ephy_location_entry_set_property (GObject *object,
                ephy_location_entry_set_favicon (entry,
                                                 g_value_get_object (value));
                break;
-       case PROP_LOCK_STATE:
-               ephy_location_entry_set_lock_state (entry,
-                                                   g_value_get_enum (value));
+       case PROP_SECURITY_LEVEL:
+               ephy_location_entry_set_security_level (entry,
+                                                       g_value_get_enum (value));
                break;
        case PROP_SHOW_LOCK:
                ephy_location_entry_set_show_lock (entry,
@@ -256,17 +257,17 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass)
                                                              G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | 
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
 
        /**
-       * EphyLocationEntry:lock-state:
+       * EphyLocationEntry:security-level:
        *
        * State of the security icon.
        */
        g_object_class_install_property (object_class,
-                                        PROP_LOCK_STATE,
-                                        g_param_spec_enum  ("lock-state",
-                                                            "Lock state",
+                                        PROP_SECURITY_LEVEL,
+                                        g_param_spec_enum  ("security-level",
+                                                            "Security level",
                                                             "State of the security icon",
-                                                            EPHY_TYPE_LOCATION_LOCK_STATE,
-                                                            EPHY_LOCATION_LOCK_STATE_UNKNOWN,
+                                                            EPHY_TYPE_SECURITY_LEVEL,
+                                                            EPHY_SECURITY_LEVEL_NO_SECURITY,
                                                             G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | 
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
 
        /**
@@ -1598,9 +1599,7 @@ ephy_location_entry_set_show_favicon (EphyLocationEntry *entry,
  * of the page
  *
  * If @show_lock is TRUE, the location bar will show an icon reflecting the
- * security level of the page, by default it's shown only in secure and
- * insecure pages (insecure meaning secure pages with something broken in such
- * security)
+ * security level of the page, by default it's shown only in secure (HTTPS) pages
  *
  **/
 void
@@ -1621,17 +1620,17 @@ ephy_location_entry_set_show_lock (EphyLocationEntry *entry,
 }
 
 /**
- * ephy_location_entry_set_lock_state:
+ * ephy_location_entry_set_security_level:
  * @entry: an #EphyLocationEntry widget
- * @state: the #EphyLocationLockState
+ * @state: the #EphySecurityLevel
  *
  * Set the lock icon to be displayed, to actually show the icon see 
  * ephy_location_entry_set_show_lock.
  *
  **/
 void
-ephy_location_entry_set_lock_state (EphyLocationEntry *entry,
-                                   EphyLocationLockState state)
+ephy_location_entry_set_security_level (EphyLocationEntry *entry,
+                                       EphySecurityLevel security_level)
 
 {
        EphyLocationEntryPrivate *priv;
@@ -1643,21 +1642,23 @@ ephy_location_entry_set_lock_state (EphyLocationEntry *entry,
        if (priv->lock_gicon)
                g_object_unref (priv->lock_gicon);
 
-       /* At the moment we basically only show two kinds of
-        * locks. Full/green for secure sites, Broken/red for sites
-        * that are supposed to be secure but have some issues in
-        * their security infrastructure (broken cert, etc). For
-        * everything else, nothing is shown.
-        */
-       if (state == EPHY_LOCATION_LOCK_STATE_SECURE)
-               priv->lock_gicon = g_themed_icon_new_with_default_fallbacks ("channel-secure-symbolic");
-       else
+       switch (security_level) {
+       case EPHY_SECURITY_LEVEL_NO_SECURITY:
+               /* Fall through, but this icon should not be displayed... */
+       case EPHY_SECURITY_LEVEL_BROKEN_SECURITY:
                priv->lock_gicon = g_themed_icon_new_with_default_fallbacks ("channel-insecure-symbolic");
+               break;
+       case EPHY_SECURITY_LEVEL_STRONG_SECURITY:
+               priv->lock_gicon = g_themed_icon_new_with_default_fallbacks ("channel-secure-symbolic");
+               break;
+       }
 
-       if (priv->show_lock)
+       if (priv->show_lock) {
+               g_warn_if_fail (security_level != EPHY_SECURITY_LEVEL_NO_SECURITY);
                gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry),
                                               GTK_ENTRY_ICON_SECONDARY,
                                               priv->lock_gicon);
+       }
 }
 
 /**
diff --git a/lib/widgets/ephy-location-entry.h b/lib/widgets/ephy-location-entry.h
index 014b910..f5a0bb3 100644
--- a/lib/widgets/ephy-location-entry.h
+++ b/lib/widgets/ephy-location-entry.h
@@ -28,6 +28,8 @@
 
 #include <gtk/gtk.h>
 
+#include "ephy-security-levels.h"
+
 G_BEGIN_DECLS
 
 #define EPHY_TYPE_LOCATION_ENTRY               (ephy_location_entry_get_type())
@@ -61,13 +63,6 @@ struct _EphyLocationEntry
        EphyLocationEntryPrivate *priv;
 };
 
-typedef enum {
-  EPHY_LOCATION_LOCK_STATE_UNKNOWN = 0,
-  EPHY_LOCATION_LOCK_STATE_BROKEN,
-  EPHY_LOCATION_LOCK_STATE_INSECURE,
-  EPHY_LOCATION_LOCK_STATE_SECURE
-} EphyLocationLockState;
-
 GType          ephy_location_entry_get_type            (void);
 
 GtkWidget      *ephy_location_entry_new                        (void);
@@ -113,8 +108,8 @@ void            ephy_location_entry_set_show_favicon    (EphyLocationEntry *entr
 void           ephy_location_entry_set_show_lock       (EphyLocationEntry *entry,
                                                         gboolean show_lock);
 
-void           ephy_location_entry_set_lock_state      (EphyLocationEntry *entry,
-                                                        EphyLocationLockState state);
+void           ephy_location_entry_set_security_level  (EphyLocationEntry *entry,
+                                                        EphySecurityLevel security_level);
 
 void           ephy_location_entry_set_lock_tooltip    (EphyLocationEntry *entry,
                                                         const char *tooltip);
diff --git a/src/ephy-title-box.c b/src/ephy-title-box.c
index 1b414ac..910593b 100644
--- a/src/ephy-title-box.c
+++ b/src/ephy-title-box.c
@@ -647,16 +647,16 @@ ephy_title_box_set_show_lock (EphyTitleBox *title_box,
 }
 
 /**
- * ephy_title_box_set_lock_state:
+ * ephy_title_box_set_security_level:
  * @title_box: an #EphyTitleBox
- * @mode: an #EphyLocationLockState
+ * @mode: an #EphySecurityLevel
  *
- * Set the lock icon to be displayed, to actually show the icon see
+ * Set the lock icon to be displayed; to actually show the icon see
  * ephy_title_box_set_show_lock.
  **/
 void
-ephy_title_box_set_lock_state (EphyTitleBox         *title_box,
-                               EphyLocationLockState state)
+ephy_title_box_set_security_level (EphyTitleBox         *title_box,
+                                   EphySecurityLevel     security_level)
 {
   EphyTitleBoxPrivate *priv;
 
@@ -664,11 +664,11 @@ ephy_title_box_set_lock_state (EphyTitleBox         *title_box,
 
   priv = ephy_title_box_get_instance_private (title_box);
 
-  g_object_set (priv->lock_image, "icon-name", state == EPHY_LOCATION_LOCK_STATE_SECURE ?
+  g_object_set (priv->lock_image, "icon-name", security_level == EPHY_SECURITY_LEVEL_STRONG_SECURITY ?
                                                "channel-secure-symbolic" : "channel-insecure-symbolic",
                                   NULL);
 
-  ephy_location_entry_set_lock_state (EPHY_LOCATION_ENTRY (priv->entry), state);
+  ephy_location_entry_set_security_level (EPHY_LOCATION_ENTRY (priv->entry), security_level);
 }
 
 /**
diff --git a/src/ephy-title-box.h b/src/ephy-title-box.h
index 85c7437..3321d94 100644
--- a/src/ephy-title-box.h
+++ b/src/ephy-title-box.h
@@ -71,8 +71,8 @@ void                ephy_title_box_set_mode             (EphyTitleBox         *t
 void                ephy_title_box_set_show_lock        (EphyTitleBox         *title_box,
                                                          gboolean              show_lock);
 
-void                ephy_title_box_set_lock_state       (EphyTitleBox         *title_box,
-                                                         EphyLocationLockState state);
+void                ephy_title_box_set_security_level   (EphyTitleBox         *title_box,
+                                                         EphySecurityLevel     security_level);
 
 GtkWidget          *ephy_title_box_get_location_entry   (EphyTitleBox         *title_box);
 
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 5b257a5..0021eaa 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -713,7 +713,7 @@ sync_tab_load_status (EphyWebView *view,
 static void
 _ephy_window_set_security_state (EphyWindow *window,
                                 gboolean show_lock,
-                                EphyLocationLockState state)
+                                EphySecurityLevel security_level)
 {
        EphyWindowPrivate *priv = window->priv;
        EphyTitleBox *title_box;
@@ -722,7 +722,7 @@ _ephy_window_set_security_state (EphyWindow *window,
 
        priv->show_lock = show_lock != FALSE;
 
-       ephy_title_box_set_lock_state (title_box, state);
+       ephy_title_box_set_security_level (title_box, security_level);
        ephy_title_box_set_show_lock (title_box, priv->show_lock);
 }
 
@@ -732,33 +732,21 @@ sync_tab_security (EphyWebView *view,
                   EphyWindow *window)
 {
        EphyWindowPrivate *priv = window->priv;
-       EphyWebViewSecurityLevel level;
-       EphyLocationLockState state = EPHY_LOCATION_LOCK_STATE_INSECURE;
+       EphySecurityLevel security_level;
        gboolean show_lock = FALSE;
 
        if (priv->closing) return;
 
-       ephy_web_view_get_security_level (view, &level, NULL, NULL);
+       ephy_web_view_get_security_level (view, &security_level, NULL, NULL);
 
-       switch (level)
+       switch (security_level)
        {
-               case EPHY_WEB_VIEW_STATE_IS_UNKNOWN:
-               case EPHY_WEB_VIEW_STATE_IS_INSECURE:
-                       /* Nothing to do. */
+               case EPHY_SECURITY_LEVEL_NO_SECURITY:
                        break;
-               case EPHY_WEB_VIEW_STATE_IS_BROKEN:
-                       state = EPHY_LOCATION_LOCK_STATE_INSECURE;
+               case EPHY_SECURITY_LEVEL_BROKEN_SECURITY:
                         show_lock = TRUE;
                         break;
-               case EPHY_WEB_VIEW_STATE_IS_SECURE_LOW:
-               case EPHY_WEB_VIEW_STATE_IS_SECURE_MED:
-                       /* We deliberately don't show the 'secure' icon
-                        * for low & medium secure sites; see bug #151709.
-                        */
-                       state = EPHY_LOCATION_LOCK_STATE_INSECURE;
-                       break;
-               case EPHY_WEB_VIEW_STATE_IS_SECURE_HIGH:
-                       state = EPHY_LOCATION_LOCK_STATE_SECURE;
+               case EPHY_SECURITY_LEVEL_STRONG_SECURITY:
                        show_lock = TRUE;
                        break;
                default:
@@ -766,7 +754,7 @@ sync_tab_security (EphyWebView *view,
                        break;
        }
 
-       _ephy_window_set_security_state (window, show_lock, state);
+       _ephy_window_set_security_state (window, show_lock, security_level);
 }
 
 static void


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