1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

Cleanup and tidy up window.open workaround.

This commit is contained in:
Laurent MONIN 2006-01-25 17:20:47 +01:00 committed by Laurent MONIN
parent f6f66a28c8
commit cf8de45782

View File

@ -231,8 +231,6 @@ js_window_open(struct SEE_interpreter *interp, struct SEE_object *self,
unsigned char *url, *url2; unsigned char *url, *url2;
struct uri *uri; struct uri *uri;
struct SEE_value url_value, target_value; struct SEE_value url_value, target_value;
static struct SEE_string *url_string[8], *target_string[8];
static int indeks;
#if 0 #if 0
static time_t ratelimit_start; static time_t ratelimit_start;
static int ratelimit_count; static int ratelimit_count;
@ -263,20 +261,34 @@ js_window_open(struct SEE_interpreter *interp, struct SEE_object *self,
#endif #endif
SEE_ToString(interp, argv[0], &url_value); SEE_ToString(interp, argv[0], &url_value);
if (argc > 1) { if (argc > 1) {
/* 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.
*/
#define NUMBER_OF_URLS_TO_REMEMBER 8
static struct {
struct SEE_string *url;
struct SEE_string *target;
} strings[NUMBER_OF_URLS_TO_REMEMBER];
static int indeks = 0;
int i; int i;
SEE_ToString(interp, argv[1], &target_value); SEE_ToString(interp, argv[1], &target_value);
for (i = 0; i < 8; i++) { for (i = 0; i < NUMBER_OF_URLS_TO_REMEMBER; i++) {
if (url_string[i] && target_string[i]) { if (!(strings[i].url && strings[i].target))
if (!SEE_string_cmp(url_value.u.string, url_string[i]) continue;
&& !SEE_string_cmp(target_value.u.string, target_string[i])) if (!SEE_string_cmp(url_value.u.string, strings[i].url)
return; && !SEE_string_cmp(target_value.u.string, strings[i].target))
} return;
} }
url_string[indeks] = url_value.u.string; strings[indeks].url = url_value.u.string;
target_string[indeks] = target_value.u.string; strings[indeks].target = target_value.u.string;
indeks = (indeks + 1) & 7; indeks++;
if (indeks >= NUMBER_OF_URLS_TO_REMEMBER) indeks = 0;
#undef NUMBER_OF_URLS_TO_REMEMBER
} }
url = SEE_string_to_unsigned_char(url_value.u.string); url = SEE_string_to_unsigned_char(url_value.u.string);
if (!url) return; if (!url) return;