Bug 1443379 - Stop pretending cacheKey can be anything other than uint32_t, r=smaug

This commit is contained in:
Nika Layzell 2018-03-05 22:19:42 -05:00
parent adc5b074cd
commit b286bc10d9
25 changed files with 74 additions and 216 deletions

View File

@ -155,7 +155,7 @@ nsMacShellService::SetDesktopBackground(nsIDOMElement* aElement,
loadContext = do_QueryInterface(docShell);
}
return wbp->SaveURI(imageURI, nullptr,
return wbp->SaveURI(imageURI, 0,
docURI, content->OwnerDoc()->GetReferrerPolicy(),
nullptr, nullptr,
mBackgroundFile, loadContext);

View File

@ -404,10 +404,6 @@ let SourceActor = ActorClassWithSpec(sourceSpec, {
if (loadFromCache &&
webNav.currentDocumentChannel instanceof Ci.nsICacheInfoChannel) {
cacheKey = webNav.currentDocumentChannel.cacheKey;
assert(
cacheKey,
"Could not fetch the cacheKey from the related document."
);
}
}

View File

@ -514,7 +514,7 @@ function mainThreadFetch(urlIn, aOptions = { loadFromCache: true,
window: null,
charset: null,
principal: null,
cacheKey: null }) {
cacheKey: 0 }) {
// Create a channel.
let url = urlIn.split(" -> ").pop();
let channel;
@ -532,7 +532,7 @@ function mainThreadFetch(urlIn, aOptions = { loadFromCache: true,
// When loading from cache, the cacheKey allows us to target a specific
// SHEntry and offer ways to restore POST requests from cache.
if (aOptions.loadFromCache &&
aOptions.cacheKey && channel instanceof Ci.nsICacheInfoChannel) {
aOptions.cacheKey != 0 && channel instanceof Ci.nsICacheInfoChannel) {
channel.cacheKey = aOptions.cacheKey;
}

View File

@ -580,7 +580,7 @@ var saveToFile = Task.async(function* (context, reply) {
let listener = new DownloadListener(window, tr);
persist.progressListener = listener;
persist.savePrivacyAwareURI(sourceURI,
null,
0,
document.documentURIObject,
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
null,

View File

@ -10006,7 +10006,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
mLoadType, true, true, true);
nsCOMPtr<nsIInputStream> postData;
nsCOMPtr<nsISupports> cacheKey;
uint32_t cacheKey = 0;
bool scrollRestorationIsManual = false;
if (mOSHE) {
@ -10021,7 +10021,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
// wouldn't want here.
if (aLoadType & LOAD_CMD_NORMAL) {
mOSHE->GetPostData(getter_AddRefs(postData));
mOSHE->GetCacheKey(getter_AddRefs(cacheKey));
mOSHE->GetCacheKey(&cacheKey);
// Link our new SHEntry to the old SHEntry's back/forward
// cache data, since the two SHEntries correspond to the
@ -10057,7 +10057,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
// Make sure we won't just repost without hitting the
// cache first
if (cacheKey) {
if (cacheKey != 0) {
mOSHE->SetCacheKey(cacheKey);
}
}
@ -10890,12 +10890,12 @@ nsDocShell::DoURILoad(nsIURI* aURI,
nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(channel));
/* Get the cache Key from SH */
nsCOMPtr<nsISupports> cacheKey;
uint32_t cacheKey = 0;
if (cacheChannel) {
if (mLSHE) {
mLSHE->GetCacheKey(getter_AddRefs(cacheKey));
mLSHE->GetCacheKey(&cacheKey);
} else if (mOSHE) { // for reload cases
mOSHE->GetCacheKey(getter_AddRefs(cacheKey));
mOSHE->GetCacheKey(&cacheKey);
}
}
@ -10922,7 +10922,7 @@ nsDocShell::DoURILoad(nsIURI* aURI,
* data *only* from the cache. If it is a normal reload, the
* cache is free to go to the server for updated postdata.
*/
if (cacheChannel && cacheKey) {
if (cacheChannel && cacheKey != 0) {
if (mLoadType == LOAD_HISTORY ||
mLoadType == LOAD_RELOAD_CHARSET_CHANGE) {
cacheChannel->SetCacheKey(cacheKey);
@ -10947,7 +10947,7 @@ nsDocShell::DoURILoad(nsIURI* aURI,
mLoadType == LOAD_RELOAD_CHARSET_CHANGE ||
mLoadType == LOAD_RELOAD_CHARSET_CHANGE_BYPASS_CACHE ||
mLoadType == LOAD_RELOAD_CHARSET_CHANGE_BYPASS_PROXY_AND_CACHE) {
if (cacheChannel && cacheKey) {
if (cacheChannel && cacheKey != 0) {
cacheChannel->SetCacheKey(cacheKey);
}
}
@ -11517,10 +11517,10 @@ nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
" reloads unless we're in a newly created iframe!");
nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(aChannel));
nsCOMPtr<nsISupports> cacheKey;
uint32_t cacheKey = 0;
// Get the Cache Key and store it in SH.
if (cacheChannel) {
cacheChannel->GetCacheKey(getter_AddRefs(cacheKey));
cacheChannel->GetCacheKey(&cacheKey);
}
// If we already have a loading history entry, store the new cache key
// in it. Otherwise, since we're doing a reload and won't be updating
@ -12091,7 +12091,7 @@ nsDocShell::AddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel,
bool loadReplace = false;
nsCOMPtr<nsIURI> referrerURI;
uint32_t referrerPolicy = mozilla::net::RP_Unset;
nsCOMPtr<nsISupports> cacheKey;
uint32_t cacheKey = 0;
nsCOMPtr<nsIPrincipal> triggeringPrincipal = aTriggeringPrincipal;
nsCOMPtr<nsIPrincipal> principalToInherit = aPrincipalToInherit;
bool expired = false;
@ -12104,7 +12104,7 @@ nsDocShell::AddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel,
* in SH.
*/
if (cacheChannel) {
cacheChannel->GetCacheKey(getter_AddRefs(cacheKey));
cacheChannel->GetCacheKey(&cacheKey);
}
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aChannel));

View File

@ -168,7 +168,7 @@ interface nsISHEntry : nsISupports
attribute unsigned long ID;
/** attribute to set and get the cache key for the entry */
attribute nsISupports cacheKey;
attribute unsigned long cacheKey;
/** attribute to indicate whether layoutHistoryState should be saved */
attribute boolean saveLayoutStateFlag;
@ -203,7 +203,7 @@ interface nsISHEntry : nsISupports
[noscript] void create(in nsIURI URI, in AString title,
in nsIInputStream inputStream,
in nsILayoutHistoryState layoutHistoryState,
in nsISupports cacheKey, in ACString contentType,
in unsigned long cacheKey, in ACString contentType,
in nsIPrincipal triggeringPrincipal,
in nsIPrincipal principalToInherit,
in nsIDRef docshellID,

View File

@ -376,15 +376,14 @@ nsSHEntry::SetIsSubFrame(bool aFlag)
}
NS_IMETHODIMP
nsSHEntry::GetCacheKey(nsISupports** aResult)
nsSHEntry::GetCacheKey(uint32_t* aResult)
{
*aResult = mShared->mCacheKey;
NS_IF_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::SetCacheKey(nsISupports* aCacheKey)
nsSHEntry::SetCacheKey(uint32_t aCacheKey)
{
mShared->mCacheKey = aCacheKey;
return NS_OK;
@ -440,7 +439,7 @@ NS_IMETHODIMP
nsSHEntry::Create(nsIURI* aURI, const nsAString& aTitle,
nsIInputStream* aInputStream,
nsILayoutHistoryState* aLayoutHistoryState,
nsISupports* aCacheKey, const nsACString& aContentType,
uint32_t aCacheKey, const nsACString& aContentType,
nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit,
const nsID& aDocShellID,

View File

@ -37,6 +37,7 @@ nsSHEntryShared::Shutdown()
nsSHEntryShared::nsSHEntryShared()
: mDocShellID({0})
, mCacheKey(0)
, mLastTouched(0)
, mID(gSHEntrySharedID++)
, mViewerBounds(0, 0, 0, 0)

View File

@ -73,7 +73,7 @@ private:
nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
nsCString mContentType;
nsCOMPtr<nsISupports> mCacheKey;
uint32_t mCacheKey;
uint32_t mLastTouched;
// These members aren't copied by nsSHEntryShared::Duplicate() because

View File

@ -165,7 +165,7 @@ nsContentAreaDragDropDataProvider::SaveURIToFile(nsIURI* inSourceURI,
persist->SetPersistFlags(nsIWebBrowserPersist::PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION);
// referrer policy can be anything since the referrer is nullptr
return persist->SavePrivacyAwareURI(inSourceURI, nullptr, nullptr,
return persist->SavePrivacyAwareURI(inSourceURI, 0, nullptr,
mozilla::net::RP_Unset,
nullptr, nullptr,
inDestFile, isPrivate);

View File

@ -168,23 +168,12 @@ WebBrowserPersistLocalDocument::GetContentDisposition(nsAString& aCD)
NS_IMETHODIMP
WebBrowserPersistLocalDocument::GetCacheKey(uint32_t* aKey)
{
*aKey = 0;
nsCOMPtr<nsISHEntry> history = GetHistory();
if (!history) {
*aKey = 0;
return NS_OK;
if (history) {
history->GetCacheKey(aKey);
}
nsCOMPtr<nsISupports> abstractKey;
nsresult rv = history->GetCacheKey(getter_AddRefs(abstractKey));
if (NS_WARN_IF(NS_FAILED(rv)) || !abstractKey) {
*aKey = 0;
return NS_OK;
}
nsCOMPtr<nsISupportsPRUint32> u32 = do_QueryInterface(abstractKey);
if (NS_WARN_IF(!u32)) {
*aKey = 0;
return NS_OK;
}
return u32->GetData(aKey);
return NS_OK;
}
NS_IMETHODIMP

View File

@ -117,10 +117,7 @@ interface nsIWebBrowserPersist : nsICancelable
* @param aURI URI to save to file. Some implementations of this interface
* may also support <CODE>nullptr</CODE> to imply the currently
* loaded URI.
* @param aCacheKey An object representing the URI in the cache or
* <CODE>nullptr</CODE>. This can be a necko cache key,
* an nsIWebPageDescriptor, or the currentDescriptor of an
* nsIWebPageDescriptor.
* @param aCacheKey The necko cache key integer.
* @param aReferrer The referrer URI to pass with an HTTP request or
* <CODE>nullptr</CODE>.
* @param aReferrerPolicy The referrer policy for when and what to send via
@ -146,7 +143,7 @@ interface nsIWebBrowserPersist : nsICancelable
*
* @throws NS_ERROR_INVALID_ARG One or more arguments was invalid.
*/
void saveURI(in nsIURI aURI, in nsISupports aCacheKey,
void saveURI(in nsIURI aURI, in unsigned long aCacheKey,
in nsIURI aReferrer, in unsigned long aReferrerPolicy,
in nsIInputStream aPostData,
in string aExtraHeaders, in nsISupports aFile,
@ -158,7 +155,7 @@ interface nsIWebBrowserPersist : nsICancelable
* of intermediate data, etc.)
* @see saveURI for all other parameter descriptions
*/
void savePrivacyAwareURI(in nsIURI aURI, in nsISupports aCacheKey,
void savePrivacyAwareURI(in nsIURI aURI, in unsigned long aCacheKey,
in nsIURI aReferrer, in unsigned long aReferrerPolicy,
in nsIInputStream aPostData,
in string aExtraHeaders, in nsISupports aFile,

View File

@ -413,7 +413,7 @@ NS_IMETHODIMP nsWebBrowserPersist::SetProgressListener(
}
NS_IMETHODIMP nsWebBrowserPersist::SaveURI(
nsIURI *aURI, nsISupports *aCacheKey,
nsIURI *aURI, uint32_t aCacheKey,
nsIURI *aReferrer, uint32_t aReferrerPolicy,
nsIInputStream *aPostData, const char *aExtraHeaders,
nsISupports *aFile, nsILoadContext* aPrivacyContext)
@ -424,7 +424,7 @@ NS_IMETHODIMP nsWebBrowserPersist::SaveURI(
}
NS_IMETHODIMP nsWebBrowserPersist::SavePrivacyAwareURI(
nsIURI *aURI, nsISupports *aCacheKey,
nsIURI *aURI, uint32_t aCacheKey,
nsIURI *aReferrer, uint32_t aReferrerPolicy,
nsIInputStream *aPostData, const char *aExtraHeaders,
nsISupports *aFile, bool aIsPrivate)
@ -631,7 +631,7 @@ nsWebBrowserPersist::SerializeNextFile()
// The Referrer Policy doesn't matter here since the referrer is
// nullptr.
rv = SaveURIInternal(uri, nullptr, nullptr,
rv = SaveURIInternal(uri, 0, nullptr,
mozilla::net::RP_Unset, nullptr, nullptr,
fileAsURI, true, mIsPrivate);
// If SaveURIInternal fails, then it will have called EndDownload,
@ -1328,7 +1328,7 @@ nsWebBrowserPersist::AppendPathToURI(nsIURI *aURI, const nsAString & aPath, nsCO
}
nsresult nsWebBrowserPersist::SaveURIInternal(
nsIURI *aURI, nsISupports *aCacheKey, nsIURI *aReferrer,
nsIURI *aURI, uint32_t aCacheKey, nsIURI *aReferrer,
uint32_t aReferrerPolicy, nsIInputStream *aPostData,
const char *aExtraHeaders, nsIURI *aFile,
bool aCalcFileExt, bool aIsPrivate)
@ -1350,36 +1350,6 @@ nsresult nsWebBrowserPersist::SaveURIInternal(
loadFlags |= nsIRequest::LOAD_FROM_CACHE;
}
// Extract the cache key
nsCOMPtr<nsISupports> cacheKey;
if (aCacheKey)
{
// Test if the cache key is actually a web page descriptor (docshell)
// 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));
shEntry = do_QueryInterface(currentDescriptor);
}
}
if (shEntry)
{
shEntry->GetCacheKey(getter_AddRefs(cacheKey));
}
else
{
// Assume a plain cache key
cacheKey = aCacheKey;
}
}
// Open a channel to the URI
nsCOMPtr<nsIChannel> inputChannel;
rv = NS_NewChannel(getter_AddRefs(inputChannel),
@ -1452,9 +1422,8 @@ nsresult nsWebBrowserPersist::SaveURIInternal(
// Cache key
nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(httpChannel));
if (cacheChannel && cacheKey)
{
cacheChannel->SetCacheKey(cacheKey);
if (cacheChannel && aCacheKey != 0) {
cacheChannel->SetCacheKey(aCacheKey);
}
// Headers

View File

@ -57,7 +57,7 @@ public:
private:
virtual ~nsWebBrowserPersist();
nsresult SaveURIInternal(
nsIURI *aURI, nsISupports *aCacheKey, nsIURI *aReferrer,
nsIURI *aURI, uint32_t aCacheKey, nsIURI *aReferrer,
uint32_t aReferrerPolicy, nsIInputStream *aPostData,
const char *aExtraHeaders, nsIURI *aFile,
bool aCalcFileExt, bool aIsPrivate);

View File

@ -51,23 +51,22 @@ interface nsICacheInfoChannel : nsISupports
uint64_t getCacheEntryId();
/**
* Set/get the cache key... uniquely identifies the data in the cache
* for this channel. Holding a reference to this key does NOT prevent
* the cached data from being removed.
* Set/get the cache key. This integer uniquely identifies the data in
* the cache for this channel.
*
* A cache key retrieved from a particular instance of nsICacheInfoChannel
* could be set on another instance of nsICacheInfoChannel provided the
* underlying implementations are compatible and provided the new
* underlying implementations are compatible and provided the new
* channel instance was created with the same URI. The implementation of
* nsICacheInfoChannel would be expected to use the cache entry identified
* by the cache token. Depending on the value of nsIRequest::loadFlags,
* the cache entry may be validated, overwritten, or simply read.
*
* The cache key may be NULL indicating that the URI of the channel is
* sufficient to locate the same cache entry. Setting a NULL cache key
* The cache key may be 0 indicating that the URI of the channel is
* sufficient to locate the same cache entry. Setting a 0 cache key
* is likewise valid.
*/
attribute nsISupports cacheKey;
attribute unsigned long cacheKey;
/**
* Tells the channel to behave as if the LOAD_FROM_CACHE flag has been set,

View File

@ -161,6 +161,7 @@ InterceptStreamListener::Cleanup()
HttpChannelChild::HttpChannelChild()
: HttpAsyncAborter<HttpChannelChild>(this)
, NeckoTargetHolder(nullptr)
, mCacheKey(0)
, mSynthesizedStreamLength(0)
, mIsFromCache(false)
, mCacheEntryAvailable(false)
@ -226,7 +227,6 @@ HttpChannelChild::ReleaseMainThreadOnlyReferences()
}
nsTArray<nsCOMPtr<nsISupports>> arrayToRelease;
arrayToRelease.AppendElement(mCacheKey.forget());
arrayToRelease.AppendElement(mRedirectChannelChild.forget());
// To solve multiple inheritence of nsISupports in InterceptStreamListener
@ -652,20 +652,7 @@ HttpChannelChild::OnStartRequest(const nsresult& channelStatus,
AutoEventEnqueuer ensureSerialDispatch(mEventQ);
nsresult rv;
nsCOMPtr<nsISupportsPRUint32> container =
do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
Cancel(rv);
return;
}
rv = container->SetData(cacheKey);
if (NS_FAILED(rv)) {
Cancel(rv);
return;
}
mCacheKey = container;
mCacheKey = cacheKey;
// replace our request headers with what actually got sent in the parent
mRequestHead.SetHeaders(requestHeaders);
@ -2735,19 +2722,7 @@ HttpChannelChild::ContinueAsyncOpen()
openArgs.tlsFlags() = mTlsFlags;
openArgs.initialRwin() = mInitialRwin;
uint32_t cacheKey = 0;
if (mCacheKey) {
nsCOMPtr<nsISupportsPRUint32> container = do_QueryInterface(mCacheKey);
if (!container) {
return NS_ERROR_ILLEGAL_VALUE;
}
nsresult rv = container->GetData(&cacheKey);
if (NS_FAILED(rv)) {
return rv;
}
}
openArgs.cacheKey() = cacheKey;
openArgs.cacheKey() = mCacheKey;
openArgs.blockAuthPrompt() = mBlockAuthPrompt;
@ -3048,17 +3023,17 @@ HttpChannelChild::GetCacheEntryId(uint64_t *aCacheEntryId)
}
NS_IMETHODIMP
HttpChannelChild::GetCacheKey(nsISupports **cacheKey)
HttpChannelChild::GetCacheKey(uint32_t *cacheKey)
{
if (mSynthesizedCacheInfo) {
return mSynthesizedCacheInfo->GetCacheKey(cacheKey);
}
NS_IF_ADDREF(*cacheKey = mCacheKey);
*cacheKey = mCacheKey;
return NS_OK;
}
NS_IMETHODIMP
HttpChannelChild::SetCacheKey(nsISupports *cacheKey)
HttpChannelChild::SetCacheKey(uint32_t cacheKey)
{
if (mSynthesizedCacheInfo) {
return mSynthesizedCacheInfo->SetCacheKey(cacheKey);

View File

@ -196,7 +196,7 @@ protected:
private:
// this section is for main-thread-only object
// all the references need to be proxy released on main thread.
nsCOMPtr<nsISupports> mCacheKey;
uint32_t mCacheKey;
nsCOMPtr<nsIChildChannel> mRedirectChannelChild;
RefPtr<InterceptStreamListener> mInterceptListener;
// Needed to call AsyncOpen in FinishInterceptedRedirect

View File

@ -681,21 +681,10 @@ HttpChannelParent::DoAsyncOpen( const URIParams& aURI,
httpChannel->SetLoadFlags(newLoadFlags);
}
nsCOMPtr<nsISupportsPRUint32> cacheKey =
do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
return SendFailedAsyncOpen(rv);
}
rv = cacheKey->SetData(aCacheKey);
if (NS_FAILED(rv)) {
return SendFailedAsyncOpen(rv);
}
nsCOMPtr<nsICacheInfoChannel> cacheChannel =
do_QueryInterface(static_cast<nsIChannel*>(httpChannel.get()));
if (cacheChannel) {
cacheChannel->SetCacheKey(cacheKey);
cacheChannel->SetCacheKey(aCacheKey);
cacheChannel->PreferAlternativeDataType(aPreferredAlternativeType);
cacheChannel->SetAllowStaleCacheContent(aAllowStaleCacheContent);
@ -1508,7 +1497,7 @@ HttpChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
// It could be already released by nsHttpChannel at that time.
nsCOMPtr<nsISupports> cacheEntry;
nsresult channelStatus = NS_OK;
uint32_t cacheKeyValue = 0;
uint32_t cacheKey = 0;
nsAutoCString altDataType;
if (httpChannelImpl) {
@ -1517,19 +1506,7 @@ HttpChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
httpChannelImpl->GetStatus(&channelStatus);
nsCOMPtr<nsISupports> cacheKey;
httpChannelImpl->GetCacheKey(getter_AddRefs(cacheKey));
if (cacheKey) {
nsCOMPtr<nsISupportsPRUint32> container = do_QueryInterface(cacheKey);
if (!container) {
return NS_ERROR_ILLEGAL_VALUE;
}
nsresult rv = container->GetData(&cacheKeyValue);
if (NS_FAILED(rv)) {
return rv;
}
}
httpChannelImpl->GetCacheKey(&cacheKey);
httpChannelImpl->GetAlternativeDataType(altDataType);
}
@ -1579,7 +1556,7 @@ HttpChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
cachedCharset, secInfoSerialization,
chan->GetSelfAddr(), chan->GetPeerAddr(),
redirectCount,
cacheKeyValue,
cacheKey,
altDataType,
altDataLen,
ipcController,

View File

@ -1330,7 +1330,7 @@ InterceptedHttpChannel::OpenAlternativeOutputStream(const nsACString & type, nsI
}
NS_IMETHODIMP
InterceptedHttpChannel::GetCacheKey(nsISupports **key)
InterceptedHttpChannel::GetCacheKey(uint32_t* key)
{
if (mSynthesizedCacheInfo) {
return mSynthesizedCacheInfo->GetCacheKey(key);
@ -1339,7 +1339,7 @@ InterceptedHttpChannel::GetCacheKey(nsISupports **key)
}
NS_IMETHODIMP
InterceptedHttpChannel::SetCacheKey(nsISupports *key)
InterceptedHttpChannel::SetCacheKey(uint32_t key)
{
if (mSynthesizedCacheInfo) {
return mSynthesizedCacheInfo->SetCacheKey(key);

View File

@ -7929,46 +7929,24 @@ nsHttpChannel::SetOfflineCacheToken(nsISupports *token)
}
NS_IMETHODIMP
nsHttpChannel::GetCacheKey(nsISupports **key)
nsHttpChannel::GetCacheKey(uint32_t* key)
{
nsresult rv;
NS_ENSURE_ARG_POINTER(key);
LOG(("nsHttpChannel::GetCacheKey [this=%p]\n", this));
*key = nullptr;
nsCOMPtr<nsISupportsPRUint32> container =
do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv);
if (!container)
return NS_ERROR_OUT_OF_MEMORY;
rv = container->SetData(mPostID);
if (NS_FAILED(rv)) return rv;
return CallQueryInterface(container.get(), key);
*key = mPostID;
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::SetCacheKey(nsISupports *key)
nsHttpChannel::SetCacheKey(uint32_t key)
{
nsresult rv;
LOG(("nsHttpChannel::SetCacheKey [this=%p key=%p]\n", this, key));
LOG(("nsHttpChannel::SetCacheKey [this=%p key=%u]\n", this, key));
ENSURE_CALLED_BEFORE_CONNECT();
if (!key)
mPostID = 0;
else {
// extract the post id
nsCOMPtr<nsISupportsPRUint32> container = do_QueryInterface(key, &rv);
if (NS_FAILED(rv)) return rv;
rv = container->GetData(&mPostID);
if (NS_FAILED(rv)) return rv;
}
mPostID = key;
return NS_OK;
}

View File

@ -986,7 +986,7 @@ nsWebBrowser::SetProgressListener(nsIWebProgressListener* aProgressListener)
NS_IMETHODIMP
nsWebBrowser::SaveURI(nsIURI* aURI,
nsISupports* aCacheKey,
uint32_t aCacheKey,
nsIURI* aReferrer,
uint32_t aReferrerPolicy,
nsIInputStream* aPostData,
@ -1001,7 +1001,7 @@ nsWebBrowser::SaveURI(nsIURI* aURI,
NS_IMETHODIMP
nsWebBrowser::SavePrivacyAwareURI(nsIURI* aURI,
nsISupports* aCacheKey,
uint32_t aCacheKey,
nsIURI* aReferrer,
uint32_t aReferrerPolicy,
nsIInputStream* aPostData,

View File

@ -299,7 +299,7 @@ function promiseStartLegacyDownload(aSourceUrl, aOptions) {
// Start the actual download process.
persist.savePrivacyAwareURI(
sourceURI, null, referrer, Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
sourceURI, 0, referrer, Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
null, null, targetFile, isPrivate);
}).catch(do_report_unexpected_exception);

View File

@ -191,12 +191,12 @@ function saveDocument(aDocument, aSkipPrompt) {
throw "Must have a document when calling saveDocument";
let contentDisposition = null;
let cacheKeyInt = null;
let cacheKey = 0;
if (aDocument instanceof Ci.nsIWebBrowserPersistDocument) {
// nsIWebBrowserPersistDocument exposes these directly.
contentDisposition = aDocument.contentDisposition;
cacheKeyInt = aDocument.cacheKey;
cacheKey = aDocument.cacheKey;
} else if (aDocument instanceof Ci.nsIDOMDocument) {
// Otherwise it's an actual nsDocument (and possibly a CPOW).
// We want to use cached data because the document is currently visible.
@ -219,25 +219,12 @@ function saveDocument(aDocument, aSkipPrompt) {
.currentDescriptor
.QueryInterface(Ci.nsISHEntry);
let cacheKey = shEntry.cacheKey
.QueryInterface(Ci.nsISupportsPRUint32)
.data;
// cacheKey might be a CPOW, which can't be passed to native
// code, but the data attribute is just a number.
cacheKeyInt = cacheKey.data;
cacheKey = shEntry.cacheKey;
} catch (ex) {
// We might not find it in the cache. Oh, well.
}
}
// Convert the cacheKey back into an XPCOM object.
let cacheKey = null;
if (cacheKeyInt) {
cacheKey = Cc["@mozilla.org/supports-PRUint32;1"]
.createInstance(Ci.nsISupportsPRUint32);
cacheKey.data = cacheKeyInt;
}
internalSave(aDocument.documentURI, aDocument, null, contentDisposition,
aDocument.contentType, false, null, null,
aDocument.referrer ? makeURI(aDocument.referrer) : null,
@ -364,7 +351,7 @@ function internalSave(aURL, aDocument, aDefaultFileName, aContentDisposition,
aSkipPrompt = false;
if (aCacheKey == undefined)
aCacheKey = null;
aCacheKey = 0;
// Note: aDocument == null when this code is used by save-link-as...
var saveMode = GetSaveModeForContentType(aContentType, aDocument);
@ -454,7 +441,7 @@ function internalSave(aURL, aDocument, aDefaultFileName, aContentDisposition,
* @param persistArgs.sourceURI
* The nsIURI of the document being saved
* @param persistArgs.sourceCacheKey [optional]
* If set will be passed to saveURI
* If set will be passed to savePrivacyAwareURI
* @param persistArgs.sourceDocument [optional]
* The document to be saved, or null if not saving a complete document
* @param persistArgs.sourceReferrer

View File

@ -138,13 +138,7 @@ var SessionHistoryInternal = {
entry.subframe = true;
}
let cacheKey = shEntry.cacheKey;
if (cacheKey && cacheKey instanceof Ci.nsISupportsPRUint32 &&
cacheKey.data != 0) {
// XXXbz would be better to have cache keys implement
// nsISerializable or something.
entry.cacheKey = cacheKey.data;
}
entry.cacheKey = shEntry.cacheKey;
entry.ID = shEntry.ID;
entry.docshellUUID = shEntry.docshellID.toString();
@ -391,10 +385,7 @@ var SessionHistoryInternal = {
shEntry.baseURI = Utils.makeURI(entry.baseURI);
if (entry.cacheKey) {
var cacheKey = Cc["@mozilla.org/supports-PRUint32;1"].
createInstance(Ci.nsISupportsPRUint32);
cacheKey.data = entry.cacheKey;
shEntry.cacheKey = cacheKey;
shEntry.cacheKey = entry.cacheKey;
}
if (entry.ID) {

View File

@ -859,7 +859,7 @@ function _persistImage(sourceURL, localFileName, successCallback) {
persist.progressListener = new _persistProgressListener(successCallback);
persist.saveURI(sourceURI, null,
persist.saveURI(sourceURI, 0,
null, Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
null, null, targetURI, null);
}