[Xfce4-commits] <midori:master> Show infobars instead of dialogues for alerts

Christian Dywan noreply at xfce.org
Mon Apr 4 03:04:01 CEST 2011


Updating branch refs/heads/master
         to 8134789973eb0038728747646cf98c4c2eaeb46f (commit)
       from b299608352e0a1c20416bed1e1d39dc71fc5742b (commit)

commit 8134789973eb0038728747646cf98c4c2eaeb46f
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Apr 4 02:59:16 2011 +0200

    Show infobars instead of dialogues for alerts
    
    Also limit the number of alerts to 5 at any one time.

 midori/midori-view.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/midori/midori-view.c b/midori/midori-view.c
index 679d8ba..1a73b7e 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -96,6 +96,7 @@ struct _MidoriView
     gboolean close_buttons_on_tabs;
     MidoriNewPage open_new_pages_in;
     gint find_links;
+    gint alerts;
 
     GtkWidget* menu_item;
     GtkWidget* tab_label;
@@ -1193,6 +1194,10 @@ midori_view_add_info_bar (MidoriView*    view,
     GtkWidget* content_area;
     va_list args;
     const gchar* button_text;
+
+    g_return_val_if_fail (message != NULL, NULL);
+    g_return_val_if_fail (response_cb != NULL, NULL);
+
     va_start (args, first_button_text);
 
     #if HAVE_GTK_INFO_BAR
@@ -3048,6 +3053,36 @@ webkit_web_view_console_message_cb (GtkWidget*   web_view,
     return TRUE;
 }
 
+static void
+midori_view_script_response_cb (GtkWidget*  infobar,
+                                gint        response,
+                                MidoriView* view)
+{
+    view->alerts--;
+}
+
+static gboolean
+midori_view_web_view_script_alert_cb (GtkWidget*      web_view,
+                                      WebKitWebFrame* web_frame,
+                                      const gchar*    message,
+                                      MidoriView*     view)
+{
+    gchar* text;
+
+    /* Allow a maximum of 5 alerts */
+    if (view->alerts > 4)
+        return TRUE;
+
+    view->alerts++;
+    /* i18n: The text of an infobar for JavaScript alert messages */
+    text = g_strdup_printf ("JavaScript: %s", message);
+    midori_view_add_info_bar (view, GTK_MESSAGE_WARNING, text,
+        G_CALLBACK (midori_view_script_response_cb), view,
+        GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
+    g_free (text);
+    return TRUE;
+}
+
 #if WEBKIT_CHECK_VERSION (1, 1, 5)
 static gboolean
 midori_view_web_view_print_requested_cb (GtkWidget*      web_view,
@@ -3147,6 +3182,7 @@ midori_view_init (MidoriView* view)
     view->selected_text = NULL;
     view->news_feeds = katze_array_new (KATZE_TYPE_ITEM);
     view->find_links = -1;
+    view->alerts = 0;
 
     view->item = katze_item_new ();
 
@@ -3680,6 +3716,8 @@ midori_view_construct_web_view (MidoriView* view)
                       webkit_web_view_populate_popup_cb, view,
                       "signal::console-message",
                       webkit_web_view_console_message_cb, view,
+                      "signal::script-alert",
+                      midori_view_web_view_script_alert_cb, view,
                       "signal::window-object-cleared",
                       webkit_web_view_window_object_cleared_cb, view,
                       "signal::create-web-view",



More information about the Xfce4-commits mailing list