Bug 1554947 - Update nsIWebBrowserPersist to use referrerInfo class instead of referrer and referrerr policy r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D33938

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Thomas Nguyen 2019-07-16 18:02:16 +00:00
parent 0b20e8b949
commit a951305e06
11 changed files with 52 additions and 55 deletions

View File

@ -153,9 +153,11 @@ nsMacShellService::SetDesktopBackground(Element* aElement, int32_t aPosition,
loadContext = do_QueryInterface(docShell);
}
return wbp->SaveURI(imageURI, aElement->NodePrincipal(), 0, docURI,
aElement->OwnerDoc()->GetReferrerPolicy(), nullptr,
nullptr, mBackgroundFile, loadContext);
nsCOMPtr<nsIReferrerInfo> referrerInfo = new mozilla::dom::ReferrerInfo();
referrerInfo->InitWithNode(aElement);
return wbp->SaveURI(imageURI, aElement->NodePrincipal(), 0, referrerInfo,
nullptr, nullptr, mBackgroundFile, loadContext);
}
NS_IMETHODIMP

View File

@ -148,8 +148,8 @@ nsresult nsContentAreaDragDropDataProvider::SaveURIToFile(
// referrer policy can be anything since the referrer is nullptr
return persist->SavePrivacyAwareURI(inSourceURI, inTriggeringPrincipal, 0,
nullptr, mozilla::net::RP_Unset, nullptr,
nullptr, inDestFile, isPrivate);
nullptr, nullptr, nullptr, inDestFile,
isPrivate);
}
/*

View File

@ -13,6 +13,8 @@ include protocol PParentToChildStream; //FIXME: bug #792908
include PBackgroundSharedTypes;
include IPCStream;
using refcounted class nsIReferrerInfo from "mozilla/dom/ReferrerInfoUtils.h";
namespace mozilla {
// nsIWebBrowserPersistDocument has attributes which can be read
@ -26,7 +28,7 @@ struct WebBrowserPersistDocumentAttrs {
nsCString contentType;
nsCString characterSet;
nsString title;
nsString referrer;
nsIReferrerInfo referrerInfo;
nsString contentDisposition;
uint32_t cacheKey;
uint32_t persistFlags;

View File

@ -37,6 +37,7 @@ void WebBrowserPersistDocumentChild::Start(
}
nsCOMPtr<nsIPrincipal> principal;
nsCOMPtr<nsIReferrerInfo> referrerInfo;
WebBrowserPersistDocumentAttrs attrs;
nsCOMPtr<nsIInputStream> postDataStream;
#define ENSURE(e) \
@ -53,7 +54,6 @@ void WebBrowserPersistDocumentChild::Start(
ENSURE(aDocument->GetContentType(attrs.contentType()));
ENSURE(aDocument->GetCharacterSet(attrs.characterSet()));
ENSURE(aDocument->GetTitle(attrs.title()));
ENSURE(aDocument->GetReferrer(attrs.referrer()));
ENSURE(aDocument->GetContentDisposition(attrs.contentDisposition()));
ENSURE(aDocument->GetCacheKey(&(attrs.cacheKey())));
ENSURE(aDocument->GetPersistFlags(&(attrs.persistFlags())));
@ -61,6 +61,9 @@ void WebBrowserPersistDocumentChild::Start(
ENSURE(aDocument->GetPrincipal(getter_AddRefs(principal)));
ENSURE(ipc::PrincipalToPrincipalInfo(principal, &(attrs.principal())));
ENSURE(aDocument->GetReferrerInfo(getter_AddRefs(referrerInfo)));
attrs.referrerInfo() = referrerInfo;
ENSURE(aDocument->GetPostData(getter_AddRefs(postDataStream)));
#undef ENSURE

View File

@ -127,8 +127,9 @@ WebBrowserPersistLocalDocument::GetTitle(nsAString& aTitle) {
}
NS_IMETHODIMP
WebBrowserPersistLocalDocument::GetReferrer(nsAString& aReferrer) {
mDocument->GetReferrer(aReferrer);
WebBrowserPersistLocalDocument::GetReferrerInfo(nsIReferrerInfo** aReferrerInfo) {
*aReferrerInfo = mDocument->GetReferrerInfo();
NS_IF_ADDREF(*aReferrerInfo);
return NS_OK;
}

View File

@ -73,8 +73,9 @@ WebBrowserPersistRemoteDocument::GetTitle(nsAString& aTitle) {
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetReferrer(nsAString& aReferrer) {
aReferrer = mAttrs.referrer();
WebBrowserPersistRemoteDocument::GetReferrerInfo(nsIReferrerInfo** aReferrerInfo) {
*aReferrerInfo = mAttrs.referrerInfo();
NS_IF_ADDREF(*aReferrerInfo);
return NS_OK;
}

View File

@ -13,6 +13,7 @@ interface nsIFile;
interface nsIChannel;
interface nsILoadContext;
interface nsIPrincipal;
interface nsIReferrerInfo;
/**
* Interface for persisting DOM documents and URIs to local or remote storage.
@ -114,12 +115,8 @@ interface nsIWebBrowserPersist : nsICancelable
* @param aTriggeringPrincipal
* The triggering principal for the URI we're saving.
* @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
* HTTP Referer header. Ignored if aReferrer is
* <CODE>nullptr</CODE>. Taken from REFERRER_POLICY
* constants in nsIHttpChannel.
* @param aReferrerInfo The referrer info for compute and send referrer via
* HTTP Referer header.
* @param aPostData Post data to pass with an HTTP request or
* <CODE>nullptr</CODE>.
* @param aExtraHeaders Additional headers to supply with an HTTP request
@ -141,7 +138,7 @@ interface nsIWebBrowserPersist : nsICancelable
*/
void saveURI(in nsIURI aURI, in nsIPrincipal aTriggeringPrincipal,
in unsigned long aCacheKey,
in nsIURI aReferrer, in unsigned long aReferrerPolicy,
in nsIReferrerInfo aReferrerInfo,
in nsIInputStream aPostData,
in string aExtraHeaders, in nsISupports aFile,
in nsILoadContext aPrivacyContext);
@ -154,7 +151,7 @@ interface nsIWebBrowserPersist : nsICancelable
*/
void savePrivacyAwareURI(in nsIURI aURI,
in nsIPrincipal aTriggeringPrincipal, in unsigned long aCacheKey,
in nsIURI aReferrer, in unsigned long aReferrerPolicy,
in nsIReferrerInfo aReferrerInfo,
in nsIInputStream aPostData,
in string aExtraHeaders, in nsISupports aFile,
in boolean aIsPrivate);

View File

@ -13,6 +13,7 @@ interface nsIPrincipal;
interface nsIRemoteTab;
interface nsIWebBrowserPersistResourceVisitor;
interface nsIWebBrowserPersistWriteCompletion;
interface nsIReferrerInfo;
/**
* Interface for the URI-mapping information that can be supplied when
@ -59,7 +60,7 @@ interface nsIWebBrowserPersistDocument : nsISupports
readonly attribute ACString contentType;
readonly attribute ACString characterSet;
readonly attribute AString title;
readonly attribute AString referrer;
readonly attribute nsIReferrerInfo referrerInfo;
readonly attribute AString contentDisposition;
readonly attribute nsIInputStream postData;
readonly attribute nsIPrincipal principal;

View File

@ -369,18 +369,17 @@ NS_IMETHODIMP nsWebBrowserPersist::SetProgressListener(
NS_IMETHODIMP nsWebBrowserPersist::SaveURI(
nsIURI* aURI, nsIPrincipal* aPrincipal, uint32_t aCacheKey,
nsIURI* aReferrer, uint32_t aReferrerPolicy, nsIInputStream* aPostData,
nsIReferrerInfo* aReferrerInfo, nsIInputStream* aPostData,
const char* aExtraHeaders, nsISupports* aFile,
nsILoadContext* aPrivacyContext) {
bool isPrivate = aPrivacyContext && aPrivacyContext->UsePrivateBrowsing();
return SavePrivacyAwareURI(aURI, aPrincipal, aCacheKey, aReferrer,
aReferrerPolicy, aPostData, aExtraHeaders, aFile,
isPrivate);
return SavePrivacyAwareURI(aURI, aPrincipal, aCacheKey, aReferrerInfo,
aPostData, aExtraHeaders, aFile, isPrivate);
}
NS_IMETHODIMP nsWebBrowserPersist::SavePrivacyAwareURI(
nsIURI* aURI, nsIPrincipal* aPrincipal, uint32_t aCacheKey,
nsIURI* aReferrer, uint32_t aReferrerPolicy, nsIInputStream* aPostData,
nsIReferrerInfo* aReferrerInfo, nsIInputStream* aPostData,
const char* aExtraHeaders, nsISupports* aFile, bool aIsPrivate) {
NS_ENSURE_TRUE(mFirstAndOnlyUse, NS_ERROR_FAILURE);
mFirstAndOnlyUse = false; // Stop people from reusing this object!
@ -393,8 +392,8 @@ NS_IMETHODIMP nsWebBrowserPersist::SavePrivacyAwareURI(
// SaveURI doesn't like broken uris.
mPersistFlags |= PERSIST_FLAGS_FAIL_ON_BROKEN_LINKS;
rv = SaveURIInternal(aURI, aPrincipal, nsIContentPolicy::TYPE_SAVEAS_DOWNLOAD,
aCacheKey, aReferrer, aReferrerPolicy, aPostData,
aExtraHeaders, fileAsURI, false, aIsPrivate);
aCacheKey, aReferrerInfo, aPostData, aExtraHeaders,
fileAsURI, false, aIsPrivate);
return NS_FAILED(rv) ? rv : NS_OK;
}
@ -569,12 +568,9 @@ void nsWebBrowserPersist::SerializeNextFile() {
break;
}
// The Referrer Policy doesn't matter here since the referrer is
// nullptr.
rv = SaveURIInternal(uri, data->mTriggeringPrincipal,
data->mContentPolicyType, 0, nullptr,
mozilla::net::RP_Unset, nullptr, nullptr, fileAsURI,
true, mIsPrivate);
data->mContentPolicyType, 0, nullptr, nullptr,
nullptr, fileAsURI, true, mIsPrivate);
// If SaveURIInternal fails, then it will have called EndDownload,
// which means that |data| is no longer valid memory. We MUST bail.
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -1216,7 +1212,7 @@ nsresult nsWebBrowserPersist::AppendPathToURI(nsIURI* aURI,
nsresult nsWebBrowserPersist::SaveURIInternal(
nsIURI* aURI, nsIPrincipal* aTriggeringPrincipal,
nsContentPolicyType aContentPolicyType, uint32_t aCacheKey,
nsIURI* aReferrer, uint32_t aReferrerPolicy, nsIInputStream* aPostData,
nsIReferrerInfo* aReferrerInfo, nsIInputStream* aPostData,
const char* aExtraHeaders, nsIURI* aFile, bool aCalcFileExt,
bool aIsPrivate) {
NS_ENSURE_ARG_POINTER(aURI);
@ -1270,12 +1266,9 @@ nsresult nsWebBrowserPersist::SaveURIInternal(
// Set the referrer, post data and headers if any
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(inputChannel));
if (httpChannel) {
// Referrer
if (aReferrer) {
nsCOMPtr<nsIReferrerInfo> referrerInfo =
new ReferrerInfo(aReferrer, aReferrerPolicy);
rv = httpChannel->SetReferrerInfoWithoutClone(referrerInfo);
MOZ_ASSERT(NS_SUCCEEDED(rv));
if (aReferrerInfo) {
DebugOnly<nsresult> success = httpChannel->SetReferrerInfo(aReferrerInfo);
MOZ_ASSERT(NS_SUCCEEDED(success));
}
// Post data

View File

@ -57,10 +57,9 @@ class nsWebBrowserPersist final : public nsIInterfaceRequestor,
virtual ~nsWebBrowserPersist();
nsresult SaveURIInternal(nsIURI* aURI, nsIPrincipal* aTriggeringPrincipal,
nsContentPolicyType aContentPolicyType,
uint32_t aCacheKey, nsIURI* aReferrer,
uint32_t aReferrerPolicy, nsIInputStream* aPostData,
const char* aExtraHeaders, nsIURI* aFile,
bool aCalcFileExt, bool aIsPrivate);
uint32_t aCacheKey, nsIReferrerInfo* aReferrerInfo,
nsIInputStream* aPostData, const char* aExtraHeaders,
nsIURI* aFile, bool aCalcFileExt, bool aIsPrivate);
nsresult SaveChannelInternal(nsIChannel* aChannel, nsIURI* aFile,
bool aCalcFileExt);
nsresult SaveDocumentInternal(nsIWebBrowserPersistDocument* aDocument,

View File

@ -738,20 +738,18 @@ nsWebBrowser::SetProgressListener(nsIWebProgressListener* aProgressListener) {
NS_IMETHODIMP
nsWebBrowser::SaveURI(nsIURI* aURI, nsIPrincipal* aPrincipal,
uint32_t aCacheKey, nsIURI* aReferrer,
uint32_t aReferrerPolicy, nsIInputStream* aPostData,
const char* aExtraHeaders, nsISupports* aFile,
nsILoadContext* aPrivacyContext) {
uint32_t aCacheKey, nsIReferrerInfo* aReferrerInfo,
nsIInputStream* aPostData, const char* aExtraHeaders,
nsISupports* aFile, nsILoadContext* aPrivacyContext) {
return SavePrivacyAwareURI(
aURI, aPrincipal, aCacheKey, aReferrer, aReferrerPolicy, aPostData,
aExtraHeaders, aFile,
aPrivacyContext && aPrivacyContext->UsePrivateBrowsing());
aURI, aPrincipal, aCacheKey, aReferrerInfo, aPostData, aExtraHeaders,
aFile, aPrivacyContext && aPrivacyContext->UsePrivateBrowsing());
}
NS_IMETHODIMP
nsWebBrowser::SavePrivacyAwareURI(nsIURI* aURI, nsIPrincipal* aPrincipal,
uint32_t aCacheKey, nsIURI* aReferrer,
uint32_t aReferrerPolicy,
uint32_t aCacheKey,
nsIReferrerInfo* aReferrerInfo,
nsIInputStream* aPostData,
const char* aExtraHeaders, nsISupports* aFile,
bool aIsPrivate) {
@ -784,9 +782,9 @@ nsWebBrowser::SavePrivacyAwareURI(nsIURI* aURI, nsIPrincipal* aPrincipal,
mPersist->SetPersistFlags(mPersistFlags);
mPersist->GetCurrentState(&mPersistCurrentState);
rv = mPersist->SavePrivacyAwareURI(uri, aPrincipal, aCacheKey, aReferrer,
aReferrerPolicy, aPostData, aExtraHeaders,
aFile, aIsPrivate);
rv = mPersist->SavePrivacyAwareURI(uri, aPrincipal, aCacheKey, aReferrerInfo,
aPostData, aExtraHeaders, aFile,
aIsPrivate);
if (NS_FAILED(rv)) {
mPersist = nullptr;
}