More ownership work.
This commit is contained in:
2
rebuild
2
rebuild
@ -3,5 +3,5 @@ make distclean
|
||||
pushd ..
|
||||
./autogen.sh
|
||||
popd
|
||||
../configure --prefix=/opt/local --enable-ipv6
|
||||
../configure --prefix=/opt/local --enable-ipv6 CXXFLAGS="-O0 -g"
|
||||
make -kj11
|
||||
|
37
src/bw.cc
37
src/bw.cc
@ -21,6 +21,8 @@
|
||||
#include "capi.hh"
|
||||
#include "uicmd.hh"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
/*
|
||||
* Local Data
|
||||
*/
|
||||
@ -67,7 +69,6 @@ BrowserWindow *a_Bw_new(void)
|
||||
bw->NumImages = 0;
|
||||
bw->NumImagesGot = 0;
|
||||
bw->NumPendingStyleSheets = 0;
|
||||
bw->PageUrls = dList_new(8);
|
||||
bw->Docs = dList_new(8);
|
||||
|
||||
bw->num_page_bugs = 0;
|
||||
@ -96,9 +97,9 @@ BrowserWindow::~BrowserWindow()
|
||||
dList_free(this->Docs);
|
||||
|
||||
delete this->nav_expect_url;
|
||||
for (j = 0; j < dList_length(this->PageUrls); ++j)
|
||||
delete reinterpret_cast< DilloUrl * >( dList_nth_data(this->PageUrls, j) );
|
||||
dList_free(this->PageUrls);
|
||||
//for (j = 0; j < dList_length(this->PageUrls); ++j)
|
||||
//delete reinterpret_cast< DilloUrl * >( dList_nth_data(this->PageUrls, j) );
|
||||
//dList_free(this->PageUrls);
|
||||
|
||||
for (j = 0; j < dList_length(this->nav_stack); ++j)
|
||||
dFree(dList_nth_data(this->nav_stack, j));
|
||||
@ -201,13 +202,16 @@ void a_Bw_stop_clients(BrowserWindow *bw, int flags)
|
||||
* This helps us keep track of page-requested URLs so that it's
|
||||
* possible to stop, abort and reload them.
|
||||
*/
|
||||
void a_Bw_add_url(BrowserWindow *bw, const DilloUrl *Url)
|
||||
void a_Bw_add_url(BrowserWindow *bw, std::unique_ptr< DilloUrl > Url)
|
||||
{
|
||||
dReturn_if_fail ( bw != NULL && Url != NULL );
|
||||
|
||||
if (!dList_find_custom(bw->PageUrls, Url, (dCompareFunc)a_Url_cmp)) {
|
||||
dList_append(bw->PageUrls, a_Url_dup(Url).release());
|
||||
}
|
||||
auto found= std::find_if( begin( bw->PageUrls ), end( bw->PageUrls ),
|
||||
[&Url]( const auto &url ) { return *url == *Url; } );
|
||||
|
||||
if( end( bw->PageUrls ) != found ) return;
|
||||
|
||||
bw->PageUrls.push_back( std::move( Url ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,14 +246,14 @@ void *a_Bw_get_current_doc(BrowserWindow *bw)
|
||||
* This is currently used by popup menus that need to ensure that the
|
||||
* page has not changed while the menu was popped up.
|
||||
*/
|
||||
void *a_Bw_get_url_doc(BrowserWindow *bw, const DilloUrl *url)
|
||||
void *a_Bw_get_url_doc(BrowserWindow *bw, const DilloUrl *Url)
|
||||
{
|
||||
void *doc = NULL;
|
||||
if( not Url ) return nullptr;
|
||||
auto found= std::find_if( begin( bw->PageUrls ), end( bw->PageUrls ),
|
||||
[&Url]( const auto &url ) { return *url == *Url; } );
|
||||
|
||||
if (url && dList_find_custom(bw->PageUrls, url, (dCompareFunc)a_Url_cmp)) {
|
||||
doc = a_Bw_get_current_doc(bw);
|
||||
}
|
||||
return doc;
|
||||
if( end( bw->PageUrls ) != found ) return a_Bw_get_current_doc( bw );
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -282,10 +286,7 @@ void a_Bw_cleanup(BrowserWindow *bw)
|
||||
dList_remove_fast(bw->ImageClients, data);
|
||||
}
|
||||
/* Remove PageUrls */
|
||||
while ((data = dList_nth_data(bw->PageUrls, 0))) {
|
||||
delete reinterpret_cast< DilloUrl * >( data );
|
||||
dList_remove_fast(bw->PageUrls, data);
|
||||
}
|
||||
bw->PageUrls.clear();
|
||||
|
||||
/* Zero image-progress data */
|
||||
bw->NumImages = 0;
|
||||
|
10
src/bw.hh
10
src/bw.hh
@ -15,6 +15,12 @@
|
||||
|
||||
#include "url.hh" /* for DilloUrl */
|
||||
|
||||
extern "C++"
|
||||
{
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
}
|
||||
|
||||
/*
|
||||
* Flag Defines for a_Bw_stop_clients()
|
||||
*/
|
||||
@ -47,7 +53,7 @@ struct BrowserWindow {
|
||||
/** Number of not yet arrived style sheets */
|
||||
int NumPendingStyleSheets;
|
||||
/** List of all Urls requested by this page (and its types) */
|
||||
Dlist *PageUrls;
|
||||
std::vector< std::unique_ptr< DilloUrl > > PageUrls;
|
||||
|
||||
/** The navigation stack (holds indexes to history list) */
|
||||
Dlist *nav_stack;
|
||||
@ -98,7 +104,7 @@ void a_Bw_add_doc(BrowserWindow *bw, void *vdoc);
|
||||
void *a_Bw_get_current_doc(BrowserWindow *bw);
|
||||
void *a_Bw_get_url_doc(BrowserWindow *bw, const DilloUrl *Url);
|
||||
void a_Bw_remove_doc(BrowserWindow *bw, void *vdoc);
|
||||
void a_Bw_add_url(BrowserWindow *bw, const DilloUrl *Url);
|
||||
void a_Bw_add_url(BrowserWindow *bw, std::unique_ptr< DilloUrl > Url);
|
||||
void a_Bw_cleanup(BrowserWindow *bw);
|
||||
/* expect API */
|
||||
void a_Bw_expect(BrowserWindow *bw, const DilloUrl *Url);
|
||||
|
@ -2204,7 +2204,7 @@ static bool Html_load_image(BrowserWindow *bw, DilloUrl *url,
|
||||
/* Request image data from the cache */
|
||||
if ((ClientKey = a_Capi_open_url(Web, NULL, NULL)) != 0) {
|
||||
a_Bw_add_client(bw, ClientKey, 0);
|
||||
a_Bw_add_url(bw, url);
|
||||
a_Bw_add_url(bw, a_Url_dup( url ));
|
||||
}
|
||||
return ClientKey != 0;
|
||||
}
|
||||
@ -3281,7 +3281,7 @@ void a_Html_load_stylesheet(DilloHtml *html, DilloUrl *url)
|
||||
if ((ClientKey = a_Capi_open_url(Web, Html_css_load_callback, NULL))) {
|
||||
++html->bw->NumPendingStyleSheets;
|
||||
a_Bw_add_client(html->bw, ClientKey, 0);
|
||||
a_Bw_add_url(html->bw, url);
|
||||
a_Bw_add_url(html->bw, a_Url_dup( url ));
|
||||
MSG("NumPendingStyleSheets=%d\n", html->bw->NumPendingStyleSheets);
|
||||
}
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ static void Nav_open_url(BrowserWindow *bw, const DilloUrl *url,
|
||||
Web->flags |= WEB_RootUrl;
|
||||
if ((ClientKey = a_Capi_open_url(Web, NULL, NULL)) != 0) {
|
||||
a_Bw_add_client(bw, ClientKey, 1);
|
||||
a_Bw_add_url(bw, url);
|
||||
a_Bw_add_url(bw, a_Url_dup( url ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -364,7 +364,7 @@ void StyleEngine::apply (int i, StyleAttrs *attrs, CssPropertyList *props,
|
||||
Font *parentFont = stack.at (i - 1).style->font;
|
||||
char *c, *fontName;
|
||||
int lineHeight;
|
||||
DilloUrl *imgUrl = NULL;
|
||||
std::unique_ptr< DilloUrl > imgUrl;
|
||||
|
||||
/* Determine font first so it can be used to resolve relative lengths. */
|
||||
for (int j = 0; j < props->size (); j++) {
|
||||
@ -531,7 +531,7 @@ void StyleEngine::apply (int i, StyleAttrs *attrs, CssPropertyList *props,
|
||||
break;
|
||||
case CSS_PROPERTY_BACKGROUND_IMAGE:
|
||||
// p->value.strVal should be absolute, so baseUrl is not needed
|
||||
imgUrl = a_Url_new (p->value.strVal, NULL).release();
|
||||
imgUrl = a_Url_new (p->value.strVal, NULL);
|
||||
break;
|
||||
case CSS_PROPERTY_BACKGROUND_POSITION:
|
||||
computeLength (&attrs->backgroundPositionX, p->value.posVal->posX,
|
||||
@ -766,7 +766,7 @@ void StyleEngine::apply (int i, StyleAttrs *attrs, CssPropertyList *props,
|
||||
|
||||
// we use the pageUrl as requester to prevent cross
|
||||
// domain requests as specified in domainrc
|
||||
DilloWeb *web = a_Web_new(bw, imgUrl, pageUrl);
|
||||
DilloWeb *web = a_Web_new(bw, imgUrl.get(), pageUrl);
|
||||
web->Image = image;
|
||||
a_Image_ref(image);
|
||||
web->flags |= WEB_Image;
|
||||
@ -774,12 +774,11 @@ void StyleEngine::apply (int i, StyleAttrs *attrs, CssPropertyList *props,
|
||||
int clientKey;
|
||||
if ((clientKey = a_Capi_open_url(web, NULL, NULL)) != 0) {
|
||||
a_Bw_add_client(bw, clientKey, 0);
|
||||
a_Bw_add_url(bw, imgUrl);
|
||||
a_Bw_add_url(bw, std::move( imgUrl ));
|
||||
attrs->backgroundImage->connectDeletion
|
||||
(new StyleImageDeletionReceiver (clientKey));
|
||||
}
|
||||
}
|
||||
delete imgUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,6 +112,8 @@ struct DilloUrl {
|
||||
int illegal_chars_spc; /**< number of illegal space chars */
|
||||
|
||||
~DilloUrl();
|
||||
|
||||
friend bool operator == ( const DilloUrl &lhs, const DilloUrl &rhs );
|
||||
};
|
||||
|
||||
|
||||
@ -121,6 +123,12 @@ char *a_Url_str(const DilloUrl *url);
|
||||
const char *a_Url_hostname(const DilloUrl *u);
|
||||
std::unique_ptr< DilloUrl > a_Url_dup(const DilloUrl *u);
|
||||
int a_Url_cmp(const DilloUrl *A, const DilloUrl *B);
|
||||
|
||||
inline bool
|
||||
operator == ( const DilloUrl &lhs, const DilloUrl &rhs )
|
||||
{
|
||||
return a_Url_cmp( &lhs, &rhs ) == 0;
|
||||
}
|
||||
void a_Url_set_flags(DilloUrl *u, int flags);
|
||||
void a_Url_set_data(DilloUrl *u, std::string_view data);
|
||||
void a_Url_set_ismap_coords(DilloUrl *u, char *coord_str);
|
||||
|
Reference in New Issue
Block a user