From 66a87fc8824054b8909bd8481afb3e7c65209618 Mon Sep 17 00:00:00 2001 From: "vidur%netscape.com" Date: Mon, 9 Aug 1999 19:10:24 +0000 Subject: [PATCH] Implemented document.lastModified --- content/html/document/src/nsHTMLDocument.cpp | 56 ++++++++++++++++++-- content/html/document/src/nsHTMLDocument.h | 3 ++ content/html/document/src/nsIHTMLDocument.h | 2 + layout/html/document/src/nsHTMLDocument.cpp | 56 ++++++++++++++++++-- layout/html/document/src/nsHTMLDocument.h | 3 ++ layout/html/document/src/nsIHTMLDocument.h | 2 + 6 files changed, 116 insertions(+), 6 deletions(-) diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 8333a40be516..93b1e8e3129f 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -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 aURL; rv = aChannel->GetURI(getter_AddRefs(aURL)); if (NS_FAILED(rv)) return rv; + + nsCOMPtr 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; } diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index a6bf843a145b..05782f9d5558 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -87,6 +87,8 @@ public: NS_IMETHOD GetBaseTarget(nsString& aTarget) const; NS_IMETHOD SetBaseTarget(const nsString& aTarget); + NS_IMETHOD SetLastModified(const nsString& aLastModified); + NS_IMETHOD GetDTDMode(nsDTDMode& aMode); NS_IMETHOD SetDTDMode(nsDTDMode aMode); @@ -204,6 +206,7 @@ protected: nsIHTMLCSSStyleSheet* mStyleAttrStyleSheet; nsIURI* mBaseURL; nsString* mBaseTarget; + nsString* mLastModified; nsDTDMode mDTDMode; nsVoidArray mImageMaps; nsICSSLoader* mCSSLoader; diff --git a/content/html/document/src/nsIHTMLDocument.h b/content/html/document/src/nsIHTMLDocument.h index d00110172bcd..fc85a47542fe 100644 --- a/content/html/document/src/nsIHTMLDocument.h +++ b/content/html/document/src/nsIHTMLDocument.h @@ -63,6 +63,8 @@ public: NS_IMETHOD GetBaseTarget(nsString& aTarget) const = 0; NS_IMETHOD SetBaseTarget(const nsString& aTarget) = 0; + NS_IMETHOD SetLastModified(const nsString& aLastModified) = 0; + /** * Access DTD compatibility mode for this document */ diff --git a/layout/html/document/src/nsHTMLDocument.cpp b/layout/html/document/src/nsHTMLDocument.cpp index 8333a40be516..93b1e8e3129f 100644 --- a/layout/html/document/src/nsHTMLDocument.cpp +++ b/layout/html/document/src/nsHTMLDocument.cpp @@ -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 aURL; rv = aChannel->GetURI(getter_AddRefs(aURL)); if (NS_FAILED(rv)) return rv; + + nsCOMPtr 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; } diff --git a/layout/html/document/src/nsHTMLDocument.h b/layout/html/document/src/nsHTMLDocument.h index a6bf843a145b..05782f9d5558 100644 --- a/layout/html/document/src/nsHTMLDocument.h +++ b/layout/html/document/src/nsHTMLDocument.h @@ -87,6 +87,8 @@ public: NS_IMETHOD GetBaseTarget(nsString& aTarget) const; NS_IMETHOD SetBaseTarget(const nsString& aTarget); + NS_IMETHOD SetLastModified(const nsString& aLastModified); + NS_IMETHOD GetDTDMode(nsDTDMode& aMode); NS_IMETHOD SetDTDMode(nsDTDMode aMode); @@ -204,6 +206,7 @@ protected: nsIHTMLCSSStyleSheet* mStyleAttrStyleSheet; nsIURI* mBaseURL; nsString* mBaseTarget; + nsString* mLastModified; nsDTDMode mDTDMode; nsVoidArray mImageMaps; nsICSSLoader* mCSSLoader; diff --git a/layout/html/document/src/nsIHTMLDocument.h b/layout/html/document/src/nsIHTMLDocument.h index d00110172bcd..fc85a47542fe 100644 --- a/layout/html/document/src/nsIHTMLDocument.h +++ b/layout/html/document/src/nsIHTMLDocument.h @@ -63,6 +63,8 @@ public: NS_IMETHOD GetBaseTarget(nsString& aTarget) const = 0; NS_IMETHOD SetBaseTarget(const nsString& aTarget) = 0; + NS_IMETHOD SetLastModified(const nsString& aLastModified) = 0; + /** * Access DTD compatibility mode for this document */