Implemented document.lastModified

git-svn-id: svn://10.0.0.236/trunk@42777 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
vidur%netscape.com
1999-08-09 19:10:24 +00:00
parent 2e65afe54f
commit fe08914eae
6 changed files with 116 additions and 6 deletions

View File

@@ -16,6 +16,7 @@
* Reserved.
*/
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsHTMLDocument.h"
#include "nsIParser.h"
#include "nsIParserFilter.h"
@@ -70,7 +71,7 @@
#include "nsGenericHTMLElement.h"
#include "nsGenericDOMNodeList.h"
#include "nsICSSLoader.h"
#include "nsIHTTPChannel.h"
#include "nsICharsetDetector.h"
#include "nsICharsetDetectionAdaptor.h"
@@ -140,7 +141,8 @@ nsHTMLDocument::nsHTMLDocument()
mAttrStyleSheet(nsnull),
mStyleAttrStyleSheet(nsnull),
mBaseURL(nsnull),
mBaseTarget(nsnull)
mBaseTarget(nsnull),
mLastModified(nsnull)
{
mImages = nsnull;
mApplets = nsnull;
@@ -197,6 +199,10 @@ nsHTMLDocument::~nsHTMLDocument()
delete mBaseTarget;
mBaseTarget = nsnull;
}
if (nsnull != mLastModified) {
delete mLastModified;
mLastModified = nsnull;
}
NS_IF_RELEASE(mParser);
for (i = 0; i < mImageMaps.Count(); i++) {
nsIDOMHTMLMapElement* map = (nsIDOMHTMLMapElement*)mImageMaps.ElementAt(i);
@@ -372,6 +378,25 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr<nsIURI> aURL;
rv = aChannel->GetURI(getter_AddRefs(aURL));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
nsXPIDLCString header;
nsAutoString lastModified;
nsIAtom* key = NS_NewAtom("last-modified");
rv = httpChannel->GetResponseHeader(key,
getter_Copies(header));
NS_RELEASE(key);
if (NS_SUCCEEDED(rv)) {
lastModified = header;
SetLastModified(lastModified);
}
// Don't propogate the result code beyond here, since it
// could just be that the response header wasn't found.
rv = NS_OK;
}
#endif
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
@@ -757,6 +782,25 @@ nsHTMLDocument:: SetBaseTarget(const nsString& aTarget)
return NS_OK;
}
NS_IMETHODIMP
nsHTMLDocument::SetLastModified(const nsString& aLastModified)
{
if (0 < aLastModified.Length()) {
if (nsnull != mLastModified) {
*mLastModified = aLastModified;
}
else {
mLastModified = aLastModified.ToNewString();
}
}
else if (nsnull != mLastModified) {
delete mLastModified;
mLastModified = nsnull;
}
return NS_OK;
}
NS_IMETHODIMP
nsHTMLDocument::GetCSSLoader(nsICSSLoader*& aLoader)
{
@@ -1956,7 +2000,13 @@ NS_IMETHODIMP
nsHTMLDocument::GetLastModified(nsString& aLastModified)
{
//XXX TBImplemented
aLastModified.Truncate();
if (nsnull != mLastModified) {
aLastModified = *mLastModified;
}
else {
aLastModified.SetString("January 1, 1970 GMT");
}
return NS_OK;
}