Changed: Use url from <base> element for relative urls

This commit is contained in:
Nimetu 2016-01-20 19:15:20 +02:00
parent 16a6f7b271
commit 5c3e84cf1b
2 changed files with 37 additions and 3 deletions

View file

@ -369,13 +369,21 @@ namespace NLGUI
// Delete page content and prepare next page
void removeContent ();
// Current URL
// Current URL for relative links in page
std::string _URL;
// Current URL
std::string _DocumentUrl;
// Valid base href was found
bool _IgnoreBaseUrlTag;
// Fragment from loading url
std::string _UrlFragment;
std::map<std::string,NLGUI::CInterfaceElement *> _Anchors;
std::vector<std::string> _AnchorName;
// Parser context
bool _ReadingHeadTag;
bool _IgnoreHeadTag;
// Current DOMAIN
bool _TrustedDomain;

View file

@ -1117,6 +1117,24 @@ namespace NLGUI
// Paragraph ?
switch(element_number)
{
case HTML_HEAD:
_ReadingHeadTag = !_IgnoreHeadTag;
_IgnoreHeadTag = true;
break;
case HTML_BASE:
if (_ReadingHeadTag && !_IgnoreBaseUrlTag)
{
if (present[HTML_BASE_HREF] && value[HTML_BASE_HREF])
{
CUrlParser uri(value[HTML_BASE_HREF]);
if (uri.isAbsolute())
{
_URL = uri.toString();
_IgnoreBaseUrlTag = true;
}
}
}
break;
case HTML_A:
{
CStyleParams style;
@ -2110,6 +2128,9 @@ namespace NLGUI
// Paragraph ?
switch(element_number)
{
case HTML_HEAD:
_ReadingHeadTag = false;
break;
case HTML_FONT:
popIfNotEmpty (_TextColor);
popIfNotEmpty (_FontSize);
@ -2397,6 +2418,7 @@ namespace NLGUI
_LI = false;
_SelectOption = false;
_GroupListAdaptor = NULL;
_DocumentUrl = "";
_UrlFragment.clear();
// Register
@ -3481,11 +3503,11 @@ namespace NLGUI
// Anchor to scroll after page has loaded
_UrlFragment = uri.hash;
uri.inherit(_URL);
uri.inherit(_DocumentUrl);
uri.hash.clear();
// compare urls and see if we only navigating to new anchor
if (!force && _URL == uri.toString())
if (!force && _DocumentUrl == uri.toString())
{
// scroll happens in updateCoords()
invalidateCoords();
@ -4097,6 +4119,9 @@ namespace NLGUI
_TextArea = false;
_Object = false;
_Localize = false;
_ReadingHeadTag = false;
_IgnoreHeadTag = false;
_IgnoreBaseUrlTag = false;
// TR
@ -4751,6 +4776,7 @@ namespace NLGUI
//
_Browsing = true;
_DocumentUrl = _URL;
// clear content
beginBuild();