Merge commit 'scj/master' into experimental
authorDieter Plaetinck <dieter@plaetinck.be>
Sat, 6 Jun 2009 20:04:09 +0000 (22:04 +0200)
committerDieter Plaetinck <dieter@plaetinck.be>
Sat, 6 Jun 2009 20:04:09 +0000 (22:04 +0200)
AUTHORS
Makefile-new-test [new file with mode: 0644]
docs/FAQ
docs/INSTALL
examples/configs/sampleconfig
examples/configs/sampleconfig-dev
examples/scripts/cookies.sh
examples/scripts/download.sh
examples/scripts/session.sh
uzbl.c
uzbl.h

diff --git a/AUTHORS b/AUTHORS
index 24597f1..ee9d1dc 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -18,6 +18,11 @@ Contributors:
     Sylvester Johansson (scj) - form filler script & different take on link follower 
     (mxf) - uzblcat
     Mark Nevill - misc patches
+    Uli Schlachter (psychon) - basic mime_policy_cb & Makefile patch
+    (uranther) - zoom level
+    (bobpaul) - session script patches
+    Tom Adams (holizz) - few patches
+    neutralinsomniac - load_progress = 0 fix
 
 Originaly based on http://trac.webkit.org/browser/trunk/WebKitTools/GtkLauncher/main.c
 Which is  copyrighted:
diff --git a/Makefile-new-test b/Makefile-new-test
new file mode 100644 (file)
index 0000000..5985c90
--- /dev/null
@@ -0,0 +1,51 @@
+LIBS      := gtk+-2.0 webkit-1.0
+ARCH      := $(shell uname -m)
+COMMIT    := $(shell git log | head -n1 | sed "s/.* //")
+DEBUG     := -ggdb -Wall -W -DG_ERRORCHECK_MUTEXES
+
+CFLAGS    := $(shell --cflags $(LIBS)) $(DEBUG) -DARCH="$(ARCH)" -DCOMMIT="\"$(COMMIT)\""
+LDFLAGS   := $(shell --libs $(LIBS)) $(LDFLAGS)
+
+PREFIX    ?= $(DESTDIR)/usr
+BINDIR    ?= $(PREFIX)/bin
+UZBLDATA  ?= $(PREFIX)/share/uzbl
+DOCSDIR   ?= $(PREFIX)/share/uzbl/docs
+EXMPLSDIR ?= $(PREFIX)/share/uzbl/examples
+
+all: uzbl uzblctrl
+
+uzbl: uzbl.c uzbl.h config.h
+
+%: %.c
+       $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBS) -o $@ $<
+
+test: uzbl
+       ./uzbl --uri http://www.uzbl.org
+
+test-config: uzbl
+       ./uzbl --uri http://www.uzbl.org < examples/configs/sampleconfig-dev
+
+test-config-real: uzbl
+       ./uzbl --uri http://www.uzbl.org < $(EXMPLSDIR)/configs/sampleconfig
+       
+clean:
+       rm -f uzbl
+       rm -f uzblctrl
+
+install:
+       install -d $(BINDIR)
+       install -d $(DOCSDIR)
+       install -d $(EXMPLSDIR)
+       install -D -m755 uzbl $(BINDIR)/uzbl
+       install -D -m755 uzblctrl $(BINDIR)/uzblctrl
+       cp -ax docs/*   $(DOCSDIR)
+       cp -ax config.h $(DOCSDIR)
+       cp -ax examples/* $(EXMPLSDIR)
+       install -D -m644 AUTHORS $(DOCSDIR)
+       install -D -m644 README $(DOCSDIR)
+
+
+uninstall:
+       rm -rf $(BINDIR)/uzbl
+       rm -rf $(BINDIR)/uzblctrl
+       rm -rf $(UZBLDATA)
index 7286ec7..79e1364 100644 (file)
--- a/docs/FAQ
+++ b/docs/FAQ
@@ -37,6 +37,10 @@ You have to look at the bigger picture.  In fact, we do support all these things
 These ideas are something we want to consistently apply throughout the entire application.  (Even more, throughout our entire desktop environment)
 In fact, we actually ship various sample scripts and some sample configs that make it easy for you to implement your workflow.
 
+### Okay, what can I actually do?  What commands are there?  How do I get more information?
+  * Commands and other features are documented in README.  Read it.
+  * You should also peek into the sampleconfigs to see how commands are used in practice.
+
 ### Why can't I type anything in forms?  How does the keybinding work?
 You are in command mode, not in insert mode.
 
index 3453e03..1c0d007 100644 (file)
@@ -1,11 +1,13 @@
-Arch Linux
-----------
+Packages
+--------
 [Arch Linux](http://www.archlinux.org) is our distro of choice, and the distro we use for testing.
 
 You can find a [PKGBUILD](http://aur.archlinux.org/packages.php?ID=25972) on the AUR, which installs the latest
 from the master branch. You can edit the PKGBUILD to change to any other
 branch you want.
 
+For other distros, see [uzbl.org/wiki/howtos](http://www.uzbl.org/wiki/howtos)
+
 From source
 -----------
 You can pull the code from git or get a tagged tarball.
index 621d438..e853836 100644 (file)
@@ -69,6 +69,8 @@ bind    r         = reload
 bind    R         = reload_ign_cache
 bind    +         = zoom_in
 bind    -         = zoom_out
+bind    1         = sh "echo set zoom_level = 1.0 > $4"
+bind    2         = sh "echo set zoom_level = 2.0 > $4"
 bind    t         = toggle_status
 # Hilight matches. Notice the * after the slash - it makes the command incremental, i.e. gets called
 # on every character you type.  You can do `bind /_ = search %s' if you want it less interactive.
index 3e2920f..ad6de24 100644 (file)
@@ -104,6 +104,8 @@ bind    r         = reload
 bind    R         = reload_ign_cache
 bind    +         = zoom_in
 bind    -         = zoom_out
+bind    1         = sh "echo set zoom_level = 1.0 > $4"
+bind    2         = sh "echo set zoom_level = 2.0 > $4"
 bind    t         = toggle_status
 # Hilight matches. Notice the * after the slash - it makes the command incremental, i.e. gets called
 # on every character you type.  You can do `bind /_ = search %s' if you want it less interactive.
@@ -126,8 +128,8 @@ bind    B         = spawn ./examples/scripts/insert_bookmark.sh
 bind    U         = spawn ./examples/scripts/load_url_from_history.sh
 bind    u         = spawn ./examples/scripts/load_url_from_bookmarks.sh
 # with the sample yank script, you can yank one of the arguments into clipboard/selection
-bind    yurl      = spawn ./examples/scripts/yank.sh 8 primary
-bind    ytitle    = spawn ./examples/scripts/yank.sh 9 clipboard
+bind    yurl      = spawn ./examples/scripts/yank.sh 6 primary
+bind    ytitle    = spawn ./examples/scripts/yank.sh 7 clipboard
 # does the same as yurl but without needing a script
 bind    y2url     = sh 'echo -n $6 | xclip'
 # go the page from primary selection
index efac322..c0c37db 100755 (executable)
 # http://kb.mozillazine.org/Cookies.txt
 # don't always append cookies, sometimes we need to overwrite
 
-[ -f /usr/share/uzbl/examples/configs/cookies ] && file=/usr/share/uzbl/examples/configs/cookies
-[ -f $XDG_CONFIG_HOME/uzbl/cookies            ] && file=$XDG_CONFIG_HOME/uzbl/cookies
-[ -f ./examples/configs/cookies               ] && file=./examples/configs/cookies #useful when developing
-[ -z "$file" ] && exit 1
+[ -f /usr/share/uzbl/examples/configs/cookies ] && cookie_config=/usr/share/uzbl/examples/configs/cookies
+[ -f $XDG_CONFIG_HOME/uzbl/cookies            ] && cookie_config=$XDG_CONFIG_HOME/uzbl/cookies
+[ -f ./examples/configs/cookies               ] && cookie_config=./examples/configs/cookies #useful when developing
+[ -z "$cookie_config" ] && exit 1
+
+[ -d /usr/share/uzbl/examples/data ] && cookie_data=/usr/share/uzbl/examples/data/cookies.txt
+[ -d $XDG_DATA_HOME/uzbl/          ] && cookie_data=$XDG_DATA_HOME/uzbl/cookies.txt
+[ -d ./examples/data/              ] && cookie_data=./examples/data/cookies.txt #useful when developing
+[ -z "$cookie_data" ] && exit 1
 
-[ -d /usr/share/uzbl/examples/data ] && cookie_file=/usr/share/uzbl/examples/data/cookies.txt
-[ -d $XDG_DATA_HOME/uzbl/          ] && cookie_file=$XDG_DATA_HOME/uzbl/cookies.txt
-[ -d ./examples/data/              ] && cookie_file=./examples/data/cookies.txt #useful when developing
-[ -z "$cookie_file" ] && exit 1
 
-# if this variable is set, we will use it to inform you when and which cookies we store, and when/which we send.
 #notifier=
 #notifier=notify-send
 notify_wrapper () {
        echo "$@" >> $HOME/cookielog
 }
+
+# if this variable is set, we will use it to inform you when and which cookies we store, and when/which we send.
 notifier=notify_wrapper
 which zenity &>/dev/null || exit 2
 
@@ -90,17 +92,17 @@ function parse_cookie () {
        unset IFS
 }
 
-# match cookies in cookies.txt againsh hostname and path
+# match cookies in cookies.txt against hostname and path
 function get_cookie () {
        path_esc=${path//\//\\/}
        search="^[^\t]*$host\t[^\t]*\t$path_esc"
-       cookie=`awk "/$search/" $cookie_file 2>/dev/null | tail -n 1`
+       cookie=`awk "/$search/" $cookie_data 2>/dev/null | tail -n 1`
        if [ -z "$cookie" ]
        then
-               notify "Get_cookie: search: $search in $cookie_file -> no result"
+               notify "Get_cookie: search: $search in $cookie_data -> no result"
                false
        else
-               notify "Get_cookie: search: $search in $cookie_file -> result: $cookie"
+               notify "Get_cookie: search: $search in $cookie_data -> result: $cookie"
                read domain alow_read_other_subdomains path http_required expiration name value <<< "$cookie"
                cookie="$name=$value" 
                true
@@ -111,8 +113,8 @@ function save_cookie () {
        if parse_cookie
        then
                data="$field_domain\tFALSE\t$field_path\tFALSE\t$field_exp\t$field_name\t$field_value"
-               notify "save_cookie: adding $data to $cookie_file"
-               echo -e "$data" >> $cookie_file
+               notify "save_cookie: adding $data to $cookie_data"
+               echo -e "$data" >> $cookie_data
        else
                notify "not saving a cookie. since we don't have policies yet, parse_cookie must have returned false. this is a bug"
        fi
@@ -128,15 +130,15 @@ exit
 # $1 = section (TRUSTED or DENY)
 # $2 =url
 function match () {
-       sed -n "/$1/,/^\$/p" $file 2>/dev/null | grep -q "^$host"
+       sed -n "/$1/,/^\$/p" $cookie_config 2>/dev/null | grep -q "^$host"
 }
 
 function fetch_cookie () {
-       cookie=`cat $cookie_file/$host.cookie`
+       cookie=`cat $cookie_data`
 }
 
 function store_cookie () {
-       echo $cookie > $cookie_file/$host.cookie
+       echo $cookie > $cookie_data
 }
 
 if match TRUSTED $host
index 0d38d3c..d87335f 100755 (executable)
@@ -7,10 +7,9 @@ WGET="wget --user-agent=Firefox"
 
 if [[ $8 =~ .*(.torrent) ]] 
 then
-    pushd $HOME
+    cd $HOME
     $WGET $8
 else
-    pushd $HOME
+    cd $HOME
     $WGET $8
 fi
-popd
index b8e2bd6..e2642c7 100755 (executable)
@@ -1,42 +1,62 @@
 #!/bin/bash
 
 # Very simple session manager for uzbl.  When called with "endsession" as the
-# argument, it'lla empty the sessionfile, look for fifos in $fifodir and
+# argument, it'll backup $sessionfile, look for fifos in $fifodir and
 # instruct each of them to store their current url in $sessionfile and
 # terminate themselves.  Run with "launch" as the argument and an instance of
 # uzbl will be launched for each stored url.  "endinstance" is used internally
 # and doesn't need to be called manually at any point.
+# Add a line like 'bind quit = /path/to/session.sh endsession' to your config
 
-
-scriptfile=$XDG_CONFIG_HOME/uzbl/session.sh # this script
+scriptfile=$0                          # this script
 sessionfile=$XDG_DATA_HOME/uzbl/session # the file in which the "session" (i.e. urls) are stored
-UZBL="uzbl" # add custom flags and whatever here.
+configfile=$XDG_DATA_HOME/uzbl/config   # uzbl configuration file
+UZBL="uzbl -c $configfile"           # add custom flags and whatever here.
 
 fifodir=/tmp # remember to change this if you instructed uzbl to put its fifos elsewhere
 thisfifo="$4"
 act="$8"
 url="$6"
 
+if [ "$act." = "." ]; then
+   act="$1"
+fi
+
+
 case $act in
   "launch" )
-    for url in $(cat $sessionfile); do
-      $UZBL --uri "$url" &
-    done
-    exit 0;;
+    urls=$(cat $sessionfile)
+    if [ "$urls." = "." ]; then
+      $UZBL
+    else
+      for url in $urls; do
+        $UZBL --uri "$url" &
+      done
+    fi
+    exit 0
+    ;;
+
   "endinstance" )
     if [ "$url" != "(null)" ]; then
       echo "$url" >> $sessionfile;
     fi
     echo "exit" > "$thisfifo"
     ;;
+
   "endsession" )
-    echo -n "" > "$sessionfile"
+    mv "$sessionfile" "$sessionfile~"
     for fifo in $fifodir/uzbl_fifo_*; do
       if [ "$fifo" != "$thisfifo" ]; then
         echo "spawn $scriptfile endinstance" > "$fifo"
       fi
     done
-    echo "spawn $scriptfile endinstance" > "$thisfifo";;
-  * ) echo "session manager: bad action";;
+    echo "spawn $scriptfile endinstance" > "$thisfifo"
+    ;;
+
+  * ) echo "session manager: bad action"
+      echo "Usage: $scriptfile [COMMAND] where commands are:"
+      echo " launch    - Restore a saved session or start a new one"
+      echo " endsession        - Quit the running session. Must be called from uzbl"
+      ;;
 esac
 
diff --git a/uzbl.c b/uzbl.c
index bb11fcf..bd54c7d 100644 (file)
--- a/uzbl.c
+++ b/uzbl.c
 #include <sys/utsname.h>
 #include <sys/time.h>
 #include <webkit/webkit.h>
+#include <libsoup/soup.h>
+
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <errno.h>
-#include <string.h>
 #include <fcntl.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <libsoup/soup.h>
 #include <signal.h>
 #include "uzbl.h"
 #include "config.h"
@@ -85,7 +83,7 @@ typedef const struct {
     void (*func)(void);
 } uzbl_cmdprop;
 
-enum {TYPE_INT, TYPE_STR};
+enum {TYPE_INT, TYPE_STR, TYPE_FLOAT};
 
 /* an abbreviation to help keep the table's width humane */
 #define PTR(var, t, d, fun) { .ptr = (void*)&(var), .type = TYPE_##t, .dump = d, .func = fun }
@@ -133,7 +131,8 @@ const struct {
     { "max_conns",           PTR(uzbl.net.max_conns,              INT,  1,   cmd_max_conns)},
     { "max_conns_host",      PTR(uzbl.net.max_conns_host,         INT,  1,   cmd_max_conns_host)},
     { "useragent",           PTR(uzbl.net.useragent,              STR,  1,   cmd_useragent)},
-    /* exported WebKitWebSettings properties*/
+    /* exported WebKitWebSettings properties */
+    { "zoom_level",          PTR(uzbl.behave.zoom_level,          FLOAT,1,   cmd_zoom_level)},
     { "font_size",           PTR(uzbl.behave.font_size,           INT,  1,   cmd_font_size)},
     { "monospace_size",      PTR(uzbl.behave.monospace_size,      INT,  1,   cmd_font_size)},
     { "minimum_font_size",   PTR(uzbl.behave.minimum_font_size,   INT,  1,   cmd_minimum_font_size)},
@@ -392,6 +391,23 @@ new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequ
     return (FALSE);
 }
 
+static gboolean
+mime_policy_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, gchar *mime_type,  WebKitWebPolicyDecision *policy_decision, gpointer user_data) {
+    (void) frame;
+    (void) request;
+    (void) user_data;
+
+    /* If we can display it, let's display it... */
+    if (webkit_web_view_can_show_mime_type (web_view, mime_type)) {
+        webkit_web_policy_decision_use (policy_decision);
+        return TRUE;
+    }
+
+    /* ...everything we can't displayed is downloaded */
+    webkit_web_policy_decision_download (policy_decision);
+    return TRUE;
+}
+
 WebKitWebView*
 create_web_view_cb (WebKitWebView  *web_view, WebKitWebFrame *frame, gpointer user_data) {
     (void) web_view;
@@ -529,6 +545,7 @@ load_start_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data) {
     (void) page;
     (void) frame;
     (void) data;
+    uzbl.gui.sbar.load_progress = 0;
     g_string_truncate(uzbl.state.keycmd, 0); // don't need old commands to remain on new page?
     if (uzbl.behave.load_start_handler)
         run_handler(uzbl.behave.load_start_handler, "");
@@ -582,7 +599,6 @@ VIEWFUNC(go_forward)
 #undef VIEWFUNC
 
 /* -- command to callback/function map for things we cannot attach to any signals */
-// TODO: reload
 static struct {char *name; Command command[2];} cmdlist[] =
 {   /* key                   function      no_split      */
     { "back",               {view_go_back, 0}              },
@@ -716,7 +732,11 @@ static void
 load_uri (WebKitWebView *web_view, GArray *argv) {
     if (argv_idx(argv, 0)) {
         GString* newuri = g_string_new (argv_idx(argv, 0));
-        if (g_strrstr (argv_idx(argv, 0), "://") == NULL)
+        if (g_strstr_len (argv_idx(argv, 0), 11, "javascript:") != NULL) {
+            run_js(web_view, argv);
+            return;
+        }
+        if (g_strrstr (argv_idx(argv, 0), "://") == NULL && g_strstr_len (argv_idx(argv, 0), 5, "data:") == NULL)
             g_string_prepend (newuri, "http://");
         /* if we do handle cookies, ask our handler for them */
         webkit_web_view_load_uri (web_view, newuri->str);
@@ -952,7 +972,7 @@ expand_template(const char *template, gboolean escape_markup) {
          token = g_scanner_get_next_token(uzbl.scan);
 
          if(token == G_TOKEN_SYMBOL) {
-             sym = (int)g_scanner_cur_value(uzbl.scan).v_symbol;
+             sym = GPOINTER_TO_INT(g_scanner_cur_value(uzbl.scan).v_symbol);
              switch(sym) {
                  case SYM_URI:
                      if(escape_markup) {
@@ -1351,6 +1371,11 @@ cmd_font_size() {
 }
 
 static void
+cmd_zoom_level() {
+    webkit_web_view_set_zoom_level (uzbl.gui.web_view, uzbl.behave.zoom_level);
+}
+
+static void
 cmd_disable_plugins() {
     g_object_set (G_OBJECT(view_settings()), "enable-plugins", 
             !uzbl.behave.disable_plugins, NULL);
@@ -1530,6 +1555,11 @@ set_var_value(gchar *name, gchar *val) {
             buf = expand_vars(val);
             *ip = (int)strtoul(buf, &endp, 10);
             g_free(buf);
+        } else if (c->type == TYPE_FLOAT) {
+            float *fp = (float *)c->ptr;
+            buf = expand_vars(val);
+            *fp = strtod(buf, &endp);
+            g_free(buf);
         }
 
         /* invoke a command specific function */
@@ -1980,6 +2010,7 @@ create_browser () {
     g_signal_connect (G_OBJECT (g->web_view), "new-window-policy-decision-requested", G_CALLBACK (new_window_cb), g->web_view);
     g_signal_connect (G_OBJECT (g->web_view), "download-requested", G_CALLBACK (download_cb), g->web_view);
     g_signal_connect (G_OBJECT (g->web_view), "create-web-view", G_CALLBACK (create_web_view_cb), g->web_view);
+    g_signal_connect (G_OBJECT (g->web_view), "mime-type-policy-decision-requested", G_CALLBACK (mime_policy_cb), g->web_view);
 
     return scrolled_window;
 }
@@ -2127,6 +2158,8 @@ add_binding (const gchar *key, const gchar *act) {
         printf ("Binding %-10s : %s\n", key, act);
     action = new_action(parts[0], parts[1]);
 
+    if (g_hash_table_remove (uzbl.bindings, key))
+        g_warning ("Overwriting existing binding for \"%s\"", key);
     g_hash_table_replace(uzbl.bindings, g_strdup(key), action);
     g_strfreev(parts);
 }
@@ -2210,7 +2243,7 @@ settings_init () {
             printf ("No configuration file loaded.\n");
     }
 
-    g_signal_connect(n->soup_session, "request-queued", G_CALLBACK(handle_cookies), NULL);
+    g_signal_connect_after(n->soup_session, "request-started", G_CALLBACK(handle_cookies), NULL);
 }
 
 static void handle_cookies (SoupSession *session, SoupMessage *msg, gpointer user_data){
diff --git a/uzbl.h b/uzbl.h
index 846dad6..ab45bae 100644 (file)
--- a/uzbl.h
+++ b/uzbl.h
@@ -149,6 +149,7 @@ typedef struct {
     guint    font_size;
     guint    monospace_size;
     guint    minimum_font_size;
+    gfloat   zoom_level;
     guint    disable_plugins;
     guint    disable_scripts;
     guint    autoload_img;    
@@ -248,6 +249,9 @@ print(WebKitWebView *page, GArray *argv);
 static gboolean
 new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data);
 
+static gboolean
+mime_policy_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, gchar *mime_type,  WebKitWebPolicyDecision *policy_decision, gpointer user_data);
+
 WebKitWebView*
 create_web_view_cb (WebKitWebView  *web_view, WebKitWebFrame *frame, gpointer user_data);
 
@@ -474,10 +478,15 @@ cmd_max_conns();
 static void
 cmd_max_conns_host();
 
+/* exported WebKitWebSettings properties */
+
 static void
 cmd_font_size();
 
 static void
+cmd_zoom_level();
+
+static void
 cmd_disable_plugins();
 
 static void