diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index fd8224cb9df..7288ed8f926 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -27,6 +27,7 @@ #include "nsIContent.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" +#include "nsIDOMNSDocument.h" #include "nsIDOMElement.h" #include "nsIDocumentViewer.h" #include "nsIDocumentLoaderFactory.h" @@ -724,6 +725,7 @@ nsDocShell::LoadURI(nsIURI * aURI, owner, inheritOwner, target.get(), + nsnull, // No type hint postStream, headersStream, loadType, @@ -2744,16 +2746,30 @@ nsDocShell::Reload(PRUint32 aReloadFlags) return NS_OK; /* If you change this part of code, make sure bug 45297 does not re-occur */ - if (mOSHE) + if (mOSHE) { rv = LoadHistoryEntry(mOSHE, type); - else if (mLSHE) // In case a reload happened before the current load is done + } + else if (mLSHE) { // In case a reload happened before the current load is done rv = LoadHistoryEntry(mLSHE, type); - else + } + else { + nsAutoString contentTypeHint; + nsCOMPtr window(do_GetInterface((nsIDocShell*)this)); + if (window) { + nsCOMPtr document; + window->GetDocument(getter_AddRefs(document)); + nsCOMPtr doc(do_QueryInterface(document)); + if (doc) { + doc->GetContentType(contentTypeHint); + } + } + rv = InternalLoad(mCurrentURI, mReferrerURI, nsnull, // No owner PR_TRUE, // Inherit owner from document nsnull, // No window target + NS_LossyConvertUCS2toASCII(contentTypeHint).get(), nsnull, // No post data nsnull, // No headers data type, // Load type @@ -2761,6 +2777,8 @@ nsDocShell::Reload(PRUint32 aReloadFlags) PR_TRUE, nsnull, // No nsIDocShell nsnull); // No nsIRequest + } + return rv; } @@ -4877,6 +4895,7 @@ nsDocShell::InternalLoad(nsIURI * aURI, nsISupports * aOwner, PRBool aInheritOwner, const PRUnichar *aWindowTarget, + const char* aTypeHint, nsIInputStream * aPostData, nsIInputStream * aHeadersData, PRUint32 aLoadType, @@ -5043,6 +5062,7 @@ nsDocShell::InternalLoad(nsIURI * aURI, owner, aInheritOwner, nsnull, // No window target + aTypeHint, aPostData, aHeadersData, aLoadType, @@ -5218,8 +5238,8 @@ nsDocShell::InternalLoad(nsIURI * aURI, // been called. mLSHE = aSHEntry; - rv = DoURILoad(aURI, aReferrer, owner, aPostData, aHeadersData, firstParty, - aDocShell, aRequest); + rv = DoURILoad(aURI, aReferrer, owner, aTypeHint, aPostData, aHeadersData, + firstParty, aDocShell, aRequest); if (NS_FAILED(rv)) { DisplayLoadError(rv, aURI, nsnull); @@ -5272,6 +5292,7 @@ nsresult nsDocShell::DoURILoad(nsIURI * aURI, nsIURI * aReferrerURI, nsISupports * aOwner, + const char * aTypeHint, nsIInputStream * aPostData, nsIInputStream * aHeadersData, PRBool firstParty, @@ -5324,7 +5345,10 @@ nsDocShell::DoURILoad(nsIURI * aURI, } channel->SetOriginalURI(aURI); - + if (aTypeHint && *aTypeHint) { + channel->SetContentType(nsDependentCString(aTypeHint)); + } + //hack nsCOMPtr httpChannel(do_QueryInterface(channel)); nsCOMPtr httpChannelInternal(do_QueryInterface(channel)); @@ -6088,6 +6112,7 @@ nsDocShell::AddToSessionHistory(nsIURI * aURI, nsCOMPtr cacheToken; PRBool expired = PR_FALSE; PRBool discardLayoutState = PR_FALSE; + nsCAutoString contentType; if (aChannel) { nsCOMPtr cacheChannel(do_QueryInterface(aChannel)); @@ -6113,6 +6138,7 @@ nsDocShell::AddToSessionHistory(nsIURI * aURI, discardLayoutState = ShouldDiscardLayoutState(httpChannel); } + aChannel->GetContentType(contentType); } //Title is set in nsDocShell::SetTitle() @@ -6121,7 +6147,8 @@ nsDocShell::AddToSessionHistory(nsIURI * aURI, nsnull, // DOMDocument inputStream, // Post data stream nsnull, // LayoutHistory state - cacheKey); // CacheKey + cacheKey, // CacheKey + contentType); // Content-type entry->SetReferrerURI(referrerURI); /* If cache got a 'no-store', ask SH not to store * HistoryLayoutState. By default, SH will set this @@ -6193,6 +6220,7 @@ nsDocShell::LoadHistoryEntry(nsISHEntry * aEntry, PRUint32 aLoadType) nsCOMPtr uri; nsCOMPtr postData; nsCOMPtr referrerURI; + nsCAutoString contentType; NS_ENSURE_TRUE(aEntry, NS_ERROR_FAILURE); nsCOMPtr hEntry(do_QueryInterface(aEntry)); @@ -6203,6 +6231,7 @@ nsDocShell::LoadHistoryEntry(nsISHEntry * aEntry, PRUint32 aLoadType) NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(aEntry->GetPostData(getter_AddRefs(postData)), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(aEntry->GetContentType(contentType), NS_ERROR_FAILURE); /* If there is a valid postdata *and* the user pressed * reload or shift-reload, take user's permission before we @@ -6234,16 +6263,17 @@ nsDocShell::LoadHistoryEntry(nsISHEntry * aEntry, PRUint32 aLoadType) rv = InternalLoad(uri, referrerURI, - nsnull, // No owner - PR_FALSE, // Do not inherit owner from document (security-critical!) - nsnull, // No window target - postData, // Post data stream - nsnull, // No headers stream - aLoadType, // Load type - aEntry, // SHEntry + nsnull, // No owner + PR_FALSE, // Do not inherit owner from document (security-critical!) + nsnull, // No window target + contentType.get(), // Type hint + postData, // Post data stream + nsnull, // No headers stream + aLoadType, // Load type + aEntry, // SHEntry PR_TRUE, - nsnull, // No nsIDocShell - nsnull); // No nsIRequest + nsnull, // No nsIDocShell + nsnull); // No nsIRequest return rv; } diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 0ea4d16656b..eac49d0b48a 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -231,6 +231,7 @@ protected: virtual nsresult DoURILoad(nsIURI * aURI, nsIURI * aReferrer, nsISupports * aOwner, + const char * aTypeHint, nsIInputStream * aPostData, nsIInputStream * aHeadersData, PRBool firstParty, diff --git a/mozilla/docshell/base/nsIDocShell.idl b/mozilla/docshell/base/nsIDocShell.idl index e47e4c1e7cc..70bcafe8237 100644 --- a/mozilla/docshell/base/nsIDocShell.idl +++ b/mozilla/docshell/base/nsIDocShell.idl @@ -110,6 +110,8 @@ interface nsIDocShell : nsISupports * @param aStopActiveDoc - Flag indicating whether loading the current * document should be stopped. * @param aWindowTarget - Window target for the load. + * @param aTypeHint - A hint as to the content-type of the resulting + * data. May be null or empty if no hint. * @param aPostDataStream - Post data stream (if POSTing) * @param aHeadersStream - Stream containing "extra" request headers... * @param aLoadFlags - Flags to modify load behaviour. Flags are defined @@ -121,6 +123,7 @@ interface nsIDocShell : nsISupports in nsISupports aOwner, in boolean aInheritOwner, in wstring aWindowTarget, + in string aTypeHint, in nsIInputStream aPostDataStream, in nsIInputStream aHeadersStream, in unsigned long aLoadFlags, diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index a7710176990..581b9c2fcb7 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -85,6 +85,7 @@ #include "nsIDOMRange.h" #include "nsIURIContentListener.h" #include "nsIDOMDocument.h" +#include "nsIDOMHTMLAnchorElement.h" #include "nsIBaseWindow.h" #include "nsIDocShell.h" #include "nsIDocShellTreeItem.h" @@ -657,6 +658,13 @@ nsWebShell::OnLinkClickSync(nsIContent *aContent, nsAutoString target(aTargetSpec); + // If this is an anchor element, grab its type property to use as a hint + nsAutoString typeHint; + nsCOMPtr anchor(do_QueryInterface(aContent)); + if (anchor) { + anchor->GetType(typeHint); + } + // Initialize the DocShell / Request if (aDocShell) { *aDocShell = nsnull; @@ -678,6 +686,7 @@ nsWebShell::OnLinkClickSync(nsIContent *aContent, nsnull, // No onwer PR_TRUE, // Inherit owner from document target.get(), // Window target + NS_LossyConvertUCS2toASCII(typeHint).get(), aPostDataStream, // Post data stream aHeadersDataStream, // Headers stream LOAD_LINK, // Load type @@ -1053,6 +1062,7 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress, nsnull, // Owner PR_TRUE, // Inherit owner nsnull, // No window target + nsnull, // No type hint inputStream, // Post data stream nsnull, // No headers stream LOAD_RELOAD_BYPASS_PROXY_AND_CACHE,// Load type diff --git a/mozilla/xpfe/components/shistory/public/nsISHEntry.idl b/mozilla/xpfe/components/shistory/public/nsISHEntry.idl index e162f6977d0..1b171a80ec6 100644 --- a/mozilla/xpfe/components/shistory/public/nsISHEntry.idl +++ b/mozilla/xpfe/components/shistory/public/nsISHEntry.idl @@ -95,14 +95,18 @@ attribute boolean saveLayoutStateFlag; /** attribute to indicate whether the page is already expired in cache */ attribute boolean expirationStatus; +/** attribute to indicate the content-type of the document that this + is a session history entry for */ +attribute ACString contentType; + /** Set/Get scrollers' positon in anchored pages */ void setScrollPosition(in PRInt32 x, in PRInt32 y); void getScrollPosition(out PRInt32 x, out PRInt32 y); /** Additional ways to create an entry */ void create(in nsIURI aURI, in wstring aTitle, in nsIDOMDocument aDocument, - in nsIInputStream aInputStream, in nsILayoutHistoryState aHistoryLayoutState, - in nsISupports aCacheKey); + in nsIInputStream aInputStream, in nsILayoutHistoryState aHistoryLayoutState, + in nsISupports aCacheKey, in ACString aContentType); nsISHEntry clone(); diff --git a/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp b/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp index d2ac5f5685b..1ad76a4e58e 100644 --- a/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp +++ b/mozilla/xpfe/components/shistory/src/nsSHEntry.cpp @@ -258,20 +258,34 @@ NS_IMETHODIMP nsSHEntry::SetExpirationStatus(PRBool aFlag) return NS_OK; } +NS_IMETHODIMP nsSHEntry::GetContentType(nsACString& aContentType) +{ + aContentType = mContentType; + return NS_OK; +} + +NS_IMETHODIMP nsSHEntry::SetContentType(const nsACString& aContentType) +{ + mContentType = aContentType; + return NS_OK; +} + NS_IMETHODIMP -nsSHEntry::Create(nsIURI * aURI, const PRUnichar * aTitle, nsIDOMDocument * aDOMDocument, - nsIInputStream * aInputStream, nsILayoutHistoryState * aHistoryLayoutState, - nsISupports * aCacheKey) +nsSHEntry::Create(nsIURI * aURI, const PRUnichar * aTitle, + nsIDOMDocument * aDOMDocument, nsIInputStream * aInputStream, + nsILayoutHistoryState * aHistoryLayoutState, + nsISupports * aCacheKey, const nsACString& aContentType) { SetURI(aURI); - SetTitle(aTitle); - SetDocument(aDOMDocument); - SetPostData(aInputStream); - SetLayoutHistoryState(aHistoryLayoutState); - SetCacheKey(aCacheKey); - + SetTitle(aTitle); + SetDocument(aDOMDocument); + SetPostData(aInputStream); + SetLayoutHistoryState(aHistoryLayoutState); + SetCacheKey(aCacheKey); + SetContentType(aContentType); + // Set the LoadType by default to loadHistory during creation - SetLoadType((PRInt32)nsIDocShellLoadInfo::loadHistory); + SetLoadType((PRInt32)nsIDocShellLoadInfo::loadHistory); // By default all entries are set false for subframe flag. // nsDocShell::CloneAndReplace() which creates entries for diff --git a/mozilla/xpfe/components/shistory/src/nsSHEntry.h b/mozilla/xpfe/components/shistory/src/nsSHEntry.h index 8479f1832d0..e0097405957 100644 --- a/mozilla/xpfe/components/shistory/src/nsSHEntry.h +++ b/mozilla/xpfe/components/shistory/src/nsSHEntry.h @@ -69,6 +69,7 @@ private: PRPackedBool mIsFrameNavigation; PRPackedBool mSaveLayoutState; PRPackedBool mExpired; + nsCString mContentType; nsCOMPtr mCacheKey; nsISHEntry * mParent; // weak reference };