summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Catanzaro <mcatanzaro@gnome.org>2016-08-07 22:04:19 -0500
committerMichael Catanzaro <mcatanzaro@gnome.org>2016-08-07 22:06:15 -0500
commit6ee2083665d8c78cbbf561389a49095953df8e53 (patch)
tree763f6fdbc5b1ec3d9ff5ddca7804f8a1d634eb98
parent24588da891eced576fd1b92a15272b786003566d (diff)
downloadepiphany-6ee2083665d8c78cbbf561389a49095953df8e53.tar.gz
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
-rw-r--r--embed/ephy-web-view.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 7fb006ccd..ebd89440d 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);