summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xamiga/gui.c36
-rwxr-xr-xatari/gui.c29
-rw-r--r--beos/beos_gui.cpp46
-rw-r--r--cocoa/gui.m14
-rw-r--r--content/fetch.c2
-rw-r--r--content/fetchers/resource.c100
-rw-r--r--desktop/gui.h6
-rw-r--r--framebuffer/findfile.c13
-rw-r--r--framebuffer/gui.c14
-rw-r--r--gtk/gui.c33
-rw-r--r--monkey/main.c24
-rw-r--r--render/html.c77
-rw-r--r--render/html.h4
-rw-r--r--riscos/gui.c70
-rw-r--r--windows/main.c27
15 files changed, 254 insertions, 241 deletions
diff --git a/amiga/gui.c b/amiga/gui.c
index 729942f90..e7fff73c5 100755
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -135,10 +135,6 @@
#define EXTRADOWN (IECODE_5TH_BUTTON)
#define EXTRAUP (IECODE_5TH_BUTTON | IECODE_UP_PREFIX)
-char *default_stylesheet_url;
-char *quirks_stylesheet_url;
-char *adblock_stylesheet_url;
-
struct MsgPort *appport;
struct Library *KeymapBase = NULL;
struct KeymapIFace *IKeymap = NULL;
@@ -450,21 +446,23 @@ void ami_amiupdate(void)
}
}
-char* gui_get_resource_url(const char *filename)
+nsurl *gui_get_resource_url(const char *path)
{
- char path[1024];
- char filename2[1024];
+ char buf[1024];
+ char path2[1024];
+ char *raw;
+ nsurl *url = NULL;
- if(ami_locate_resource(path, filename) == false)
+ if(ami_locate_resource(buf, path) == false)
{
- if((strncmp(filename + strlen(filename) - 4, ".htm", 4) == 0) ||
- (strncmp(filename + strlen(filename) - 5, ".html", 5) == 0))
+ if((strncmp(path + strlen(path) - SLEN(".htm"), ".htm", SLEN(".htm")) == 0) ||
+ (strncmp(path + strlen(path) - SLEN(".html"), ".html", SLEN(".html")) == 0))
{
/* Try with RISC OS HTML filetype, might work */
- strcpy(filename2, filename);
- strcat(filename2, ",faf");
+ strcpy(path2, path);
+ strcat(path2, ",faf");
- if(ami_locate_resource(path, filename2) == false)
+ if(ami_locate_resource(buf, path2) == false)
{
return NULL;
}
@@ -472,7 +470,13 @@ char* gui_get_resource_url(const char *filename)
else return NULL;
}
- return path_to_url(path);
+ raw = path_to_url(buf);
+ if (raw != NULL) {
+ nsurl_create(raw, &url);
+ free(raw);
+ }
+
+ return url;
}
void gui_init(int argc, char** argv)
@@ -489,10 +493,6 @@ void gui_init(int argc, char** argv)
win_destroyed = false;
nsscreentitle = ASPrintf("NetSurf %s",netsurf_version);
- default_stylesheet_url = "file:///PROGDIR:Resources/amiga.css";
- quirks_stylesheet_url = "file:///PROGDIR:Resources/quirks.css";
- adblock_stylesheet_url = "file:///PROGDIR:Resources/adblock.css";
-
ami_font_setdevicedpi(0); /* for early font requests, eg treeview init */
ami_amiupdate(); /* set env-vars for AmiUpdate */
diff --git a/atari/gui.c b/atari/gui.c
index ce1750526..ff7c034c4 100755
--- a/atari/gui.c
+++ b/atari/gui.c
@@ -78,9 +78,6 @@
#define TODO() (0)/*printf("%s Unimplemented!\n", __FUNCTION__)*/
-char *default_stylesheet_url;
-char *adblock_stylesheet_url;
-char *quirks_stylesheet_url;
char *tmp_clipboard;
struct gui_window *input_window = NULL;
struct gui_window *window_list = NULL;
@@ -961,15 +958,20 @@ static inline void create_cursor(int flags, short mode, void * form, MFORM_EX *
}
}
-char* gui_get_resource_url(const char *filename)
+nsurl *gui_get_resource_url(const char *path)
{
char buf[PATH_MAX];
- int len;
- char * ret;
- atari_find_resource((char*)&buf, filename, filename);
- /* TODO: handle failure? */
- len = strlen( (char*)&buf ) + 1;
- return( path_to_url((char*)&buf) );
+ char *raw;
+ nsurl *url = NULL;
+
+ atari_find_resource((char*)&buf, path, path);
+ raw = path_to_url((char*)&buf);
+ if (raw != NULL) {
+ nsurl_create(raw, &url);
+ free(raw);
+ }
+
+ return url;
}
static void gui_init(int argc, char** argv)
@@ -1018,13 +1020,6 @@ static void gui_init(int argc, char** argv)
LOG(("Enabling core select menu"));
option_core_select_menu = true;
- atari_find_resource(buf, "default.css", "./res/default.css");
- default_stylesheet_url = path_to_url(buf);
- LOG(("Using '%s' as Default CSS URL", default_stylesheet_url));
-
- atari_find_resource(buf, "quirks.css", "./res/quirks.css");
- quirks_stylesheet_url = path_to_url(buf);
-
if( strlen(option_url_file) ){
urldb_load(option_url_file);
}
diff --git a/beos/beos_gui.cpp b/beos/beos_gui.cpp
index 970932fea..8adff7589 100644
--- a/beos/beos_gui.cpp
+++ b/beos/beos_gui.cpp
@@ -93,9 +93,6 @@ void gui_init(int argc, char** argv);
bool replicated = false; /**< if we are running as a replicant */
-char *default_stylesheet_url;
-char *quirks_stylesheet_url;
-char *adblock_stylesheet_url;
char *options_file_location;
char *glade_file_location;
@@ -421,12 +418,17 @@ static int32 bapp_thread(void *arg)
return 0;
}
-char* gui_get_resource_url(const char *filename)
+nsurl *gui_get_resource_url(const char *path)
{
+ nsurl *url = NULL;
BString u("rsrc:/");
- u << filename;
- fprintf(stderr, "%s(%s) -> '%s'\n", __FUNCTION__, filename, u.String());
- return strdup(u.String());
+ if (strcmp(path, "default.css") == 0)
+ u << "beosdefault.css";
+ else
+ u << path;
+ fprintf(stderr, "%s(%s) -> '%s'\n", __FUNCTION__, path, u.String());
+ nsurl_create(u.String(), &url);
+ return url;
}
static void gui_init2(int argc, char** argv)
@@ -612,33 +614,6 @@ void gui_init(int argc, char** argv)
//find_resource(buf, "mime.types", "/etc/mime.types");
beos_fetch_filetype_init();
- /* set up stylesheet urls */
-
-#ifdef USE_RESOURCES
- default_stylesheet_url = strdup("rsrc:/beosdefault.css");
-#else
- find_resource(buf, "beosdefault.css", "./beos/res/beosdefault.css");
- default_stylesheet_url = path_to_url(buf);
-#endif
- //default_stylesheet_url = generate_default_css();
- LOG(("Using '%s' as Default CSS URL", default_stylesheet_url));
-
-#ifdef USE_RESOURCES
- quirks_stylesheet_url = strdup("rsrc:/quirks.css");
-#else
- find_resource(buf, "quirks.css", "./beos/res/quirks.css");
- default_stylesheet_url = path_to_url(buf);
-#endif
-
-
-#ifdef USE_RESOURCES
- adblock_stylesheet_url = strdup("rsrc:/adblock.css");
-#else
- find_resource(buf, "adblock.css", "./beos/res/adblock.css");
- adblock_stylesheet_url = path_to_url(buf);
-#endif
- LOG(("Using '%s' as AdBlock CSS URL", adblock_stylesheet_url));
-
urldb_load(option_url_file);
urldb_load_cookies(option_cookie_file);
@@ -765,9 +740,6 @@ void gui_quit(void)
urldb_save(option_url_file);
//options_save_tree(hotlist,option_hotlist_file,messages_get("TreeHotlist"));
- free(default_stylesheet_url);
- free(quirks_stylesheet_url);
- free(adblock_stylesheet_url);
free(option_cookie_file);
free(option_cookie_jar);
beos_fetch_filetype_fin();
diff --git a/cocoa/gui.m b/cocoa/gui.m
index 1364077c8..dc2155164 100644
--- a/cocoa/gui.m
+++ b/cocoa/gui.m
@@ -36,10 +36,6 @@
#import "image/ico.h"
#import "content/fetchers/resource.h"
-char *default_stylesheet_url = (char *)"resource:default.css";
-char *adblock_stylesheet_url = (char *)"resource:adblock.css";
-char *quirks_stylesheet_url = (char *)"resource:quirks.css";
-
NSString * const kCookiesFileOption = @"CookiesFile";
NSString * const kURLsFileOption = @"URLsFile";
NSString * const kHotlistFileOption = @"Hotlist";
@@ -50,11 +46,13 @@ NSString * const kAlwaysCloseMultipleTabs = @"AlwaysCloseMultipleTabs";
#define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ )
-char* gui_get_resource_url(const char *filename)
+nsurl *gui_get_resource_url(const char *path)
{
- NSString *path = [[NSBundle mainBundle] pathForResource: [NSString stringWithUTF8String: filename] ofType: @""];
- if (path == nil) return NULL;
- return strdup( [[[NSURL fileURLWithPath: path] absoluteString] UTF8String] );
+ nsurl *url = NULL;
+ NSString *nspath = [[NSBundle mainBundle] pathForResource: [NSString stringWithUTF8String: path] ofType: @""];
+ if (nspath == nil) return NULL;
+ nsurl_create([[[NSURL fileURLWithPath: nspath] absoluteString] UTF8String], &url);
+ return url;
}
void gui_poll(bool active)
diff --git a/content/fetch.c b/content/fetch.c
index 3508b78cf..e6b36f341 100644
--- a/content/fetch.c
+++ b/content/fetch.c
@@ -107,8 +107,6 @@ static lwc_string *fetch_https_lwc;
/**
* Initialise the fetcher.
- *
- * Must be called once before any other function.
*/
void fetch_init(void)
diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c
index c8557b6ea..87eaa3860 100644
--- a/content/fetchers/resource.c
+++ b/content/fetchers/resource.c
@@ -42,7 +42,6 @@
#include "content/fetchers/resource.h"
#include "content/urldb.h"
#include "desktop/gui.h"
-#include "desktop/netsurf.h"
#include "desktop/options.h"
#include "utils/log.h"
#include "utils/messages.h"
@@ -63,14 +62,29 @@ struct fetch_resource_context {
bool aborted; /**< Flag indicating fetch has been aborted */
bool locked; /**< Flag indicating entry is already entered */
- char *url;
- char *redirect_url; /**< The url the fetch redirects to */
+ nsurl *url;
+ nsurl *redirect_url; /**< The url the fetch redirects to */
fetch_resource_handler handler;
};
static struct fetch_resource_context *ring = NULL;
+/** Valid resource paths */
+static const char *fetch_resource_paths[] = {
+ "adblock.css",
+ "default.css",
+ "internal.css",
+ "quirks.css",
+ "credits.html",
+ "licence.html",
+ "netsurf.png"
+};
+static struct fetch_resource_map_entry {
+ lwc_string *path;
+ nsurl *url;
+} fetch_resource_map[NOF_ELEMENTS(fetch_resource_paths)];
+
/** issue fetch callbacks with locking */
static inline bool fetch_resource_send_callback(fetch_msg msg,
struct fetch_resource_context *ctx, const void *data,
@@ -109,7 +123,8 @@ static bool fetch_resource_redirect_handler(struct fetch_resource_context *ctx)
/* content is going to return redirect */
fetch_set_http_code(ctx->fetchh, 302);
- fetch_resource_send_callback(FETCH_REDIRECT, ctx, ctx->redirect_url, 0,
+ fetch_resource_send_callback(FETCH_REDIRECT, ctx,
+ nsurl_access(ctx->redirect_url), 0,
FETCH_ERROR_NO_ERROR);
return true;
@@ -136,7 +151,7 @@ static bool fetch_resource_notfound_handler(struct fetch_resource_context *ctx)
snprintf(buffer, sizeof buffer, "<html><head><title>%s</title></head>"
"<body><h1>%s</h1>"
"<p>Error %d while fetching file %s</p></body></html>",
- title, title, code, ctx->url);
+ title, title, code, nsurl_access(ctx->url));
if (fetch_resource_send_callback(FETCH_DATA, ctx, buffer, strlen(buffer),
FETCH_ERROR_NO_ERROR))
@@ -154,12 +169,48 @@ fetch_resource_notfound_handler_aborted:
/** callback to initialise the resource fetcher. */
static bool fetch_resource_initialise(lwc_string *scheme)
{
+ struct fetch_resource_map_entry *e;
+ uint32_t i;
+
+ for (i = 0; i < NOF_ELEMENTS(fetch_resource_paths); i++) {
+ e = &fetch_resource_map[i];
+
+ if (lwc_intern_string(fetch_resource_paths[i],
+ strlen(fetch_resource_paths[i]),
+ &e->path) != lwc_error_ok) {
+ while (i > 0) {
+ i--;
+ lwc_string_unref(fetch_resource_map[i].path);
+ nsurl_unref(fetch_resource_map[i].url);
+ }
+ }
+
+ e->url = gui_get_resource_url(fetch_resource_paths[i]);
+ if (e->url == NULL) {
+ lwc_string_unref(e->path);
+
+ while (i > 0) {
+ i--;
+ lwc_string_unref(fetch_resource_map[i].path);
+ nsurl_unref(fetch_resource_map[i].url);
+ }
+
+ return false;
+ }
+ }
+
return true;
}
-/** callback to initialise the resource fetcher. */
+/** callback to finalise the resource fetcher. */
static void fetch_resource_finalise(lwc_string *scheme)
{
+ uint32_t i;
+
+ for (i = 0; i < NOF_ELEMENTS(fetch_resource_map); i++) {
+ lwc_string_unref(fetch_resource_map[i].path);
+ nsurl_unref(fetch_resource_map[i].url);
+ }
}
/** callback to set up a resource fetch context. */
@@ -172,24 +223,35 @@ fetch_resource_setup(struct fetch *fetchh,
const char **headers)
{
struct fetch_resource_context *ctx;
- struct url_components urlcomp;
+ lwc_string *path;
ctx = calloc(1, sizeof(*ctx));
if (ctx == NULL)
return NULL;
- url_get_components(nsurl_access(url), &urlcomp);
+ ctx->handler = fetch_resource_notfound_handler;
+
+ if ((path = nsurl_get_component(url, NSURL_PATH)) != NULL) {
+ uint32_t i;
+ bool match;
+
+ /* Ensure requested path is valid */
+ for (i = 0; i < NOF_ELEMENTS(fetch_resource_map); i++) {
+ if (lwc_string_isequal(path,
+ fetch_resource_map[i].path,
+ &match) == lwc_error_ok && match) {
+ ctx->redirect_url =
+ nsurl_ref(fetch_resource_map[i].url);
+ ctx->handler =
+ fetch_resource_redirect_handler;
+ break;
+ }
+ }
- ctx->redirect_url = gui_get_resource_url(urlcomp.path);
- if (ctx->redirect_url == NULL) {
- ctx->handler = fetch_resource_notfound_handler;
- } else {
- ctx->handler = fetch_resource_redirect_handler;
+ lwc_string_unref(path);
}
- ctx->url = strdup(nsurl_access(url));
-
- url_destroy_components(&urlcomp);
+ ctx->url = nsurl_ref(url);
ctx->fetchh = fetchh;
@@ -202,8 +264,10 @@ fetch_resource_setup(struct fetch *fetchh,
static void fetch_resource_free(void *ctx)
{
struct fetch_resource_context *c = ctx;
- free(c->redirect_url);
- free(c->url);
+ if (c->redirect_url != NULL)
+ nsurl_unref(c->redirect_url);
+ if (c->url != NULL)
+ nsurl_unref(c->url);
RING_REMOVE(ring, c);
free(ctx);
}
diff --git a/desktop/gui.h b/desktop/gui.h
index 0b2c6c0c0..dc2841fb8 100644
--- a/desktop/gui.h
+++ b/desktop/gui.h
@@ -139,15 +139,15 @@ void gui_cert_verify(const char *url, const struct ssl_cert_info *certs,
/**
* Callback to translate resource to full url.
*
- * Transforms a resource: filename into a full URL. The returned URL
+ * Transforms a resource: path into a full URL. The returned URL
* is used as the target for a redirect. The caller takes ownership of
* the returned nsurl including unrefing it when finished with it.
*
- * \param filename The filename of the resource to locate.
+ * \param path The path of the resource to locate.
* \return A string containing the full URL of the target object or
* NULL if no suitable resource can be found.
*/
-char* gui_get_resource_url(const char *filename);
+nsurl* gui_get_resource_url(const char *path);
/** css callback to obtain named system colours from a frontend. */
css_error gui_system_colour(void *pw, lwc_string *name, css_color *color);
diff --git a/framebuffer/findfile.c b/framebuffer/findfile.c
index 588acfb4d..5cfde1656 100644
--- a/framebuffer/findfile.c
+++ b/framebuffer/findfile.c
@@ -98,10 +98,19 @@ char *url_to_path(const char *url)
return respath;
}
-char* gui_get_resource_url(const char *filename)
+nsurl *gui_get_resource_url(const char *path)
{
char buf[PATH_MAX];
- return path_to_url(filepath_sfind(respaths, buf, filename));
+ char *raw;
+ nsurl *url = NULL;
+
+ raw = path_to_url(filepath_sfind(respaths, buf, path));
+ if (raw != NULL) {
+ nsurl_create(raw, &url);
+ free(raw);
+ }
+
+ return url;
}
/*
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index e8f3f2983..03362a2bb 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -62,10 +62,6 @@
#define NSFB_TOOLBAR_DEFAULT_LAYOUT "blfsrut"
-char *default_stylesheet_url;
-char *quirks_stylesheet_url;
-char *adblock_stylesheet_url;
-
fbtk_widget_t *fbtk;
struct gui_window *input_window = NULL;
@@ -446,16 +442,6 @@ gui_init(int argc, char** argv)
option_core_select_menu = true;
- /* set up stylesheet urls */
- default_stylesheet_url = strdup("resource:default.css");
- LOG(("Using '%s' as Default CSS URL", default_stylesheet_url));
-
- quirks_stylesheet_url = strdup("resource:quirks.css");
- LOG(("Using '%s' as quirks CSS URL", quirks_stylesheet_url));
-
- adblock_stylesheet_url = strdup("resource:adblock.css");
- LOG(("Using '%s' as AdBlock CSS URL", adblock_stylesheet_url));
-
if (option_cookie_file == NULL) {
option_cookie_file = strdup("~/.netsurf/Cookies");
LOG(("Using '%s' as Cookies file", option_cookie_file));
diff --git a/gtk/gui.c b/gtk/gui.c
index 271eb2890..e72b2fc8e 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -81,9 +81,6 @@
#include "utils/utf8.h"
#include "utils/utils.h"
-char *default_stylesheet_url;
-char *quirks_stylesheet_url;
-char *adblock_stylesheet_url;
char *options_file_location;
char *toolbar_indices_file_location;
char *res_dir_location;
@@ -320,10 +317,23 @@ static void check_options(char **respath)
}
-char* gui_get_resource_url(const char *filename)
+nsurl *gui_get_resource_url(const char *path)
{
char buf[PATH_MAX];
- return path_to_url(filepath_sfind(respaths, buf, filename));
+ char *raw;
+ nsurl *url = NULL;
+
+ /* default.css -> gtkdefault.css */
+ if (strcmp(path, "default.css") == 0)
+ path = "gtkdefault.css";
+
+ raw = path_to_url(filepath_sfind(respaths, buf, path));
+ if (raw != NULL) {
+ nsurl_create(raw, &url);
+ free(raw);
+ }
+
+ return url;
}
@@ -390,16 +400,6 @@ static void gui_init(int argc, char** argv, char **respath)
filepath_sfinddef(respath, buf, "mime.types", "/etc/");
gtk_fetch_filetype_init(buf);
- /* set up stylesheet urls */
- default_stylesheet_url = strdup("resource:gtkdefault.css");
- LOG(("Using '%s' as Default CSS URL", default_stylesheet_url));
-
- quirks_stylesheet_url = strdup("resource:quirks.css");
- LOG(("Using '%s' as quirks CSS URL", quirks_stylesheet_url));
-
- adblock_stylesheet_url = strdup("resource:adblock.css");
- LOG(("Using '%s' as AdBlock CSS URL", adblock_stylesheet_url));
-
urldb_load(option_url_file);
urldb_load_cookies(option_cookie_file);
@@ -571,9 +571,6 @@ void gui_quit(void)
nsgtk_history_destroy();
nsgtk_hotlist_destroy();
sslcert_cleanup();
- free(default_stylesheet_url);
- free(quirks_stylesheet_url);
- free(adblock_stylesheet_url);
free(option_cookie_file);
free(option_cookie_jar);
free(print_options_file_location);
diff --git a/monkey/main.c b/monkey/main.c
index f4b75e00e..d1507f6b4 100644
--- a/monkey/main.c
+++ b/monkey/main.c
@@ -34,10 +34,6 @@
#include "utils/filepath.h"
#include "utils/url.h"
-char *default_stylesheet_url = NULL;
-char *quirks_stylesheet_url = NULL;
-char *adblock_stylesheet_url = NULL;
-
static char **respaths; /** resource search path vector */
/* Stolen from gtk/gui.c */
@@ -64,18 +60,24 @@ void gui_quit(void)
urldb_save_cookies(option_cookie_jar);
urldb_save(option_url_file);
sslcert_cleanup();
- free(default_stylesheet_url);
- free(quirks_stylesheet_url);
- free(adblock_stylesheet_url);
free(option_cookie_file);
free(option_cookie_jar);
gtk_fetch_filetype_fin();
}
-char* gui_get_resource_url(const char *filename)
+nsurl *gui_get_resource_url(const char *path)
{
char buf[PATH_MAX];
- return path_to_url(filepath_sfind(respaths, buf, filename));
+ char *raw;
+ nsurl *url = NULL;
+
+ raw = path_to_url(filepath_sfind(respaths, buf, path));
+ if (raw != NULL) {
+ nsurl_create(raw, &url);
+ free(raw);
+ }
+
+ return url;
}
void
@@ -115,10 +117,6 @@ main(int argc, char **argv)
filepath_sfinddef(respaths, buf, "mime.types", "/etc/");
gtk_fetch_filetype_init(buf);
- default_stylesheet_url = strdup("resource:gtkdefault.css");
- quirks_stylesheet_url = strdup("resource:quirks.css");
- adblock_stylesheet_url = strdup("resource:adblock.css");
-
urldb_load(option_url_file);
urldb_load_cookies(option_cookie_file);
diff --git a/render/html.c b/render/html.c
index a14c37fea..93b34cafb 100644
--- a/render/html.c
+++ b/render/html.c
@@ -149,6 +149,10 @@ static const char *html_types[] = {
static lwc_string *html_charset;
+static nsurl *html_default_stylesheet_url;
+static nsurl *html_adblock_stylesheet_url;
+static nsurl *html_quirks_stylesheet_url;
+
nserror html_init(void)
{
uint32_t i;
@@ -161,6 +165,21 @@ nserror html_init(void)
goto error;
}
+ error = nsurl_create("resource:default.css",
+ &html_default_stylesheet_url);
+ if (error != NSERROR_OK)
+ goto error;
+
+ error = nsurl_create("resource:adblock.css",
+ &html_adblock_stylesheet_url);
+ if (error != NSERROR_OK)
+ goto error;
+
+ error = nsurl_create("resource:quirks.css",
+ &html_quirks_stylesheet_url);
+ if (error != NSERROR_OK)
+ goto error;
+
for (i = 0; i < NOF_ELEMENTS(html_types); i++) {
error = content_factory_register_handler(html_types[i],
&html_content_handler);
@@ -178,6 +197,21 @@ error:
void html_fini(void)
{
+ if (html_quirks_stylesheet_url != NULL) {
+ nsurl_unref(html_quirks_stylesheet_url);
+ html_quirks_stylesheet_url = NULL;
+ }
+
+ if (html_adblock_stylesheet_url != NULL) {
+ nsurl_unref(html_adblock_stylesheet_url);
+ html_adblock_stylesheet_url = NULL;
+ }
+
+ if (html_default_stylesheet_url != NULL) {
+ nsurl_unref(html_default_stylesheet_url);
+ html_default_stylesheet_url = NULL;
+ }
+
if (html_charset != NULL) {
lwc_string_unref(html_charset);
html_charset = NULL;
@@ -986,11 +1020,6 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
struct html_stylesheet *stylesheets;
hlcache_child_context child;
nserror ns_error;
-
- nsurl *html_default_css = NULL;
- nsurl *html_quirks_css = NULL;
- nsurl *html_adblock_css = NULL;
-
nsurl *joined;
child.charset = c->encoding;
@@ -1013,11 +1042,7 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
c->base.active = 0;
- ns_error = nsurl_create(default_stylesheet_url, &html_default_css);
- if (ns_error != NSERROR_OK)
- goto no_memory;
-
- ns_error = hlcache_handle_retrieve(html_default_css, 0,
+ ns_error = hlcache_handle_retrieve(html_default_stylesheet_url, 0,
content__get_url(&c->base), NULL,
html_convert_css_callback, c, &child, accept,
&c->stylesheets[STYLESHEET_BASE].data.external);
@@ -1027,13 +1052,8 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
c->base.active++;
if (c->quirks == BINDING_QUIRKS_MODE_FULL) {
-
- ns_error = nsurl_create(quirks_stylesheet_url, &html_quirks_css);
- if (ns_error != NSERROR_OK)
- goto no_memory;
-
- ns_error = hlcache_handle_retrieve(html_quirks_css, 0,
- content__get_url(&c->base), NULL,
+ ns_error = hlcache_handle_retrieve(html_quirks_stylesheet_url,
+ 0, content__get_url(&c->base), NULL,
html_convert_css_callback, c, &child, accept,
&c->stylesheets[STYLESHEET_QUIRKS].
data.external);
@@ -1044,13 +1064,8 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
}
if (option_block_ads) {
-
- ns_error = nsurl_create(adblock_stylesheet_url, &html_adblock_css);
- if (ns_error != NSERROR_OK)
- goto no_memory;
-
- ns_error = hlcache_handle_retrieve(html_adblock_css, 0,
- content__get_url(&c->base), NULL,
+ ns_error = hlcache_handle_retrieve(html_adblock_stylesheet_url,
+ 0, content__get_url(&c->base), NULL,
html_convert_css_callback, c, &child, accept,
&c->stylesheets[STYLESHEET_ADBLOCK].
data.external);
@@ -1060,13 +1075,6 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
c->base.active++;
}
- if (html_default_css != NULL)
- nsurl_unref(html_default_css);
- if (html_adblock_css != NULL)
- nsurl_unref(html_adblock_css);
- if (html_quirks_css != NULL)
- nsurl_unref(html_quirks_css);
-
node = html;
/* depth-first search the tree for link elements */
@@ -1181,13 +1189,6 @@ bool html_find_stylesheets(html_content *c, xmlNode *html)
return true;
no_memory:
- if (html_default_css != NULL)
- nsurl_unref(html_default_css);
- if (html_adblock_css != NULL)
- nsurl_unref(html_adblock_css);
- if (html_quirks_css != NULL)
- nsurl_unref(html_quirks_css);
-
msg_data.error = messages_get("NoMemory");
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
return false;
diff --git a/render/html.h b/render/html.h
index a8f163574..648c9751f 100644
--- a/render/html.h
+++ b/render/html.h
@@ -134,10 +134,6 @@ struct content_html_iframe {
#define STYLESHEET_ADBLOCK 2 /* adblocking stylesheet */
#define STYLESHEET_START 3 /* start of document stylesheets */
-extern char *default_stylesheet_url;
-extern char *adblock_stylesheet_url;
-extern char *quirks_stylesheet_url;
-
/** Render padding and margin box outlines in html_redraw(). */
extern bool html_redraw_debug;
diff --git a/riscos/gui.c b/riscos/gui.c
index e39538c8d..9a6494c3e 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -169,10 +169,6 @@ extern int __dynamic_num;
const char * NETSURF_DIR;
-char *default_stylesheet_url;
-char *quirks_stylesheet_url;
-char *adblock_stylesheet_url;
-
static const char *task_name = "NetSurf";
#define CHOICES_PREFIX "<Choices$Write>.WWW.NetSurf."
@@ -285,31 +281,50 @@ static void ro_msg_save_desktop(wimp_message *message);
static void ro_msg_window_info(wimp_message *message);
static void ro_gui_view_source_bounce(wimp_message *message);
-char* gui_get_resource_url(const char *filename)
+nsurl *gui_get_resource_url(const char *path)
{
- const char base_url[] = "file:///NetSurf:/Resources/";
- size_t filename_len = strlen(filename);
+ static const char base_url[] = "file:///NetSurf:/Resources/";
+ size_t path_len, length;
+ char *raw;
+ nsurl *url = NULL;
- /* Find max URL length */
- size_t length = SLEN(base_url) + SLEN("xx/") + filename_len + 1;
+ /* Map paths first */
+ if (strcmp(path, "adblock.css") == 0)
+ path = "AdBlock";
+ else if (strcmp(path, "default.css") == 0)
+ path = "CSS";
+ else if (strcmp(path, "quirks.css") == 0)
+ path = "Quirks";
- /* Allocate memory for URL (will be owned and freed by the core) */
- char *resource_url = malloc(length);
- if (resource_url == NULL)
- return NULL;
+ path_len = strlen(path);
+
+ /* Find max URL length */
+ length = SLEN(base_url) + SLEN("xx/") + path_len + 1;
+
+ raw = malloc(length);
+ if (raw != NULL) {
+ /* Insert base URL */
+ char *ptr = memcpy(raw, base_url, SLEN(base_url));
+ ptr += SLEN(base_url);
+
+ /* Add language directory to URL, for translated files */
+ /* TODO: handle non-en langauages
+ * handle non-html translated files */
+ if (path_len > SLEN(".html") &&
+ strncmp(path + path_len - SLEN(".html"),
+ ".html", SLEN(".html")) == 0) {
+ memcpy(ptr, "en/", SLEN("en/"));
+ ptr += SLEN("en/");
+ }
- /* Insert base URL */
- resource_url = strcpy(resource_url, base_url);
+ /* Add filename to URL */
+ memcpy(ptr, path, path_len);
- /* Add language directory to URL, for translated files */
- /* TODO: handle non-en langauages
- * handle non-html translated files */
- if (strncmp(filename + filename_len - 5, ".html", 5) == 0) {
- resource_url = strcat(resource_url, "en/");
+ nsurl_create(raw, &url);
+ free(raw);
}
- /* Add filename to URL */
- return strcat(resource_url, filename);
+ return url;
}
/**
@@ -429,14 +444,6 @@ static void gui_init(int argc, char** argv)
if (!NETSURF_DIR)
die("Failed duplicating NetSurf directory string");
- /* Initialise stylesheet URLs */
- default_stylesheet_url = strdup("resource:CSS");
- quirks_stylesheet_url = strdup("resource:Quirks");
- adblock_stylesheet_url = strdup("resource:AdBlock");
- if (!default_stylesheet_url || !quirks_stylesheet_url ||
- !adblock_stylesheet_url)
- die("Failed initialising string constants.");
-
/* Initialise filename allocator */
filename_initialise();
@@ -823,9 +830,6 @@ void gui_quit(void)
rufl_quit();
free(gui_sprites);
xwimp_close_down(task_handle);
- free(default_stylesheet_url);
- free(quirks_stylesheet_url);
- free(adblock_stylesheet_url);
xhourglass_off();
}
diff --git a/windows/main.c b/windows/main.c
index 1a38f815e..26b966d25 100644
--- a/windows/main.c
+++ b/windows/main.c
@@ -35,16 +35,21 @@
static char **respaths; /** resource search path vector. */
-char *default_stylesheet_url;
-char *adblock_stylesheet_url;
-char *quirks_stylesheet_url;
-
char *options_file_location;
-char* gui_get_resource_url(const char *filename)
+nsurl *gui_get_resource_url(const char *path)
{
char buf[PATH_MAX];
- return path_to_url(filepath_sfind(respaths, buf, filename));
+ char *raw;
+ nsurl *url = NULL;
+
+ raw = path_to_url(filepath_sfind(respaths, buf, path));
+ if (raw != NULL) {
+ nsurl_create(raw, &url);
+ free(raw);
+ }
+
+ return url;
}
void gui_launch_url(const char *url)
@@ -122,16 +127,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
free(messages);
- /* set up stylesheet urls */
- default_stylesheet_url = strdup("resource:default.css");
- LOG(("Using '%s' as Default CSS URL", default_stylesheet_url));
-
- quirks_stylesheet_url = strdup("resource:quirks.css");
- LOG(("Using '%s' as quirks CSS URL", quirks_stylesheet_url));
-
- adblock_stylesheet_url = strdup("resource:adblock.css");
- LOG(("Using '%s' as AdBlock CSS URL", adblock_stylesheet_url));
-
ret = nsws_create_main_class(hInstance);
ret = nsws_create_drawable_class(hInstance);
ret = nsws_create_localhistory_class(hInstance);