From 8611281b2efde71e17f20aedc9db22c1493788cc Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 19 Jun 2012 22:57:29 +0000 Subject: add content handler for javascript svn path=/trunk/netsurf/; revision=13971 --- Makefile.sources | 2 +- content/content_type.h | 9 ++++ content/hlcache.c | 2 +- javascript/content.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ render/html.c | 2 +- 5 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 javascript/content.c diff --git a/Makefile.sources b/Makefile.sources index 50c8a9b50..96bbdb6fa 100644 --- a/Makefile.sources +++ b/Makefile.sources @@ -29,7 +29,7 @@ S_DESKTOP := cookies.c history_global_core.c hotlist.c knockout.c \ # Javascript sources ifeq ($(NETSURF_USE_JS),YES) -S_JAVASCRIPT += jsapi.c jsapi/global.c +S_JAVASCRIPT += jsapi.c jsapi/global.c content.c else S_JAVASCRIPT += none.c endif diff --git a/content/content_type.h b/content/content_type.h index 8e24e4e8e..c0b3a2b23 100644 --- a/content/content_type.h +++ b/content/content_type.h @@ -36,12 +36,21 @@ typedef enum { CONTENT_TEXTPLAIN = 0x02, CONTENT_CSS = 0x04, + /** All images */ CONTENT_IMAGE = 0x08, + /** Navigator API Plugins */ CONTENT_PLUGIN = 0x10, + /** Themes (only GTK) */ CONTENT_THEME = 0x20, + /** Javascript */ + CONTENT_JS = 0x40, + /** All script types. */ + CONTENT_SCRIPT = 0x40, + + /** Any content matches */ CONTENT_ANY = 0x3f } content_type; diff --git a/content/hlcache.c b/content/hlcache.c index a22162f50..e99f238ad 100644 --- a/content/hlcache.c +++ b/content/hlcache.c @@ -656,7 +656,7 @@ nserror hlcache_migrate_ctx(hlcache_retrieval_ctx *ctx, hlcache_event hlevent; hlevent.type = CONTENT_MSG_ERROR; - hlevent.data.error = messages_get("BadType"); + hlevent.data.error = messages_get("UnacceptableType"); ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); diff --git a/javascript/content.c b/javascript/content.c new file mode 100644 index 000000000..d14862859 --- /dev/null +++ b/javascript/content.c @@ -0,0 +1,119 @@ +/* + * Copyright 2012 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** \file + * Content for javascript (implementation) + */ + +#include +#include +#include +#include +#include + +#include "utils/config.h" +#include "content/content_protected.h" +#include "content/hlcache.h" +#include "desktop/plotters.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/talloc.h" +#include "utils/utils.h" + +typedef struct javascript_content { + struct content base; +} javascript_content; + +static nserror javascript_create(const content_handler *handler, + lwc_string *imime_type, const http_parameter *params, + llcache_handle *llcache, const char *fallback_charset, + bool quirks, struct content **c) +{ + javascript_content *script; + nserror error; + + script = talloc_zero(0, javascript_content); + if (script == NULL) + return NSERROR_NOMEM; + + error = content__init(&script->base, handler, imime_type, params, + llcache, fallback_charset, quirks); + if (error != NSERROR_OK) { + talloc_free(script); + return error; + } + + *c = (struct content *) script; + + return NSERROR_OK; +} + +static bool javascript_convert(struct content *c) +{ + content_set_ready(c); + content_set_done(c); + + return true; +} + +static nserror +javascript_clone(const struct content *old, struct content **newc) +{ + javascript_content *script; + nserror error; + + script = talloc_zero(0, javascript_content); + if (script == NULL) + return NSERROR_NOMEM; + + error = content__clone(old, &script->base); + if (error != NSERROR_OK) { + content_destroy(&script->base); + return error; + } + + *newc = (struct content *) script; + + return NSERROR_OK; +} + +static void javascript_destroy(struct content *c) +{ +} + +static content_type javascript_content_type(void) +{ + return CONTENT_JS; +} + + +static const content_handler javascript_content_handler = { + .create = javascript_create, + .data_complete = javascript_convert, + .destroy = javascript_destroy, + .clone = javascript_clone, + .type = javascript_content_type, + .no_share = false, +}; + +static const char *javascript_types[] = { + "application/javascript", + "text/javascript" +}; + +CONTENT_FACTORY_REGISTER_TYPES(javascript, javascript_types, javascript_content_handler); diff --git a/render/html.c b/render/html.c index b40c89893..882da45d4 100644 --- a/render/html.c +++ b/render/html.c @@ -1882,7 +1882,7 @@ html_process_script(dom_node *node, dom_string *name, void *ctx) html_convert_script_callback, c, &child, - CONTENT_ANY, + CONTENT_SCRIPT, &nscript->data.external); nsurl_unref(joined); -- cgit v1.2.3