From f6bcc72c17219b7deb9bfcbd3bce8558fbed5c82 Mon Sep 17 00:00:00 2001 From: "valeski%netscape.com" Date: Wed, 4 Aug 1999 21:19:22 +0000 Subject: [PATCH] we now handle the URL attribute in a http-equiv refresh tag git-svn-id: svn://10.0.0.236/trunk@42205 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/document/src/nsHTMLContentSink.cpp | 55 ++++++++++++++++--- .../html/document/src/nsHTMLContentSink.cpp | 55 ++++++++++++++++--- 2 files changed, 92 insertions(+), 18 deletions(-) diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index 5cf57f84868..9a07a7458d0 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -2884,23 +2884,60 @@ HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode) // XXX necko isn't going to process headers coming in from the parser //NS_WARNING("need to fix how necko adds mime headers (in HTMLContentSink::ProcessMETATag)"); - // parse out the content + // see if we have a refresh "header". if (!header.Compare("refresh", PR_TRUE)) { - nsIRefreshURI *reefer = nsnull; - rv = mWebShell->QueryInterface(nsCOMTypeInfo::GetIID(), (void**)&reefer); + // Refresh haders are parsed with the following format in mind + // + // By the time we are here, the following is true: + // header = "REFRESH" + // result = "5; URL=http://uri" // note the URL attribute is optional, if it + // is absent, the currently loaded url is used. + const PRUnichar *uriCStr = nsnull; + nsAutoString uriAttribStr; + + // first get our baseURI + rv = mWebShell->GetURL(&uriCStr); if (NS_FAILED(rv)) return rv; - - const PRUnichar *uriStr = nsnull; - rv = mWebShell->GetURL(&uriStr); + + nsIURI *baseURI = nsnull; + rv = NS_NewURI(&baseURI, uriCStr, nsnull); if (NS_FAILED(rv)) return rv; + // next get any uri provided as an attribute in the tag. + PRInt32 urlLoc = result.Find("url", PR_TRUE); + if (urlLoc > -1) { + // there is a url attribute, let's use it. + urlLoc += 3; + // go past the '=' sign + urlLoc = result.Find("=", PR_TRUE, urlLoc); + if (urlLoc > -1) { + urlLoc++; // leading/trailign spaces get trimmed in url creating code. + result.Mid(uriAttribStr, urlLoc, result.Length() - urlLoc); + uriCStr = uriAttribStr.GetUnicode(); + } + } + nsIURI *uri = nsnull; - rv = NS_NewURI(&uri, uriStr, nsnull); + rv = NS_NewURI(&uri, uriCStr, baseURI); + NS_RELEASE(baseURI); if (NS_FAILED(rv)) return rv; - PRInt32 error; - PRInt32 millis = result.ToInteger(&error) * 1000; + // the units of the numeric value contained in the result are seconds. + // we need them in milliseconds before handing off to the refresh interface. + // NOTE: we're no longer using the urlLoc variable, just stick it in here + // as the error argument to ::ToInteger() as an optimization. + PRInt32 millis = result.ToInteger(&urlLoc) * 1000; + + nsIRefreshURI *reefer = nsnull; + rv = mWebShell->QueryInterface(nsCOMTypeInfo::GetIID(), (void**)&reefer); + if (NS_FAILED(rv)) { + NS_RELEASE(uri); + return rv; + }; + rv = reefer->RefreshURI(uri, millis, PR_FALSE); + NS_RELEASE(uri); + NS_RELEASE(reefer); if (NS_FAILED(rv)) return rv; } #else diff --git a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp index 5cf57f84868..9a07a7458d0 100644 --- a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp @@ -2884,23 +2884,60 @@ HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode) // XXX necko isn't going to process headers coming in from the parser //NS_WARNING("need to fix how necko adds mime headers (in HTMLContentSink::ProcessMETATag)"); - // parse out the content + // see if we have a refresh "header". if (!header.Compare("refresh", PR_TRUE)) { - nsIRefreshURI *reefer = nsnull; - rv = mWebShell->QueryInterface(nsCOMTypeInfo::GetIID(), (void**)&reefer); + // Refresh haders are parsed with the following format in mind + // + // By the time we are here, the following is true: + // header = "REFRESH" + // result = "5; URL=http://uri" // note the URL attribute is optional, if it + // is absent, the currently loaded url is used. + const PRUnichar *uriCStr = nsnull; + nsAutoString uriAttribStr; + + // first get our baseURI + rv = mWebShell->GetURL(&uriCStr); if (NS_FAILED(rv)) return rv; - - const PRUnichar *uriStr = nsnull; - rv = mWebShell->GetURL(&uriStr); + + nsIURI *baseURI = nsnull; + rv = NS_NewURI(&baseURI, uriCStr, nsnull); if (NS_FAILED(rv)) return rv; + // next get any uri provided as an attribute in the tag. + PRInt32 urlLoc = result.Find("url", PR_TRUE); + if (urlLoc > -1) { + // there is a url attribute, let's use it. + urlLoc += 3; + // go past the '=' sign + urlLoc = result.Find("=", PR_TRUE, urlLoc); + if (urlLoc > -1) { + urlLoc++; // leading/trailign spaces get trimmed in url creating code. + result.Mid(uriAttribStr, urlLoc, result.Length() - urlLoc); + uriCStr = uriAttribStr.GetUnicode(); + } + } + nsIURI *uri = nsnull; - rv = NS_NewURI(&uri, uriStr, nsnull); + rv = NS_NewURI(&uri, uriCStr, baseURI); + NS_RELEASE(baseURI); if (NS_FAILED(rv)) return rv; - PRInt32 error; - PRInt32 millis = result.ToInteger(&error) * 1000; + // the units of the numeric value contained in the result are seconds. + // we need them in milliseconds before handing off to the refresh interface. + // NOTE: we're no longer using the urlLoc variable, just stick it in here + // as the error argument to ::ToInteger() as an optimization. + PRInt32 millis = result.ToInteger(&urlLoc) * 1000; + + nsIRefreshURI *reefer = nsnull; + rv = mWebShell->QueryInterface(nsCOMTypeInfo::GetIID(), (void**)&reefer); + if (NS_FAILED(rv)) { + NS_RELEASE(uri); + return rv; + }; + rv = reefer->RefreshURI(uri, millis, PR_FALSE); + NS_RELEASE(uri); + NS_RELEASE(reefer); if (NS_FAILED(rv)) return rv; } #else