Bug 84106. Actually pass a cache key to web browser persist so that POST result pages have a chance of being read from cache. Also change nsWebBrowserPersist to accept a session history entry, not just an nsIWebPageDescriptor or necko cache key, as its cache key argument. r=gavin, r+sr=jst

This commit is contained in:
Boris Zbarsky 2009-02-19 14:18:02 -05:00
Родитель 86f419fd3f
Коммит f952d65c4e
3 изменённых файлов: 45 добавлений и 22 удалений

Просмотреть файл

@ -148,7 +148,9 @@ interface nsIWebBrowserPersist : nsICancelable
* may also support <CODE>nsnull</CODE> to imply the currently
* loaded URI.
* @param aCacheKey An object representing the URI in the cache or
* <CODE>nsnull</CODE>.
* <CODE>nsnull</CODE>. This can be a necko cache key,
* an nsIWebPageDescriptor, or the currentDescriptor of an
* nsIWebPageDescriptor.
* @param aReferrer The referrer URI to pass with an HTTP request or
* <CODE>nsnull</CODE>.
* @param aPostData Post data to pass with an HTTP request or

Просмотреть файл

@ -1218,22 +1218,24 @@ nsresult nsWebBrowserPersist::SaveURIInternal(
if (aCacheKey)
{
// Test if the cache key is actually a web page descriptor (docshell)
nsCOMPtr<nsIWebPageDescriptor> webPageDescriptor = do_QueryInterface(aCacheKey);
// or session history entry.
nsCOMPtr<nsISHEntry> shEntry = do_QueryInterface(aCacheKey);
if (!shEntry)
{
nsCOMPtr<nsIWebPageDescriptor> webPageDescriptor =
do_QueryInterface(aCacheKey);
if (webPageDescriptor)
{
nsCOMPtr<nsISupports> currentDescriptor;
webPageDescriptor->GetCurrentDescriptor(getter_AddRefs(currentDescriptor));
if (currentDescriptor)
{
// Descriptor is actually a session history entry
nsCOMPtr<nsISHEntry> shEntry = do_QueryInterface(currentDescriptor);
NS_ASSERTION(shEntry, "The descriptor is meant to be a session history entry");
shEntry = do_QueryInterface(currentDescriptor);
}
}
if (shEntry)
{
shEntry->GetCacheKey(getter_AddRefs(cacheKey));
}
}
}
else
{
// Assume a plain cache key

Просмотреть файл

@ -108,7 +108,7 @@ function saveURL(aURL, aFileName, aFilePickerTitleKey, aShouldBypassCache,
aSkipPrompt, aReferrer)
{
internalSave(aURL, null, aFileName, null, null, aShouldBypassCache,
aFilePickerTitleKey, null, aReferrer, aSkipPrompt);
aFilePickerTitleKey, null, aReferrer, aSkipPrompt, null);
}
// Just like saveURL, but will get some info off the image before
@ -139,7 +139,8 @@ function saveImageURL(aURL, aFileName, aFilePickerTitleKey, aShouldBypassCache,
}
}
internalSave(aURL, null, aFileName, contentDisposition, contentType,
aShouldBypassCache, aFilePickerTitleKey, null, aReferrer, aSkipPrompt);
aShouldBypassCache, aFilePickerTitleKey, null, aReferrer,
aSkipPrompt, null);
}
function saveFrameDocument()
@ -155,20 +156,32 @@ function saveDocument(aDocument, aSkipPrompt)
throw "Must have a document when calling saveDocument";
// We want to use cached data because the document is currently visible.
var ifreq =
aDocument.defaultView
.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var contentDisposition = null;
try {
contentDisposition =
aDocument.defaultView
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils)
.getDocumentMetadata("content-disposition");
ifreq.getInterface(Components.interfaces.nsIDOMWindowUtils)
getDocumentMetadata("content-disposition");
} catch (ex) {
// Failure to get a content-disposition is ok
}
var cacheKey = null;
try {
cacheKey =
ifreq.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIWebPageDescriptor);
} catch (ex) {
// We might not find it in the cache. Oh, well.
}
internalSave(aDocument.location.href, aDocument, null, contentDisposition,
aDocument.contentType, false, null, null,
aDocument.referrer ? makeURI(aDocument.referrer) : null,
aSkipPrompt);
aSkipPrompt, cacheKey);
}
function DownloadListener(win, transfer) {
@ -252,14 +265,20 @@ const kSaveAsType_Text = 2; // Save document, converting to plain text.
* @param aSkipPrompt [optional]
* If set to true, we will attempt to save the file to the
* default downloads folder without prompting.
* @param aCacheKey [optional]
* If set will be passed to saveURI. See nsIWebBrowserPersist for
* allowed values.
*/
function internalSave(aURL, aDocument, aDefaultFileName, aContentDisposition,
aContentType, aShouldBypassCache, aFilePickerTitleKey,
aChosenData, aReferrer, aSkipPrompt)
aChosenData, aReferrer, aSkipPrompt, aCacheKey)
{
if (aSkipPrompt == undefined)
aSkipPrompt = false;
if (aCacheKey == undefined)
aCacheKey = null;
// Note: aDocument == null when this code is used by save-link-as...
var saveMode = GetSaveModeForContentType(aContentType);
var isDocument = aDocument != null && saveMode != SAVEMODE_FILEONLY;
@ -376,7 +395,7 @@ function internalSave(aURL, aDocument, aDefaultFileName, aContentDisposition,
persistArgs.target, "", null, null, null, persist);
persist.progressListener = new DownloadListener(window, tr);
persist.saveURI((aChosenData ? aChosenData.uri : source),
null, aReferrer, persistArgs.postData, null,
aCacheKey, aReferrer, persistArgs.postData, null,
persistArgs.target);
}
}