summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/adblock.c3
-rw-r--r--src/commands.c21
-rw-r--r--src/config.h2
-rw-r--r--src/dom.c121
-rw-r--r--src/dom.h26
-rw-r--r--src/dwb.c256
-rw-r--r--src/dwb.h5
-rw-r--r--src/editor.c177
-rw-r--r--src/editor.h24
-rw-r--r--src/plugins.c3
-rw-r--r--src/scripts.c12
-rw-r--r--src/scripts.h1
-rw-r--r--src/view.c5
13 files changed, 406 insertions, 250 deletions
diff --git a/src/adblock.c b/src/adblock.c
index e6b65f4b..328403f4 100644
--- a/src/adblock.c
+++ b/src/adblock.c
@@ -23,6 +23,7 @@
#include "domain.h"
#include "adblock.h"
#include "js.h"
+#include "dom.h"
@@ -435,7 +436,7 @@ adblock_frame_load_status_cb(WebKitWebFrame *frame, GParamSpec *p, GList *gl)
if (status == WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT)
adblock_apply_element_hider(frame, gl);
else if (status == WEBKIT_LOAD_COMMITTED)
- dwb_dom_add_frame_listener(frame, "beforeload", G_CALLBACK(adblock_before_load_cb), true, gl);
+ dom_add_frame_listener(frame, "beforeload", G_CALLBACK(adblock_before_load_cb), true, gl);
}
/* adblock_frame_created_cb {{{*/
diff --git a/src/commands.c b/src/commands.c
index b8de8ffb..4b885fd3 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -30,6 +30,8 @@
#include "download.h"
#include "js.h"
#include "scripts.h"
+#include "editor.h"
+#include "dom.h"
inline static int
dwb_floor(double x) {
@@ -54,6 +56,21 @@ commands_simple_command(KeyMap *km)
completion_clean_autocompletion();
}
+ if (EMIT_SCRIPT(EXECUTE_COMMAND))
+ {
+ char *json = util_create_json(3,
+ CHAR, "command", km->map->n.first,
+ CHAR, "argument", arg->p,
+ INTEGER, "nummod", dwb.state.nummod);
+ ScriptSignal sig = { NULL, SCRIPTS_SIG_META(json, EXECUTE_COMMAND, 0) } ;
+
+ gboolean prevent = scripts_emit(&sig);
+ g_free(json);
+
+ if (prevent)
+ return STATUS_OK;
+ }
+
ret = func(km, arg);
switch (ret)
{
@@ -770,7 +787,7 @@ commands_fullscreen(KeyMap *km, Arg *arg)
DwbStatus
commands_open_editor(KeyMap *km, Arg *arg)
{
- return dwb_open_in_editor();
+ return editor_open();
}/*}}}*/
/* dwb_command_mode {{{*/
@@ -803,7 +820,7 @@ commands_set_bars(int status)
gtk_widget_set_visible(dwb.gui.topbox, (status & BAR_VIS_TOP) && (GET_BOOL("show-single-tab") || dwb.state.views->next));
gtk_widget_set_visible(dwb.gui.bottombox, status & BAR_VIS_STATUS);
if ((status & BAR_VIS_STATUS) )
- dwb_dom_remove_from_parent(WEBKIT_DOM_NODE(CURRENT_VIEW()->hover.element), NULL);
+ dom_remove_from_parent(WEBKIT_DOM_NODE(CURRENT_VIEW()->hover.element), NULL);
}
/* commands_toggle_bars {{{*/
DwbStatus
diff --git a/src/config.h b/src/config.h
index 81c6cb09..9f126c95 100644
--- a/src/config.h
+++ b/src/config.h
@@ -1170,4 +1170,6 @@ static WebSettings DWB_SETTINGS[] = {
SETTING_GLOBAL, BOOLEAN, { .b = false }, NULL, { 0 }, },
{ { "print-previewer", "Command used for the printing preview", },
SETTING_GLOBAL, CHAR, { .p = NULL }, NULL, { 0 }, },
+ { { "accept-language", "If set will be used for 'Accept-Language' header in all requests", },
+ SETTING_GLOBAL | SETTING_ONINIT, CHAR, { .p = NULL }, (S_Func)dwb_set_accept_language, { 0 }, },
};/*}}}*/
diff --git a/src/dom.c b/src/dom.c
new file mode 100644
index 00000000..60885d51
--- /dev/null
+++ b/src/dom.c
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2010-2013 Stefan Bolte <portix@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <string.h>
+#include "dwb.h"
+
+gboolean
+dom_add_frame_listener(WebKitWebFrame *frame, const char *signal, GCallback callback, gboolean bubble, GList *gl)
+{
+ char *framesrc, *tagname;
+ gboolean ret = false;
+ WebKitDOMDOMWindow *win;
+ WebKitDOMNode *node;
+ WebKitWebView *wv = webkit_web_frame_get_web_view(frame);
+ WebKitDOMDocument *doc = webkit_web_view_get_dom_document(wv);
+ const char *src = webkit_web_frame_get_uri(frame);
+ if (g_strcmp0(src, "about:blank"))
+ {
+ /* We have to find the correct frame, but there is no access from the web_frame
+ * to the Htmlelement */
+ WebKitDOMNodeList *frames = webkit_dom_document_query_selector_all(doc, "iframe, frame", NULL);
+ for (guint i=0; i<webkit_dom_node_list_get_length(frames) && ret == false; i++)
+ {
+ node = webkit_dom_node_list_item(frames, i);
+ tagname = webkit_dom_node_get_node_name(node);
+ if (!g_ascii_strcasecmp(tagname, "iframe"))
+ {
+ framesrc = webkit_dom_html_iframe_element_get_src(WEBKIT_DOM_HTML_IFRAME_ELEMENT(node));
+ win = webkit_dom_html_iframe_element_get_content_window(WEBKIT_DOM_HTML_IFRAME_ELEMENT(node));
+ }
+ else
+ {
+ framesrc = webkit_dom_html_frame_element_get_src(WEBKIT_DOM_HTML_FRAME_ELEMENT(node));
+ win = webkit_dom_html_frame_element_get_content_window(WEBKIT_DOM_HTML_FRAME_ELEMENT(node));
+ }
+ if (!g_strcmp0(src, framesrc))
+ ret = webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(win), signal, callback, true, gl);
+
+ g_free(framesrc);
+ }
+ g_object_unref(frames);
+ }
+ return ret;
+}
+
+/* dwb_get_editable(WebKitDOMElement *) {{{*/
+gboolean
+dom_get_editable(WebKitDOMElement *element)
+{
+ if (element == NULL)
+ return false;
+
+ char *tagname = webkit_dom_node_get_node_name(WEBKIT_DOM_NODE(element));
+ if (tagname == NULL)
+ return false;
+ if (!strcasecmp(tagname, "INPUT"))
+ {
+ char *type = webkit_dom_element_get_attribute((void*)element, "type");
+ if (!g_strcmp0(type, "text") || !g_strcmp0(type, "search")|| !g_strcmp0(type, "password"))
+ return true;
+ }
+ else if (!strcasecmp(tagname, "TEXTAREA"))
+ return true;
+
+ return false;
+}/*}}}*/
+
+/* dom_get_active_element(WebKitDOMDocument ) {{{*/
+WebKitDOMElement *
+dom_get_active_element(WebKitDOMDocument *doc)
+{
+ WebKitDOMElement *ret = NULL;
+ WebKitDOMDocument *d = NULL;
+
+ WebKitDOMElement *active = webkit_dom_html_document_get_active_element((void*)doc);
+ char *tagname = webkit_dom_element_get_tag_name(active);
+
+ if (! g_strcmp0(tagname, "FRAME"))
+ {
+ d = webkit_dom_html_frame_element_get_content_document(WEBKIT_DOM_HTML_FRAME_ELEMENT(active));
+ ret = dom_get_active_element(d);
+ }
+ else if (! g_strcmp0(tagname, "IFRAME"))
+ {
+ d = webkit_dom_html_iframe_element_get_content_document(WEBKIT_DOM_HTML_IFRAME_ELEMENT(active));
+ ret = dom_get_active_element(d);
+ }
+ else
+ ret = active;
+
+ return ret;
+}/*}}}*/
+
+
+/* dwb_dom_remove_from_parent(WebKitDOMNode *node, GError **error) {{{*/
+gboolean
+dom_remove_from_parent(WebKitDOMNode *node, GError **error)
+{
+ WebKitDOMNode *parent = webkit_dom_node_get_parent_node(node);
+ if (parent != NULL)
+ {
+ webkit_dom_node_remove_child(parent, node, error);
+ return true;
+ }
+ return false;
+}/*}}}*/
diff --git a/src/dom.h b/src/dom.h
new file mode 100644
index 00000000..e1b4ed4a
--- /dev/null
+++ b/src/dom.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2010-2013 Stefan Bolte <portix@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef DOM_H
+#define DOM_H
+
+gboolean dom_add_frame_listener(WebKitWebFrame *frame, const char *signal, GCallback callback, gboolean bubble, GList *gl);
+gboolean dom_get_editable(WebKitDOMElement *element);
+WebKitDOMElement * dom_get_active_element(WebKitDOMDocument *doc);
+gboolean dom_remove_from_parent(WebKitDOMNode *node, GError **error);
+#endif
diff --git a/src/dwb.c b/src/dwb.c
index d54c84a6..b03e4671 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -47,6 +47,7 @@
#include "domain.h"
#include "application.h"
#include "scripts.h"
+#include "dom.h"
/* DECLARATIONS {{{*/
static DwbStatus dwb_webkit_setting(GList *, WebSettings *);
@@ -77,6 +78,7 @@ static DwbStatus dwb_set_ntlm(GList *gl, WebSettings *s);
static DwbStatus dwb_set_find_delay(GList *gl, WebSettings *s);
static DwbStatus dwb_set_do_not_track(GList *gl, WebSettings *s);
static DwbStatus dwb_set_show_single_tab(GList *gl, WebSettings *s);
+static DwbStatus dwb_set_accept_language(GList *gl, WebSettings *s);
#ifdef WITH_LIBSOUP_2_38
static DwbStatus dwb_set_dns_lookup(GList *gl, WebSettings *s);
#endif
@@ -98,13 +100,6 @@ static void dwb_init_gui(void);
static Navigation * dwb_get_search_completion(const char *text);
static void dwb_clean_vars(void);
-typedef struct _EditorInfo {
- char *filename;
- char *id;
- GList *gl;
- WebKitDOMElement *element;
- char *tagname;
-} EditorInfo;
typedef struct _UserScriptEnv {
GIOChannel *channel;
@@ -175,6 +170,14 @@ dwb_set_adblock(GList *gl, WebSettings *s)
}
}/*}}}*/
+/*{{{*/
+static DwbStatus
+dwb_set_accept_language(GList *gl, WebSettings *s)
+{
+ g_object_set(webkit_get_default_session(), "accept-language", s->arg_local.p, NULL);
+ return STATUS_OK;
+}/*}}}*/
+
/* dwb_set_cookies {{{ */
static DwbStatus
dwb_set_cookies(GList *gl, WebSettings *s) {
@@ -584,7 +587,7 @@ dwb_hide_message()
if (gtk_widget_get_visible(dwb.gui.bottombox))
CLEAR_COMMAND_TEXT();
else
- dwb_dom_remove_from_parent(WEBKIT_DOM_NODE(CURRENT_VIEW()->status_element), NULL);
+ dom_remove_from_parent(WEBKIT_DOM_NODE(CURRENT_VIEW()->status_element), NULL);
}
return NULL;
}/*}}}*/
@@ -1049,241 +1052,12 @@ dwb_scroll(GList *gl, double step, ScrollDirection dir)
gtk_adjustment_set_value(a, scroll);
}/*}}}*/
-/* dwb_editor_watch (GChildWatchFunc) {{{*/
-static void
-dwb_editor_watch(GPid pid, int status, EditorInfo *info)
-{
- gsize length;
- WebKitDOMElement *e = NULL;
- WebKitWebView *wv;
-
- char *content = util_get_file_content(info->filename, &length);
-
- if (content == NULL)
- goto clean;
-
- if (!info->gl || !g_list_find(dwb.state.views, info->gl->data))
- {
- if (info->id == NULL)
- goto clean;
- else
- wv = CURRENT_WEBVIEW();
- }
- else
- wv = WEBVIEW(info->gl);
- if (info->id != NULL)
- {
- WebKitDOMDocument *doc = webkit_web_view_get_dom_document(wv);
- e = webkit_dom_document_get_element_by_id(doc, info->id);
-
- if (e == NULL && (e = info->element) == NULL )
- goto clean;
- }
- else
- e = info->element;
-
- /* g_file_get_contents adds an additional newline */
- if (length > 0 && content[length-1] == '\n')
- content[length-1] = 0;
-
- if (!strcasecmp(info->tagname, "INPUT"))
- webkit_dom_html_input_element_set_value(WEBKIT_DOM_HTML_INPUT_ELEMENT(e), content);
- else if (!strcasecmp(info->tagname, "TEXTAREA"))
- webkit_dom_html_text_area_element_set_value(WEBKIT_DOM_HTML_TEXT_AREA_ELEMENT(e), content);
-
-clean:
- unlink(info->filename);
- g_free(info->filename);
- g_free(info->id);
- g_free(info);
-}/*}}}*/
-
-/* dwb_dom_remove_from_parent(WebKitDOMNode *node, GError **error) {{{*/
-gboolean
-dwb_dom_remove_from_parent(WebKitDOMNode *node, GError **error)
-{
- WebKitDOMNode *parent = webkit_dom_node_get_parent_node(node);
- if (parent != NULL)
- {
- webkit_dom_node_remove_child(parent, node, error);
- return true;
- }
- return false;
-}/*}}}*/
-
-
-gboolean
-dwb_dom_add_frame_listener(WebKitWebFrame *frame, const char *signal, GCallback callback, gboolean bubble, GList *gl)
-{
- char *framesrc, *tagname;
- gboolean ret = false;
- WebKitDOMDOMWindow *win;
- WebKitDOMNode *node;
- WebKitWebView *wv = webkit_web_frame_get_web_view(frame);
- WebKitDOMDocument *doc = webkit_web_view_get_dom_document(wv);
- const char *src = webkit_web_frame_get_uri(frame);
- if (g_strcmp0(src, "about:blank"))
- {
- /* We have to find the correct frame, but there is no access from the web_frame
- * to the Htmlelement */
- WebKitDOMNodeList *frames = webkit_dom_document_query_selector_all(doc, "iframe, frame", NULL);
- for (guint i=0; i<webkit_dom_node_list_get_length(frames) && ret == false; i++)
- {
- node = webkit_dom_node_list_item(frames, i);
- tagname = webkit_dom_node_get_node_name(node);
- if (!g_ascii_strcasecmp(tagname, "iframe"))
- {
- framesrc = webkit_dom_html_iframe_element_get_src(WEBKIT_DOM_HTML_IFRAME_ELEMENT(node));
- win = webkit_dom_html_iframe_element_get_content_window(WEBKIT_DOM_HTML_IFRAME_ELEMENT(node));
- }
- else
- {
- framesrc = webkit_dom_html_frame_element_get_src(WEBKIT_DOM_HTML_FRAME_ELEMENT(node));
- win = webkit_dom_html_frame_element_get_content_window(WEBKIT_DOM_HTML_FRAME_ELEMENT(node));
- }
- if (!g_strcmp0(src, framesrc))
- ret = webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(win), signal, callback, true, gl);
-
- g_free(framesrc);
- }
- g_object_unref(frames);
- }
- return ret;
-}
-
-/* dwb_get_editable(WebKitDOMElement *) {{{*/
-static gboolean
-dwb_get_editable(WebKitDOMElement *element)
-{
- if (element == NULL)
- return false;
-
- char *tagname = webkit_dom_node_get_node_name(WEBKIT_DOM_NODE(element));
- if (tagname == NULL)
- return false;
- if (!strcasecmp(tagname, "INPUT"))
- {
- char *type = webkit_dom_element_get_attribute((void*)element, "type");
- if (!g_strcmp0(type, "text") || !g_strcmp0(type, "search")|| !g_strcmp0(type, "password"))
- return true;
- }
- else if (!strcasecmp(tagname, "TEXTAREA"))
- return true;
-
- return false;
-}/*}}}*/
-
-/* dwb_get_active_input(WebKitDOMDocument ) {{{*/
-static WebKitDOMElement *
-dwb_get_active_element(WebKitDOMDocument *doc)
-{
- WebKitDOMElement *ret = NULL;
- WebKitDOMDocument *d = NULL;
-
- WebKitDOMElement *active = webkit_dom_html_document_get_active_element((void*)doc);
- char *tagname = webkit_dom_element_get_tag_name(active);
-
- if (! g_strcmp0(tagname, "FRAME"))
- {
- d = webkit_dom_html_frame_element_get_content_document(WEBKIT_DOM_HTML_FRAME_ELEMENT(active));
- ret = dwb_get_active_element(d);
- }
- else if (! g_strcmp0(tagname, "IFRAME"))
- {
- d = webkit_dom_html_iframe_element_get_content_document(WEBKIT_DOM_HTML_IFRAME_ELEMENT(active));
- ret = dwb_get_active_element(d);
- }
- else
- ret = active;
-
- return ret;
-}/*}}}*/
-
-/* dwb_open_in_editor(void) ret: gboolean success {{{*/
-DwbStatus
-dwb_open_in_editor(void)
-{
- DwbStatus ret = STATUS_OK;
- char **commands = NULL;
- char *commandstring = NULL, *tagname, *path;
- char *value = NULL;
- GPid pid;
- gboolean success;
-
- char *editor = GET_CHAR("editor");
-
- if (editor == NULL)
- return STATUS_ERROR;
-
- WebKitDOMDocument *doc = webkit_web_view_get_dom_document(CURRENT_WEBVIEW());
- WebKitDOMElement *active = dwb_get_active_element(doc);
-
- if (active == NULL)
- return STATUS_ERROR;
-
- tagname = webkit_dom_element_get_tag_name(active);
- if (tagname == NULL)
- {
- ret = STATUS_ERROR;
- goto clean;
- }
- if (! strcasecmp(tagname, "INPUT"))
- value = webkit_dom_html_input_element_get_value(WEBKIT_DOM_HTML_INPUT_ELEMENT(active));
- else if (! strcasecmp(tagname, "TEXTAREA"))
- value = webkit_dom_html_text_area_element_get_value(WEBKIT_DOM_HTML_TEXT_AREA_ELEMENT(active));
-
- if (value == NULL)
- {
- ret = STATUS_ERROR;
- goto clean;
- }
-
- path = util_get_temp_filename("edit");
-
- commandstring = util_string_replace(editor, "dwb_uri", path);
- if (commandstring == NULL)
- {
- ret = STATUS_ERROR;
- goto clean;
- }
-
- g_file_set_contents(path, value, -1, NULL);
- commands = g_strsplit(commandstring, " ", -1);
- g_free(commandstring);
-
- success = g_spawn_async(NULL, commands, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL);
- g_strfreev(commands);
- if (!success)
- {
- ret = STATUS_ERROR;
- goto clean;
- }
-
- EditorInfo *info = dwb_malloc(sizeof(EditorInfo));
- char *id = webkit_dom_html_element_get_id(WEBKIT_DOM_HTML_ELEMENT(active));
- if (id != NULL && strlen(id) > 0) {
- info->id = id;
- }
- else {
- info->id = NULL;
- }
- info->tagname = tagname;
- info->element = active;
- info->filename = path;
- info->gl = dwb.state.fview;
- g_child_watch_add(pid, (GChildWatchFunc)dwb_editor_watch, info);
-
-clean:
- g_free(value);
-
- return ret;
-}/*}}}*/
/* Auto insert mode {{{*/
static gboolean
dwb_auto_insert(WebKitDOMElement *element)
{
- if (dwb_get_editable(element))
+ if (dom_get_editable(element))
{
dwb_change_mode(INSERT_MODE);
return true;
@@ -1308,7 +1082,7 @@ void
dwb_check_auto_insert(GList *gl)
{
WebKitDOMDocument *doc = webkit_web_view_get_dom_document(WEBVIEW(gl));
- WebKitDOMElement *active = dwb_get_active_element(doc);
+ WebKitDOMElement *active = dom_get_active_element(doc);
if (!dwb_auto_insert(active))
{
WebKitDOMHTMLElement *element = webkit_dom_document_get_body(doc);
@@ -1820,7 +1594,7 @@ dwb_unfocus()
view_set_normal_style(dwb.state.fview);
dwb_source_remove();
CLEAR_COMMAND_TEXT();
- dwb_dom_remove_from_parent(WEBKIT_DOM_NODE(CURRENT_VIEW()->status_element), NULL);
+ dom_remove_from_parent(WEBKIT_DOM_NODE(CURRENT_VIEW()->status_element), NULL);
dwb.state.fview = NULL;
}
} /*}}}*/
@@ -3070,7 +2844,7 @@ dwb_normal_mode(gboolean clean)
CLEAR_COMMAND_TEXT();
}
- dwb_dom_remove_from_parent(WEBKIT_DOM_NODE(CURRENT_VIEW()->status_element), NULL);
+ dom_remove_from_parent(WEBKIT_DOM_NODE(CURRENT_VIEW()->status_element), NULL);
if (mode == NORMAL_MODE)
webkit_web_view_set_highlight_text_matches(CURRENT_WEBVIEW(), false);
diff --git a/src/dwb.h b/src/dwb.h
index 1e90d4ed..a951792c 100644
--- a/src/dwb.h
+++ b/src/dwb.h
@@ -465,6 +465,8 @@ enum Signal {
SIG_PLUGINS_FRAME_CREATED,
SIG_PLUGINS_LAST,
+ SIG_EDITOR_NAVIGATION,
+
SIG_KEY_PRESS,
SIG_KEY_RELEASE,
SIG_LAST,
@@ -941,7 +943,6 @@ DwbStatus dwb_set_clipboard(const char *text, GdkAtom atom);
char * dwb_clipboard_get_text(GdkAtom atom);
void dwb_paste_primary(void);
-DwbStatus dwb_open_in_editor(void);
gboolean dwb_confirm(GList *gl, char *prompt, ...);
void dwb_save_quickmark(const char *);
@@ -970,9 +971,7 @@ DwbStatus dwb_scheme_handler(GList *gl, WebKitNetworkRequest *request);
GList *dwb_get_simple_list(GList *, const char *filename);
char * dwb_prompt(gboolean visibility, char *prompt, ...);
-gboolean dwb_dom_remove_from_parent(WebKitDOMNode *node, GError **error);
char * dwb_get_raw_data(GList *gl);
-gboolean dwb_dom_add_frame_listener(WebKitWebFrame *frame, const char *signal, GCallback callback, gboolean bubble, GList *gl);
void dwb_free_list(GList *list, void (*func)(void*));
void dwb_init(void);
diff --git a/src/editor.c b/src/editor.c
new file mode 100644
index 00000000..ccef61aa
--- /dev/null
+++ b/src/editor.c
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2010-2013 Stefan Bolte <portix@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <string.h>
+#include "dwb.h"
+#include "editor.h"
+#include "util.h"
+#include "dom.h"
+
+typedef struct _EditorInfo {
+ char *filename;
+ char *id;
+ GList *gl;
+ WebKitDOMElement *element;
+ char *tagname;
+} EditorInfo;
+
+/* dwb_editor_watch (GChildWatchFunc) {{{*/
+static void
+editor_watch(GPid pid, int status, EditorInfo *info)
+{
+ gsize length;
+ WebKitDOMElement *e = NULL;
+ WebKitWebView *wv;
+
+ char *content = util_get_file_content(info->filename, &length);
+
+ if (content == NULL)
+ goto clean;
+
+ if (!info->gl || !g_list_find(dwb.state.views, info->gl->data))
+ {
+ if (info->id == NULL)
+ goto clean;
+ else
+ wv = CURRENT_WEBVIEW();
+ }
+ else
+ wv = WEBVIEW(info->gl);
+ if (info->id != NULL)
+ {
+ WebKitDOMDocument *doc = webkit_web_view_get_dom_document(wv);
+ e = webkit_dom_document_get_element_by_id(doc, info->id);
+
+ if (e == NULL && (e = info->element) == NULL )
+ goto clean;
+ }
+ else if (info->element)
+ e = info->element;
+ else
+ goto clean;
+
+ /* g_file_get_contents adds an additional newline */
+ if (length > 0 && content[length-1] == '\n')
+ content[length-1] = 0;
+
+ if (!strcasecmp(info->tagname, "INPUT"))
+ webkit_dom_html_input_element_set_value(WEBKIT_DOM_HTML_INPUT_ELEMENT(e), content);
+ else if (!strcasecmp(info->tagname, "TEXTAREA"))
+ webkit_dom_html_text_area_element_set_value(WEBKIT_DOM_HTML_TEXT_AREA_ELEMENT(e), content);
+
+clean:
+ unlink(info->filename);
+ g_free(info->filename);
+ g_free(info->id);
+ g_free(info);
+}/*}}}*/
+
+static gboolean
+navigation_cb(WebKitWebView *web, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *action,
+ WebKitWebPolicyDecision *policy, EditorInfo *info)
+{
+ if (frame == webkit_web_view_get_main_frame(web))
+ {
+ info->element = NULL;
+ g_free(info->id);
+ info->id = NULL;
+ g_signal_handler_disconnect(web, VIEW(info->gl)->status->signals[SIG_EDITOR_NAVIGATION]);
+ }
+ return false;
+}
+
+/* dwb_open_in_editor(void) ret: gboolean success {{{*/
+DwbStatus
+editor_open(void)
+{
+ DwbStatus ret = STATUS_OK;
+ char **commands = NULL;
+ char *commandstring = NULL, *tagname, *path;
+ char *value = NULL;
+ GPid pid;
+ gboolean success;
+
+ char *editor = GET_CHAR("editor");
+
+ if (editor == NULL)
+ return STATUS_ERROR;
+
+ WebKitDOMDocument *doc = webkit_web_view_get_dom_document(CURRENT_WEBVIEW());
+ WebKitDOMElement *active = dom_get_active_element(doc);
+
+ if (active == NULL)
+ return STATUS_ERROR;
+
+ tagname = webkit_dom_element_get_tag_name(active);
+ if (tagname == NULL)
+ {
+ ret = STATUS_ERROR;
+ goto clean;
+ }
+ if (! strcasecmp(tagname, "INPUT"))
+ value = webkit_dom_html_input_element_get_value(WEBKIT_DOM_HTML_INPUT_ELEMENT(active));
+ else if (! strcasecmp(tagname, "TEXTAREA"))
+ value = webkit_dom_html_text_area_element_get_value(WEBKIT_DOM_HTML_TEXT_AREA_ELEMENT(active));
+
+ if (value == NULL)
+ {
+ ret = STATUS_ERROR;
+ goto clean;
+ }
+
+ path = util_get_temp_filename("edit");
+
+ commandstring = util_string_replace(editor, "dwb_uri", path);
+ if (commandstring == NULL)
+ {
+ ret = STATUS_ERROR;
+ goto clean;
+ }
+
+ g_file_set_contents(path, value, -1, NULL);
+ commands = g_strsplit(commandstring, " ", -1);
+ g_free(commandstring);
+
+ success = g_spawn_async(NULL, commands, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL);
+ g_strfreev(commands);
+ if (!success)
+ {
+ ret = STATUS_ERROR;
+ goto clean;
+ }
+
+ EditorInfo *info = dwb_malloc(sizeof(EditorInfo));
+ char *id = webkit_dom_html_element_get_id(WEBKIT_DOM_HTML_ELEMENT(active));
+ if (id != NULL && strlen(id) > 0) {
+ info->id = id;
+ }
+ else {
+ info->id = NULL;
+ }
+ info->tagname = tagname;
+ info->element = active;
+ info->filename = path;
+ info->gl = dwb.state.fview;
+ g_child_watch_add(pid, (GChildWatchFunc)editor_watch, info);
+ VIEW(dwb.state.fview)->status->signals[SIG_EDITOR_NAVIGATION] =
+ g_signal_connect(CURRENT_WEBVIEW(), "navigation-policy-decision-requested", G_CALLBACK(navigation_cb), info);
+clean:
+ g_free(value);
+
+ return ret;
+}/*}}}*/
diff --git a/src/editor.h b/src/editor.h
new file mode 100644
index 00000000..634cdeb3
--- /dev/null
+++ b/src/editor.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2010-2013 Stefan Bolte <portix@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef EDITOR_H
+#define EDITOR_H
+
+DwbStatus editor_open(void);
+
+#endif
diff --git a/src/plugins.c b/src/plugins.c
index e71c216e..10f98f83 100644
--- a/src/plugins.c
+++ b/src/plugins.c
@@ -19,6 +19,7 @@
#include "dwb.h"
#include "util.h"
#include "view.h"
+#include "dom.h"
#define ALLOWED(g) (VIEW(g)->status->allowed_plugins)
@@ -187,7 +188,7 @@ plugins_load_status_cb(WebKitWebView *wv, GParamSpec *p, GList *gl)
void
plugins_frame_load_cb(WebKitWebFrame *frame, GParamSpec *p, GList *gl)
{
- dwb_dom_add_frame_listener(frame, "beforeload", G_CALLBACK(plugins_before_load_cb), true, gl);
+ dom_add_frame_listener(frame, "beforeload", G_CALLBACK(plugins_before_load_cb), true, gl);
}
void
diff --git a/src/scripts.c b/src/scripts.c
index f3989656..b23868e9 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -97,6 +97,7 @@ static Sigmap s_sigmap[] = {
{ SCRIPTS_SIG_STATUS_BAR, "statusBarChange" },
{ SCRIPTS_SIG_TAB_BUTTON_PRESS, "tabButtonPress" },
{ SCRIPTS_SIG_CHANGE_MODE, "changeMode" },
+ { SCRIPTS_SIG_EXECUTE_COMMAND, "executeCommand" },
{ 0, NULL },
};
@@ -129,6 +130,7 @@ static GQuark s_ref_quark;
static JSObjectRef s_init_before, s_init_after;
static JSObjectRef s_constructors[CONSTRUCTOR_LAST];
static gboolean s_opt_force = false;
+static JSObjectRef s_soup_session;
/* Only defined once */
static JSValueRef UNDEFINED, NIL;
@@ -879,6 +881,11 @@ global_get(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef
{
return JSContextGetGlobalObject(ctx);
}
+static JSValueRef
+global_get_webkit_session(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
+{
+ return s_soup_session;
+}
/* global_execute {{{*/
static JSValueRef
global_execute(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
@@ -2492,6 +2499,7 @@ create_global_object()
JSStaticValue global_values[] = {
{ "global", global_get, NULL, kJSDefaultAttributes },
+ { "session", global_get_webkit_session, NULL, kJSDefaultAttributes },
{ 0, 0, 0, 0 },
};
@@ -2723,6 +2731,9 @@ create_global_object()
s_download_class = JSClassCreate(&cd);
s_constructors[CONSTRUCTOR_DOWNLOAD] = create_constructor(s_global_context, "Download", s_download_class, download_constructor_cb, NULL);
+
+ s_soup_session = make_object_for_class(s_global_context, s_gobject_class, G_OBJECT(webkit_get_default_session()), false);
+ JSValueProtect(s_global_context, s_soup_session);
}/*}}}*/
/*}}}*/
@@ -2925,6 +2936,7 @@ scripts_end()
JSValueUnprotect(s_global_context, s_array_contructor);
JSValueUnprotect(s_global_context, UNDEFINED);
JSValueUnprotect(s_global_context, NIL);
+ JSValueUnprotect(s_global_context, s_soup_session);
JSClassRelease(s_gobject_class);
JSClassRelease(s_webview_class);
JSClassRelease(s_frame_class);
diff --git a/src/scripts.h b/src/scripts.h
index 77a400a8..77203f25 100644
--- a/src/scripts.h
+++ b/src/scripts.h
@@ -47,6 +47,7 @@ enum SIGNALS {
SCRIPTS_SIG_STATUS_BAR,
SCRIPTS_SIG_TAB_BUTTON_PRESS,
SCRIPTS_SIG_CHANGE_MODE,
+ SCRIPTS_SIG_EXECUTE_COMMAND,
SCRIPTS_SIG_LAST,
} ;
diff --git a/src/view.c b/src/view.c
index e1485311..7f3b64e5 100644
--- a/src/view.c
+++ b/src/view.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2012 Stefan Bolte <portix@gmx.net>
+ * Copyright (c) 2010-2013 Stefan Bolte <portix@gmx.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -32,6 +32,7 @@
#include "adblock.h"
#include "js.h"
#include "scripts.h"
+#include "dom.h"
static void view_ssl_state(GList *);
static unsigned long s_click_time;
@@ -421,7 +422,7 @@ view_hovering_over_link_cb(WebKitWebView *web, char *title, char *uri, GList *gl
VIEW(gl)->status->hover_uri = NULL;
dwb_update_uri(gl);
if (! (dwb.state.bar_visible & BAR_VIS_STATUS))
- dwb_dom_remove_from_parent(WEBKIT_DOM_NODE(VIEW(gl)->hover.element), NULL);
+ dom_remove_from_parent(WEBKIT_DOM_NODE(VIEW(gl)->hover.element), NULL);
}
}/*}}}*/