Bug 1646573: Part 1 - Fix GetInProcessParent usage in WindowShouldMatchActiveTab. r=zombie,nika

Differential Revision: https://phabricator.services.mozilla.com/D90334
This commit is contained in:
Kris Maglione 2020-09-22 17:41:34 +00:00
parent 6b380a56a7
commit 6f26095043
5 changed files with 30 additions and 25 deletions

View File

@ -191,6 +191,12 @@ bool WindowContext::CanSet(FieldIndex<IDX_IsSecureContext>,
return CheckOnlyOwningProcessCanSet(aSource);
}
bool WindowContext::CanSet(FieldIndex<IDX_IsOriginalFrameSource>,
const bool& aIsOriginalFrameSource,
ContentParent* aSource) {
return CheckOnlyOwningProcessCanSet(aSource);
}
bool WindowContext::CanSet(FieldIndex<IDX_DocTreeHadAudibleMedia>,
const bool& aValue, ContentParent* aSource) {
return IsTop();

View File

@ -49,6 +49,7 @@ class BrowsingContextGroup;
* tracking resource */ \
FIELD(IsThirdPartyTrackingResourceWindow, bool) \
FIELD(IsSecureContext, bool) \
FIELD(IsOriginalFrameSource, bool) \
/* Mixed-Content: If the corresponding documentURI is https, \
* then this flag is true. */ \
FIELD(IsSecure, bool) \
@ -215,6 +216,8 @@ class WindowContext : public nsISupports, public nsWrapperCache {
ContentParent* aSource);
bool CanSet(FieldIndex<IDX_IsSecureContext>, const bool& aIsSecureContext,
ContentParent* aSource);
bool CanSet(FieldIndex<IDX_IsOriginalFrameSource>,
const bool& aIsOriginalFrameSource, ContentParent* aSource);
bool CanSet(FieldIndex<IDX_DocTreeHadAudibleMedia>, const bool& aValue,
ContentParent* aSource);
bool CanSet(FieldIndex<IDX_AutoplayPermission>, const uint32_t& aValue,

View File

@ -128,6 +128,9 @@ WindowGlobalInit WindowGlobalActor::WindowInitializer(
nsCOMPtr<nsITransportSecurityInfo> securityInfo;
if (nsCOMPtr<nsIChannel> channel = doc->GetChannel()) {
nsCOMPtr<nsILoadInfo> loadInfo(channel->LoadInfo());
fields.mIsOriginalFrameSource = loadInfo->GetOriginalFrameSrcLoad();
nsCOMPtr<nsISupports> securityInfoSupports;
channel->GetSecurityInfo(getter_AddRefs(securityInfoSupports));
securityInfo = do_QueryInterface(securityInfoSupports);

View File

@ -225,6 +225,13 @@ void WindowGlobalChild::OnNewDocument(Document* aDocument) {
txn.SetEmbedderPolicy(policy.ref());
}
if (nsCOMPtr<nsIChannel> channel = aDocument->GetChannel()) {
nsCOMPtr<nsILoadInfo> loadInfo(channel->LoadInfo());
txn.SetIsOriginalFrameSource(loadInfo->GetOriginalFrameSrcLoad());
} else {
txn.SetIsOriginalFrameSource(false);
}
// Init Mixed Content Fields
nsCOMPtr<nsIURI> innerDocURI =
NS_GetInnermostURI(aDocument->GetDocumentURI());

View File

@ -801,33 +801,19 @@ bool DocInfo::IsTopLevel() const {
}
bool WindowShouldMatchActiveTab(nsPIDOMWindowOuter* aWin) {
if (aWin->GetBrowsingContext()->IsTopContent()) {
for (WindowContext* wc = aWin->GetCurrentInnerWindow()->GetWindowContext();
wc; wc = wc->GetParentWindowContext()) {
BrowsingContext* bc = wc->GetBrowsingContext();
if (bc->IsTopContent()) {
return true;
}
nsIDocShell* docshell = aWin->GetDocShell();
if (!docshell || docshell->GetCreatedDynamically()) {
if (bc->GetCreatedDynamically() || !wc->GetIsOriginalFrameSource()) {
return false;
}
Document* doc = aWin->GetExtantDoc();
if (!doc) {
return false;
}
nsIChannel* channel = doc->GetChannel();
if (!channel) {
MOZ_ASSERT_UNREACHABLE("Should reach top content before end of loop");
return false;
}
nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
if (!loadInfo->GetOriginalFrameSrcLoad()) {
return false;
}
nsCOMPtr<nsPIDOMWindowOuter> parent = aWin->GetInProcessParent();
MOZ_ASSERT(parent != nullptr);
return WindowShouldMatchActiveTab(parent);
}
bool DocInfo::ShouldMatchActiveTabPermission() const {