From 44710bb1e9800d2edd5fb936856d610156ba7847 Mon Sep 17 00:00:00 2001 From: Date: Mon, 30 Jan 2006 10:47:24 +0100 Subject: [PATCH] The same trick as in SEE: Remember last 8 locations and do not open them again --- src/ecmascript/spidermonkey/window.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/ecmascript/spidermonkey/window.c b/src/ecmascript/spidermonkey/window.c index 4a6b1790..767f910e 100644 --- a/src/ecmascript/spidermonkey/window.c +++ b/src/ecmascript/spidermonkey/window.c @@ -310,10 +310,38 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) if (argc < 1) return JS_TRUE; + url = jsval_to_string(ctx, &argv[0]); + if (argc > 1) { + JSString *url_string = JS_ValueToString(ctx, argv[0]); + JSString *target_string = JS_ValueToString(ctx, argv[1]); + int i; +#define NUMBER_OF_URLS_TO_REMEMBER 8 + static struct { + JSContext *ctx; + JSString *url; + JSString *frame; + } strings[NUMBER_OF_URLS_TO_REMEMBER]; + static int indeks; + + for (i = 0; i < NUMBER_OF_URLS_TO_REMEMBER; i++) { + if (!(strings[i].ctx && strings[i].url && strings[i].frame)) + continue; + if (ctx == strings[i].ctx + && !JS_CompareStrings(url_string, strings[i].url) + && !JS_CompareStrings(target_string, strings[i].frame)) + return JS_TRUE; + } + strings[indeks].ctx = ctx; + strings[indeks].url = JS_InternString(ctx, url); + strings[indeks].frame = JS_InternString(ctx, target); + indeks++; + if (indeks >= NUMBER_OF_URLS_TO_REMEMBER) indeks = 0; +#undef NUMBER_OF_URLS_TO_REMEMBER + } + /* 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. */ - if (!ratelimit_start || time(NULL) - ratelimit_start > 2) { ratelimit_start = time(NULL); ratelimit_count = 0; @@ -323,8 +351,6 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) return JS_TRUE; } - url = jsval_to_string(ctx, &argv[0]); - /* TODO: Support for window naming and perhaps some window features? */ url = join_urls(doc_view->document->uri, @@ -334,7 +360,6 @@ window_open(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) mem_free(url); if (!uri) return JS_TRUE; - if (argc > 1) target = jsval_to_string(ctx, &argv[1]); if (*target && strcasecmp(target, "_blank")) { struct delayed_open *deo = mem_calloc(1, sizeof(*deo)); -- 2.11.4.GIT