summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2004-07-30 23:40:01 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2004-07-30 23:40:01 +0000
commit8e650e3e39771431267aa6275d596516d1e34abb (patch)
tree89b376e980f7ba32abd4d2df53c676f1290af803 /render
parentd601aa71887b45b4fbd1c1c86f5cfe2971100216 (diff)
downloadnetsurf-8e650e3e39771431267aa6275d596516d1e34abb.tar.gz
netsurf-8e650e3e39771431267aa6275d596516d1e34abb.tar.bz2
[project @ 2004-07-30 23:40:00 by jmb]
Rework stylesheet fetching code to remove dependence on magic numbers (now uses values defined in html.h) Make ad blocking optional. svn path=/import/netsurf/; revision=1168
Diffstat (limited to 'render')
-rw-r--r--render/html.c67
-rw-r--r--render/html.h9
2 files changed, 52 insertions, 24 deletions
diff --git a/render/html.c b/render/html.c
index 5fce63c26..7bda3b02a 100644
--- a/render/html.c
+++ b/render/html.c
@@ -23,6 +23,7 @@
#ifdef riscos
#include "netsurf/desktop/gui.h"
#endif
+#include "netsurf/desktop/options.h"
#include "netsurf/render/html.h"
#include "netsurf/render/layout.h"
#include "netsurf/utils/log.h"
@@ -326,30 +327,52 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
{
xmlNode *node, *node2;
char *rel, *type, *media, *href, *data, *url;
- unsigned int i = 2;
+ unsigned int i = STYLESHEET_START;
unsigned int last_active = 0;
union content_msg_data msg_data;
- /* stylesheet 0 is the base style sheet, stylesheet 1 is any <style> elements */
- c->data.html.stylesheet_content = xcalloc(2, sizeof(*c->data.html.stylesheet_content));
- c->data.html.stylesheet_content[1] = 0;
- c->data.html.stylesheet_count = 2;
+ /* stylesheet 0 is the base style sheet,
+ * stylesheet 1 is the adblocking stylesheet,
+ * stylesheet 2 is any <style> elements */
+ c->data.html.stylesheet_content = xcalloc(STYLESHEET_START, sizeof(*c->data.html.stylesheet_content));
+ c->data.html.stylesheet_content[STYLESHEET_ADBLOCK] = 0;
+ c->data.html.stylesheet_content[STYLESHEET_STYLE] = 0;
+ c->data.html.stylesheet_count = STYLESHEET_START;
c->active = 0;
- c->data.html.stylesheet_content[0] = fetchcache(
+ c->data.html.stylesheet_content[STYLESHEET_BASE] = fetchcache(
#ifdef riscos
"file:/<NetSurf$Dir>/Resources/CSS",
#else
"file:///home/james/Projects/netsurf/CSS",
#endif
- html_convert_css_callback, c, 0,
- c->width, c->height, true, 0, 0, false);
- assert(c->data.html.stylesheet_content[0]);
+ html_convert_css_callback, c,
+ (void *) STYLESHEET_BASE, c->width, c->height,
+ true, 0, 0, false);
+ assert(c->data.html.stylesheet_content[STYLESHEET_BASE]);
c->active++;
- fetchcache_go(c->data.html.stylesheet_content[0], 0,
- html_convert_css_callback, c, 0,
- 0, 0, false);
+ fetchcache_go(c->data.html.stylesheet_content[STYLESHEET_BASE], 0,
+ html_convert_css_callback, c,
+ (void *) STYLESHEET_BASE, 0, 0, false);
+
+ if (option_block_ads) {
+ c->data.html.stylesheet_content[STYLESHEET_ADBLOCK] = fetchcache(
+#ifdef riscos
+ "file:/<NetSurf$Dir>/Resources/AdBlock",
+#else
+ "file:///home/james/Projects/netsurf/AdBlock",
+#endif
+ html_convert_css_callback, c,
+ (void *) STYLESHEET_ADBLOCK, c->width,
+ c->height, true, 0, 0, false);
+ if (c->data.html.stylesheet_content[STYLESHEET_ADBLOCK]) {
+ c->active++;
+ fetchcache_go(c->data.html.stylesheet_content[STYLESHEET_ADBLOCK],
+ 0, html_convert_css_callback, c,
+ (void *) STYLESHEET_ADBLOCK, 0, 0, false);
+ }
+ }
for (node = head == 0 ? 0 : head->children; node != 0; node = node->next) {
if (node->type != XML_ELEMENT_NODE)
@@ -438,15 +461,15 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
/* create stylesheet */
LOG(("style element"));
- if (c->data.html.stylesheet_content[1] == 0) {
+ if (c->data.html.stylesheet_content[STYLESHEET_STYLE] == 0) {
const char *params[] = { 0 };
- c->data.html.stylesheet_content[1] =
+ c->data.html.stylesheet_content[STYLESHEET_STYLE] =
content_create(c->data.html.
base_url);
- if (!c->data.html.stylesheet_content[1])
+ if (!c->data.html.stylesheet_content[STYLESHEET_STYLE])
return;
if (!content_set_type(c->data.html.
- stylesheet_content[1],
+ stylesheet_content[STYLESHEET_STYLE],
CONTENT_CSS, "text/css",
params))
return;
@@ -457,7 +480,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
for (node2 = node->children; node2 != 0; node2 = node2->next) {
data = xmlNodeGetContent(node2);
if (!content_process_data(c->data.html.
- stylesheet_content[1],
+ stylesheet_content[STYLESHEET_STYLE],
data, strlen(data))) {
xmlFree(data);
return;
@@ -469,15 +492,15 @@ void html_find_stylesheets(struct content *c, xmlNode *head)
c->data.html.stylesheet_count = i;
- if (c->data.html.stylesheet_content[1] != 0) {
- if (css_convert(c->data.html.stylesheet_content[1], c->width,
+ if (c->data.html.stylesheet_content[STYLESHEET_STYLE] != 0) {
+ if (css_convert(c->data.html.stylesheet_content[STYLESHEET_STYLE], c->width,
c->height)) {
- content_add_user(c->data.html.stylesheet_content[1],
+ content_add_user(c->data.html.stylesheet_content[STYLESHEET_STYLE],
html_convert_css_callback,
- c, (void *) 1);
+ c, (void *) STYLESHEET_STYLE);
} else {
/* conversion failed */
- c->data.html.stylesheet_content[1] = 0;
+ c->data.html.stylesheet_content[STYLESHEET_STYLE] = 0;
}
}
diff --git a/render/html.h b/render/html.h
index 4dc1ca2a4..bd876a902 100644
--- a/render/html.h
+++ b/render/html.h
@@ -26,6 +26,12 @@ struct content;
struct object_params;
struct imagemap;
+/* entries in stylesheet_content */
+#define STYLESHEET_BASE 0 /* base style sheet */
+#define STYLESHEET_ADBLOCK 1 /* adblocking stylesheet */
+#define STYLESHEET_STYLE 2 /* <style> elements (not cached) */
+#define STYLESHEET_START 3 /* start of document stylesheets */
+
/** Data specific to CONTENT_HTML. */
struct content_html_data {
htmlParserCtxt *parser; /**< HTML parser context. */
@@ -41,8 +47,7 @@ struct content_html_data {
/** Number of entries in stylesheet_content. */
unsigned int stylesheet_count;
- /** Stylesheets. Each may be 0. Stylesheet 0 is the base style sheet,
- * stylesheet 1 is any <style> elements (not cached). */
+ /** Stylesheets. Each may be 0. */
struct content **stylesheet_content;
struct css_style *style; /**< Base style. */