From 317d1bfa566e8217d53dffbb8aeb455ad139b8dbc9bbe8641e0aafb79cc5d849 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Fri, 18 Apr 2025 13:29:29 -0400 Subject: [PATCH] Some further expansion of ownership for `Widget`. --- src/web.cc | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/web.cc b/src/web.cc index e3b5aea..2e90161 100644 --- a/src/web.cc +++ b/src/web.cc @@ -50,8 +50,6 @@ void a_Web_init(void) int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web, CA_Callback_t *Call, void **Data) { - Widget *dw = NULL; - _MSG("a_Web_dispatch_by_type\n"); BrowserWindow *bw = Web->bw; @@ -78,16 +76,14 @@ int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web, StyleEngine styleEngine (layout, Web->url, Web->url, bw->zoom); styleEngine.startElement ("body", Web->bw); - dw = (Widget*) viewer(Type, Web, Call, Data); - if (dw == NULL) + std::unique_ptr< Widget > dw( reinterpret_cast< Widget* >( viewer(Type, Web, Call, Data) ) ); + if (not dw) return -1; dw->setStyle (styleEngine.style (Web->bw)); /* This method frees the old dw if any */ - std::unique_ptr< Widget > dw_unique; - dw_unique.reset( dw ); - layout->setWidget(std::move( dw_unique )); + layout->setWidget(std::move( dw )); /* Set the page title with the bare filename (e.g. for images), * HTML pages with a tag will overwrite it later */ @@ -104,16 +100,19 @@ int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web, /* Let the Nav module know... */ a_Nav_expect_done(Web->bw); - } else { + return 1; + + } /* A non-RootUrl. At this moment we only handle image-children */ if (!dStrnAsciiCasecmp(Type, "image/", 6)) { - dw = (Widget*) viewer(Type, Web, Call, Data); - } else { + auto dw = (Widget*) viewer(Type, Web, Call, Data); + return (dw ? 1 : -1); + + } + MSG_HTTP("'%s' cannot be displayed as image; has media type '%s'\n", URL_STR(Web->url), Type); - } - } - return (dw ? 1 : -1); + return -1; }