Plumb the ownership up a bit.
The HTML function returning a DilloUrl now returns ownership. More releases scattered, but we can clean those up in time.
This commit is contained in:
@ -1666,10 +1666,9 @@ void CssParser::parseImport(DilloHtml *html)
|
||||
if (urlStr) {
|
||||
if (importSyntaxIsOK && mediaIsSelected) {
|
||||
MSG("CssParser::parseImport(): @import %s\n", urlStr);
|
||||
DilloUrl *url = a_Html_url_new (html, urlStr, a_Url_str(*this->baseUrl),
|
||||
auto url = a_Html_url_new (html, urlStr, a_Url_str(*this->baseUrl),
|
||||
this->baseUrl ? 1 : 0);
|
||||
a_Html_load_stylesheet(html, url);
|
||||
delete url;
|
||||
a_Html_load_stylesheet(html, url.get());
|
||||
}
|
||||
dFree (urlStr);
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ void Html_tag_open_form(DilloHtml *html, const char *tag, int tagsize)
|
||||
}
|
||||
}
|
||||
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "action")))
|
||||
action = a_Html_url_new(html, attrbuf, NULL, 0);
|
||||
action = a_Html_url_new(html, attrbuf, NULL, 0).release();
|
||||
else {
|
||||
if (html->DocType != DT_HTML || html->DocTypeVersion <= 4.01f)
|
||||
BUG_MSG("<form> requires action attribute.");
|
||||
@ -607,7 +607,7 @@ void Html_tag_open_isindex(DilloHtml *html, const char *tag, int tagsize)
|
||||
}
|
||||
|
||||
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "action")))
|
||||
action = a_Html_url_new(html, attrbuf, NULL, 0);
|
||||
action = a_Html_url_new(html, attrbuf, NULL, 0).release();
|
||||
else
|
||||
action = a_Url_dup(*html->base_url).release();
|
||||
|
||||
|
59
src/html.cc
59
src/html.cc
@ -171,21 +171,21 @@ void DilloHtml::bugMessage(const char *format, ... )
|
||||
* Wrapper for a_Url_new that adds an error detection message.
|
||||
* If use_base_url is TRUE, it uses base_url. Otherwise it uses html->base_url.
|
||||
*/
|
||||
DilloUrl *a_Html_url_new(DilloHtml *html,
|
||||
std::unique_ptr< DilloUrl > a_Html_url_new(DilloHtml *html,
|
||||
const char *url_str, const char *base_url,
|
||||
int use_base_url)
|
||||
{
|
||||
if (!url_str) {
|
||||
MSG("a_Html_url_new: URL is NULL\n");
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DilloUrl *url = a_Url_new(url_str,
|
||||
(use_base_url) ? base_url : URL_STR_(html->base_url)).release();
|
||||
std::unique_ptr< DilloUrl > url = a_Url_new(url_str,
|
||||
(use_base_url) ? base_url : URL_STR_(html->base_url));
|
||||
|
||||
if (!url) {
|
||||
BUG_MSG("URL is not valid '%s'.", url_str);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int n_ic, n_ic_spc;
|
||||
@ -1920,7 +1920,7 @@ static void Html_tag_open_frame (DilloHtml *html, const char *tag, int tagsize)
|
||||
if (!(attrbuf = a_Html_get_attr(html, tag, tagsize, "src")))
|
||||
return;
|
||||
|
||||
if (!(url = a_Html_url_new(html, attrbuf, NULL, 0)))
|
||||
if (!(url = a_Html_url_new(html, attrbuf, NULL, 0).release()))
|
||||
return;
|
||||
|
||||
if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
|
||||
@ -2135,7 +2135,7 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
|
||||
DilloImage *image;
|
||||
|
||||
if (!(attrbuf = a_Html_get_attr(html, tag, tagsize, "src")) ||
|
||||
!(url = a_Html_url_new(html, attrbuf, NULL, 0)))
|
||||
!(url = a_Html_url_new(html, attrbuf, NULL, 0).release()))
|
||||
return NULL;
|
||||
|
||||
alt_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "alt", NULL);
|
||||
@ -2265,7 +2265,6 @@ static void Html_tag_open_img(DilloHtml *html, const char *tag, int tagsize)
|
||||
static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize)
|
||||
{
|
||||
DilloImage *Image;
|
||||
DilloUrl *usemap_url;
|
||||
const char *attrbuf;
|
||||
|
||||
/* This avoids loading images. Useful for viewing suspicious HTML email. */
|
||||
@ -2276,7 +2275,7 @@ static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize)
|
||||
if (!Image)
|
||||
return;
|
||||
|
||||
usemap_url = NULL;
|
||||
std::unique_ptr< DilloUrl > usemap_url;
|
||||
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "usemap")))
|
||||
/* TODO: usemap URLs outside of the document are not used. */
|
||||
usemap_url = a_Html_url_new(html, attrbuf, NULL, 0);
|
||||
@ -2293,7 +2292,7 @@ static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize)
|
||||
dwi->setIsMap();
|
||||
_MSG(" Html_tag_open_img: server-side map (ISMAP)\n");
|
||||
} else if (html->style ()->x_link != -1 &&
|
||||
usemap_url == NULL) {
|
||||
usemap_url == nullptr) {
|
||||
/* For simple links, we have to suppress the "image_pressed" signal.
|
||||
* This is overridden for USEMAP images. */
|
||||
// a_Dw_widget_set_button_sensitive (IM2DW(Image->dw), FALSE);
|
||||
@ -2301,7 +2300,6 @@ static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize)
|
||||
|
||||
if (usemap_url) {
|
||||
dwi->setUseMap(&html->maps, new ::object::String(URL_STR(usemap_url)));
|
||||
delete usemap_url;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2312,7 +2310,6 @@ static void Html_tag_content_map(DilloHtml *html, const char *tag, int tagsize)
|
||||
{
|
||||
char *hash_name;
|
||||
const char *attrbuf;
|
||||
DilloUrl *url;
|
||||
|
||||
if (html->InFlags & IN_MAP) {
|
||||
BUG_MSG("Nested <map>.");
|
||||
@ -2320,9 +2317,8 @@ static void Html_tag_content_map(DilloHtml *html, const char *tag, int tagsize)
|
||||
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "name"))) {
|
||||
html->InFlags |= IN_MAP;
|
||||
hash_name = dStrconcat("#", attrbuf, NULL);
|
||||
url = a_Html_url_new(html, hash_name, NULL, 0);
|
||||
auto url = a_Html_url_new(html, hash_name, NULL, 0);
|
||||
html->maps.startNewMap(new ::object::String(URL_STR(url)));
|
||||
delete url;
|
||||
dFree(hash_name);
|
||||
} else {
|
||||
BUG_MSG("<map> requires name attribute.");
|
||||
@ -2451,7 +2447,7 @@ static void
|
||||
}
|
||||
if (shape != NULL || type == BACKGROUND) {
|
||||
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "href"))) {
|
||||
url = a_Html_url_new(html, attrbuf, NULL, 0);
|
||||
url = a_Html_url_new(html, attrbuf, NULL, 0).release();
|
||||
dReturn_if_fail ( url != NULL );
|
||||
|
||||
link = Html_set_new_link(html, &url);
|
||||
@ -2469,7 +2465,8 @@ static void
|
||||
*/
|
||||
static void Html_tag_open_object(DilloHtml *html, const char *tag, int tagsize)
|
||||
{
|
||||
DilloUrl *url, *base_url = NULL;
|
||||
DilloUrl *url;
|
||||
std::unique_ptr< DilloUrl > base_url;
|
||||
const char *attrbuf;
|
||||
|
||||
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "codebase"))) {
|
||||
@ -2478,7 +2475,7 @@ static void Html_tag_open_object(DilloHtml *html, const char *tag, int tagsize)
|
||||
|
||||
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "data"))) {
|
||||
url = a_Html_url_new(html, attrbuf,
|
||||
URL_STR(base_url), (base_url != NULL));
|
||||
URL_STR(base_url), (base_url != NULL)).release();
|
||||
dReturn_if_fail ( url != NULL );
|
||||
|
||||
if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
|
||||
@ -2490,7 +2487,6 @@ static void Html_tag_open_object(DilloHtml *html, const char *tag, int tagsize)
|
||||
html->styleEngine->setNonCssHint(PROPERTY_X_LINK, CSS_TYPE_INTEGER,
|
||||
Html_set_new_link(html, &url));
|
||||
}
|
||||
delete base_url;
|
||||
}
|
||||
|
||||
static void Html_tag_content_object(DilloHtml *html, const char *tag,
|
||||
@ -2516,7 +2512,7 @@ static void Html_tag_open_video(DilloHtml *html, const char *tag, int tagsize)
|
||||
/* TODO: poster attr */
|
||||
|
||||
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "src"))) {
|
||||
url = a_Html_url_new(html, attrbuf, NULL, 0);
|
||||
url = a_Html_url_new(html, attrbuf, NULL, 0).release();
|
||||
dReturn_if_fail ( url != NULL );
|
||||
|
||||
if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
|
||||
@ -2548,7 +2544,7 @@ static void Html_tag_open_audio(DilloHtml *html, const char *tag, int tagsize)
|
||||
}
|
||||
|
||||
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "src"))) {
|
||||
url = a_Html_url_new(html, attrbuf, NULL, 0);
|
||||
url = a_Html_url_new(html, attrbuf, NULL, 0).release();
|
||||
dReturn_if_fail ( url != NULL );
|
||||
|
||||
if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
|
||||
@ -2583,7 +2579,7 @@ static void Html_tag_open_source(DilloHtml *html, const char *tag,
|
||||
BUG_MSG("<source> requires src attribute.");
|
||||
return;
|
||||
} else {
|
||||
DilloUrl *url = a_Html_url_new(html, attrbuf, NULL, 0);
|
||||
DilloUrl *url = a_Html_url_new(html, attrbuf, NULL, 0).release();
|
||||
|
||||
dReturn_if_fail ( url != NULL );
|
||||
|
||||
@ -2621,7 +2617,7 @@ static void Html_tag_open_embed(DilloHtml *html, const char *tag, int tagsize)
|
||||
const char *attrbuf;
|
||||
|
||||
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "src"))) {
|
||||
DilloUrl *url = a_Html_url_new(html, attrbuf, NULL, 0);
|
||||
DilloUrl *url = a_Html_url_new(html, attrbuf, NULL, 0).release();
|
||||
|
||||
dReturn_if_fail ( url != NULL );
|
||||
|
||||
@ -2702,7 +2698,7 @@ static void Html_tag_open_a(DilloHtml *html, const char *tag, int tagsize)
|
||||
if (D_ASCII_TOLOWER(attrbuf[0]) == 'j')
|
||||
attrbuf = Html_get_javascript_link(html);
|
||||
|
||||
url = a_Html_url_new(html, attrbuf, NULL, 0);
|
||||
url = a_Html_url_new(html, attrbuf, NULL, 0).release();
|
||||
dReturn_if_fail ( url != NULL );
|
||||
|
||||
if (a_Capi_get_flags_with_redirection(url) & CAPI_IsCached) {
|
||||
@ -3125,7 +3121,6 @@ static void Html_tag_open_meta(DilloHtml *html, const char *tag, int tagsize)
|
||||
|
||||
const char *p, *equiv, *charset, *content;
|
||||
char delay_str[64], *mr_url;
|
||||
DilloUrl *new_url;
|
||||
int delay;
|
||||
|
||||
/* only valid inside HEAD */
|
||||
@ -3174,7 +3169,7 @@ static void Html_tag_open_meta(DilloHtml *html, const char *tag, int tagsize)
|
||||
mr_url = dStrdup("");
|
||||
}
|
||||
|
||||
new_url = a_Html_url_new(html, mr_url, NULL, 0);
|
||||
auto new_url = a_Html_url_new(html, mr_url, NULL, 0);
|
||||
|
||||
if (a_Url_cmp(*html->base_url, *new_url) == 0) {
|
||||
/* redirection loop, or empty url string: ignore */
|
||||
@ -3186,8 +3181,8 @@ static void Html_tag_open_meta(DilloHtml *html, const char *tag, int tagsize)
|
||||
if (URL_FLAGS(html->base_url) & URL_SpamSafe) {
|
||||
a_UIcmd_set_msg(html->bw,
|
||||
"WARNING: local URL with META refresh. Aborting.");
|
||||
} else if (a_Capi_dpi_verify_request(html->bw, new_url)) {
|
||||
a_UIcmd_redirection0((void*)html->bw, new_url);
|
||||
} else if (a_Capi_dpi_verify_request(html->bw, new_url.get())) {
|
||||
a_UIcmd_redirection0((void*)html->bw, new_url.get());
|
||||
}
|
||||
} else {
|
||||
/* Send a custom HTML message.
|
||||
@ -3206,7 +3201,6 @@ static void Html_tag_open_meta(DilloHtml *html, const char *tag, int tagsize)
|
||||
}
|
||||
dStr_free(ds_msg, 1);
|
||||
}
|
||||
delete new_url;
|
||||
dFree(mr_url);
|
||||
|
||||
} else if (!dStrAsciiCasecmp(equiv, "content-type") &&
|
||||
@ -3294,7 +3288,7 @@ void a_Html_load_stylesheet(DilloHtml *html, DilloUrl *url)
|
||||
*/
|
||||
static void Html_tag_open_link(DilloHtml *html, const char *tag, int tagsize)
|
||||
{
|
||||
DilloUrl *url;
|
||||
std::unique_ptr< DilloUrl > url;
|
||||
const char *attrbuf;
|
||||
|
||||
//char *tag_str = dStrndup(tag, tagsize);
|
||||
@ -3335,8 +3329,7 @@ static void Html_tag_open_link(DilloHtml *html, const char *tag, int tagsize)
|
||||
|
||||
_MSG(" Html_tag_open_link(): addCssUrl %s\n", URL_STR(url));
|
||||
|
||||
html->addCssUrl(url);
|
||||
delete url;
|
||||
html->addCssUrl(url.get());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3352,8 +3345,8 @@ static void Html_tag_open_base(DilloHtml *html, const char *tag, int tagsize)
|
||||
bool_t html5 = html->DocType == DT_HTML &&
|
||||
html->DocTypeVersion >= 5.0f;
|
||||
|
||||
BaseUrl = html5 ? a_Html_url_new(html, attrbuf, NULL, 0) :
|
||||
a_Html_url_new(html, attrbuf, "", 1);
|
||||
BaseUrl = html5 ? a_Html_url_new(html, attrbuf, NULL, 0).release() :
|
||||
a_Html_url_new(html, attrbuf, "", 1).release();
|
||||
|
||||
if (html5 || URL_SCHEME_(BaseUrl)) {
|
||||
/* Pass the URL_SpamSafe flag to the new base url */
|
||||
|
@ -277,7 +277,7 @@ char *a_Html_get_attr_wdef(DilloHtml *html,
|
||||
const char *attrname,
|
||||
const char *def);
|
||||
|
||||
DilloUrl *a_Html_url_new(DilloHtml *html,
|
||||
std::unique_ptr< DilloUrl > a_Html_url_new(DilloHtml *html,
|
||||
const char *url_str, const char *base_url,
|
||||
int use_base_url);
|
||||
|
||||
|
Reference in New Issue
Block a user