diff options
author | Gabriel Ivascu <gabrielivascu@gnome.org> | 2017-10-18 18:14:38 +0300 |
---|---|---|
committer | Gabriel Ivascu <gabrielivascu@gnome.org> | 2017-10-18 22:03:24 +0300 |
commit | 22c6aec089ff440f05fe3cdf3b668942d12bab6c (patch) | |
tree | 6f37404a727e4904cb299a93c5bd7970af1a71fc | |
parent | 6d54eef8489d2d4d81c1a63482a912616d378966 (diff) | |
download | epiphany-22c6aec089ff440f05fe3cdf3b668942d12bab6c.tar.gz |
Move safe browsing verification from EphyWebView to EphyWindow
https://bugzilla.gnome.org/show_bug.cgi?id=788899
-rw-r--r-- | embed/ephy-web-view.c | 107 | ||||
-rw-r--r-- | embed/ephy-web-view.h | 3 | ||||
-rw-r--r-- | src/ephy-window.c | 119 |
3 files changed, 135 insertions, 94 deletions
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c index f0ba23a54..b6ad01051 100644 --- a/embed/ephy-web-view.c +++ b/embed/ephy-web-view.c @@ -79,7 +79,6 @@ struct _EphyWebView { guint load_failed : 1; guint history_frozen : 1; guint ever_committed : 1; - guint bypass_gsb_verification : 1; char *address; char *display_address; @@ -120,6 +119,7 @@ struct _EphyWebView { GTlsCertificate *certificate; GTlsCertificateFlags tls_errors; + gboolean bypass_safe_browsing; gboolean loading_error_page; char *tls_error_failing_uri; @@ -836,7 +836,7 @@ allow_unsafe_browsing_cb (EphyEmbedShell *shell, if (webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)) != page_id) return; - view->bypass_gsb_verification = TRUE; + ephy_web_view_set_should_bypass_safe_browsing (view, TRUE); ephy_web_view_load_url (view, ephy_web_view_get_address (view)); } @@ -1277,74 +1277,12 @@ new_window_cb (EphyWebView *view, popups_manager_add_window (view, container); } -typedef struct { - EphyWebView *web_view; - WebKitPolicyDecision *decision; - char *request_uri; -} VerifyUrlData; - -static inline VerifyUrlData * -verify_url_data_new (EphyWebView *web_view, - WebKitPolicyDecision *decision, - const char *request_uri) -{ - VerifyUrlData *data = g_slice_new (VerifyUrlData); - - data->web_view = g_object_ref (web_view); - data->decision = g_object_ref (decision); - data->request_uri = g_strdup (request_uri); - - return data; -} - -static inline void -verify_url_data_free (VerifyUrlData *data) -{ - g_object_unref (data->web_view); - g_object_unref (data->decision); - g_free (data->request_uri); - g_slice_free (VerifyUrlData, data); -} - -static void -verify_url_cb (GHashTable *threats, - gpointer user_data) -{ - VerifyUrlData *data = (VerifyUrlData *)user_data; - EphyGSBThreatList *list; - GList *threat_lists; - - if (g_hash_table_size (threats) == 0) { - webkit_policy_decision_use (data->decision); - goto out; - } - - webkit_policy_decision_ignore (data->decision); - - /* Very rarely there are URLs that pose multiple types of threats. - * However, inform the user only about the first threat type. - */ - threat_lists = g_hash_table_get_keys (threats); - list = threat_lists->data; - ephy_web_view_load_error_page (data->web_view, data->request_uri, - EPHY_WEB_VIEW_ERROR_UNSAFE_BROWSING, - NULL, list->threat_type); - - g_list_free (threat_lists); -out: - g_hash_table_unref (threats); - verify_url_data_free (data); -} - static gboolean decide_policy_cb (WebKitWebView *web_view, WebKitPolicyDecision *decision, WebKitPolicyDecisionType decision_type, gpointer user_data) { - EphyGSBService *service; - WebKitNavigationPolicyDecision *navigation_decision; - WebKitNavigationAction *action; WebKitResponsePolicyDecision *response_decision; WebKitURIResponse *response; WebKitURIRequest *request; @@ -1353,30 +1291,6 @@ decide_policy_cb (WebKitWebView *web_view, const char *mime_type; const char *request_uri; - if (decision_type == WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION) { - if (!g_settings_get_boolean (EPHY_SETTINGS_WEB, - EPHY_PREFS_WEB_ENABLE_SAFE_BROWSING)) - return FALSE; - - if (EPHY_WEB_VIEW (web_view)->bypass_gsb_verification) { - EPHY_WEB_VIEW (web_view)->bypass_gsb_verification = FALSE; - return FALSE; - } - - navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision); - action = webkit_navigation_policy_decision_get_navigation_action (navigation_decision); - request = webkit_navigation_action_get_request (action); - request_uri = webkit_uri_request_get_uri (request); - - service = ephy_embed_shell_get_global_gsb_service (ephy_embed_shell_get_default ()); - ephy_gsb_service_verify_url (service, request_uri, verify_url_cb, - verify_url_data_new (EPHY_WEB_VIEW (web_view), - decision, request_uri)); - - /* Delay decision until the safe browsing verification has completed. */ - return TRUE; - } - if (decision_type != WEBKIT_POLICY_DECISION_TYPE_RESPONSE) return FALSE; @@ -3111,6 +3025,23 @@ ephy_web_view_set_typed_address (EphyWebView *view, g_object_notify_by_pspec (G_OBJECT (view), obj_properties[PROP_TYPED_ADDRESS]); } +gboolean +ephy_web_view_get_should_bypass_safe_browsing (EphyWebView *view) +{ + g_assert (EPHY_IS_WEB_VIEW (view)); + + return view->bypass_safe_browsing; +} + +void +ephy_web_view_set_should_bypass_safe_browsing (EphyWebView *view, + gboolean bypass_safe_browsing) +{ + g_assert (EPHY_IS_WEB_VIEW (view)); + + view->bypass_safe_browsing = bypass_safe_browsing; +} + static void has_modified_forms_cb (EphyWebExtensionProxy *web_extension, GAsyncResult *result, diff --git a/embed/ephy-web-view.h b/embed/ephy-web-view.h index 49da569b9..765a27fd5 100644 --- a/embed/ephy-web-view.h +++ b/embed/ephy-web-view.h @@ -91,6 +91,9 @@ void ephy_web_view_set_security_level (EphyWebView const char * ephy_web_view_get_typed_address (EphyWebView *view); void ephy_web_view_set_typed_address (EphyWebView *view, const char *address); +gboolean ephy_web_view_get_should_bypass_safe_browsing (EphyWebView *view); +void ephy_web_view_set_should_bypass_safe_browsing (EphyWebView *view, + gboolean bypass_safe_browsing); gboolean ephy_web_view_get_is_blank (EphyWebView *view); gboolean ephy_web_view_is_overview (EphyWebView *view); void ephy_web_view_has_modified_forms (EphyWebView *view, diff --git a/src/ephy-window.c b/src/ephy-window.c index b0c0024cd..5009ebcc6 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -34,6 +34,7 @@ #include "ephy-embed-utils.h" #include "ephy-file-helpers.h" #include "ephy-find-toolbar.h" +#include "ephy-gsb-utils.h" #include "ephy-gui.h" #include "ephy-header-bar.h" #include "ephy-link.h" @@ -1875,11 +1876,47 @@ create_web_view_cb (WebKitWebView *web_view, return new_web_view; } +typedef struct { + EphyWindow *window; + WebKitWebView *web_view; + WebKitPolicyDecision *decision; + WebKitPolicyDecisionType decision_type; + char *request_uri; +} VerifyUrlAsyncData; + +static inline VerifyUrlAsyncData * +verify_url_async_data_new (EphyWindow *window, + WebKitWebView *web_view, + WebKitPolicyDecision *decision, + WebKitPolicyDecisionType decision_type, + const char *request_uri) +{ + VerifyUrlAsyncData *data = g_slice_new (VerifyUrlAsyncData); + + data->window = g_object_ref (window); + data->web_view = g_object_ref (web_view); + data->decision = g_object_ref (decision); + data->decision_type = decision_type; + data->request_uri = g_strdup (request_uri); + + return data; +} + +static inline void +verify_url_async_data_free (VerifyUrlAsyncData *data) +{ + g_object_unref (data->window); + g_object_unref (data->web_view); + g_object_unref (data->decision); + g_free (data->request_uri); + g_slice_free (VerifyUrlAsyncData, data); +} + static gboolean -decide_policy_cb (WebKitWebView *web_view, - WebKitPolicyDecision *decision, - WebKitPolicyDecisionType decision_type, - EphyWindow *window) +decide_navigation_policy (WebKitWebView *web_view, + WebKitPolicyDecision *decision, + WebKitPolicyDecisionType decision_type, + EphyWindow *window) { WebKitNavigationPolicyDecision *navigation_decision; WebKitNavigationAction *navigation_action; @@ -1888,8 +1925,10 @@ decide_policy_cb (WebKitWebView *web_view, const char *uri; EphyEmbed *embed; - if (decision_type == WEBKIT_POLICY_DECISION_TYPE_RESPONSE) - return FALSE; + g_assert (WEBKIT_IS_WEB_VIEW (web_view)); + g_assert (WEBKIT_IS_NAVIGATION_POLICY_DECISION (decision)); + g_assert (decision_type != WEBKIT_POLICY_DECISION_TYPE_RESPONSE); + g_assert (EPHY_IS_WINDOW (window)); navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision); navigation_action = webkit_navigation_policy_decision_get_navigation_action (navigation_decision); @@ -2031,6 +2070,74 @@ decide_policy_cb (WebKitWebView *web_view, } static void +verify_url_cb (GHashTable *threats, + gpointer user_data) +{ + VerifyUrlAsyncData *data = user_data; + + if (g_hash_table_size (threats) > 0) { + GList *threat_lists = g_hash_table_get_keys (threats); + EphyGSBThreatList *list = threat_lists->data; + + webkit_policy_decision_ignore (data->decision); + + /* Very rarely there are URLs that pose multiple types of threats. + * However, inform the user only about the first threat type. + */ + ephy_web_view_load_error_page (EPHY_WEB_VIEW (data->web_view), + data->request_uri, + EPHY_WEB_VIEW_ERROR_UNSAFE_BROWSING, + NULL, list->threat_type); + + g_list_free (threat_lists); + } else { + decide_navigation_policy (data->web_view, data->decision, + data->decision_type, data->window); + } + + g_hash_table_unref (threats); + verify_url_async_data_free (data); +} + +static gboolean +decide_policy_cb (WebKitWebView *web_view, + WebKitPolicyDecision *decision, + WebKitPolicyDecisionType decision_type, + EphyWindow *window) +{ + EphyGSBService *service; + WebKitNavigationPolicyDecision *navigation_decision; + WebKitNavigationAction *navigation_action; + WebKitURIRequest *request; + const char *request_uri; + + if (decision_type == WEBKIT_POLICY_DECISION_TYPE_RESPONSE) + return FALSE; + + navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision); + navigation_action = webkit_navigation_policy_decision_get_navigation_action (navigation_decision); + request = webkit_navigation_action_get_request (navigation_action); + request_uri = webkit_uri_request_get_uri (request); + + if (g_settings_get_boolean (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_ENABLE_SAFE_BROWSING)) { + if (ephy_web_view_get_should_bypass_safe_browsing (EPHY_WEB_VIEW (web_view))) { + /* This means the user has decided to proceed to an unsafe website. */ + ephy_web_view_set_should_bypass_safe_browsing (EPHY_WEB_VIEW (web_view), FALSE); + return decide_navigation_policy (web_view, decision, decision_type, window); + } + + service = ephy_embed_shell_get_global_gsb_service (ephy_embed_shell_get_default ()); + ephy_gsb_service_verify_url (service, request_uri, verify_url_cb, + verify_url_async_data_new (window, web_view, + decision, decision_type, + request_uri)); + return TRUE; + } + + return decide_navigation_policy (web_view, decision, decision_type, window); +} + +static void ephy_window_connect_active_embed (EphyWindow *window) { EphyEmbed *embed; |