[epiphany/wip/security-origins: 2/8] web-view: Use security origins on error pages where appropriate



commit 5a14ec6c09a793ff01104ace2c7158d36954e2ec
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Thu Dec 29 12:56:23 2016 -0600

    web-view: Use security origins on error pages where appropriate

 embed/ephy-web-view.c |   34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 60c2a56..4cf7a72 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1864,6 +1864,7 @@ ephy_web_view_get_error_page (EphyWebView *view)
 
 static void
 format_network_error_page (const char  *uri,
+                           const char  *origin,
                            const char  *reason,
                            char       **page_title,
                            char       **message_title,
@@ -1874,7 +1875,7 @@ format_network_error_page (const char  *uri,
                            const char **button_accesskey,
                            const char **icon_name)
 {
-  char *formatted_uri;
+  char *formatted_origin;
   char *formatted_reason;
   char *first_paragraph;
   const char *second_paragraph;
@@ -1885,11 +1886,11 @@ format_network_error_page (const char  *uri,
   /* Message title when a site cannot be loaded due to a network error. */
   *message_title = g_strdup (_("Unable to display this website"));
 
-  formatted_uri = g_strdup_printf ("<strong>%s</strong>", uri);
+  formatted_origin = g_strdup_printf ("<strong>%s</strong>", origin);
   /* Error details when a site cannot be loaded due to a network error. */
   first_paragraph = g_strdup_printf (_("The site at %s seems to be "
                                        "unavailable."),
-                                     formatted_uri);
+                                     formatted_origin);
   /* Further error details when a site cannot be loaded due to a network error. */
   second_paragraph = _("It may be temporarily inaccessible or moved to a new "
                        "address. You may wish to verify that your internet "
@@ -1913,7 +1914,7 @@ format_network_error_page (const char  *uri,
 
   *icon_name = "network-error-symbolic.png";
 
-  g_free (formatted_uri);
+  g_free (formatted_origin);
   g_free (formatted_reason);
   g_free (first_paragraph);
 }
@@ -1941,7 +1942,7 @@ format_crash_error_page (const char  *uri,
 
   formatted_uri = g_strdup_printf ("<strong>%s</strong>", uri);
   /* Error details when a site cannot be loaded due to a page crash error. */
-  first_paragraph = g_strdup_printf (_("The site at %s may have caused Web to "
+  first_paragraph = g_strdup_printf (_("The page %s may have caused Web to "
                                        "close unexpectedly."),
                                      formatted_uri);
 
@@ -2008,7 +2009,7 @@ format_process_crash_error_page (const char  *uri,
 
 static void
 format_tls_error_page (EphyWebView *view,
-                       const char  *hostname,
+                       const char  *origin,
                        char       **page_title,
                        char       **message_title,
                        char       **message_body,
@@ -2021,7 +2022,7 @@ format_tls_error_page (EphyWebView *view,
                        const char **hidden_button_accesskey,
                        const char **icon_name)
 {
-  char *formatted_hostname;
+  char *formatted_origin;
   char *first_paragraph;
 
   /* Page title when a site is not loaded due to an invalid TLS certificate. */
@@ -2030,13 +2031,13 @@ format_tls_error_page (EphyWebView *view,
   /* Message title when a site is not loaded due to an invalid TLS certificate. */
   *message_title = g_strdup (_("This Connection is Not Secure"));
 
-  formatted_hostname = g_strdup_printf ("<strong>%s</strong>", hostname);
+  formatted_origin = g_strdup_printf ("<strong>%s</strong>", origin);
   /* Error details when a site is not loaded due to an invalid TLS certificate. */
   first_paragraph = g_strdup_printf (_("This does not look like the real %s. "
                                        "Attackers might be trying to steal or "
                                        "alter information going to or from "
                                        "this site."),
-                                     formatted_hostname);
+                                     formatted_origin);
 
   *message_body = g_strdup_printf ("<p>%s</p>", first_paragraph);
   *message_details = detailed_message_from_tls_errors (view->tls_errors);
@@ -2056,7 +2057,7 @@ format_tls_error_page (EphyWebView *view,
 
   *icon_name = "channel-insecure-symbolic.png";
 
-  g_free (formatted_hostname);
+  g_free (formatted_origin);
   g_free (first_paragraph);
 }
 
@@ -2078,7 +2079,7 @@ ephy_web_view_load_error_page (EphyWebView         *view,
 {
   GBytes *html_file;
   GString *html = g_string_new ("");
-  char *hostname = NULL;
+  char *origin = NULL;
   char *lang = NULL;
   char *page_title = NULL;
   char *msg_title = NULL;
@@ -2106,9 +2107,9 @@ ephy_web_view_load_error_page (EphyWebView         *view,
 
   reason = error ? error->message : _("None specified");
 
-  hostname = ephy_string_get_host_name (uri);
-  if (hostname == NULL)
-    hostname = g_strdup (uri);
+  origin = ephy_uri_to_security_origin (uri);
+  if (origin == NULL)
+    origin = g_strdup (uri);
 
   lang = g_strdup (pango_language_to_string (gtk_get_default_language ()));
   g_strdelimit (lang, "_-@", '\0');
@@ -2118,6 +2119,7 @@ ephy_web_view_load_error_page (EphyWebView         *view,
   switch (page) {
     case EPHY_WEB_VIEW_ERROR_PAGE_NETWORK_ERROR:
       format_network_error_page (uri,
+                                 origin,
                                  reason,
                                  &page_title,
                                  &msg_title,
@@ -2150,7 +2152,7 @@ ephy_web_view_load_error_page (EphyWebView         *view,
       break;
     case EPHY_WEB_VIEW_ERROR_INVALID_TLS_CERTIFICATE:
       format_tls_error_page (view,
-                             hostname,
+                             origin,
                              &page_title,
                              &msg_title,
                              &msg_body,
@@ -2194,7 +2196,7 @@ ephy_web_view_load_error_page (EphyWebView         *view,
 #pragma GCC diagnostic pop
 
   g_bytes_unref (html_file);
-  g_free (hostname);
+  g_free (origin);
   g_free (lang);
   g_free (page_title);
   g_free (msg_title);


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