From 221f246d4c02dd12d87e2a825dff1510c6946778 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Mon, 19 Jul 2021 22:12:03 +0200 Subject: [PATCH] [iframe] Begining of iframe rewrite --- src/document/document.c | 2 ++ src/document/document.h | 1 + src/document/html/parser/link.c | 11 +++++++++++ src/document/html/renderer.c | 12 ++++++++++++ src/document/html/renderer.h | 1 + src/session/session.c | 15 +++++++++++++++ 6 files changed, 42 insertions(+) diff --git a/src/document/document.c b/src/document/document.c index 80e528f5..ba5d466b 100644 --- a/src/document/document.c +++ b/src/document/document.c @@ -271,6 +271,7 @@ reset_document(struct document *document) /// kill_timer(&document->timeout); /// free_document(document->dom); #endif + free_uri_list(&document->iframes); free_list(document->tags); free_list(document->nodes); @@ -336,6 +337,7 @@ done_document(struct document *document) mem_free_if(document->text); free_document(document->dom); #endif + free_uri_list(&document->iframes); free_list(document->tags); free_list(document->nodes); diff --git a/src/document/document.h b/src/document/document.h index 6bf30e86..d08be4f6 100644 --- a/src/document/document.h +++ b/src/document/document.h @@ -223,6 +223,7 @@ struct document { * Used for checking rerendering for available CSS imports. */ unsigned long css_magic; #endif + struct uri_list iframes; struct uri *uri; diff --git a/src/document/html/parser/link.c b/src/document/html/parser/link.c index 1a64aa95..d0bdfc16 100644 --- a/src/document/html/parser/link.c +++ b/src/document/html/parser/link.c @@ -468,6 +468,7 @@ html_iframe_do(char *a, char *object_src, struct html_context *html_context) { char *name, *url = NULL; + struct uri *uri; url = null_or_stracpy(object_src); if (!url) url = get_url_val(a, "src", html_context->doc_cp); @@ -491,6 +492,16 @@ html_iframe_do(char *a, char *object_src, html_context->options->framename, html_context); } + char *url2 = join_urls(html_context->base_href, url); + + uri = get_uri(url2, URI_BASE); + if (uri) { + /* Request the imported script as part of the document ... */ + html_context->special_f(html_context, SP_IFRAME, name, uri); + done_uri(uri); + mem_free(url2); + } + mem_free(name); mem_free(url); } diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c index e5a53660..f7538e0c 100644 --- a/src/document/html/renderer.c +++ b/src/document/html/renderer.c @@ -2355,6 +2355,18 @@ html_special(struct html_context *html_context, enum html_special_type c, ...) } #endif break; + + case SP_IFRAME: + { + if (document) { + char *name = va_arg(l, char *); + struct uri *uri = va_arg(l, struct uri *); + + add_to_uri_list(&document->iframes, uri); + } + break; + } + } va_end(l); diff --git a/src/document/html/renderer.h b/src/document/html/renderer.h index 49a93336..2fb24489 100644 --- a/src/document/html/renderer.h +++ b/src/document/html/renderer.h @@ -34,6 +34,7 @@ enum html_special_type { SP_STYLESHEET, SP_COLOR_LINK_LINES, SP_SCRIPT, + SP_IFRAME }; diff --git a/src/session/session.c b/src/session/session.c index 15008a56..5bb3ff5f 100644 --- a/src/session/session.c +++ b/src/session/session.c @@ -477,6 +477,20 @@ load_ecmascript_imports(struct session *ses, struct document_view *doc_view) #define load_ecmascript_imports(ses, doc_view) #endif +static void +load_iframes(struct session *ses, struct document_view *doc_view) +{ + struct document *document = doc_view->document; + struct uri *uri; + int index; + + if (!document) return; + + foreach_uri (uri, index, &document->iframes) { + open_uri_in_new_tab(ses, uri, 0, 0); + } +} + NONSTATIC_INLINE void load_frames(struct session *ses, struct document_view *doc_view) { @@ -514,6 +528,7 @@ display_timer(struct session *ses) load_frames(ses, ses->doc_view); load_css_imports(ses, ses->doc_view); load_ecmascript_imports(ses, ses->doc_view); + load_iframes(ses, ses->doc_view); process_file_requests(ses); }