c->focus_new_tab = focus_tab;
- if (related_wv == NULL)
- c->web_view = webkit_web_view_new();
- else
+ if (related_wv == NULL) {
+ WebKitUserContentManager *ucm = webkit_user_content_manager_new();
+ WebKitUserScript *wkscript;
+ WebKitUserStyleSheet *wkstyle;
+ gchar *path = NULL, *source, *base;
+ const gchar *entry = NULL;
+ GDir *dir = NULL;
+
+ base = g_build_filename(g_get_user_data_dir(), __NAME__, "user-scripts",
+ NULL);
+ dir = g_dir_open(base, 0, NULL);
+ if (dir != NULL) {
+ while ((entry = g_dir_read_name(dir)) != NULL) {
+ path = g_build_filename(base, entry, NULL);
+ if (g_str_has_suffix(path, ".js")) {
+ g_file_get_contents(path, &source, NULL, NULL);
+ wkscript = webkit_user_script_new(
+ source, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
+ WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START, NULL,
+ NULL);
+ webkit_user_content_manager_add_script(ucm, wkscript);
+ webkit_user_script_unref(wkscript);
+ }
+ g_free(path);
+ g_free(source);
+ }
+ g_dir_close(dir);
+ }
+
+ base = g_build_filename(g_get_user_data_dir(), __NAME__, "user-styles",
+ NULL);
+ dir = g_dir_open(base, 0, NULL);
+ if (dir != NULL) {
+ while ((entry = g_dir_read_name(dir)) != NULL) {
+ path = g_build_filename(base, entry, NULL);
+ if (g_str_has_suffix(path, ".css")) {
+ g_file_get_contents(path, &source, NULL, NULL);
+ wkstyle = webkit_user_style_sheet_new(
+ source, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
+ WEBKIT_USER_STYLE_LEVEL_USER, NULL, NULL);
+ webkit_user_content_manager_add_style_sheet(ucm, wkstyle);
+ webkit_user_style_sheet_unref(wkstyle);
+ }
+ g_free(path);
+ g_free(source);
+ }
+ g_dir_close(dir);
+ }
+
+ g_free(base);
+
+ c->web_view = webkit_web_view_new_with_user_content_manager(ucm);
+ } else {
c->web_view = webkit_web_view_new_with_related_view(related_wv);
+ }
c->settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view));
-
webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view),
cfg.global_zoom);
webkit_settings_set_enable_javascript(c->settings,
* references. */
webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(c->web_view), grab_feeds,
NULL, grab_feeds_finished, c);
-
- run_user_scripts(WEBKIT_WEB_VIEW(c->web_view));
}
gtk_entry_set_progress_fraction(GTK_ENTRY(c->location), p);
}
return TRUE;
}
-void
-run_user_scripts(WebKitWebView *web_view) {
- gchar *base = NULL, *path = NULL, *contents = NULL;
- const gchar *entry = NULL;
- GDir *scriptdir = NULL;
-
- base =
- g_build_filename(g_get_user_data_dir(), __NAME__, "user-scripts", NULL);
- scriptdir = g_dir_open(base, 0, NULL);
- if (scriptdir != NULL) {
- while ((entry = g_dir_read_name(scriptdir)) != NULL) {
- path = g_build_filename(base, entry, NULL);
- char *jscmd = malloc(strlen(path) + 36);
- sprintf(jscmd, "console.log(\"Running userscript %s\");", path);
- if (g_str_has_suffix(path, ".js")) {
- if (g_file_get_contents(path, &contents, NULL, NULL)) {
- webkit_web_view_run_javascript(web_view, jscmd, NULL, NULL,
- NULL);
- webkit_web_view_run_javascript(web_view, contents, NULL,
- NULL, NULL);
- g_free(contents);
- g_free(jscmd);
- }
- }
- g_free(path);
- }
- g_dir_close(scriptdir);
- }
-
- g_free(base);
-}
-
void
show_web_view(WebKitWebView *web_view, gpointer data) {
struct Client *c = (struct Client *)data;
GTlsCertificate *cert;
gchar *basedir, *absfile;
const gchar *file;
- GDir *dir;
+ GDir *dir = NULL;
basedir = g_build_filename(g_get_user_data_dir(), __NAME__, "certs", NULL);
dir = g_dir_open(basedir, 0, NULL);