diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 17ccde0fd36..2518ce31c99 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -83,6 +83,7 @@ #include "nsNodeInfoManager.h" #include "nsIXBLService.h" #include "nsIXPointer.h" +#include "nsIFileChannel.h" #include "nsNetUtil.h" // for NS_MakeAbsoluteURI @@ -786,36 +787,7 @@ nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, CopyASCIItoUCS2(Substring(start, semicolon), mContentType); } - PRBool have_contentLanguage = PR_FALSE; - nsCOMPtr httpChannel = do_QueryInterface(aChannel); - if (httpChannel) { - nsCAutoString contentLanguage; - rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Language"), - contentLanguage); - - if (NS_SUCCEEDED(rv)) { - // XXX what's wrong w/ ASCII? - CopyASCIItoUCS2(contentLanguage, mContentLanguage); - - have_contentLanguage = PR_TRUE; - } - } - - if (!have_contentLanguage) { - nsCOMPtr prefBranch = - do_GetService(NS_PREFSERVICE_CONTRACTID); - - if (prefBranch) { - nsXPIDLCString prefLanguage; - - rv = prefBranch->GetCharPref("intl.accept_languages", - getter_Copies(prefLanguage)); - - if (NS_SUCCEEDED(rv)) { - mContentLanguage.AssignWithConversion(prefLanguage); - } - } - } + RetrieveRelevantHeaders(aChannel); return rv; } @@ -843,6 +815,18 @@ nsDocument::GetDocumentURL(nsIURI** aURI) const return NS_OK; } +NS_IMETHODIMP +nsDocument::GetLastModified(nsAString& aLastModified) +{ + if (!mLastModified.IsEmpty()) { + aLastModified.Assign(mLastModified); + } else { + aLastModified.Assign(NS_LITERAL_STRING("January 1, 1970 GMT")); + } + + return NS_OK; +} + NS_IMETHODIMP nsDocument::GetPrincipal(nsIPrincipal **aPrincipal) { @@ -4137,3 +4121,79 @@ nsDocument::SetBidiEnabled(PRBool aBidiEnabled) return NS_OK; } + +void +nsDocument::RetrieveRelevantHeaders(nsIChannel *aChannel) +{ + nsCOMPtr httpChannel = do_QueryInterface(aChannel); + nsresult rv; + PRBool have_contentLanguage = PR_FALSE; + + if (httpChannel) { + nsCAutoString header; + + rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("last-modified"), + header); + + if (NS_SUCCEEDED(rv)) { + CopyASCIItoUCS2(header, mLastModified); + } + + rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Language"), + header); + + if (NS_SUCCEEDED(rv)) { + // XXX what's wrong w/ ASCII? + CopyASCIItoUCS2(header, mContentLanguage); + + have_contentLanguage = PR_TRUE; + } + } + + if (!have_contentLanguage) { + nsCOMPtr prefBranch = + do_GetService(NS_PREFSERVICE_CONTRACTID); + + if (prefBranch) { + nsXPIDLCString prefLanguage; + + rv = prefBranch->GetCharPref("intl.accept_languages", + getter_Copies(prefLanguage)); + + if (NS_SUCCEEDED(rv)) { + CopyASCIItoUCS2(prefLanguage, mContentLanguage); + } + } + } + + nsCOMPtr fileChannel = do_QueryInterface(aChannel); + if (fileChannel) { + PRTime modDate, usecs; + nsCOMPtr file; + nsresult rv = fileChannel->GetFile(getter_AddRefs(file)); + if (NS_SUCCEEDED(rv)) { + rv = file->GetLastModifiedTime(&modDate); + if (NS_SUCCEEDED(rv)) { + PRExplodedTime prtime; + char buf[100]; + PRInt64 intermediateValue; + + LL_I2L(intermediateValue, PR_USEC_PER_MSEC); + LL_MUL(usecs, modDate, intermediateValue); + PR_ExplodeTime(usecs, PR_LocalTimeParameters, &prtime); + + // Use '%#c' for windows, because '%c' is backward-compatible and + // non-y2k with msvc; '%#c' requests that a full year be used in the + // result string. Other OSes just use "%c". + PR_FormatTime(buf, sizeof buf, +#ifdef XP_WIN + "%#c", +#else + "%c", +#endif + &prtime); + mLastModified.AssignWithConversion(buf); + } + } + } +} diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 8a55cba8a3f..f2987201970 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -286,7 +286,7 @@ public: // Already declared in nsIDOMNSDocument /** - * Get the Content-Type of this document. + * Set the Content-Type of this document. */ NS_IMETHOD SetContentType(const nsAString& aContentType); @@ -588,6 +588,8 @@ protected: virtual already_AddRefed InternalGetStyleSheetAt(PRInt32 aIndex); virtual PRInt32 InternalGetNumberOfStyleSheets(); + virtual void RetrieveRelevantHeaders(nsIChannel *aChannel); + nsresult doCreateShell(nsIPresContext* aContext, nsIViewManager* aViewManager, nsIStyleSet* aStyleSet, nsCompatibility aCompatMode, @@ -598,6 +600,7 @@ protected: nsCOMPtr mArena; nsString mDocumentTitle; + nsString mLastModified; nsCOMPtr mDocumentURL; nsCOMPtr mDocumentBaseURL; nsCOMPtr mPrincipal; diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index de144f5c6c1..673437d23a5 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -40,7 +40,6 @@ #include "nsICharsetAlias.h" #include "nsCOMPtr.h" -#include "nsIFileChannel.h" #include "nsXPIDLString.h" #include "nsPrintfCString.h" #include "nsReadableUtils.h" @@ -754,20 +753,16 @@ nsHTMLDocument::StartAutodetection(nsIDocShell *aDocShell, nsAString& aCharset, } } -nsresult +void nsHTMLDocument::RetrieveRelevantHeaders(nsIChannel *aChannel) { mHttpChannel = do_QueryInterface(aChannel); - nsresult rv; + + nsDocument::RetrieveRelevantHeaders(aChannel); if (mHttpChannel) { nsCAutoString header; - rv = mHttpChannel->GetResponseHeader(NS_LITERAL_CSTRING("last-modified"), - header); - - if (NS_SUCCEEDED(rv)) { - SetLastModified(NS_ConvertASCIItoUCS2(header)); - } + nsresult rv; // The misspelled key 'referer' is as per the HTTP spec rv = mHttpChannel->GetRequestHeader(NS_LITERAL_CSTRING("referer"), @@ -777,43 +772,7 @@ nsHTMLDocument::RetrieveRelevantHeaders(nsIChannel *aChannel) } } - nsCOMPtr fileChannel = do_QueryInterface(aChannel); - if (fileChannel) { - PRTime modDate, usecs; - nsCOMPtr file; - nsresult rv = fileChannel->GetFile(getter_AddRefs(file)); - if (NS_SUCCEEDED(rv)) { - // if we failed to get a last modification date, then we don't - // want to necessarily fail to create a document for this - // file. Just don't set the last modified date on it... - rv = file->GetLastModifiedTime(&modDate); - if (NS_SUCCEEDED(rv)) { - nsAutoString lastModified; - PRExplodedTime prtime; - char buf[100]; - PRInt64 intermediateValue; - - LL_I2L(intermediateValue, PR_USEC_PER_MSEC); - LL_MUL(usecs, modDate, intermediateValue); - PR_ExplodeTime(usecs, PR_LocalTimeParameters, &prtime); - - // Use '%#c' for windows, because '%c' is backward-compatible and - // non-y2k with msvc; '%#c' requests that a full year be used in the - // result string. Other OSes just use "%c". - PR_FormatTime(buf, sizeof buf, -#ifdef XP_WIN - "%#c", -#else - "%c", -#endif - &prtime); - lastModified.AssignWithConversion(buf); - SetLastModified(lastModified); - } - } - } - - return NS_OK; + return; } NS_IMETHODIMP @@ -865,8 +824,6 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, return rv; } - RetrieveRelevantHeaders(aChannel); - nsCOMPtr cachingChan = do_QueryInterface(aChannel); if (cachingChan) { nsCOMPtr cacheToken; @@ -1326,14 +1283,6 @@ nsHTMLDocument::SetBaseTarget(const nsAString& aTarget) return NS_OK; } -NS_IMETHODIMP -nsHTMLDocument::SetLastModified(const nsAString& aLastModified) -{ - mLastModified.Assign(aLastModified); - - return NS_OK; -} - NS_IMETHODIMP nsHTMLDocument::SetReferrer(const nsAString& aReferrer) { @@ -3285,18 +3234,6 @@ nsHTMLDocument::SetFgColor(const nsAString& aFgColor) return NS_OK; } -NS_IMETHODIMP -nsHTMLDocument::GetLastModified(nsAString& aLastModified) -{ - if (!mLastModified.IsEmpty()) { - aLastModified.Assign(mLastModified); - } else { - aLastModified.Assign(NS_LITERAL_STRING("January 1, 1970 GMT")); - } - - return NS_OK; -} - NS_IMETHODIMP nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds) diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index 4d12db70dd3..462da74ea93 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -120,7 +120,6 @@ public: NS_IMETHOD GetBaseTarget(nsAString& aTarget); NS_IMETHOD SetBaseTarget(const nsAString& aTarget); - NS_IMETHOD SetLastModified(const nsAString& aLastModified); NS_IMETHOD SetReferrer(const nsAString& aReferrer); NS_IMETHOD GetCompatibilityMode(nsCompatibility& aMode); @@ -260,13 +259,12 @@ protected: nsresult BaseResetToURI(nsIURI* aURI); - nsresult RetrieveRelevantHeaders(nsIChannel *aChannel); + virtual void RetrieveRelevantHeaders(nsIChannel *aChannel); nsCOMPtr mAttrStyleSheet; nsCOMPtr mStyleAttrStyleSheet; nsString mBaseTarget; - nsString mLastModified; nsString mReferrer; nsCOMPtr mHttpChannel; diff --git a/mozilla/content/html/document/src/nsIHTMLDocument.h b/mozilla/content/html/document/src/nsIHTMLDocument.h index d0a9b110d0c..29f2a39e685 100644 --- a/mozilla/content/html/document/src/nsIHTMLDocument.h +++ b/mozilla/content/html/document/src/nsIHTMLDocument.h @@ -72,7 +72,6 @@ public: NS_IMETHOD RemoveImageMap(nsIDOMHTMLMapElement* aMap) = 0; - NS_IMETHOD SetLastModified(const nsAString& aLastModified) = 0; NS_IMETHOD SetReferrer(const nsAString& aReferrer) = 0; /** diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index ffebd8642b4..d355c2efc9c 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -578,6 +578,8 @@ nsXULDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, rv = PrepareStyleSheets(mDocumentURL); if (NS_FAILED(rv)) return rv; + RetrieveRelevantHeaders(aChannel); + // Look in the chrome cache: we've got this puppy loaded // already. nsCOMPtr proto; diff --git a/mozilla/dom/public/idl/core/nsIDOMNSDocument.idl b/mozilla/dom/public/idl/core/nsIDOMNSDocument.idl index eb1c1243124..3982cd08f17 100644 --- a/mozilla/dom/public/idl/core/nsIDOMNSDocument.idl +++ b/mozilla/dom/public/idl/core/nsIDOMNSDocument.idl @@ -55,6 +55,7 @@ interface nsIDOMNSDocument : nsISupports attribute DOMString title; readonly attribute DOMString contentType; + readonly attribute DOMString lastModified; nsIBoxObject getBoxObjectFor(in nsIDOMElement elt); void setBoxObjectFor(in nsIDOMElement elt, diff --git a/mozilla/dom/public/idl/html/nsIDOMNSHTMLDocument.idl b/mozilla/dom/public/idl/html/nsIDOMNSHTMLDocument.idl index 70a7f15e2e9..818e17db948 100644 --- a/mozilla/dom/public/idl/html/nsIDOMNSHTMLDocument.idl +++ b/mozilla/dom/public/idl/html/nsIDOMNSHTMLDocument.idl @@ -50,7 +50,6 @@ interface nsIDOMNSHTMLDocument : nsISupports attribute DOMString vlinkColor; attribute DOMString bgColor; attribute DOMString fgColor; - readonly attribute DOMString lastModified; attribute DOMString domain; readonly attribute nsIDOMHTMLCollection embeds;