mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
1038: Remove remembering last 8 URLs. It did not work.
Enable the rate limiting of opening new windows in SEE to be consistent with SpiderMonkey. Fixed a possible memleak (the frame variable).
This commit is contained in:
parent
327fc1e46e
commit
7116daf43e
@ -66,53 +66,6 @@ static struct option_info ecmascript_options[] = {
|
||||
NULL_OPTION_INFO,
|
||||
};
|
||||
|
||||
#define NUMBER_OF_URLS_TO_REMEMBER 8
|
||||
static struct {
|
||||
unsigned char *url;
|
||||
unsigned char *frame;
|
||||
} u[NUMBER_OF_URLS_TO_REMEMBER];
|
||||
static int url_index = 0;
|
||||
|
||||
int
|
||||
ecmascript_check_url(unsigned char *url, unsigned char *frame)
|
||||
{
|
||||
int i;
|
||||
/* Because of gradual rendering window.open is called many
|
||||
* times with the same arguments.
|
||||
* This workaround remembers NUMBER_OF_URLS_TO_REMEMBER last
|
||||
* opened URLs and do not let open them again.
|
||||
*/
|
||||
|
||||
for (i = 0; i < NUMBER_OF_URLS_TO_REMEMBER; i++) {
|
||||
if (!u[i].url) break;
|
||||
if (!strcmp(u[i].url, url) && !strcmp(u[i].frame, frame)) {
|
||||
mem_free(url);
|
||||
mem_free(frame);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
mem_free_if(u[url_index].url);
|
||||
mem_free_if(u[url_index].frame);
|
||||
u[url_index].url = url;
|
||||
u[url_index].frame = frame;
|
||||
url_index++;
|
||||
if (url_index >= NUMBER_OF_URLS_TO_REMEMBER) url_index = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
ecmascript_free_urls(struct module *module)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NUMBER_OF_URLS_TO_REMEMBER; i++) {
|
||||
mem_free_if(u[i].url);
|
||||
mem_free_if(u[i].frame);
|
||||
}
|
||||
}
|
||||
|
||||
#undef NUMBER_OF_URLS_TO_REMEMBER
|
||||
|
||||
struct ecmascript_interpreter *
|
||||
ecmascript_get_interpreter(struct view_state *vs)
|
||||
{
|
||||
@ -401,5 +354,5 @@ struct module ecmascript_module = struct_module(
|
||||
/* submodules: */ ecmascript_modules,
|
||||
/* data: */ NULL,
|
||||
/* init: */ NULL,
|
||||
/* done: */ ecmascript_free_urls
|
||||
/* done: */ NULL
|
||||
);
|
||||
|
@ -241,14 +241,12 @@ js_window_open(struct SEE_interpreter *interp, struct SEE_object *self,
|
||||
struct view_state *vs = win->vs;
|
||||
struct document_view *doc_view = vs->doc_view;
|
||||
struct session *ses = doc_view->session;
|
||||
unsigned char *frame = "";
|
||||
unsigned char *frame = NULL;
|
||||
unsigned char *url, *url2;
|
||||
struct uri *uri;
|
||||
struct SEE_value url_value;
|
||||
#if 0
|
||||
static time_t ratelimit_start;
|
||||
static int ratelimit_count;
|
||||
#endif
|
||||
|
||||
/* Do not check thisobj->objectclass. ELinks sets this
|
||||
* function as a property of both the window object and the
|
||||
@ -263,7 +261,7 @@ js_window_open(struct SEE_interpreter *interp, struct SEE_object *self,
|
||||
}
|
||||
|
||||
if (argc < 1) return;
|
||||
#if 0
|
||||
|
||||
/* Ratelimit window opening. Recursive window.open() is very nice.
|
||||
* We permit at most 20 tabs in 2 seconds. The ratelimiter is very
|
||||
* rough but shall suffice against the usual cases. */
|
||||
@ -276,7 +274,7 @@ js_window_open(struct SEE_interpreter *interp, struct SEE_object *self,
|
||||
if (ratelimit_count > 20)
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
SEE_ToString(interp, argv[0], &url_value);
|
||||
url = see_string_to_unsigned_char(url_value.u.string);
|
||||
if (!url) return;
|
||||
@ -290,19 +288,23 @@ js_window_open(struct SEE_interpreter *interp, struct SEE_object *self,
|
||||
mem_free(url);
|
||||
return;
|
||||
}
|
||||
/* url and frame will be freed by ecmascript_check_url */
|
||||
if (!ecmascript_check_url(url, frame)) return;
|
||||
}
|
||||
/* TODO: Support for window naming and perhaps some window features? */
|
||||
|
||||
url2 = join_urls(doc_view->document->uri, url);
|
||||
mem_free(url);
|
||||
if (!url2) return;
|
||||
if (!url2) {
|
||||
mem_free_if(frame);
|
||||
return;
|
||||
}
|
||||
uri = get_uri(url2, 0);
|
||||
mem_free(url2);
|
||||
if (!uri) return;
|
||||
if (!uri) {
|
||||
mem_free_if(frame);
|
||||
return;
|
||||
}
|
||||
|
||||
if (*frame && strcasecmp(frame, "_blank")) {
|
||||
if (frame && *frame && strcasecmp(frame, "_blank")) {
|
||||
struct delayed_open *deo = mem_calloc(1, sizeof(*deo));
|
||||
|
||||
if (deo) {
|
||||
@ -335,6 +337,7 @@ js_window_open(struct SEE_interpreter *interp, struct SEE_object *self,
|
||||
|
||||
end:
|
||||
done_uri(uri);
|
||||
mem_free_if(frame);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -341,7 +341,7 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
struct view_state *vs;
|
||||
struct document_view *doc_view;
|
||||
struct session *ses;
|
||||
unsigned char *frame = "";
|
||||
unsigned char *frame = NULL;
|
||||
unsigned char *url, *url2;
|
||||
struct uri *uri;
|
||||
static time_t ratelimit_start;
|
||||
@ -362,17 +362,6 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
|
||||
if (argc < 1) return JS_TRUE;
|
||||
|
||||
url = stracpy(jsval_to_string(ctx, &argv[0]));
|
||||
trim_chars(url, ' ', 0);
|
||||
if (argc > 1) {
|
||||
frame = stracpy(jsval_to_string(ctx, &argv[1]));
|
||||
if (!frame) {
|
||||
mem_free(url);
|
||||
return JS_TRUE;
|
||||
}
|
||||
if (!ecmascript_check_url(url, frame)) return JS_TRUE;
|
||||
}
|
||||
|
||||
/* Ratelimit window opening. Recursive window.open() is very nice.
|
||||
* We permit at most 20 tabs in 2 seconds. The ratelimiter is very
|
||||
* rough but shall suffice against the usual cases. */
|
||||
@ -381,23 +370,36 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
ratelimit_count = 0;
|
||||
} else {
|
||||
ratelimit_count++;
|
||||
if (ratelimit_count > 20)
|
||||
if (ratelimit_count > 20) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: Support for window naming and perhaps some window features? */
|
||||
|
||||
url = stracpy(jsval_to_string(ctx, &argv[0]));
|
||||
trim_chars(url, ' ', 0);
|
||||
url2 = join_urls(doc_view->document->uri, url);
|
||||
mem_free(url);
|
||||
if (!url2) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
if (argc > 1) {
|
||||
frame = stracpy(jsval_to_string(ctx, &argv[1]));
|
||||
if (!frame) {
|
||||
mem_free(url2);
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: Support for window naming and perhaps some window features? */
|
||||
|
||||
uri = get_uri(url2, 0);
|
||||
mem_free(url2);
|
||||
if (!uri) return JS_TRUE;
|
||||
if (!uri) {
|
||||
mem_free_if(frame);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (*frame && strcasecmp(frame, "_blank")) {
|
||||
if (frame && *frame && strcasecmp(frame, "_blank")) {
|
||||
struct delayed_open *deo = mem_calloc(1, sizeof(*deo));
|
||||
|
||||
if (deo) {
|
||||
@ -434,6 +436,7 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
|
||||
end:
|
||||
done_uri(uri);
|
||||
mem_free_if(frame);
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user