Remove windowobjectcleared(), execute scripts on load finished
[surf.git] / surf.c
diff --git a/surf.c b/surf.c
index 6bf7989..eb57824 100644 (file)
--- a/surf.c
+++ b/surf.c
@@ -161,6 +161,7 @@ static Client *newclient(Client *c);
 static WebKitWebView *newview(Client *c, WebKitWebView *rv);
 static void showview(WebKitWebView *v, Client *c);
 static void newwindow(Client *c, const Arg *arg, gboolean noembed);
+static GtkWidget *createwindow(Client *c);
 static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
 static void print(Client *c, const Arg *arg);
 static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event,
@@ -187,8 +188,6 @@ static void togglestyle(Client *c, const Arg *arg);
 static void updatetitle(Client *c);
 static void updatewinid(Client *c);
 static void usage(void);
-static void windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame,
-                                JSContextRef js, JSObjectRef win, Client *c);
 static void zoom(Client *c, const Arg *arg);
 
 /* configuration, allows nested code to access above variables */
@@ -992,9 +991,6 @@ newview(Client *c, WebKitWebView *rv)
        g_signal_connect(G_OBJECT(v),
                         "decide-policy",
                         G_CALLBACK(decidepolicy), c);
-       g_signal_connect(G_OBJECT(v),
-                        "window-object-cleared",
-                        G_CALLBACK(windowobjectcleared), c);
        g_signal_connect(G_OBJECT(v),
                         "load-changed",
                         G_CALLBACK(loadchanged), c);
@@ -1017,33 +1013,7 @@ showview(WebKitWebView *v, Client *c)
        GdkRGBA bgcolor = { 0 };
        GdkWindow *gwin;
 
-       /* Window */
-       if (embed) {
-               c->win = gtk_plug_new(embed);
-       } else {
-               c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-
-               /* TA:  20091214:  Despite what the GNOME docs say, the ICCCM
-                * is always correct, so we should still call this function.
-                * But when doing so, we *must* differentiate between a
-                * WM_CLASS and a resource on the window.  By convention, the
-                * window class (WM_CLASS) is capped, while the resource is in
-                * lowercase.   Both these values come as a pair.
-                */
-               gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "Surf");
-
-               /* TA:  20091214:  And set the role here as well -- so that
-                * sessions can pick this up.
-                */
-               gtk_window_set_role(GTK_WINDOW(c->win), "Surf");
-       }
-       gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
-       g_signal_connect(G_OBJECT(c->win),
-                        "destroy",
-                        G_CALLBACK(destroywin), c);
-       g_signal_connect(G_OBJECT(c->win),
-                        "leave_notify_event",
-                        G_CALLBACK(titlechangeleave), c);
+       c->win = createwindow(c);
 
        if (!kioskmode)
                addaccelgroup(c);
@@ -1062,8 +1032,6 @@ showview(WebKitWebView *v, Client *c)
        gdk_window_set_events(gwin, GDK_ALL_EVENTS_MASK);
        gdk_window_add_filter(gwin, processx, c);
 
-       runscript(frame);
-
        /* This might conflict with _zoomto96dpi_. */
        if (zoomlevel != 1.0)
                webkit_web_view_set_zoom_level(c->view, zoomlevel);
@@ -1128,6 +1096,41 @@ newwindow(Client *c, const Arg *arg, gboolean noembed)
        spawn(NULL, &a);
 }
 
+GtkWidget *
+createwindow(Client *c)
+{
+       GtkWidget *w;
+
+       if (embed) {
+               w = gtk_plug_new(embed);
+       } else {
+               w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+
+               /* TA:  20091214:  Despite what the GNOME docs say, the ICCCM
+                * is always correct, so we should still call this function.
+                * But when doing so, we *must* differentiate between a
+                * WM_CLASS and a resource on the window.  By convention, the
+                * window class (WM_CLASS) is capped, while the resource is in
+                * lowercase.   Both these values come as a pair.
+                */
+               gtk_window_set_wmclass(GTK_WINDOW(w), "surf", "Surf");
+
+               /* TA:  20091214:  And set the role here as well -- so that
+                * sessions can pick this up.
+                */
+               gtk_window_set_role(GTK_WINDOW(w), "Surf");
+
+               gtk_window_set_default_size(GTK_WINDOW(w), 800, 600);
+       }
+
+       g_signal_connect(G_OBJECT(w), "destroy",
+           G_CALLBACK(destroywin), c);
+       g_signal_connect(G_OBJECT(w), "leave_notify_event",
+           G_CALLBACK(titlechangeleave), c);
+
+       return w;
+}
+
 void
 pasteuri(GtkClipboard *clipboard, const char *text, gpointer d)
 {
@@ -1518,13 +1521,6 @@ usage(void)
            "[-u useragent] [-z zoomlevel] [uri]\n", basename(argv0));
 }
 
-void
-windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js,
-                    JSObjectRef win, Client *c)
-{
-       runscript(frame);
-}
-
 void
 zoom(Client *c, const Arg *arg)
 {