[epiphany/gnome-3-20] web-view: limit permission request info bars



commit 6ee2083665d8c78cbbf561389a49095953df8e53
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Aug 7 22:04:19 2016 -0500

    web-view: limit permission request info bars
    
    Else a web page can fill the browser window with unlimited notification
    permission requests. Limit ourselves to one info bar per permission
    request type, same as we already limit ourselves to one password info
    bar.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764593

 embed/ephy-web-view.c |   50 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 39 insertions(+), 11 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 7fb006c..ebd8944 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -95,6 +95,8 @@ struct _EphyWebView {
   GSList *hidden_popups;
   GSList *shown_popups;
 
+  GtkWidget *geolocation_info_bar;
+  GtkWidget *notification_info_bar;
   GtkWidget *password_info_bar;
 
   EphyHistoryService *history_service;
@@ -479,6 +481,26 @@ ephy_web_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
   return GTK_WIDGET_CLASS (ephy_web_view_parent_class)->button_press_event (widget, event);
 }
 
+static void
+ephy_web_view_track_info_bar (GtkWidget  *new_info_bar,
+                              GtkWidget **tracked_info_bar)
+{
+  g_assert (GTK_IS_INFO_BAR (new_info_bar));
+  g_assert (tracked_info_bar);
+  g_assert (!*tracked_info_bar || GTK_IS_INFO_BAR (*tracked_info_bar));
+
+  /* We track info bars so we only ever show one of a kind. */
+  if (*tracked_info_bar) {
+    g_object_remove_weak_pointer (G_OBJECT (*tracked_info_bar),
+                                  (gpointer *)tracked_info_bar);
+    gtk_widget_destroy (*tracked_info_bar);
+  }
+
+  *tracked_info_bar = new_info_bar;
+  g_object_add_weak_pointer (G_OBJECT (new_info_bar),
+                             (gpointer *)tracked_info_bar);
+}
+
 static GtkWidget *
 ephy_web_view_create_form_auth_save_confirmation_info_bar (EphyWebView *web_view,
                                                            const char  *hostname,
@@ -514,20 +536,11 @@ ephy_web_view_create_form_auth_save_confirmation_info_bar (EphyWebView *web_view
   gtk_container_add (GTK_CONTAINER (content_area), label);
   gtk_widget_show (label);
 
+  ephy_web_view_track_info_bar (info_bar, &web_view->password_info_bar);
+
   ephy_embed_add_top_widget (EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (web_view),
                              info_bar, FALSE);
 
-  if (web_view->password_info_bar) {
-    g_object_remove_weak_pointer (G_OBJECT (web_view->password_info_bar),
-                                  (gpointer *)&web_view->password_info_bar);
-    gtk_widget_destroy (web_view->password_info_bar);
-  }
-
-  /* We track the info_bar, so we only ever show one */
-  web_view->password_info_bar = info_bar;
-  g_object_add_weak_pointer (G_OBJECT (info_bar),
-                             (gpointer *)&web_view->password_info_bar);
-
   return info_bar;
 }
 
@@ -760,6 +773,16 @@ ephy_web_view_dispose (GObject *object)
     view->web_extension = NULL;
   }
 
+  if (view->geolocation_info_bar) {
+    g_object_remove_weak_pointer (G_OBJECT (view->geolocation_info_bar), (gpointer 
*)&view->geolocation_info_bar);
+    view->geolocation_info_bar = NULL;
+  }
+
+  if (view->notification_info_bar) {
+    g_object_remove_weak_pointer (G_OBJECT (view->notification_info_bar), (gpointer 
*)&view->notification_info_bar);
+    view->notification_info_bar = NULL;
+  }
+
   if (view->password_info_bar) {
     g_object_remove_weak_pointer (G_OBJECT (view->password_info_bar), (gpointer *)&view->password_info_bar);
     view->password_info_bar = NULL;
@@ -1293,6 +1316,11 @@ permission_request_cb (WebKitWebView           *web_view,
                     G_CALLBACK (decide_on_permission_request),
                     g_object_ref (decision));
 
+  if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST (decision))
+    ephy_web_view_track_info_bar (info_bar, &EPHY_WEB_VIEW (web_view)->geolocation_info_bar);
+  else
+    ephy_web_view_track_info_bar (info_bar, &EPHY_WEB_VIEW (web_view)->notification_info_bar);
+
   ephy_embed_add_top_widget (EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (web_view),
                              info_bar, TRUE);
 


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