[epiphany/wip/google-safe-browsing: 34/57] web-view: Add unsafe browsing error page



commit 6400b159a1701d07c42a73bdaa5c6962a838576c
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Sep 18 11:36:08 2016 -0500

    web-view: Add unsafe browsing error page

 embed/ephy-web-view.c                    |  106 +++++++++++++++++++++++++++---
 embed/ephy-web-view.h                    |    3 +-
 src/resources/epiphany.gresource.xml     |    1 +
 src/resources/security-high-symbolic.png |  Bin 0 -> 703 bytes
 4 files changed, 100 insertions(+), 10 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 0ebdc56..c83e564 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1956,7 +1956,8 @@ format_network_error_page (const char  *uri,
                            char       **button_label,
                            char       **button_action,
                            const char **button_accesskey,
-                           const char **icon_name)
+                           const char **icon_name,
+                           const char **style)
 {
   char *formatted_origin;
   char *formatted_reason;
@@ -1996,6 +1997,7 @@ format_network_error_page (const char  *uri,
   *button_accesskey = C_("reload-access-key", "R");
 
   *icon_name = "network-error-symbolic.png";
+  *style = "default";
 
   g_free (formatted_origin);
   g_free (formatted_reason);
@@ -2010,7 +2012,8 @@ format_crash_error_page (const char  *uri,
                          char       **button_label,
                          char       **button_action,
                          const char **button_accesskey,
-                         const char **icon_name)
+                         const char **icon_name,
+                         const char **style)
 {
   char *formatted_uri;
   char *formatted_distributor;
@@ -2047,6 +2050,7 @@ format_crash_error_page (const char  *uri,
   *button_accesskey = C_("reload-access-key", "R");
 
   *icon_name = "computer-fail-symbolic.png";
+  *style = "default";
 
   g_free (formatted_uri);
   g_free (formatted_distributor);
@@ -2062,7 +2066,8 @@ format_process_crash_error_page (const char  *uri,
                                  char       **button_label,
                                  char       **button_action,
                                  const char **button_accesskey,
-                                 const char **icon_name)
+                                 const char **icon_name,
+                                 const char **style)
 {
   const char *first_paragraph;
   const char *second_paragraph;
@@ -2088,6 +2093,7 @@ format_process_crash_error_page (const char  *uri,
   *button_accesskey = C_("reload-access-key", "R");
 
   *icon_name = "computer-fail-symbolic.png";
+  *style = "default";
 }
 
 static void
@@ -2103,7 +2109,8 @@ format_tls_error_page (EphyWebView *view,
                        char       **hidden_button_label,
                        char       **hidden_button_action,
                        const char **hidden_button_accesskey,
-                       const char **icon_name)
+                       const char **icon_name,
+                       const char **style)
 {
   char *formatted_origin;
   char *first_paragraph;
@@ -2139,6 +2146,65 @@ format_tls_error_page (EphyWebView *view,
   *hidden_button_accesskey = C_("proceed-anyway-access-key", "P");
 
   *icon_name = "channel-insecure-symbolic.png";
+  *style = "danger";
+
+  g_free (formatted_origin);
+  g_free (first_paragraph);
+}
+
+static void
+format_unsafe_browsing_error_page (EphyWebView *view,
+                                   const char  *origin,
+                                   char       **page_title,
+                                   char       **message_title,
+                                   char       **message_body,
+                                   char       **message_details,
+                                   char       **button_label,
+                                   char       **button_action,
+                                   const char **button_accesskey,
+                                   char       **hidden_button_label,
+                                   char       **hidden_button_action,
+                                   const char **hidden_button_accesskey,
+                                   const char **icon_name,
+                                   const char **style)
+{
+  char *formatted_origin;
+  char *first_paragraph;
+
+  /* Page title when a site is flagged by Google Safe Browsing verification. */
+  *page_title = g_strdup_printf (_("Security Warning"));
+
+  /* Message title on the unsafe browsing error page. */
+  *message_title = g_strdup (_("Unsafe website detected!"));
+
+  formatted_origin = g_strdup_printf ("<strong>%s</strong>", origin);
+  /* Error details on the unsafe browsing error page. */
+  first_paragraph = g_strdup_printf (_("%s is reported to be unsafe. It might "
+                                       "trick you by pretending to be a "
+                                       "different website to steal your "
+                                       "information, or it might harm "
+                                       "your computer by installing malicious "
+                                       "software."), /* FIXME: be more accurate */
+                                     formatted_origin);
+
+  *message_body = g_strdup_printf ("<p>%s</p>", first_paragraph);
+  *message_details = g_strdup (""); /* FIXME */
+
+  /* The button on unsafe browsing error page. DO NOT ADD MNEMONICS HERE. */
+  *button_label = g_strdup (_("Go Back"));
+  *button_action = g_strdup ("window.history.back();");
+  /* Mnemonic for the Go Back button on the unsafe browsing error page. */
+  *button_accesskey = C_("back-access-key", "B");
+
+  /* The hidden button on the unsafe browsing error page. Do not add mnemonics here. */
+  *hidden_button_label = g_strdup (_("Accept Risk and Proceed"));
+  *hidden_button_action = g_strdup_printf 
("window.webkit.messageHandlers.unsafeBrowsingErrorPage.postMessage(%"G_GUINT64_FORMAT ");",
+                                           webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)));
+  /* Mnemonic for the Accept Risk and Proceed button on the unsafe browsing error page. */
+  *hidden_button_accesskey = C_("proceed-anyway-access-key", "P");
+
+  *icon_name = "security-high-symbolic.png";
+  *style = "danger";
 
   g_free (formatted_origin);
   g_free (first_paragraph);
@@ -2176,6 +2242,7 @@ ephy_web_view_load_error_page (EphyWebView         *view,
   const char *button_accesskey = NULL;
   const char *hidden_button_accesskey = NULL;
   const char *icon_name = NULL;
+  const char *style = NULL;
   const char *reason = NULL;
 
   g_assert (page != EPHY_WEB_VIEW_ERROR_PAGE_NONE);
@@ -2211,7 +2278,8 @@ ephy_web_view_load_error_page (EphyWebView         *view,
                                  &button_label,
                                  &button_action,
                                  &button_accesskey,
-                                 &icon_name);
+                                 &icon_name,
+                                 &style);
       break;
     case EPHY_WEB_VIEW_ERROR_PAGE_CRASH:
       format_crash_error_page (uri,
@@ -2221,7 +2289,8 @@ ephy_web_view_load_error_page (EphyWebView         *view,
                                &button_label,
                                &button_action,
                                &button_accesskey,
-                               &icon_name);
+                               &icon_name,
+                               &style);
       break;
     case EPHY_WEB_VIEW_ERROR_PROCESS_CRASH:
       format_process_crash_error_page (uri,
@@ -2231,7 +2300,8 @@ ephy_web_view_load_error_page (EphyWebView         *view,
                                        &button_label,
                                        &button_action,
                                        &button_accesskey,
-                                       &icon_name);
+                                       &icon_name,
+                                       &style);
       break;
     case EPHY_WEB_VIEW_ERROR_INVALID_TLS_CERTIFICATE:
       format_tls_error_page (view,
@@ -2246,8 +2316,26 @@ ephy_web_view_load_error_page (EphyWebView         *view,
                              &hidden_button_label,
                              &hidden_button_action,
                              &hidden_button_accesskey,
-                             &icon_name);
+                             &icon_name,
+                             &style);
+      break;
+    case EPHY_WEB_VIEW_ERROR_UNSAFE_BROWSING:
+      format_unsafe_browsing_error_page (view,
+                                         origin,
+                                         &page_title,
+                                         &msg_title,
+                                         &msg_body,
+                                         &msg_details,
+                                         &button_label,
+                                         &button_action,
+                                         &button_accesskey,
+                                         &hidden_button_label,
+                                         &hidden_button_action,
+                                         &hidden_button_accesskey,
+                                         &icon_name,
+                                         &style);
       break;
+
     case EPHY_WEB_VIEW_ERROR_PAGE_NONE:
     default:
       g_assert_not_reached ();
@@ -2268,7 +2356,7 @@ ephy_web_view_load_error_page (EphyWebView         *view,
                    style_sheet,
                    button_action, hidden_button_action,
                    icon_name,
-                   page == EPHY_WEB_VIEW_ERROR_INVALID_TLS_CERTIFICATE ? "danger" : "default",
+                   style,
                    msg_title, msg_body,
                    msg_details ? "visible" : "hidden",
                    _("Technical information"),
diff --git a/embed/ephy-web-view.h b/embed/ephy-web-view.h
index e2c79f0..f5bbdbe 100644
--- a/embed/ephy-web-view.h
+++ b/embed/ephy-web-view.h
@@ -65,7 +65,8 @@ typedef enum {
   EPHY_WEB_VIEW_ERROR_PAGE_NETWORK_ERROR,
   EPHY_WEB_VIEW_ERROR_PAGE_CRASH,
   EPHY_WEB_VIEW_ERROR_PROCESS_CRASH,
-  EPHY_WEB_VIEW_ERROR_INVALID_TLS_CERTIFICATE
+  EPHY_WEB_VIEW_ERROR_INVALID_TLS_CERTIFICATE,
+  EPHY_WEB_VIEW_ERROR_UNSAFE_BROWSING
 } EphyWebViewErrorPage;
 
 GType                      ephy_web_view_chrome_get_type          (void);
diff --git a/src/resources/epiphany.gresource.xml b/src/resources/epiphany.gresource.xml
index 80c9e7d..a33fe45 100644
--- a/src/resources/epiphany.gresource.xml
+++ b/src/resources/epiphany.gresource.xml
@@ -6,6 +6,7 @@
     <file>incognito.png</file>
     <file>missing-thumbnail.png</file>
     <file>network-error-symbolic.png</file>
+    <file>security-high-symbolic.png</file>
     <file compressed="true">about.ini</file>
     <file compressed="true">epiphany.css</file>
     <file alias="page-templates/about.css" compressed="true">about.css</file>
diff --git a/src/resources/security-high-symbolic.png b/src/resources/security-high-symbolic.png
new file mode 100644
index 0000000..bc5752b
Binary files /dev/null and b/src/resources/security-high-symbolic.png differ


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