Bug 1264137 - Part 4: Improve the usefulness of what we pass as requestingContext to nsIContentPolicy for navigations (loads in a docshell). r=bz

For toplevel document loads (TYPE_DOCUMENT) in the content process,
we pass the currently-loaded window, if any.

For toplevel document loads in the chrome process (e.g. tabs in non-e10s mode),
we pass the node which created our docshell, if any.

For all subframe loads, we pass the node that created the docshell,
which is the frameElement of the window in the docshell.
This commit is contained in:
Yoshi Huang 2016-09-13 17:53:45 +08:00
Родитель 06ba09a073
Коммит a43d017190
1 изменённых файлов: 32 добавлений и 6 удалений

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

@ -9838,11 +9838,35 @@ nsDocShell::InternalLoad(nsIURI* aURI,
// If there's no targetDocShell, that means we are about to create a new window,
// perform a content policy check before creating the window.
if (!targetDocShell) {
nsCOMPtr<Element> requestingElement =
mScriptGlobal->AsOuter()->GetFrameElementInternal();
nsISupports* requestingContext = requestingElement;
if (!requestingContext) {
requestingContext = ToSupports(mScriptGlobal);
nsCOMPtr<Element> requestingElement;
nsISupports* requestingContext = nullptr;
if (contentType == nsIContentPolicy::TYPE_DOCUMENT) {
if (XRE_IsContentProcess()) {
// In e10s the child process doesn't have access to the element that
// contains the browsing context (because that element is in the chrome
// process). So we just pass mScriptGlobal.
requestingContext = ToSupports(mScriptGlobal);
} else {
// This is for loading non-e10s tabs and toplevel windows of various
// sorts.
// For the toplevel window cases, requestingElement will be null.
requestingElement = mScriptGlobal->AsOuter()->GetFrameElementInternal();
requestingContext = requestingElement;
}
} else {
requestingElement = mScriptGlobal->AsOuter()->GetFrameElementInternal();
requestingContext = requestingElement;
#ifdef DEBUG
// Get the docshell type for requestingElement.
nsCOMPtr<nsIDocument> requestingDoc = requestingElement->OwnerDoc();
nsCOMPtr<nsIDocShell> elementDocShell = requestingDoc->GetDocShell();
// requestingElement docshell type = current docshell type.
MOZ_ASSERT(mItemType == elementDocShell->ItemType(),
"subframes should have the same docshell type as their parent");
#endif
}
// XXXbz would be nice to know the loading principal here... but we don't
@ -9874,7 +9898,9 @@ nsDocShell::InternalLoad(nsIURI* aURI,
// would block due to mixed content, go ahead and block here. If we try to
// proceed with priming, we will error out later on.
nsCOMPtr<nsIDocShell> docShell = NS_CP_GetDocShellFromContext(requestingContext);
NS_ENSURE_TRUE(docShell, NS_OK);
// When loading toplevel windows, requestingContext can be null. We don't
// really care about HSTS in that situation, though; loads in toplevel
// windows should all be browser UI.
if (docShell) {
nsIDocument* document = docShell->GetDocument();
NS_ENSURE_TRUE(document, NS_OK);