summaryrefslogtreecommitdiff
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
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
-rw-r--r--!NetSurf/Resources/CSS,f794
-rw-r--r--desktop/browser.c3
-rw-r--r--desktop/options.c3
-rw-r--r--desktop/options.h1
-rw-r--r--render/html.c67
-rw-r--r--render/html.h9
-rw-r--r--riscos/save_complete.c6
7 files changed, 62 insertions, 31 deletions
diff --git a/!NetSurf/Resources/CSS,f79 b/!NetSurf/Resources/CSS,f79
index 6f89ea5c1..2b0575d3d 100644
--- a/!NetSurf/Resources/CSS,f79
+++ b/!NetSurf/Resources/CSS,f79
@@ -1,9 +1,7 @@
/*
* This file is part of NetSurf, http://netsurf.sourceforge.net/
*/
-
-@import url('AdBlock');
-
+
/* Elements ordered as in the HTML 4.01 specification. */
html { display: block; }
diff --git a/desktop/browser.c b/desktop/browser.c
index fabd7ab4e..c4dcc5c54 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -432,7 +432,8 @@ void browser_window_reload(struct browser_window *bw, bool all)
c->data.html.object[i].content->fresh = false;
}
/* invalidate stylesheets */
- for (i=2; i!=c->data.html.stylesheet_count; i++) {
+ for (i=STYLESHEET_START;
+ i!=c->data.html.stylesheet_count; i++) {
if (c->data.html.stylesheet_content[i] != 0)
c->data.html.stylesheet_content[i]->fresh = false;
}
diff --git a/desktop/options.c b/desktop/options.c
index c999e0ea6..ab3653e1e 100644
--- a/desktop/options.c
+++ b/desktop/options.c
@@ -51,6 +51,8 @@ char *option_accept_language = 0;
bool option_ssl_verify_certificates = true;
/** Preferred maximum size of memory cache / bytes. */
int option_memory_cache_size = 2 * 1024 * 1024;
+/** Whether to block advertisements */
+bool option_block_ads = false;
EXTRA_OPTION_DEFINE
@@ -71,6 +73,7 @@ struct {
{ "accept_language", OPTION_STRING, &option_accept_language },
{ "ssl_verify_certificates", OPTION_BOOL, &option_ssl_verify_certificates },
{ "memory_cache_size", OPTION_INTEGER, &option_memory_cache_size },
+ { "block_advertisements", OPTION_BOOL, &option_block_ads },
EXTRA_OPTION_TABLE
};
diff --git a/desktop/options.h b/desktop/options.h
index 65fa59fc2..ae35cda94 100644
--- a/desktop/options.h
+++ b/desktop/options.h
@@ -38,6 +38,7 @@ extern int option_font_min_size;
extern char *option_accept_language;
extern bool option_ssl_verify_certificates;
extern int option_memory_cache_size;
+extern bool option_block_ads;
void options_read(const char *path);
void options_write(const char *path);
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. */
diff --git a/riscos/save_complete.c b/riscos/save_complete.c
index 074a44fc2..fad990c20 100644
--- a/riscos/save_complete.c
+++ b/riscos/save_complete.c
@@ -101,8 +101,8 @@ bool save_complete_html(struct content *c, const char *path, bool index)
if (save_complete_list_check(c))
return true;
- /* save stylesheets, ignoring the base sheet */
- for (i = 1; i != c->data.html.stylesheet_count; i++) {
+ /* save stylesheets, ignoring the base and adblocking sheets */
+ for (i = STYLESHEET_STYLE; i != c->data.html.stylesheet_count; i++) {
struct content *css = c->data.html.stylesheet_content[i];
char *source;
int source_len;
@@ -120,7 +120,7 @@ bool save_complete_html(struct content *c, const char *path, bool index)
if (!save_imported_sheets(css, path))
return false;
- if (i == 1)
+ if (i == STYLESHEET_STYLE)
continue; /* don't save <style> elements */
snprintf(spath, sizeof spath, "%s.%x", path,