Hi, hopefully this patch will be useful for those doing web development
with surf or hacking surf itself. Briefly:

-l <L> set stdout log level L as described in

http://library.gnome.org/devel/libsoup/unstable/SoupLogger.html#SoupLoggerLogLevel

-n enables web inspector

http://trac.webkit.org/wiki/WebInspector

By default both options are turned off.

Best regards
--
Carlos

diff -N -up surf-0.4.1/inspector.c surf-0.4.1-devel/inspector.c
--- surf-0.4.1/inspector.c      1969-12-31 21:00:00.000000000 -0300
+++ surf-0.4.1-devel/inspector.c        2010-07-09 17:21:46.000000000 -0300
@@ -0,0 +1,47 @@
+static gboolean inspector = FALSE;
+
+gboolean
+showinspectorwindow(WebKitWebInspector* inspector, gpointer data) {
+  Client* c = (Client*) data;
+  gtk_widget_show(c->inspector_win);
+  return true;
+}
+
+void
+hideinspectorwindow(GtkWidget *widget, gpointer data) {
+  gtk_widget_hide(widget);
+}
+
+WebKitWebView*
+inspectwebview(WebKitWebInspector* web_inspector, WebKitWebView* page, 
gpointer data) {
+  Client* c = (Client*) data;
+  GtkWidget* scrolled_window;
+  GtkWidget* new_web_view;
+
+  c->inspector_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+  g_signal_connect(G_OBJECT(c->inspector_win), "delete-event", 
G_CALLBACK(hideinspectorwindow), NULL);
+
+  gtk_window_set_title(GTK_WINDOW(c->inspector_win), "Surf WebInspector");
+  gtk_window_set_default_size(GTK_WINDOW(c->inspector_win), 400, 300);
+  gtk_widget_show(c->inspector_win);
+
+  scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
+          GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+  gtk_container_add(GTK_CONTAINER(c->inspector_win), scrolled_window);
+  gtk_widget_show(scrolled_window);
+
+  new_web_view = webkit_web_view_new();
+  gtk_container_add(GTK_CONTAINER(scrolled_window), new_web_view);
+
+  return WEBKIT_WEB_VIEW(new_web_view);
+}
+
+void
+setupinspector(Client *c, WebKitWebSettings *settings) {
+  if (!inspector) return;
+  g_object_set(G_OBJECT(settings), "enable-developer-extras", inspector, NULL);
+  c->inspector = webkit_web_view_get_inspector(c->view);
+  g_signal_connect(G_OBJECT (c->inspector), "inspect-web-view", 
G_CALLBACK(inspectwebview), (gpointer) c);
+  g_signal_connect(G_OBJECT (c->inspector), "show-window", 
G_CALLBACK(showinspectorwindow), (gpointer) c);
+}
diff -N -up surf-0.4.1/Makefile surf-0.4.1-devel/Makefile
--- surf-0.4.1/Makefile 2010-06-08 04:06:41.000000000 -0300
+++ surf-0.4.1-devel/Makefile   2010-07-09 17:27:23.000000000 -0300
@@ -18,7 +18,7 @@ options:
        @echo CC $<
        @${CC} -c ${CFLAGS} $<
 
-${OBJ}: config.h config.mk
+${OBJ}: config.h config.mk inspector.c
 
 config.h:
        @echo creating $@ from config.def.h
diff -N -up surf-0.4.1/surf.c surf-0.4.1-devel/surf.c
--- surf-0.4.1/surf.c   2010-06-08 04:06:42.000000000 -0300
+++ surf-0.4.1-devel/surf.c     2010-07-09 17:28:07.000000000 -0300
@@ -40,6 +40,8 @@ typedef struct Client {
        gint progress;
        struct Client *next;
        gboolean zoomed;
+  GtkWidget *inspector_win;
+  WebKitWebInspector *inspector;
 } Client;
 
 typedef struct {
@@ -63,6 +65,7 @@ static gboolean showxid = FALSE;
 static char winid[64];
 static char *progname;
 static gboolean loadimage = 1, plugin = 1, script = 1;
+static SoupLoggerLogLevel log = SOUP_LOGGER_LOG_NONE;
 
 static char *buildpath(const char *path);
 static void cleanup(void);
@@ -113,6 +116,7 @@ static void zoom(Client *c, const Arg *a
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
+#include "inspector.c"
 
 char *
 buildpath(const char *path) {
@@ -502,6 +506,8 @@ newclient(void) {
        g_object_set(G_OBJECT(settings), "enable-scripts", script, NULL);
        g_object_set(G_OBJECT(settings), "enable-spatial-navigation", true, 
NULL);
 
+  setupinspector(c, settings);
+
        g_free(uri);
 
        setatom(c, AtomFind, "");
@@ -697,6 +703,8 @@ setup(void) {
        soup_session_remove_feature_by_type(s, soup_cookie_get_type());
        soup_session_remove_feature_by_type(s, soup_cookie_jar_get_type());
        g_signal_connect_after(G_OBJECT(s), "request-started", 
G_CALLBACK(newrequest), NULL);
+  if(log != SOUP_LOGGER_LOG_NONE)
+    soup_session_add_feature(s, SOUP_SESSION_FEATURE(soup_logger_new(log, 
-1)));
 
        /* proxy */
        if((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
@@ -774,7 +782,7 @@ updatewinid(Client *c) {
 void
 usage(void) {
        fputs("surf - simple browser\n", stderr);
-       die("usage: surf [-e xid] [-i] [-p] [-s] [-v] [-x] [uri]\n");
+       die("usage: surf [-e xid] [-i] [-p] [-s] [-v] [-n] [-x] [-l L] 
[uri]\n");
 }
 
 void
@@ -827,6 +835,15 @@ main(int argc, char *argv[]) {
                case 'x':
                        showxid = TRUE;
                        break;
+               case 'n':
+                       inspector = TRUE;
+                       break;
+               case 'l':
+      if(++i < argc)
+                       log = atoi(argv[i]);
+      else
+        usage();
+                       break;
                case 'v':
                        die("surf-"VERSION", © 2009 surf engineers, see LICENSE 
for details\n");
                default:

Reply via email to