summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/adblock.c45
-rw-r--r--src/dwb.h3
-rw-r--r--src/view.c12
3 files changed, 44 insertions, 16 deletions
diff --git a/src/adblock.c b/src/adblock.c
index 03abbe91..aa6a52b1 100644
--- a/src/adblock.c
+++ b/src/adblock.c
@@ -319,15 +319,32 @@ adblock_apply_element_hider(WebKitWebFrame *frame, GList *gl) {
if (! has_exception) {
g_string_append(css_rule, m_css_exceptions->str);
}
- if (css_rule->len > 0)
- {
- if (css_rule->str[css_rule->len-1] == ',')
- g_string_erase(css_rule, css_rule->len-1, 1);
- g_string_append(css_rule, "{display:none!important;}");
- js_call_as_function(frame, VIEW(gl)->js_base, "insertAdblockRule", css_rule->str, kJSTypeString, NULL);
+ if (css_rule->str[css_rule->len-1] == ',')
+ g_string_erase(css_rule, css_rule->len-1, 1);
+ g_string_append(css_rule, "{display:none!important;}");
+ if (frame == webkit_web_view_get_main_frame(WEBVIEW(gl))) {
+ WebKitDOMDocument *doc = webkit_web_view_get_dom_document(WEBVIEW(gl));
+ WebKitDOMHTMLHeadElement *head = webkit_dom_document_get_head(doc);
+
+ g_return_if_fail(G_IS_OBJECT(head));
+
+ for (GSList *l = VIEW(gl)->status->styles; l; l=l->next) {
+ webkit_dom_node_append_child(WEBKIT_DOM_NODE(head), WEBKIT_DOM_NODE(l->data), NULL);
+ }
+ if (css_rule->len > 0) {
+ webkit_dom_html_element_set_inner_html(WEBKIT_DOM_HTML_ELEMENT(VIEW(gl)->status->exc_style),
+ css_rule->str, NULL);
+ webkit_dom_node_append_child(WEBKIT_DOM_NODE(head), WEBKIT_DOM_NODE(VIEW(gl)->status->exc_style), NULL);
+ }
+ }
+ else {
+ if (css_rule->len > 0)
+ {
+ js_call_as_function(frame, VIEW(gl)->js_base, "insertAdblockRule", css_rule->str, kJSTypeString, NULL);
+ }
+ for (GSList *l = m_css_hider_list; l; l=l->next)
+ js_call_as_function(frame, VIEW(gl)->js_base, "insertAdblockRule", l->data, kJSTypeString, NULL);
}
- for (GSList *l = m_css_hider_list; l; l=l->next)
- js_call_as_function(frame, VIEW(gl)->js_base, "insertAdblockRule", l->data, kJSTypeString, NULL);
g_string_free(css_rule, true);
}/*}}}*/
/*}}}*/
@@ -484,10 +501,6 @@ adblock_disconnect(GList *gl) {
g_signal_handler_disconnect(WEBVIEW(gl), (VIEW(gl)->status->signals[SIG_AD_RESOURCE_REQUEST]));
v->status->signals[SIG_AD_RESOURCE_REQUEST] = 0;
}
- if (VIEW(gl)->status->style != NULL) {
- g_object_unref(VIEW(gl)->status->style);
- VIEW(gl)->status->style = NULL;
- }
}/*}}}*/
/* adblock_connect() {{{*/
@@ -502,6 +515,14 @@ adblock_connect(GList *gl) {
if (m_simple_rules->len > 0) {
VIEW(gl)->status->signals[SIG_AD_RESOURCE_REQUEST] = g_signal_connect(WEBVIEW(gl), "resource-request-starting", G_CALLBACK(adblock_resource_request_cb), gl);
}
+ WebKitDOMDocument *doc = webkit_web_view_get_dom_document(WEBVIEW(gl));
+ for (GSList *l = m_css_hider_list; l; l=l->next) {
+ WebKitDOMElement *style = webkit_dom_document_create_element(doc, "style", NULL);
+ webkit_dom_html_element_set_inner_html(WEBKIT_DOM_HTML_ELEMENT(style), l->data, NULL);
+ VIEW(gl)->status->styles = g_slist_prepend(VIEW(gl)->status->styles, style);
+ }
+ VIEW(gl)->status->exc_style = webkit_dom_document_create_element(doc, "style", NULL);
+
}/*}}}*/
/* adblock_warn_ignored(const char *message, const char *rule){{{*/
diff --git a/src/dwb.h b/src/dwb.h
index 53e14850..9fbfdfc3 100644
--- a/src/dwb.h
+++ b/src/dwb.h
@@ -649,8 +649,9 @@ struct _ViewStatus {
#endif
GSList *allowed_plugins;
unsigned int lockprotect;
- WebKitDOMElement *style;
+ GSList *styles;
GSList *frames;
+ WebKitDOMElement *exc_style;
guint group;
};
struct _View {
diff --git a/src/view.c b/src/view.c
index c6f81f94..fb240d60 100644
--- a/src/view.c
+++ b/src/view.c
@@ -911,7 +911,8 @@ view_create_web_view() {
#endif
status->progress = 0;
status->allowed_plugins = NULL;
- status->style = NULL;
+ status->exc_style = NULL;
+ status->styles = NULL;
status->lockprotect = 0;
status->frames = NULL;
status->group = 0;
@@ -1039,8 +1040,13 @@ view_clean(GList *gl) {
scripts_remove_tab(v->script_wv);
- if (v->status->style) {
- g_object_unref(v->status->style);
+ if (v->status->exc_style) {
+ g_object_unref(v->status->exc_style);
+ }
+ if (v->status->styles) {
+ for (GSList *l = v->status->styles; l; l=l->next)
+ g_object_unref(l->data);
+ g_slist_free(v->status->styles);
}
g_object_unref(v->hover.anchor);