Bug 1496251 - Convert nsDocShell::InternalLoad to using nsDocShellLoadState r=bzbarsky,nika

Move InternalLoad from 24 arguments to 3, using nsDocShellLoadState
objects. Move all internal argument references to using calls to
accessors/mutators on nsDocShellLoadState. Comments from old interface
function definition have been spread to relevant places in code.

Internal load flags in nsDocShellLoadState are also consolidated to
the LoadFlags member, as they were usually passed as that member
before nsDocShellLoadState existed. This begins the work to simplify
load flags further in a later patch (See Bug 1475331).

Depends on D13487

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kyle Machulis 2018-12-19 21:01:13 +00:00
parent 2d414e6f15
commit 0e8e78f4bb
4 changed files with 392 additions and 486 deletions

File diff suppressed because it is too large Load Diff

View File

@ -389,83 +389,12 @@ class nsDocShell final : public nsDocLoader,
mozilla::dom::BrowsingContext* GetBrowsingContext() const;
/**
* Loads the given URI. This method is identical to nsIDocShell::loadURI(...)
* except that its parameter list is broken out instead of being packaged
* inside of an nsIDocShellLoadInfo object...
*
* @param aURI - The URI to load.
* @param aOriginalURI - The URI to set as the originalURI on the channel
* that does the load. If null, aURI will be set as
* the originalURI.
* @param aResultPrincipalURI - The URI to be set to loadInfo.resultPrincipalURI
* When Nothing, there will be no change
* When Some, the principal URI will overwrite even
* with a null value.
* @param aKeepResultPrincipalURIIfSet - If a refresh is caused by
* http-equiv="refresh" we want to set
* aResultPrincipalURI, but we do not want
* to overwrite the channel's
* ResultPrincipalURI, if it has already
* been set on the channel by a protocol
* handler.
* @param aLoadReplace - If set LOAD_REPLACE flag will be set on the
* channel. aOriginalURI is null, this argument is
* ignored.
* @param aIsFromProcessingFrameAttributes
* - If this is a load triggered by changing frame
* attributes.
* @param aReferrer - Referring URI
* @param aReferrerPolicy - Referrer policy
* @param aTriggeringPrincipal - A non-null principal that initiated that load.
* Please note that this is the principal that is
* used for security checks. If the argument aURI
* is provided by the web, then please do not pass
* a SystemPrincipal as the triggeringPrincipal.
* @param aPrincipalToInherit - Principal to be inherited for that load. If this
* argument is null then principalToInherit is
* computed as follows:
* a) If INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL, and
* aLoadType is not LOAD_NORMAL_EXTERNAL, and the
* URI would normally inherit a principal, then
* principalToInherit is set to the current
* document's principal, or parent document if
* there is not a current document.
* b) If principalToInherit is still null (e.g. if
* some of the conditions of (a) were not satisfied),
* then no inheritance of any sort will happen: the
* load will just get a principal based on the URI
* being loaded.
* @param aFlags - Any of the load flags defined within above.
* @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 aFileName - Non-null when the link should be downloaded as
* the given filename.
* @param aPostDataStream - Post data stream (if POSTing)
* @param aHeadersStream - Stream containing "extra" request headers...
* @param aLoadFlags - Flags to modify load behaviour. Flags are defined
* in nsIWebNavigation.
* @param aSHEntry - Active Session History entry (if loading from SH)
* @param aSrcdoc When INTERNAL_LOAD_FLAGS_IS_SRCDOC is set, the
* contents of this parameter will be loaded instead
* of aURI.
* @param aSourceDocShell - The source browsing context for the navigation.
* @param aBaseURI - The base URI to be used for the load. Set in
* srcdoc loads as it cannot otherwise be inferred
* in certain situations such as view-source.
* Loads the given URI. See comments on nsDocShellLoadState members for more
* information on information used. aDocShell and aRequest come from
* onLinkClickSync, which is triggered during form submission.
*/
nsresult InternalLoad(
nsIURI* aURI, nsIURI* aOriginalURI,
mozilla::Maybe<nsCOMPtr<nsIURI>> const& aResultPrincipalURI,
bool aKeepResultPrincipalURIIfSet, bool aLoadReplace,
bool aIsFromProcessingFrameAttributes, nsIURI* aReferrer,
uint32_t aReferrerPolicy, nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit, uint32_t aFlags,
const nsAString& aWindowTarget, const nsACString& aTypeHint,
const nsAString& aFileName, nsIInputStream* aPostData,
nsIInputStream* aHeadersData, uint32_t aLoadType, nsISHEntry* aSHEntry,
bool aFirstParty, const nsAString& aSrcdoc, nsIDocShell* aSourceDocShell,
nsIURI* aBaseURI, nsIDocShell** aDocShell, nsIRequest** aRequest);
nsresult InternalLoad(nsDocShellLoadState* aLoadState,
nsIDocShell** aDocShell, nsIRequest** aRequest);
private: // member functions
friend class nsDSURIContentListener;

View File

@ -24,12 +24,12 @@ nsDocShellLoadState::nsDocShellLoadState()
mSendReferrer(true),
mReferrerPolicy(mozilla::net::RP_Unset),
mLoadType(LOAD_NORMAL),
mIsSrcdocLoad(false),
mTarget(),
mSrcdocData(VoidString()),
mLoadFlags(0),
mFirstParty(false),
mTypeHint(VoidCString()),
mFileName(VoidString()),
mDocShellInternalLoadFlags(0),
mIsFromProcessingFrameAttributes(false) {}
nsDocShellLoadState::~nsDocShellLoadState() {}
@ -166,20 +166,19 @@ void nsDocShellLoadState::SetSendReferrer(bool aSendReferrer) {
mSendReferrer = aSendReferrer;
}
uint32_t nsDocShellLoadState::ReferrerPolicy() const { return mReferrerPolicy; }
mozilla::net::ReferrerPolicy nsDocShellLoadState::ReferrerPolicy() const {
return mReferrerPolicy;
}
void nsDocShellLoadState::SetReferrerPolicy(
mozilla::net::ReferrerPolicy aReferrerPolicy) {
mReferrerPolicy = aReferrerPolicy;
}
bool nsDocShellLoadState::IsSrcdocLoad() const { return mIsSrcdocLoad; }
const nsString& nsDocShellLoadState::SrcdocData() const { return mSrcdocData; }
void nsDocShellLoadState::SetSrcdocData(const nsAString& aSrcdocData) {
mSrcdocData = aSrcdocData;
mIsSrcdocLoad = true;
}
nsIDocShell* nsDocShellLoadState::SourceDocShell() const {
@ -219,6 +218,16 @@ void nsDocShellLoadState::SetLoadFlags(uint32_t aLoadFlags) {
mLoadFlags = aLoadFlags;
}
void nsDocShellLoadState::SetLoadFlag(uint32_t aFlag) { mLoadFlags |= aFlag; }
void nsDocShellLoadState::UnsetLoadFlag(uint32_t aFlag) {
mLoadFlags &= ~aFlag;
}
bool nsDocShellLoadState::HasLoadFlags(uint32_t aFlags) {
return (mLoadFlags & aFlags) == aFlags;
}
bool nsDocShellLoadState::FirstParty() const { return mFirstParty; }
void nsDocShellLoadState::SetFirstParty(bool aFirstParty) {
@ -237,14 +246,6 @@ void nsDocShellLoadState::SetFileName(const nsAString& aFileName) {
mFileName = aFileName;
}
uint32_t nsDocShellLoadState::DocShellInternalLoadFlags() const {
return mDocShellInternalLoadFlags;
}
void nsDocShellLoadState::SetDocShellInternalLoadFlags(uint32_t aFlags) {
mDocShellInternalLoadFlags = aFlags;
}
nsresult nsDocShellLoadState::SetupInheritingPrincipal(
uint32_t aItemType, const mozilla::OriginAttributes& aOriginAttributes) {
// We need a principalToInherit.
@ -339,52 +340,45 @@ nsresult nsDocShellLoadState::SetupTriggeringPrincipal(
return NS_OK;
}
void nsDocShellLoadState::CalculateDocShellInternalLoadFlags() {
MOZ_ASSERT(mDocShellInternalLoadFlags == 0,
"Shouldn't have any load flags set at this point.");
void nsDocShellLoadState::CalculateLoadURIFlags() {
uint32_t oldLoadFlags = mLoadFlags;
mLoadFlags = 0;
if (mInheritPrincipal) {
MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(mPrincipalToInherit),
"Should not inherit SystemPrincipal");
mDocShellInternalLoadFlags |=
nsDocShell::INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL;
mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL;
}
if (!mSendReferrer) {
mDocShellInternalLoadFlags |=
nsDocShell::INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER;
mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER;
}
if (mLoadFlags & nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) {
mDocShellInternalLoadFlags |=
nsDocShell::INTERNAL_LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
if (oldLoadFlags & nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) {
mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
}
if (mLoadFlags & nsIWebNavigation::LOAD_FLAGS_FIRST_LOAD) {
mDocShellInternalLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_FIRST_LOAD;
if (oldLoadFlags & nsIWebNavigation::LOAD_FLAGS_FIRST_LOAD) {
mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_FIRST_LOAD;
}
if (mLoadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_CLASSIFIER) {
mDocShellInternalLoadFlags |=
nsDocShell::INTERNAL_LOAD_FLAGS_BYPASS_CLASSIFIER;
if (oldLoadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_CLASSIFIER) {
mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_BYPASS_CLASSIFIER;
}
if (mLoadFlags & nsIWebNavigation::LOAD_FLAGS_FORCE_ALLOW_COOKIES) {
mDocShellInternalLoadFlags |=
nsDocShell::INTERNAL_LOAD_FLAGS_FORCE_ALLOW_COOKIES;
if (oldLoadFlags & nsIWebNavigation::LOAD_FLAGS_FORCE_ALLOW_COOKIES) {
mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_FORCE_ALLOW_COOKIES;
}
if (mIsSrcdocLoad) {
mDocShellInternalLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_IS_SRCDOC;
if (!mSrcdocData.IsVoid()) {
mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_IS_SRCDOC;
}
if (mForceAllowDataURI) {
mDocShellInternalLoadFlags |=
nsDocShell::INTERNAL_LOAD_FLAGS_FORCE_ALLOW_DATA_URI;
mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_FORCE_ALLOW_DATA_URI;
}
if (mOriginalFrameSrc) {
mDocShellInternalLoadFlags |=
nsDocShell::INTERNAL_LOAD_FLAGS_ORIGINAL_FRAME_SRC;
mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_ORIGINAL_FRAME_SRC;
}
}

View File

@ -107,7 +107,7 @@ class nsDocShellLoadState final {
void SetSendReferrer(bool aSendReferrer);
uint32_t ReferrerPolicy() const;
mozilla::net::ReferrerPolicy ReferrerPolicy() const;
void SetReferrerPolicy(mozilla::net::ReferrerPolicy aReferrerPolicy);
@ -138,6 +138,12 @@ class nsDocShellLoadState final {
void SetLoadFlags(uint32_t aFlags);
void SetLoadFlag(uint32_t aFlag);
void UnsetLoadFlag(uint32_t aFlag);
bool HasLoadFlags(uint32_t aFlag);
bool FirstParty() const;
void SetFirstParty(bool aFirstParty);
@ -150,10 +156,6 @@ class nsDocShellLoadState final {
void SetFileName(const nsAString& aFileName);
uint32_t DocShellInternalLoadFlags() const;
void SetDocShellInternalLoadFlags(uint32_t aFlags);
// Give the type of DocShell we're loading into (chrome/content/etc) and
// origin attributes for the URI we're loading, figure out if we should
// inherit our principal from the document the load was requested from, or
@ -178,7 +180,7 @@ class nsDocShellLoadState final {
// flags needs to be set based on other values in nsDocShellLoadState. This
// function calculates those flags, before the LoadState is passed to
// nsDocShell::InternalLoad.
void CalculateDocShellInternalLoadFlags();
void CalculateLoadURIFlags();
protected:
// Destructor can't be defaulted or inlined, as header doesn't have all type
@ -192,25 +194,37 @@ class nsDocShellLoadState final {
// The URI we are navigating to. Will not be null once set.
nsCOMPtr<nsIURI> mURI;
// The originalURI to be passed to nsIDocShell.internalLoad. May be null.
// The URI to set as the originalURI on the channel that does the load. If
// null, aURI will be set as the originalURI.
nsCOMPtr<nsIURI> mOriginalURI;
// Result principal URL from nsILoadInfo, may be null. Valid only if
// mResultPrincipalURIIsSome is true (has the same meaning as isSome() on
// mozilla::Maybe.)
// The URI to be set to loadInfo.resultPrincipalURI
// - When Nothing, there will be no change
// - When Some, the principal URI will overwrite even
// with a null value.
//
// Valid only if mResultPrincipalURIIsSome is true (has the same meaning as
// isSome() on mozilla::Maybe.)
nsCOMPtr<nsIURI> mResultPrincipalURI;
bool mResultPrincipalURIIsSome;
// The principal of the load, that is, the entity responsible for causing the
// load to occur. In most cases the referrer and the triggeringPrincipal's URI
// will be identical.
//
// Please note that this is the principal that is used for security checks. If
// the argument aURI is provided by the web, then please do not pass a
// SystemPrincipal as the triggeringPrincipal.
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
// if http-equiv="refresh" cause reload we do not want to replace
// ResultPrinicpalURI if it was already set.
// If a refresh is caused by http-equiv="refresh" we want to set
// aResultPrincipalURI, but we do not want to overwrite the channel's
// ResultPrincipalURI, if it has already been set on the channel by a protocol
// handler.
bool mKeepResultPrincipalURIIfSet;
// loadReplace flag to be passed to nsIDocShell.internalLoad.
// If set LOAD_REPLACE flag will be set on the channel. If aOriginalURI is
// null, this argument is ignored.
bool mLoadReplace;
// If this attribute is true and no triggeringPrincipal is specified,
@ -226,8 +240,13 @@ class nsDocShellLoadState final {
// Principal we're inheriting. If null, this means the principal should be
// inherited from the current document. If set to NullPrincipal, the channel
// will fill in principal information later in the load. See internal function
// comments for more info.
// will fill in principal information later in the load. See internal comments
// of SetupInheritingPrincipal for more info.
//
// When passed to InternalLoad, If this argument is null then
// principalToInherit is computed differently. See nsDocShell::InternalLoad
// for more comments.
nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
// If this attribute is true, then a top-level navigation
@ -250,22 +269,18 @@ class nsDocShellLoadState final {
// constants
uint32_t mLoadType;
// SHEntry for this page
// Active Session History entry (if loading from SH)
nsCOMPtr<nsISHEntry> mSHEntry;
// Target for load, like _content, _blank etc.
nsString mTarget;
// Post data
// Post data stream (if POSTing)
nsCOMPtr<nsIInputStream> mPostDataStream;
// Additional Headers
nsCOMPtr<nsIInputStream> mHeadersStream;
// True if the docshell has been created to load an iframe where the srcdoc
// attribute has been set. Set when srcdocData is specified.
bool mIsSrcdocLoad;
// When set, the load will be interpreted as a srcdoc load, where contents of
// this string will be loaded instead of the URI. Setting srcdocData sets
// isSrcdocLoad to true
@ -278,7 +293,7 @@ class nsDocShellLoadState final {
// as this information isn't embedded in the load's URI.
nsCOMPtr<nsIURI> mBaseURI;
// Set of Load Flags, taken from nsDocShellLoadTypes.h
// Set of Load Flags, taken from nsDocShellLoadTypes.h and nsIWebNavigation
uint32_t mLoadFlags;
// Is this a First Party Load?
@ -294,11 +309,6 @@ class nsDocShellLoadState final {
// mFileName.IsVoid() should return true.
nsString mFileName;
// LoadFlags calculated in nsDocShell::LoadURI and passed to
// nsDocShell::InternalLoad, taken from the INTERNAL_LOAD consts in
// nsIDocShell.idl
uint32_t mDocShellInternalLoadFlags;
// This will be true if this load is triggered by attribute changes.
// See nsILoadInfo.isFromProcessingFrameAttributes
bool mIsFromProcessingFrameAttributes;