Bug 1471711 - Move ContentPolicyType and Srcdoc checking to DoURILoad; r=bzbarsky

Since targeting has been moved to another method, we don't need to
know the ContentPolicyType until we're in DoURILoad. We can also move
Srcdoc handling to DoURILoad, as all data is passed with the LoadState.

Depends on D17015

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kyle Machulis 2019-02-08 21:10:56 +00:00
Родитель 4257b88ad6
Коммит 1c7bc3b09f
2 изменённых файлов: 33 добавлений и 38 удалений

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

@ -9465,13 +9465,6 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
}
}
nsAutoString srcdoc;
if (aLoadState->HasLoadFlags(INTERNAL_LOAD_FLAGS_IS_SRCDOC)) {
srcdoc = aLoadState->SrcdocData();
} else {
srcdoc = VoidString();
}
bool isTopLevelDoc =
mItemType == typeContent && (!IsFrame() || GetIsMozBrowser());
@ -9483,12 +9476,8 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
PredictorPredict(aLoadState->URI(), nullptr,
nsINetworkPredictor::PREDICT_LOAD, attrs, nullptr);
Maybe<nsCOMPtr<nsIURI>> resultPrincipalURI;
aLoadState->GetMaybeResultPrincipalURI(resultPrincipalURI);
nsCOMPtr<nsIRequest> req;
rv = DoURILoad(aLoadState, loadFromExternal, aDocShell, getter_AddRefs(req),
srcdoc, contentType);
rv = DoURILoad(aLoadState, loadFromExternal, aDocShell, getter_AddRefs(req));
if (req && aRequest) {
NS_ADDREF(*aRequest = req);
}
@ -9613,8 +9602,7 @@ static bool IsConsideredSameOriginForUIR(nsIPrincipal* aTriggeringPrincipal,
nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
bool aLoadFromExternal, nsIDocShell** aDocShell,
nsIRequest** aRequest, const nsAString& aSrcdoc,
nsContentPolicyType aContentPolicyType) {
nsIRequest** aRequest) {
// Double-check that we're still around to load this URI.
if (mIsBeingDestroyed) {
// Return NS_OK despite not doing anything to avoid throwing exceptions
@ -9629,9 +9617,11 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
}
nsresult rv;
uint32_t contentPolicyType = DetermineContentType();
if (IsFrame()) {
MOZ_ASSERT(aContentPolicyType == nsIContentPolicy::TYPE_INTERNAL_IFRAME ||
aContentPolicyType == nsIContentPolicy::TYPE_INTERNAL_FRAME,
MOZ_ASSERT(contentPolicyType == nsIContentPolicy::TYPE_INTERNAL_IFRAME ||
contentPolicyType == nsIContentPolicy::TYPE_INTERNAL_FRAME,
"DoURILoad thinks this is a frame and InternalLoad does not");
if (StaticPrefs::dom_block_external_protocol_in_iframes()) {
@ -9684,14 +9674,20 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
nestedURI = do_QueryInterface(tempURI);
}
} else {
MOZ_ASSERT(aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT,
MOZ_ASSERT(contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT,
"DoURILoad thinks this is a document and InternalLoad does not");
}
// open a channel for the url
nsCOMPtr<nsIChannel> channel;
bool isSrcdoc = !aSrcdoc.IsVoid();
nsAutoString srcdoc;
bool isSrcdoc = aLoadState->HasLoadFlags(INTERNAL_LOAD_FLAGS_IS_SRCDOC);
if (isSrcdoc) {
srcdoc = aLoadState->SrcdocData();
} else {
srcdoc = VoidString();
}
// If we have a pending channel, use the channel we've already created here.
// We don't need to set up load flags for our channel, as it has already been
@ -9733,7 +9729,7 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
nsCOMPtr<nsIPrincipal> loadingPrincipal;
nsCOMPtr<nsISupports> topLevelLoadingContext;
if (aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT) {
if (contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT) {
loadingNode = nullptr;
loadingPrincipal = nullptr;
loadingWindow = mScriptGlobal->AsOuter();
@ -9827,11 +9823,11 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
}
RefPtr<LoadInfo> loadInfo =
(aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT)
(contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT)
? new LoadInfo(loadingWindow, aLoadState->TriggeringPrincipal(),
topLevelLoadingContext, securityFlags)
: new LoadInfo(loadingPrincipal, aLoadState->TriggeringPrincipal(),
loadingNode, securityFlags, aContentPolicyType);
loadingNode, securityFlags, contentPolicyType);
if (aLoadState->PrincipalToInherit()) {
loadInfo->SetPrincipalToInherit(aLoadState->PrincipalToInherit());
@ -9846,7 +9842,7 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
// OriginAttributes of the parent document. Or in case there isn't a
// parent document.
bool isTopLevelDoc = mItemType == typeContent &&
(aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT ||
(contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT ||
GetIsMozBrowser());
OriginAttributes attrs;
@ -9916,11 +9912,11 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
nsViewSourceHandler* vsh = nsViewSourceHandler::GetInstance();
NS_ENSURE_TRUE(vsh, NS_ERROR_FAILURE);
rv = vsh->NewSrcdocChannel(aLoadState->URI(), baseURI, aSrcdoc, loadInfo,
rv = vsh->NewSrcdocChannel(aLoadState->URI(), baseURI, srcdoc, loadInfo,
getter_AddRefs(channel));
} else {
rv = NS_NewInputStreamChannelInternal(
getter_AddRefs(channel), aLoadState->URI(), aSrcdoc,
getter_AddRefs(channel), aLoadState->URI(), srcdoc,
NS_LITERAL_CSTRING("text/html"), loadInfo, true);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInputStreamChannel> isc = do_QueryInterface(channel);

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

@ -523,21 +523,20 @@ class nsDocShell final : public nsDocLoader,
//
// Actually open a channel and perform a URI load. Callers need to pass a
// non-null aTriggeringPrincipal which initiated the URI load. Please note
// that aTriggeringPrincipal will be used for performing security checks.
// If the argument aURI is provided by the web, then please do not pass a
// SystemPrincipal as the triggeringPrincipal. If principalToInherit is
// null, then no inheritance of any sort will happen and the load will
// get a principal based on the URI being loaded.
// If aSrcdoc is not void, the load will be considered as a srcdoc load,
// and the contents of aSrcdoc will be loaded instead of aURI.
// aOriginalURI will be set as the originalURI on the channel that does the
// load. If aOriginalURI is null, aURI will be set as the originalURI.
// If aLoadReplace is true, LOAD_REPLACE flag will be set to the nsIChannel.
// non-null aLoadState->TriggeringPrincipal() which initiated the URI load.
// Please note that the TriggeringPrincipal will be used for performing
// security checks. If aLoadState->URI() is provided by the web, then please
// do not pass a SystemPrincipal as the triggeringPrincipal. If
// aLoadState()->PrincipalToInherit is null, then no inheritance of any sort
// will happen and the load will get a principal based on the URI being
// loaded. If the Srcdoc flag is set (INTERNAL_LOAD_FLAGS_IS_SRCDOC), the load
// will be considered as a srcdoc load, and the contents of Srcdoc will be
// loaded instead of the URI. aLoadState->OriginalURI() will be set as the
// originalURI on the channel that does the load. If OriginalURI is null, URI
// will be set as the originalURI. If LoadReplace is true, LOAD_REPLACE flag
// will be set on the nsIChannel.
nsresult DoURILoad(nsDocShellLoadState* aLoadState, bool aLoadFromExternal,
nsIDocShell** aDocShell, nsIRequest** aRequest,
const nsAString& aSrcdoc,
nsContentPolicyType aContentPolicyType);
nsIDocShell** aDocShell, nsIRequest** aRequest);
nsresult AddHeadersToChannel(nsIInputStream* aHeadersData,
nsIChannel* aChannel);