From e44414affde4e5497386ce398cc2c40356c4e466 Mon Sep 17 00:00:00 2001 From: keis Date: Mon, 28 Feb 2011 22:03:26 +0100 Subject: add clear_cookies command --- src/uzbl-core.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/uzbl-core.c') diff --git a/src/uzbl-core.c b/src/uzbl-core.c index bc75d87..3303797 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -551,7 +551,8 @@ CommandInfo cmdlist[] = { "include", include, TRUE }, { "show_inspector", show_inspector, 0 }, { "add_cookie", add_cookie, 0 }, - { "delete_cookie", delete_cookie, 0 } + { "delete_cookie", delete_cookie, 0 }, + { "clear_cookies", clear_cookies, 0 } }; void @@ -725,6 +726,18 @@ delete_cookie(WebKitWebView *page, GArray *argv, GString *result) { uzbl.net.soup_cookie_jar->in_manual_add = 0; } + +void +clear_cookies(WebKitWebView *page, GArray *argv, GString *result) { + (void) page; (void) argv; (void) result; + + // Replace the current cookie jar with a new empty jar + soup_session_remove_feature (uzbl.net.soup_session, uzbl.net.soup_cookie_jar); + g_object_unref (G_OBJECT (uzbl.net.soup_cookie_jar)); + uzbl.net.soup_cookie_jar = uzbl_cookie_jar_new (); + soup_session_add_feature(uzbl.net.soup_session, uzbl.net.soup_cookie_jar); +} + void act_dump_config() { dump_config(); -- cgit v1.2.3 From 49ce876c744ee3d6a424c50d9f2db439acbe3f28 Mon Sep 17 00:00:00 2001 From: keis Date: Thu, 17 Mar 2011 20:24:02 +0100 Subject: fix clear_cookies warning --- src/uzbl-core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/uzbl-core.c') diff --git a/src/uzbl-core.c b/src/uzbl-core.c index c879602..ec2d347 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -732,10 +732,12 @@ clear_cookies(WebKitWebView *page, GArray *argv, GString *result) { (void) page; (void) argv; (void) result; // Replace the current cookie jar with a new empty jar - soup_session_remove_feature (uzbl.net.soup_session, uzbl.net.soup_cookie_jar); + soup_session_remove_feature (uzbl.net.soup_session, + SOUP_SESSION_FEATURE (uzbl.net.soup_cookie_jar)); g_object_unref (G_OBJECT (uzbl.net.soup_cookie_jar)); uzbl.net.soup_cookie_jar = uzbl_cookie_jar_new (); - soup_session_add_feature(uzbl.net.soup_session, uzbl.net.soup_cookie_jar); + soup_session_add_feature(uzbl.net.soup_session, + SOUP_SESSION_FEATURE (uzbl.net.soup_cookie_jar)); } void -- cgit v1.2.3 From 2926b0f55122b131e0b9d2cf857d2b78d202c5ab Mon Sep 17 00:00:00 2001 From: Olof-Joachim Frahm Date: Mon, 21 Mar 2011 06:23:23 +0100 Subject: Fixed array bug. When e.g. spawn_sh modifies the array, invalid stuff is send to the python script, which then breaks while decoding them. --- src/uzbl-core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/uzbl-core.c') diff --git a/src/uzbl-core.c b/src/uzbl-core.c index c879602..ba062b6 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -1129,8 +1129,6 @@ spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result) { void run_parsed_command(const CommandInfo *c, GArray *a, GString *result) { - c->function(uzbl.gui.web_view, a, result); - /* send the COMMAND_EXECUTED event, except for set and event/request commands */ if(strcmp("set", c->key) && strcmp("event", c->key) && @@ -1141,12 +1139,18 @@ run_parsed_command(const CommandInfo *c, GArray *a, GString *result) { guint i = 0; while ((p = argv_idx(a, i++))) g_string_append_printf(param, " '%s'", p); + + /* might be destructive on array a */ + c->function(uzbl.gui.web_view, a, result); + send_event(COMMAND_EXECUTED, NULL, TYPE_NAME, c->key, TYPE_FORMATTEDSTR, param->str, NULL); g_string_free(param, TRUE); } + else + c->function(uzbl.gui.web_view, a, result); if(result) { g_free(uzbl.state.last_result); -- cgit v1.2.3 From 1282b9cf99be29db65529eec3bfb14f6685b393b Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Tue, 12 Apr 2011 22:00:35 -0600 Subject: add a 'download' command that can download the current url or an arbitrary url --- src/uzbl-core.c | 19 ++++++++++++++++++- src/uzbl-core.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src/uzbl-core.c') diff --git a/src/uzbl-core.c b/src/uzbl-core.c index e498762..3a96482 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -552,7 +552,8 @@ CommandInfo cmdlist[] = { "show_inspector", show_inspector, 0 }, { "add_cookie", add_cookie, 0 }, { "delete_cookie", delete_cookie, 0 }, - { "clear_cookies", clear_cookies, 0 } + { "clear_cookies", clear_cookies, 0 }, + { "download", download, 0 } }; void @@ -740,6 +741,22 @@ clear_cookies(WebKitWebView *page, GArray *argv, GString *result) { SOUP_SESSION_FEATURE (uzbl.net.soup_cookie_jar)); } +void +download(WebKitWebView *web_view, GArray *argv, GString *result) { + (void) result; + + const gchar *uri = NULL; + + if(argv->len > 0) + uri = argv_idx(argv, 0); + else + uri = uzbl.state.uri; + + WebKitNetworkRequest *req = webkit_network_request_new(uri); + webkit_web_view_request_download(web_view, req); + g_object_unref(req); +} + void act_dump_config() { dump_config(); diff --git a/src/uzbl-core.h b/src/uzbl-core.h index affd334..be8fccd 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -325,6 +325,7 @@ void show_inspector(WebKitWebView *page, GArray *argv, GString *result); void add_cookie(WebKitWebView *page, GArray *argv, GString *result); void delete_cookie(WebKitWebView *page, GArray *argv, GString *result); void clear_cookies(WebKitWebView *pag, GArray *argv, GString *result); +void download(WebKitWebView *pag, GArray *argv, GString *result); void builtins(); typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result); -- cgit v1.2.3 From bdfb2fb35c4d6fa407361dcc99aefb00ff185e6d Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Tue, 12 Apr 2011 22:35:42 -0600 Subject: allow a second argument to the 'download' command that specifies a destination path --- examples/data/scripts/download.sh | 14 +++++++++++--- src/callbacks.c | 8 ++++++++ src/uzbl-core.c | 18 ++++++++++++------ 3 files changed, 31 insertions(+), 9 deletions(-) (limited to 'src/uzbl-core.c') diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index fe566ed..dbc9caf 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -1,9 +1,17 @@ #!/bin/sh # uzbl's example configuration sets this script up as its download_handler. -# when uzbl starts a download it runs this script. +# this script is run when uzbl encounters a URL that it can't display, and when +# a download is requested using the 'download' command. +# # if the script prints a file path to stdout, uzbl will save the download to -# that path. -# if nothing is printed to stdout, the download will be cancelled. +# that path using it's internal downloader. +# +# if nothing is printed to stdout, the internal download will be cancelled. +# you could do your own download handling in your script that way. + +# if $5 is set, it is the path that was passed to uzbl's "download" command. +# we want to use that if it's available. +[ -n "$5" ] && echo "$5" && exit . "$UZBL_UTIL_DIR/uzbl-dir.sh" diff --git a/src/callbacks.c b/src/callbacks.c index 360b0c4..703107b 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -837,6 +837,11 @@ download_cb(WebKitWebView *web_view, WebKitDownload *download, gpointer user_dat /* get the URI being downloaded */ const gchar *uri = webkit_download_get_uri(download); + /* get the destination path, if specified. + * this is only intended to be set when this function is trigger by an + * explicit download using uzbl's 'download' action. */ + const gchar *destination = user_data; + if (uzbl.state.verbose) printf("Download requested -> %s\n", uri); @@ -883,6 +888,9 @@ download_cb(WebKitWebView *web_view, WebKitDownload *download, gpointer user_dat gchar *total_size_s = g_strdup_printf("%d", total_size); g_array_append_val(a, total_size_s); + if(destination) + g_array_append_val(a, destination); + GString *result = g_string_new (""); run_parsed_command(c, a, result); diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 3a96482..204c89c 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -745,15 +745,21 @@ void download(WebKitWebView *web_view, GArray *argv, GString *result) { (void) result; - const gchar *uri = NULL; + const gchar *uri = argv_idx(argv, 0); + const gchar *destination = NULL; + if(argv->len > 1) + destination = argv_idx(argv, 1); - if(argv->len > 0) - uri = argv_idx(argv, 0); + WebKitNetworkRequest *req = webkit_network_request_new(uri); + WebKitDownload *download = webkit_download_new(req); + + download_cb(web_view, download, destination); + + if(webkit_download_get_destination_uri(download)) + webkit_download_start(download); else - uri = uzbl.state.uri; + g_object_unref(download); - WebKitNetworkRequest *req = webkit_network_request_new(uri); - webkit_web_view_request_download(web_view, req); g_object_unref(req); } -- cgit v1.2.3 From 726e105a1269a9202690281471e5fa243223809b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 14 Apr 2011 00:20:20 -0400 Subject: Avoid --name which GTK uses internally Addresses #170. --- src/uzbl-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/uzbl-core.c') diff --git a/src/uzbl-core.c b/src/uzbl-core.c index e498762..e918451 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -47,7 +47,7 @@ GOptionEntry entries[] = { "Uri to load at startup (equivalent to 'uzbl ' or 'set uri = URI' after uzbl has launched)", "URI" }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &uzbl.state.verbose, "Whether to print all messages or just errors.", NULL }, - { "name", 'n', 0, G_OPTION_ARG_STRING, &uzbl.state.instance_name, + { "named", 'n', 0, G_OPTION_ARG_STRING, &uzbl.state.instance_name, "Name of the current instance (defaults to Xorg window id or random for GtkSocket mode)", "NAME" }, { "config", 'c', 0, G_OPTION_ARG_STRING, &uzbl.state.config_file, "Path to config file or '-' for stdin", "FILE" }, -- cgit v1.2.3 From d0b919ed5fb7fd42f6f4851443790e5c87116128 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Sun, 24 Apr 2011 00:48:53 -0600 Subject: allow processes other than uzbl-tabbed to start uzbl-browser instances that appear in -tabbed not entirely sure that this is useful yet. --- bin/uzbl-tabbed | 47 ++++++++++++++++++++++++++++++++--------------- src/uzbl-core.c | 8 ++++++-- src/uzbl-core.h | 1 + 3 files changed, 39 insertions(+), 17 deletions(-) (limited to 'src/uzbl-core.c') diff --git a/bin/uzbl-tabbed b/bin/uzbl-tabbed index a15967a..d63d6de 100755 --- a/bin/uzbl-tabbed +++ b/bin/uzbl-tabbed @@ -303,12 +303,13 @@ class SocketClient: # List of UzblInstance objects not already linked with a SocketClient instances_queue = {} - def __init__(self, socket): + def __init__(self, socket, uzbl_tabbed): self._buffer = "" self._socket = socket self._watchers = [io_add_watch(socket, IO_IN, self._socket_recv),\ io_add_watch(socket, IO_HUP, self._socket_closed)] self.uzbl = None + self.uzbl_tabbed = uzbl_tabbed def _socket_recv(self, fd, condition): @@ -341,13 +342,17 @@ class SocketClient: if cmd: self.uzbl.parse_command(cmd) else: - name = re.findall('^EVENT \[(\d+-\d+)\] INSTANCE_START \d+$', self._buffer, re.M) + name = re.findall('^EVENT \[([^]]+)\] INSTANCE_START \d+$', self._buffer, re.M) uzbl = self.instances_queue.get(name[0]) if uzbl: + # we've found the uzbl we were waiting for del self.instances_queue[name[0]] - self.uzbl = uzbl - self.uzbl.got_socket(self) - self._feed("") + else: + # an unsolicited uzbl has connected, how exciting! + uzbl = UzblInstance(self.uzbl_tabbed, None, '', '', False) + self.uzbl = uzbl + self.uzbl.got_socket(self) + self._feed("") def send(self, data): '''Child socket send function.''' @@ -376,6 +381,12 @@ class EventDispatcher: return method(*args) + def plug_created(self, plug_id): + if not self.uzbl.tab: + tab = self.parent.create_tab() + tab.add_id(int(plug_id)) + self.uzbl.set_tab(tab) + def title_changed(self, title): self.uzbl.title = title.strip() self.uzbl.title_changed(False) @@ -477,10 +488,10 @@ class EventDispatcher: class UzblInstance: '''Uzbl instance meta-data/meta-action object.''' - def __init__(self, parent, tab, name, uri, title, switch): + def __init__(self, parent, name, uri, title, switch): self.parent = parent - self.tab = tab + self.tab = None self.dispatcher = EventDispatcher(self) self.name = name @@ -490,8 +501,11 @@ class UzblInstance: self._client = None self._switch = switch # Switch to tab after loading ? - self.title_changed() + def set_tab(self, tab): + self.tab = tab + self.title_changed() + self.parent.tabs[self.tab] = self def got_socket(self, client): '''Uzbl instance is now connected''' @@ -763,7 +777,7 @@ class UzblTabbed: '''A new uzbl instance was created''' client, _ = sock.accept() - self.clients[client] = SocketClient(client) + self.clients[client] = SocketClient(client, self) return True @@ -1045,6 +1059,12 @@ class UzblTabbed: return False + def create_tab(self, next = False): + tab = gtk.Socket() + tab.show() + self.notebook.insert_page(tab, position=next and self.notebook.get_current_page() + 1 or -1) + self.notebook.set_tab_reorderable(tab, True) + return tab def new_tab(self, uri='', title='', switch=None, next=False): '''Add a new tab to the notebook and start a new instance of uzbl. @@ -1052,10 +1072,7 @@ class UzblTabbed: when you need to load multiple tabs at a time (I.e. like when restoring a session from a file).''' - tab = gtk.Socket() - tab.show() - self.notebook.insert_page(tab, position=next and self.notebook.get_current_page() + 1 or -1) - self.notebook.set_tab_reorderable(tab, True) + tab = self.create_tab(next) sid = tab.get_id() uri = uri.strip() name = "%d-%d" % (os.getpid(), self.next_pid()) @@ -1070,9 +1087,9 @@ class UzblTabbed: '--connect-socket', self.socket_path, '--uri', str(uri)] gobject.spawn_async(cmd, flags=gobject.SPAWN_SEARCH_PATH) - uzbl = UzblInstance(self, tab, name, uri, title, switch) + uzbl = UzblInstance(self, name, uri, title, switch) + uzbl.set_tab(tab) SocketClient.instances_queue[name] = uzbl - self.tabs[tab] = uzbl def clean_slate(self): diff --git a/src/uzbl-core.c b/src/uzbl-core.c index c095a7f..e461a4c 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -51,8 +51,11 @@ GOptionEntry entries[] = { "Name of the current instance (defaults to Xorg window id or random for GtkSocket mode)", "NAME" }, { "config", 'c', 0, G_OPTION_ARG_STRING, &uzbl.state.config_file, "Path to config file or '-' for stdin", "FILE" }, + /* TODO: explain the difference between these two options */ { "socket", 's', 0, G_OPTION_ARG_INT, &uzbl.state.socket_id, - "Xembed Socket ID", "SOCKET" }, + "Xembed socket ID, this window should embed itself", "SOCKET" }, + { "embed", 'e', 0, G_OPTION_ARG_NONE, &uzbl.state.embed, + "Whether this window should expect to be embedded", NULL }, { "connect-socket", 0, 0, G_OPTION_ARG_STRING_ARRAY, &uzbl.state.connect_socket_names, "Connect to server socket for event managing", "CSOCKET" }, { "print-events", 'p', 0, G_OPTION_ARG_NONE, &uzbl.state.events_stdout, @@ -1540,6 +1543,7 @@ create_window() { GtkPlug* create_plug() { + if(uzbl.state.embed) uzbl.state.socket_id = 0; GtkPlug* plug = GTK_PLUG (gtk_plug_new (uzbl.state.socket_id)); g_signal_connect (G_OBJECT (plug), "destroy", G_CALLBACK (destroy_cb), NULL); g_signal_connect (G_OBJECT (plug), "key-press-event", G_CALLBACK (key_press_cb), NULL); @@ -1746,7 +1750,7 @@ initialize(int argc, char** argv) { } /* Embedded mode */ - if (uzbl.state.socket_id) + if (uzbl.state.socket_id || uzbl.state.embed) uzbl.state.plug_mode = TRUE; if (!g_thread_supported()) diff --git a/src/uzbl-core.h b/src/uzbl-core.h index be8fccd..07b6f99 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -109,6 +109,7 @@ typedef struct { gchar* executable_path; gchar* searchtx; gboolean verbose; + gboolean embed; GdkEventButton* last_button; gchar* last_result; gboolean plug_mode; -- cgit v1.2.3