add content handler for javascript

svn path=/trunk/netsurf/; revision=13971
This commit is contained in:
Vincent Sanders 2012-06-19 22:57:29 +00:00
parent 08f18009c8
commit 8611281b2e
5 changed files with 131 additions and 3 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);

119
javascript/content.c Normal file
View File

@ -0,0 +1,119 @@
/*
* Copyright 2012 Vincent Sanders <vince@kyllikki.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/** \file
* Content for javascript (implementation)
*/
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <libnsbmp.h>
#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);

View File

@ -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);