static int user_style(Client *c, const char *name, DataType type, void *value, void *data) { WebKitUserContentManager *ucm; WebKitUserStyleSheet *style; gchar *source; gboolean enabled = *(gboolean*)value; ucm = webkit_web_view_get_user_content_manager(c->webview); if (enabled && vb.files[FILES_USER_STYLE]) { if (g_file_get_contents(vb.files[FILES_USER_STYLE], &source, NULL, NULL)) { style = 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, style); webkit_user_style_sheet_unref(style); g_free(source); } else { g_warning("Could not reed style file: %s", vb.files[FILES_USER_STYLE]); } } else { webkit_user_content_manager_remove_all_style_sheets(ucm); } /* Inject the global styles with author level to allow restyling by user * style sheets. */ style = webkit_user_style_sheet_new(CSS_HINTS, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, WEBKIT_USER_STYLE_LEVEL_AUTHOR, NULL, NULL); webkit_user_content_manager_add_style_sheet(ucm, style); webkit_user_style_sheet_unref(style); return CMD_SUCCESS; }
static void user_style_sheet_output_stream_splice_cb (GOutputStream *output_stream, GAsyncResult *result, gpointer user_data) { gssize bytes; bytes = g_output_stream_splice_finish (output_stream, result, NULL); if (bytes > 0) { WebKitUserStyleSheet *style_sheet; style_sheet = webkit_user_style_sheet_new (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output_stream)), WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, WEBKIT_USER_STYLE_LEVEL_USER, NULL, NULL); webkit_user_content_manager_add_style_sheet (WEBKIT_USER_CONTENT_MANAGER (ephy_embed_shell_get_user_content_manager (ephy_embed_shell_get_default ())), style_sheet); webkit_user_style_sheet_unref (style_sheet); } }