summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--config.mk4
-rw-r--r--scripts/hints.js49
-rw-r--r--src/commands.c10
-rw-r--r--src/dwb.c74
-rw-r--r--src/dwb.h4
-rw-r--r--src/html.c8
-rw-r--r--src/js.c64
-rw-r--r--src/js.h2
-rw-r--r--src/local.c2
-rw-r--r--src/util.c6
-rw-r--r--src/util.h2
-rw-r--r--src/view.c7
13 files changed, 168 insertions, 66 deletions
diff --git a/Makefile b/Makefile
index c68240fb..8595ea5c 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ install-man: all
install-data: all
install -d $(DESTDIR)$(DATADIR)/$(REAL_NAME)/scripts
- install -m 644 $(JSDIR)/hints.js $(DESTDIR)$(DATADIR)/$(REAL_NAME)/scripts/hints.js
+ install -m 644 $(JSDIR)/$(HINT_SCRIPT) $(DESTDIR)$(DATADIR)/$(REAL_NAME)/scripts/$(HINT_SCRIPT)
install -d $(DESTDIR)$(DATADIR)/$(REAL_NAME)/$(LIBDIR)
install -m 644 $(LIBDIR)/$(INFO_FILE) $(DESTDIR)$(DATADIR)/$(REAL_NAME)/$(LIBDIR)/$(INFO_FILE)
install -m 644 $(LIBDIR)/$(HEAD_FILE) $(DESTDIR)$(DATADIR)/$(REAL_NAME)/$(LIBDIR)/$(HEAD_FILE)
diff --git a/config.mk b/config.mk
index 18acec63..c89f6a61 100644
--- a/config.mk
+++ b/config.mk
@@ -91,6 +91,9 @@ KEY_FILE=keys.html
ERROR_FILE=error.html
LOCAL_FILE=local.html
+#hint script
+HINT_SCRIPT=hints.js
+
# VARIOUS FILES
PLUGIN_FILE=pluginblocker.asc
@@ -118,6 +121,7 @@ CFLAGS += -DHEAD_FILE=\"$(HEAD_FILE)\"
CFLAGS += -DKEY_FILE=\"$(KEY_FILE)\"
CFLAGS += -DERROR_FILE=\"$(ERROR_FILE)\"
CFLAGS += -DLOCAL_FILE=\"$(LOCAL_FILE)\"
+CFLAGS += -DHINT_SCRIPT=\"$(HINT_SCRIPT)\"
CFLAGS += -DSYSTEM_DATA_DIR=\"$(DATADIR)\"
# If execinfo.h is not available, e.g. freebsd
diff --git a/scripts/hints.js b/scripts/hints.js
index f57ac9b9..1d40f1fb 100644
--- a/scripts/hints.js
+++ b/scripts/hints.js
@@ -1,10 +1,10 @@
-String.prototype.isInt = function () {
- return !isNaN(parseInt(this, 10));
-};
-String.prototype.isLower = function () {
- return this == this.toLowerCase();
-};
-var DwbHintObj = (function () {
+(function () {
+ String.prototype.isInt = function () {
+ return !isNaN(parseInt(this, 10));
+ };
+ String.prototype.isLower = function () {
+ return this == this.toLowerCase();
+ };
var _letterSeq = "FDSARTGBVECWXQYIOPMNHZULKJ";
var _font = "bold 10px monospace";
var _style = "letter";
@@ -328,13 +328,15 @@ var DwbHintObj = (function () {
console.error(exc);
}
};
- var __showHints = function (type, new_tab) {
+ //var __showHints = function (type, new_tab) {
+ var __showHints = function (newTab, type) {
var i;
if (document.activeElement) {
document.activeElement.blur();
}
- _new_tab = new_tab;
+ _new_tab = newTab;
+ //__createHints(window, _style == "letter" ? __letterHint : __numberHint, type);
__createHints(window, _style == "letter" ? __letterHint : __numberHint, type);
var l = _elements.length;
@@ -560,7 +562,9 @@ var DwbHintObj = (function () {
};
var __submitSearchEngine = function (string) {
var e = __getActive().element;
+ console.log(e.value);
e.value = string;
+ console.log(e.name);
e.form.submit();
e.value = "";
__clear();
@@ -608,24 +612,27 @@ var DwbHintObj = (function () {
return {
- createStylesheet : function() {
+ createStyleSheet : function(obj) {
+ __init(obj.hintLetterSeq, obj.hintFont, obj.hintStyle, obj.hintFgColor,
+ obj.hintBgColor, obj.hintActiveColor, obj.hintNormalColor,
+ obj.hintBorder, obj.hintOpacity, obj.hintHighlighLinks);
__createStyleSheet(document);
},
showHints :
- function(type, new_tab) {
- return __showHints(type, new_tab);
+ function(obj) {
+ return __showHints(obj.newTab, obj.type);
},
updateHints :
- function (input, type) {
- return __updateHints(input, type);
+ function (obj) {
+ return __updateHints(obj.input, obj.type);
},
clear :
function () {
__clear();
},
followActive :
- function (type) {
- return __evaluate(__getActive().element, type);
+ function (obj) {
+ return __evaluate(__getActive().element, obj.type);
},
focusNext :
@@ -638,20 +645,16 @@ var DwbHintObj = (function () {
},
addSearchEngine :
function () {
+ console.log("add");
return __addSearchEngine();
},
submitSearchEngine :
- function (string) {
- return __submitSearchEngine(string);
+ function (obj) {
+ return __submitSearchEngine(obj.searchString);
},
focusInput :
function () {
__focusInput();
},
- init:
- function (letter_seq, font, style,
- fg_color, bg_color, active_color, normal_color, border, opacity, highlightLinks) {
- __init(letter_seq, font, style, fg_color, bg_color, active_color, normal_color, border, opacity, highlightLinks);
- }
};
})();
diff --git a/src/commands.c b/src/commands.c
index 6d433f5d..893d095f 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -28,6 +28,7 @@
#include "entry.h"
#include "adblock.h"
#include "download.h"
+#include "js.h"
static int inline dwb_floor(double x) {
return x >= 0 ? (int) x : (int) x - 1;
@@ -116,10 +117,11 @@ commands_focus_input(KeyMap *km, Arg *a) {
char *value;
DwbStatus ret = STATUS_OK;
- if ((value = dwb_execute_script(MAIN_FRAME(), "DwbHintObj.focusInput()", true)) && !g_strcmp0(value, "_dwb_no_input_")) {
- ret = STATUS_ERROR;
+ if ( (value = js_call_as_function(MAIN_FRAME(), CURRENT_VIEW()->hint_object, "focusInput", NULL, &value)) ) {
+ if (!g_strcmp0(value, "_dwb_no_input_"))
+ ret = STATUS_ERROR;
+ g_free(value);
}
- g_free(value);
return ret;
}/*}}}*/
@@ -128,7 +130,7 @@ commands_focus_input(KeyMap *km, Arg *a) {
DwbStatus
commands_add_search_field(KeyMap *km, Arg *a) {
char *value;
- if ( (value = dwb_execute_script(MAIN_FRAME(), "DwbHintObj.addSearchEngine()", true)) ) {
+ if ( (value = js_call_as_function(MAIN_FRAME(), CURRENT_VIEW()->hint_object, "addSearchEngine", NULL, &value)) ) {
if (!g_strcmp0(value, "_dwb_no_hints_")) {
return STATUS_ERROR;
}
diff --git a/src/dwb.c b/src/dwb.c
index f123458b..70c70135 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -1265,6 +1265,10 @@ dwb_clean_load_begin(GList *gl) {
dwb_change_mode(NORMAL_MODE, true);
}
view_set_favicon(gl, false);
+ if (v->hint_object != NULL) {
+ JSValueUnprotect(JS_CONEXT_REF(gl), v->hint_object);
+ v->hint_object = NULL;
+ }
}/*}}}*/
/* dwb_navigation_from_webkit_history_item(WebKitWebHistoryItem *) return: (alloc) Navigation* {{{*/
@@ -1416,12 +1420,12 @@ dwb_get_search_engine(const char *uri, gboolean force) {
/* dwb_submit_searchengine {{{*/
void
dwb_submit_searchengine(void) {
- char *com = g_strdup_printf("DwbHintObj.submitSearchEngine(\"%s\")", HINT_SEARCH_SUBMIT);
+ char buffer[64];
char *value;
- if ( (value = dwb_execute_script(MAIN_FRAME(), com, true))) {
+ snprintf(buffer, 64, "{ \"searchString\" : \"%s\" }", HINT_SEARCH_SUBMIT);
+ if ( (value = js_call_as_function(MAIN_FRAME(), CURRENT_VIEW()->hint_object, "submitSearchEngine", buffer, &value)) ) {
dwb.state.form_name = value;
}
- g_free(com);
}/*}}}*/
/* dwb_save_searchengine {{{*/
@@ -1542,20 +1546,22 @@ dwb_evaluate_hints(const char *buffer) {
/* update_hints {{{*/
gboolean
dwb_update_hints(GdkEventKey *e) {
- char *buffer = NULL;
+ char *buffer;
char *com = NULL;
- char input[BUFFER_LENGTH] = { 0 }, *val;
+ char *val;
gboolean ret = false;
+ char json[BUFFER_LENGTH] = {0};
if (e->keyval == GDK_KEY_Return) {
- com = g_strdup_printf("DwbHintObj.followActive(%d)", hint_map[dwb.state.hint_type].arg);
+ com = "followActive";
+ snprintf(json, BUFFER_LENGTH, "{ \"type\" : \"%d\" }", hint_map[dwb.state.hint_type].arg);
}
else if (DWB_TAB_KEY(e)) {
if (e->state & GDK_SHIFT_MASK) {
- com = g_strdup("DwbHintObj.focusPrev()");
+ com = "focusPrev";
}
else {
- com = g_strdup("DwbHintObj.focusNext()");
+ com = "focusNext";
}
ret = true;
}
@@ -1564,13 +1570,12 @@ dwb_update_hints(GdkEventKey *e) {
}
else {
val = util_keyval_to_char(e->keyval, true);
- snprintf(input, BUFFER_LENGTH, "%s%s", GET_TEXT(), val ? val : "");
- com = g_strdup_printf("DwbHintObj.updateHints(\"%s\", %d)", input, hint_map[dwb.state.hint_type].arg);
+ snprintf(json, BUFFER_LENGTH, "{ \"input\" : \"%s%s\", \"type\" : %d }", GET_TEXT(), val ? val : "", hint_map[dwb.state.hint_type].arg);
+ com = "updateHints";
g_free(val);
}
if (com) {
- buffer = dwb_execute_script(MAIN_FRAME(), com, true);
- g_free(com);
+ buffer = js_call_as_function(MAIN_FRAME(), CURRENT_VIEW()->hint_object, com, *json ? json : NULL, &buffer);
}
if (buffer != NULL) {
if (dwb_evaluate_hints(buffer) == STATUS_END)
@@ -1589,11 +1594,16 @@ dwb_show_hints(Arg *arg) {
}
if (dwb.state.mode != HINT_MODE) {
gtk_entry_set_text(GTK_ENTRY(dwb.gui.entry), "");
- char *command = g_strdup_printf("DwbHintObj.showHints(%d, %d)",
- hint_map[arg->i].arg,
- (dwb.state.nv & (OPEN_NEW_WINDOW|OPEN_NEW_VIEW)));
- char *jsret = dwb_execute_script(MAIN_FRAME(), command, true);
- g_free(command);
+ char json[64];
+ snprintf(json, 64, "{ \"newTab\" : \"%d\", \"type\" : \"%d\" }",
+ (dwb.state.nv & (OPEN_NEW_WINDOW|OPEN_NEW_VIEW)),
+ hint_map[arg->i].arg);
+ char *jsret;
+ js_call_as_function(MAIN_FRAME(), CURRENT_VIEW()->hint_object, "showHints", json, &jsret);
+ if (jsret) {
+ puts(jsret);
+ //g_free(jsret);
+ }
if (jsret != NULL) {
ret = dwb_evaluate_hints(jsret);
g_free(jsret);
@@ -1620,8 +1630,11 @@ dwb_execute_script(WebKitWebFrame *frame, const char *com, gboolean ret) {
g_return_val_if_fail(global_object != NULL, NULL);
JSStringRef text = JSStringCreateWithUTF8CString(com);
- eval_ret = JSEvaluateScript(context, text, global_object, NULL, 0, NULL);
+ JSValueRef exc = NULL;
+ eval_ret = JSEvaluateScript(context, text, global_object, NULL, 0, &exc);
JSStringRelease(text);
+ if (exc != NULL)
+ return NULL;
if (eval_ret && ret) {
return js_value_to_char(context, eval_ret);
@@ -2266,7 +2279,7 @@ dwb_normal_mode(gboolean clean) {
Mode mode = dwb.state.mode;
if (mode == HINT_MODE || mode == SEARCH_FIELD_MODE) {
- dwb_execute_script(MAIN_FRAME(), "DwbHintObj.clear()", false);
+ js_call_as_function(MAIN_FRAME(), CURRENT_VIEW()->hint_object, "clear", NULL, NULL);
}
else if (mode == DOWNLOAD_GET_PATH) {
completion_clean_path_completion();
@@ -2634,6 +2647,8 @@ dwb_clean_up() {
dwb.keymap = NULL;
g_hash_table_remove_all(dwb.settings);
g_string_free(dwb.state.buffer, true);
+ g_free(dwb.misc.hints);
+ g_free(dwb.misc.hint_style);
dwb_free_list(dwb.fc.bookmarks, (void_func)dwb_navigation_free);
/* TODO sqlite */
@@ -3058,13 +3073,16 @@ dwb_init_scripts() {
util_get_directory_content(&allbuffer, dwb.files.scriptdir, "all.js");
/* systemscripts */
- char *dir = NULL;
- if ( (dir = util_get_system_data_dir("scripts")) ) {
- util_get_directory_content(&normalbuffer, dir, "js");
- util_get_directory_content(&allbuffer, dir, "all.js");
- g_free(dir);
- }
- g_string_append_printf(normalbuffer, "DwbHintObj.init(\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%f\", %s);",
+ g_free(dwb.misc.hints);
+ char *scriptpath = util_get_data_file(HINT_SCRIPT, "scripts");
+ dwb.misc.hints = util_get_file_content(scriptpath);
+ g_free(scriptpath);
+
+ g_free(dwb.misc.hint_style);
+ dwb.misc.hint_style = g_strdup_printf(
+ "{ \"hintLetterSeq\" : \"%s\", \"hintFont\" : \"%s\", \"hintStyle\" : \"%s\", \"hintFgColor\" : \"%s\",\
+ \"hintBgColor\" : \"%s\", \"hintActiveColor\" : \"%s\", \"hintNormalColor\" : \"%s\", \"hintBorder\" : \"%s\",\
+ \"hintOpacity\" : \"%f\", \"hintHighlighLinks\" : %s }",
GET_CHAR("hint-letter-seq"),
GET_CHAR("hint-font"),
GET_CHAR("hint-style"),
@@ -3556,14 +3574,16 @@ dwb_init() {
dwb.misc.userscripts = NULL;
dwb.misc.proxyuri = NULL;
dwb.misc.scripts = NULL;
+ dwb.misc.hints = NULL;
dwb.misc.synctimer = 0;
dwb.misc.bar_height = 0;
dwb.misc.fifo = NULL;
+ dwb.misc.hint_style = NULL;
dwb.state.buffer = g_string_new(NULL);
dwb.misc.tabbed_browsing = GET_BOOL("tabbed-browsing");
- char *path = util_get_data_file(PLUGIN_FILE);
+ char *path = util_get_data_file(PLUGIN_FILE, "lib");
if (path) {
dwb.misc.pbbackground = util_get_file_content(path);
g_free(path);
diff --git a/src/dwb.h b/src/dwb.h
index 0694c16b..4d36c7ef 100644
--- a/src/dwb.h
+++ b/src/dwb.h
@@ -111,6 +111,7 @@
#define CLEAR_COMMAND_TEXT() dwb_set_status_bar_text(dwb.gui.lstatus, NULL, NULL, NULL, false)
#define BOOLEAN(X) (!(!(X)))
#define NAVIGATION(X) ((Navigation*)((X)->data))
+#define JS_CONEXT_REF(X) (webkit_web_frame_get_global_context(webkit_web_view_get_main_frame(WEBVIEW(gl))))
#define CURRENT_URL() webkit_web_view_get_uri(CURRENT_WEBVIEW())
@@ -594,6 +595,7 @@ struct _View {
WebKitDOMElement *anchor;
WebKitDOMCSSStyleDeclaration *style;
} hover;
+ JSObjectRef hint_object;
};
struct _Color {
DwbColor active_fg;
@@ -658,6 +660,7 @@ struct _Misc {
/* applied to the mainframe */
char *scripts;
char *scripts_onload;
+ char *hints;
/* applied to all frames */
char *allscripts;
char *allscripts_onload;
@@ -690,6 +693,7 @@ struct _Misc {
int bar_height;
char *fifo;
TabPosition tab_position;
+ char *hint_style;
};
struct _Files {
const char *bookmarks;
diff --git a/src/html.c b/src/html.c
index c41a8dec..5037294d 100644
--- a/src/html.c
+++ b/src/html.c
@@ -61,8 +61,8 @@ DwbStatus
html_load_page(WebKitWebView *wv, HtmlTable *t, char *panel) {
char *filecontent;
GString *content = g_string_new(NULL);
- char *path = util_get_data_file(t->file);
- char *headpath = util_get_data_file(HEAD_FILE);
+ char *path = util_get_data_file(t->file, "lib");
+ char *headpath = util_get_data_file(HEAD_FILE, "lib");
DwbStatus ret = STATUS_ERROR;
if (path && headpath) {
@@ -275,7 +275,7 @@ html_settings(GList *gl, HtmlTable *table) {
DwbStatus ret = STATUS_ERROR;
WebKitWebView *wv = WEBVIEW(gl);
- char *path = util_get_data_file(SETTINGS_FILE);
+ char *path = util_get_data_file(SETTINGS_FILE, "lib");
if (path != NULL) {
g_file_get_contents(path, &content, NULL, NULL);
ret = html_load_page(wv, table, content);
@@ -360,7 +360,7 @@ html_keys(GList *gl, HtmlTable *table) {
DwbStatus ret = STATUS_ERROR;
char *content = NULL;
WebKitWebView *wv = WEBVIEW(gl);
- char *path = util_get_data_file(KEY_FILE);
+ char *path = util_get_data_file(KEY_FILE, "lib");
if (path != NULL) {
g_signal_connect(wv, "notify::load-status", G_CALLBACK(html_keys_load_cb), table);
g_file_get_contents(path, &content, NULL, NULL);
diff --git a/src/js.c b/src/js.c
index ca9b7383..84b900d2 100644
--- a/src/js.c
+++ b/src/js.c
@@ -18,6 +18,7 @@
#include <JavaScriptCore/JavaScript.h>
#include "dwb.h"
+#include "util.h"
#include "js.h"
#define JS_STRING_MAX 1024
@@ -82,10 +83,73 @@ js_string_to_char(JSContextRef ctx, JSStringRef jsstring) {
return ret;
}/*}}}*/
+JSObjectRef
+js_create_object(WebKitWebFrame *frame, const char *script) {
+ if (script == NULL)
+ return NULL;
+ JSContextRef ctx = webkit_web_frame_get_global_context(frame);
+ JSStringRef jsscript = JSStringCreateWithUTF8CString(script);
+ JSValueRef exc = NULL;
+ JSValueRef ret = JSEvaluateScript(ctx, jsscript, NULL, NULL, 0, &exc);
+ if (exc != NULL)
+ return NULL;
+ JSStringRelease(jsscript);
+ JSValueProtect(ctx, ret);
+ JSObjectRef return_object = JSValueToObject(ctx, ret, &exc);
+ if (exc != NULL)
+ return NULL;
+ JSPropertyNameArrayRef array = JSObjectCopyPropertyNames(ctx, return_object);
+ for (int i=0; i<JSPropertyNameArrayGetCount(array); i++) {
+ JSStringRef prop_name = JSPropertyNameArrayGetNameAtIndex(array, i);
+ JSValueRef prop = JSObjectGetProperty(ctx, return_object, prop_name, NULL);
+ JSObjectDeleteProperty(ctx, return_object, prop_name, NULL);
+ JSObjectSetProperty(ctx, return_object, prop_name, prop,
+ kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+ }
+ JSPropertyNameArrayRelease(array);
+ return return_object;
+}
+char *
+js_call_as_function(WebKitWebFrame *frame, JSObjectRef obj, char *string, char *json, char **char_ret) {
+ if (obj == NULL) {
+ goto error_out;
+ }
+ JSContextRef ctx = webkit_web_frame_get_global_context(frame);
+ JSStringRef name = JSStringCreateWithUTF8CString(string);
+ if (!JSObjectHasProperty(ctx, obj, name)) {
+ goto error_out;
+ }
+ JSValueRef function = JSObjectGetProperty(ctx, obj, name, NULL);
+ JSObjectRef function_object = JSValueToObject(ctx, function, NULL);
+ JSValueRef ret;
+ JSValueRef v = NULL;
+ if (json != NULL) {
+ JSStringRef js_json = JSStringCreateWithUTF8CString(json);
+ v = JSValueMakeFromJSONString(ctx, js_json);
+ }
+ if (v) {
+ JSValueRef vals[] = { v };
+ ret = JSObjectCallAsFunction(ctx, function_object, NULL, 1, vals, NULL);
+ }
+ else {
+ ret = JSObjectCallAsFunction(ctx, function_object, NULL, 0, NULL, NULL);
+ }
+ if (char_ret != NULL) {
+ *char_ret = js_value_to_char(ctx, ret);
+ return *char_ret;
+ }
+error_out:
+ if (char_ret != NULL)
+ *char_ret = NULL;
+ return NULL;
+}
+
/*{{{*/
char *
js_value_to_char(JSContextRef ctx, JSValueRef value) {
JSValueRef exc = NULL;
+ if (value == NULL)
+ return NULL;
if (! JSValueIsString(ctx, value))
return NULL;
JSStringRef jsstring = JSValueToStringCopy(ctx, value, &exc);
diff --git a/src/js.h b/src/js.h
index 56403cce..a7e61f34 100644
--- a/src/js.h
+++ b/src/js.h
@@ -25,5 +25,7 @@ JSObjectRef js_get_object_property(JSContextRef ctx, JSObjectRef arg, const char
JSObjectRef js_get_object_property(JSContextRef ctx, JSObjectRef arg, const char *name);
char * js_get_string_property(JSContextRef ctx, JSObjectRef arg, const char *name);
double js_get_double_property(JSContextRef ctx, JSObjectRef arg, const char *name);
+JSObjectRef js_create_object(WebKitWebFrame *, const char *);
+char * js_call_as_function(WebKitWebFrame *, JSObjectRef, char *string, char *args, char **char_ret);
#endif
diff --git a/src/local.c b/src/local.c
index 11eb8caf..5910c261 100644
--- a/src/local.c
+++ b/src/local.c
@@ -237,7 +237,7 @@ local_show_directory(GList *gl, const char *path, gboolean add_to_history) {
g_string_append_len(path_buffer, tmp, match-tmp);
g_string_append(path_buffer, "</a>");
- char *local_file = util_get_data_file(LOCAL_FILE);
+ char *local_file = util_get_data_file(LOCAL_FILE, "lib");
char *filecontent = util_get_file_content(local_file);
if (filecontent == NULL) /* File doesn't exist or is a directory */
return;
diff --git a/src/util.c b/src/util.c
index 0e09713d..191497e2 100644
--- a/src/util.c
+++ b/src/util.c
@@ -411,20 +411,20 @@ util_get_user_data_dir(const char *dir) {
/* util_get_data_file(const char *filename) return: filename (alloc) or NULL {{{*/
char *
-util_get_data_file(const char *filename) {
+util_get_data_file(const char *filename, const char *dir) {
if (filename == NULL)
return NULL;
char *path = NULL;
char *ret = NULL;
char *basename = g_path_get_basename(filename);
- path = util_get_user_data_dir("lib");
+ path = util_get_user_data_dir(dir);
if (path != NULL) {
ret = g_build_filename(path, basename, NULL);
if (g_file_test(ret, G_FILE_TEST_EXISTS))
goto clean;
}
- path = util_get_system_data_dir("lib");
+ path = util_get_system_data_dir(dir);
if (path != NULL) {
ret = g_build_filename(path, basename, NULL);
if (g_file_test(ret, G_FILE_TEST_EXISTS))
diff --git a/src/util.h b/src/util.h
index fe86dcd0..7c855b5d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -55,7 +55,7 @@ gboolean util_set_file_content(const char *, const char *);
char * util_build_path(void);
char * util_get_system_data_dir(const char *);
char * util_get_user_data_dir(const char *);
-char * util_get_data_file(const char *);
+char * util_get_data_file(const char *, const char *);
// navigation
Navigation * dwb_navigation_new_from_line(const char *);
diff --git a/src/view.c b/src/view.c
index 29236eeb..18065640 100644
--- a/src/view.c
+++ b/src/view.c
@@ -29,6 +29,7 @@
#include "local.h"
#include "soup.h"
#include "adblock.h"
+#include "js.h"
static void view_ssl_state(GList *);
static unsigned long _click_time;
@@ -519,6 +520,7 @@ view_load_status_after_cb(WebKitWebView *web, GParamSpec *pspec, GList *gl) {
WebKitLoadStatus status = webkit_web_view_get_load_status(web);
if (status == WEBKIT_LOAD_COMMITTED) {
dwb_execute_script(webkit_web_view_get_main_frame(web), dwb.misc.scripts, false);
+ VIEW(gl)->hint_object = js_create_object(webkit_web_view_get_main_frame(web), dwb.misc.hints);
}
}/*}}}*/
/* view_load_status_cb {{{*/
@@ -544,7 +546,7 @@ view_load_status_cb(WebKitWebView *web, GParamSpec *pspec, GList *gl) {
/* This is more or less a dummy call, to compile the script and speed up
* execution time
* */
- dwb_execute_script(webkit_web_view_get_main_frame(web), "DwbHintObj.createStylesheet();", false);
+ js_call_as_function(webkit_web_view_get_main_frame(web), v->hint_object, "createStyleSheet", dwb.misc.hint_style, NULL);
break;
case WEBKIT_LOAD_COMMITTED:
view_ssl_state(gl);
@@ -595,7 +597,7 @@ view_load_error_cb(WebKitWebView *web, WebKitWebFrame *frame, char *uri, GError
return false;
- char *errorfile = util_get_data_file(ERROR_FILE);
+ char *errorfile = util_get_data_file(ERROR_FILE, "lib");
if (errorfile == NULL)
return false;
@@ -763,6 +765,7 @@ view_create_web_view() {
status->style = NULL;
status->lockprotect = 0;
+ v->hint_object = NULL;
v->plugins = plugins_new();
for (int i=0; i<SIG_LAST; i++)
status->signals[i] = 0;