mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-26 22:09:43 +03:00
add incomplete scheme fetcher for javascript urls
This commit is contained in:
parent
5b815861f3
commit
37755fb135
@ -57,6 +57,7 @@
|
|||||||
#include "content/fetchers/curl.h"
|
#include "content/fetchers/curl.h"
|
||||||
#include "content/fetchers/data.h"
|
#include "content/fetchers/data.h"
|
||||||
#include "content/fetchers/file.h"
|
#include "content/fetchers/file.h"
|
||||||
|
#include "javascript/fetcher.h"
|
||||||
#include "content/urldb.h"
|
#include "content/urldb.h"
|
||||||
|
|
||||||
/* Define this to turn on verbose fetch logging */
|
/* Define this to turn on verbose fetch logging */
|
||||||
@ -291,6 +292,7 @@ nserror fetcher_init(void)
|
|||||||
fetch_file_register();
|
fetch_file_register();
|
||||||
fetch_resource_register();
|
fetch_resource_register();
|
||||||
fetch_about_register();
|
fetch_about_register();
|
||||||
|
fetch_javascript_register();
|
||||||
|
|
||||||
return NSERROR_OK;
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file content/fetchers.h
|
/**
|
||||||
|
* \file content/fetchers.h
|
||||||
|
*
|
||||||
* Interface for fetchers factory.
|
* Interface for fetchers factory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -34,6 +36,15 @@ struct fetch;
|
|||||||
* Fetcher operations API
|
* Fetcher operations API
|
||||||
*
|
*
|
||||||
* These are the operations a fetcher must implement.
|
* These are the operations a fetcher must implement.
|
||||||
|
*
|
||||||
|
* Each fetcher is called once for initialisaion and finalisation.
|
||||||
|
* The poll entry point will be called to allow all active fetches to progress.
|
||||||
|
* The flow of a fetch operation is:
|
||||||
|
* URL is checked for aceptability.
|
||||||
|
* setup with all applicable data.
|
||||||
|
* start is called before teh first poll
|
||||||
|
* after completion or abort it is freed
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
struct fetcher_operation_table {
|
struct fetcher_operation_table {
|
||||||
/**
|
/**
|
||||||
@ -44,7 +55,7 @@ struct fetcher_operation_table {
|
|||||||
bool (*initialise)(lwc_string *scheme);
|
bool (*initialise)(lwc_string *scheme);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* can this fetcher accept a url.
|
* Can this fetcher accept a url.
|
||||||
*
|
*
|
||||||
* \param url the URL to check
|
* \param url the URL to check
|
||||||
* \return true if the fetcher can handle the url else false.
|
* \return true if the fetcher can handle the url else false.
|
||||||
@ -80,7 +91,7 @@ struct fetcher_operation_table {
|
|||||||
void (*poll)(lwc_string *scheme);
|
void (*poll)(lwc_string *scheme);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* finalise the fetcher.
|
* Finalise the fetcher.
|
||||||
*/
|
*/
|
||||||
void (*finalise)(lwc_string *scheme);
|
void (*finalise)(lwc_string *scheme);
|
||||||
};
|
};
|
||||||
@ -97,9 +108,9 @@ nserror fetcher_add(lwc_string *scheme, const struct fetcher_operation_table *op
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise the fetchers.
|
* Initialise all registered fetchers.
|
||||||
*
|
*
|
||||||
* @return NSERROR_OK or error code
|
* \return NSERROR_OK or error code
|
||||||
*/
|
*/
|
||||||
nserror fetcher_init(void);
|
nserror fetcher_init(void);
|
||||||
|
|
||||||
|
@ -54,12 +54,12 @@ ifeq ($(WANT_JS_SOURCE),YES)
|
|||||||
|
|
||||||
S_JSAPI :=
|
S_JSAPI :=
|
||||||
|
|
||||||
S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI))
|
S_JAVASCRIPT += content.c jsapi.c fetcher.c $(addprefix jsapi/,$(S_JSAPI))
|
||||||
|
|
||||||
$(eval $(foreach V,$(filter JSAPI_BINDING_%,$(.VARIABLES)),$(call convert_jsapi_binding,$($(V)),$(OBJROOT)/$(patsubst JSAPI_BINDING_%,%,$(V)).c,$(OBJROOT)/$(patsubst JSAPI_BINDING_%,%,$(V)).h,$(patsubst JSAPI_BINDING_%,%,$(V))_jsapi)))
|
$(eval $(foreach V,$(filter JSAPI_BINDING_%,$(.VARIABLES)),$(call convert_jsapi_binding,$($(V)),$(OBJROOT)/$(patsubst JSAPI_BINDING_%,%,$(V)).c,$(OBJROOT)/$(patsubst JSAPI_BINDING_%,%,$(V)).h,$(patsubst JSAPI_BINDING_%,%,$(V))_jsapi)))
|
||||||
|
|
||||||
else
|
else
|
||||||
S_JAVASCRIPT += none.c
|
S_JAVASCRIPT += none.c fetcher.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
S_JAVASCRIPT := $(addprefix javascript/,$(S_JAVASCRIPT)) $(S_JSAPI_BINDING)
|
S_JAVASCRIPT := $(addprefix javascript/,$(S_JAVASCRIPT)) $(S_JSAPI_BINDING)
|
238
javascript/fetcher.c
Normal file
238
javascript/fetcher.c
Normal file
@ -0,0 +1,238 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* implementation for javascript scheme fetcher
|
||||||
|
*
|
||||||
|
* This fetcher implements http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#javascript-protocol
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include <libwapcaplet/libwapcaplet.h>
|
||||||
|
|
||||||
|
#include "utils/config.h"
|
||||||
|
#include "utils/errors.h"
|
||||||
|
#include "utils/corestrings.h"
|
||||||
|
#include "utils/nsoption.h"
|
||||||
|
#include "utils/log.h"
|
||||||
|
#include "utils/messages.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
#include "utils/ring.h"
|
||||||
|
#include "desktop/gui_factory.h"
|
||||||
|
|
||||||
|
#include "content/fetch.h"
|
||||||
|
#include "content/fetchers.h"
|
||||||
|
#include "javascript/fetcher.h"
|
||||||
|
#include "content/urldb.h"
|
||||||
|
|
||||||
|
/** Context for an resource fetch */
|
||||||
|
struct fetch_javascript_context {
|
||||||
|
struct fetch_javascript_context *r_next, *r_prev;
|
||||||
|
|
||||||
|
struct fetch *fetchh; /**< Handle for this fetch */
|
||||||
|
|
||||||
|
bool aborted; /**< Flag indicating fetch has been aborted */
|
||||||
|
bool locked; /**< Flag indicating entry is already entered */
|
||||||
|
|
||||||
|
nsurl *url;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct fetch_javascript_context *ring = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
/** issue fetch callbacks with locking */
|
||||||
|
static inline bool fetch_javascript_send_callback(const fetch_msg *msg,
|
||||||
|
struct fetch_javascript_context *ctx)
|
||||||
|
{
|
||||||
|
ctx->locked = true;
|
||||||
|
fetch_send_callback(msg, ctx->fetchh);
|
||||||
|
ctx->locked = false;
|
||||||
|
|
||||||
|
return ctx->aborted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* called from poll to progress fetch.
|
||||||
|
*
|
||||||
|
* \todo This is currently completely unimplemented and just returns 204
|
||||||
|
*/
|
||||||
|
static bool fetch_javascript_handler(struct fetch_javascript_context *ctx)
|
||||||
|
{
|
||||||
|
fetch_msg msg;
|
||||||
|
int code = 204;
|
||||||
|
|
||||||
|
/* content is going to return error code */
|
||||||
|
fetch_set_http_code(ctx->fetchh, code);
|
||||||
|
|
||||||
|
msg.type = FETCH_FINISHED;
|
||||||
|
fetch_javascript_send_callback(&msg, ctx);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** callback to initialise the resource fetcher. */
|
||||||
|
static bool fetch_javascript_initialise(lwc_string *scheme)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** callback to finalise the resource fetcher. */
|
||||||
|
static void fetch_javascript_finalise(lwc_string *scheme)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool fetch_javascript_can_fetch(const nsurl *url)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** callback to set up a resource fetch context. */
|
||||||
|
static void *
|
||||||
|
fetch_javascript_setup(struct fetch *fetchh,
|
||||||
|
nsurl *url,
|
||||||
|
bool only_2xx,
|
||||||
|
bool downgrade_tls,
|
||||||
|
const char *post_urlenc,
|
||||||
|
const struct fetch_multipart_data *post_multipart,
|
||||||
|
const char **headers)
|
||||||
|
{
|
||||||
|
struct fetch_javascript_context *ctx;
|
||||||
|
|
||||||
|
ctx = calloc(1, sizeof(*ctx));
|
||||||
|
if (ctx == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ctx->url = nsurl_ref(url);
|
||||||
|
|
||||||
|
ctx->fetchh = fetchh;
|
||||||
|
|
||||||
|
RING_INSERT(ring, ctx);
|
||||||
|
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** callback to free a resource fetch */
|
||||||
|
static void fetch_javascript_free(void *ctx)
|
||||||
|
{
|
||||||
|
struct fetch_javascript_context *c = ctx;
|
||||||
|
if (c->url != NULL) {
|
||||||
|
nsurl_unref(c->url);
|
||||||
|
}
|
||||||
|
RING_REMOVE(ring, c);
|
||||||
|
free(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** callback to start a resource fetch */
|
||||||
|
static bool fetch_javascript_start(void *ctx)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** callback to abort a resource fetch */
|
||||||
|
static void fetch_javascript_abort(void *ctx)
|
||||||
|
{
|
||||||
|
struct fetch_javascript_context *c = ctx;
|
||||||
|
|
||||||
|
/* To avoid the poll loop having to deal with the fetch context
|
||||||
|
* disappearing from under it, we simply flag the abort here.
|
||||||
|
* The poll loop itself will perform the appropriate cleanup.
|
||||||
|
*/
|
||||||
|
c->aborted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** callback to poll for additional resource fetch contents */
|
||||||
|
static void fetch_javascript_poll(lwc_string *scheme)
|
||||||
|
{
|
||||||
|
struct fetch_javascript_context *c, *next;
|
||||||
|
|
||||||
|
if (ring == NULL) return;
|
||||||
|
|
||||||
|
/* Iterate over ring, processing each pending fetch */
|
||||||
|
c = ring;
|
||||||
|
do {
|
||||||
|
/* Ignore fetches that have been flagged as locked.
|
||||||
|
* This allows safe re-entrant calls to this function.
|
||||||
|
* Re-entrancy can occur if, as a result of a callback,
|
||||||
|
* the interested party causes fetch_poll() to be called
|
||||||
|
* again.
|
||||||
|
*/
|
||||||
|
if (c->locked == true) {
|
||||||
|
next = c->r_next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Only process non-aborted fetches */
|
||||||
|
if (c->aborted == false) {
|
||||||
|
/* resource fetches can be processed in one go */
|
||||||
|
fetch_javascript_handler(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compute next fetch item at the last possible moment
|
||||||
|
* as processing this item may have added to the ring
|
||||||
|
*/
|
||||||
|
next = c->r_next;
|
||||||
|
|
||||||
|
fetch_remove_from_queues(c->fetchh);
|
||||||
|
fetch_free(c->fetchh);
|
||||||
|
|
||||||
|
/* Advance to next ring entry, exiting if we've reached
|
||||||
|
* the start of the ring or the ring has become empty
|
||||||
|
*/
|
||||||
|
} while ( (c = next) != ring && ring != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register javascript scheme fetcher with fetcher factory.
|
||||||
|
*
|
||||||
|
* \return NSERROR_OK on success or appropriate error code on faliure.
|
||||||
|
*/
|
||||||
|
nserror fetch_javascript_register(void)
|
||||||
|
{
|
||||||
|
lwc_string *scheme = lwc_string_ref(corestring_lwc_javascript);
|
||||||
|
const struct fetcher_operation_table fetcher_ops = {
|
||||||
|
.initialise = fetch_javascript_initialise,
|
||||||
|
.acceptable = fetch_javascript_can_fetch,
|
||||||
|
.setup = fetch_javascript_setup,
|
||||||
|
.start = fetch_javascript_start,
|
||||||
|
.abort = fetch_javascript_abort,
|
||||||
|
.free = fetch_javascript_free,
|
||||||
|
.poll = fetch_javascript_poll,
|
||||||
|
.finalise = fetch_javascript_finalise
|
||||||
|
};
|
||||||
|
|
||||||
|
return fetcher_add(scheme, &fetcher_ops);
|
||||||
|
}
|
28
javascript/fetcher.h
Normal file
28
javascript/fetcher.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
|
||||||
|
*
|
||||||
|
* This file is part of NetSurf.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* javascript scheme handler
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NETSURF_JAVASCRIPT_FETCHER_H
|
||||||
|
#define NETSURF_JAVASCRIPT_FETCHER_H
|
||||||
|
|
||||||
|
nserror fetch_javascript_register(void);
|
||||||
|
|
||||||
|
#endif
|
@ -69,6 +69,7 @@ lwc_string *corestring_lwc_iframe;
|
|||||||
lwc_string *corestring_lwc_image;
|
lwc_string *corestring_lwc_image;
|
||||||
lwc_string *corestring_lwc_img;
|
lwc_string *corestring_lwc_img;
|
||||||
lwc_string *corestring_lwc_input;
|
lwc_string *corestring_lwc_input;
|
||||||
|
lwc_string *corestring_lwc_javascript;
|
||||||
lwc_string *corestring_lwc_justify;
|
lwc_string *corestring_lwc_justify;
|
||||||
lwc_string *corestring_lwc_left;
|
lwc_string *corestring_lwc_left;
|
||||||
lwc_string *corestring_lwc_li;
|
lwc_string *corestring_lwc_li;
|
||||||
@ -327,6 +328,7 @@ void corestrings_fini(void)
|
|||||||
CSS_LWC_STRING_UNREF(image);
|
CSS_LWC_STRING_UNREF(image);
|
||||||
CSS_LWC_STRING_UNREF(img);
|
CSS_LWC_STRING_UNREF(img);
|
||||||
CSS_LWC_STRING_UNREF(input);
|
CSS_LWC_STRING_UNREF(input);
|
||||||
|
CSS_LWC_STRING_UNREF(javascript);
|
||||||
CSS_LWC_STRING_UNREF(justify);
|
CSS_LWC_STRING_UNREF(justify);
|
||||||
CSS_LWC_STRING_UNREF(left);
|
CSS_LWC_STRING_UNREF(left);
|
||||||
CSS_LWC_STRING_UNREF(li);
|
CSS_LWC_STRING_UNREF(li);
|
||||||
@ -610,6 +612,7 @@ nserror corestrings_init(void)
|
|||||||
CSS_LWC_STRING_INTERN(image);
|
CSS_LWC_STRING_INTERN(image);
|
||||||
CSS_LWC_STRING_INTERN(img);
|
CSS_LWC_STRING_INTERN(img);
|
||||||
CSS_LWC_STRING_INTERN(input);
|
CSS_LWC_STRING_INTERN(input);
|
||||||
|
CSS_LWC_STRING_INTERN(javascript);
|
||||||
CSS_LWC_STRING_INTERN(justify);
|
CSS_LWC_STRING_INTERN(justify);
|
||||||
CSS_LWC_STRING_INTERN(left);
|
CSS_LWC_STRING_INTERN(left);
|
||||||
CSS_LWC_STRING_INTERN(li);
|
CSS_LWC_STRING_INTERN(li);
|
||||||
|
@ -74,6 +74,7 @@ extern lwc_string *corestring_lwc_iframe;
|
|||||||
extern lwc_string *corestring_lwc_image;
|
extern lwc_string *corestring_lwc_image;
|
||||||
extern lwc_string *corestring_lwc_img;
|
extern lwc_string *corestring_lwc_img;
|
||||||
extern lwc_string *corestring_lwc_input;
|
extern lwc_string *corestring_lwc_input;
|
||||||
|
extern lwc_string *corestring_lwc_javascript;
|
||||||
extern lwc_string *corestring_lwc_justify;
|
extern lwc_string *corestring_lwc_justify;
|
||||||
extern lwc_string *corestring_lwc_left;
|
extern lwc_string *corestring_lwc_left;
|
||||||
extern lwc_string *corestring_lwc_li;
|
extern lwc_string *corestring_lwc_li;
|
||||||
|
Loading…
Reference in New Issue
Block a user