Bug 1572798 - Make content browsing contexts for tabs start as inactive. r=nika

Otherwise autoplay blocking until-in-foreground breaks with the other
patch in this bug, because it unblocks media playback once a browsing
context is active for the first time.

Differential Revision: https://phabricator.services.mozilla.com/D42329
This commit is contained in:
Emilio Cobos Álvarez 2021-01-19 19:14:33 +00:00
Родитель 54ce0e92e6
Коммит 333b73de84
6 изменённых файлов: 45 добавлений и 9 удалений

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

@ -1970,6 +1970,7 @@
uriIsAboutBlank,
userContextId,
skipLoad,
initiallyActive,
} = {}) {
let b = document.createXULElement("browser");
// Use the JSM global to create the permanentKey, so that if the
@ -2002,6 +2003,10 @@
b.setAttribute(attribute, defaultBrowserAttributes[attribute]);
}
if (!initiallyActive) {
b.setAttribute("initiallyactive", "false");
}
if (userContextId) {
b.setAttribute("usercontextid", userContextId);
}

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

@ -344,8 +344,19 @@ already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
}
nsContentUtils::GenerateUUIDInPlace(fields.mHistoryID);
fields.mExplicitActive =
parentBC ? ExplicitActiveStatus::None : ExplicitActiveStatus::Active;
fields.mExplicitActive = [&] {
if (parentBC) {
// Non-root browsing-contexts inherit their status from its parent.
return ExplicitActiveStatus::None;
}
if (aType == Type::Content) {
// Content gets managed by the chrome front-end / embedder element and
// starts as inactive.
return ExplicitActiveStatus::Inactive;
}
// Chrome starts as active.
return ExplicitActiveStatus::Active;
}();
fields.mFullZoom = parentBC ? parentBC->FullZoom() : 1.0f;
fields.mTextZoom = parentBC ? parentBC->TextZoom() : 1.0f;
@ -576,6 +587,14 @@ bool BrowsingContext::IsActive() const {
return false;
}
void BrowsingContext::SetInitiallyActive() {
MOZ_DIAGNOSTIC_ASSERT(!EverAttached());
MOZ_DIAGNOSTIC_ASSERT(IsContent());
MOZ_DIAGNOSTIC_ASSERT(IsTop());
mFields.SetWithoutSyncing<IDX_ExplicitActive>(ExplicitActiveStatus::Active);
}
bool BrowsingContext::GetIsActiveBrowserWindow() {
if (!XRE_IsParentProcess()) {
return Top()->GetIsActiveBrowserWindowInternal();
@ -633,8 +652,7 @@ void BrowsingContext::SetEmbedderElement(Element* aEmbedder) {
if (XRE_IsParentProcess() && IsTopContent()) {
nsAutoString messageManagerGroup;
if (aEmbedder->IsXULElement()) {
aEmbedder->GetAttr(kNameSpaceID_None, nsGkAtoms::messagemanagergroup,
messageManagerGroup);
aEmbedder->GetAttr(nsGkAtoms::messagemanagergroup, messageManagerGroup);
}
txn.SetMessageManagerGroup(messageManagerGroup);

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

@ -498,6 +498,8 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
aRv);
}
void SetInitiallyActive();
bool AuthorStyleDisabledDefault() const {
return GetAuthorStyleDisabledDefault();
}

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

@ -3745,14 +3745,16 @@ bool nsFrameLoader::EnsureBrowsingContextAttached() {
// Inherit the `use` flags from our parent BrowsingContext.
bool usePrivateBrowsing = parentContext->UsePrivateBrowsing();
bool useRemoteSubframes = parentContext->UseRemoteSubframes();
bool useRemoteTabs = parentContext->UseRemoteTabs();
const bool useRemoteSubframes = parentContext->UseRemoteSubframes();
const bool useRemoteTabs = parentContext->UseRemoteTabs();
const bool isContent = mPendingBrowsingContext->IsContent();
// Determine the exact OriginAttributes which should be used for our
// BrowsingContext. This will be used to initialize OriginAttributes if the
// BrowsingContext has not already been created.
OriginAttributes attrs;
if (mPendingBrowsingContext->IsContent()) {
if (isContent) {
if (mPendingBrowsingContext->GetParent()) {
MOZ_ASSERT(mPendingBrowsingContext->GetParent() == parentContext);
parentContext->GetOriginAttributes(attrs);
@ -3784,8 +3786,7 @@ bool nsFrameLoader::EnsureBrowsingContextAttached() {
// <iframe mozbrowser> is allowed to set `mozprivatebrowsing` to
// force-enable private browsing.
if (OwnerIsMozBrowserFrame()) {
if (mOwnerContent->HasAttr(kNameSpaceID_None,
nsGkAtoms::mozprivatebrowsing)) {
if (mOwnerContent->HasAttr(nsGkAtoms::mozprivatebrowsing)) {
attrs.SyncAttributesWithPrivateBrowsing(true);
usePrivateBrowsing = true;
}
@ -3815,6 +3816,14 @@ bool nsFrameLoader::EnsureBrowsingContextAttached() {
rv = mPendingBrowsingContext->SetRemoteSubframes(useRemoteSubframes);
NS_ENSURE_SUCCESS(rv, false);
if (isContent && mOwnerContent->IsXULElement() &&
!mOwnerContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::initiallyactive,
nsGkAtoms::_false, eIgnoreCase)) {
// Content <browser> elements are active, unless told otherwise by the
// initiallyactive attribute.
mPendingBrowsingContext->SetInitiallyActive();
}
// Finish attaching.
mPendingBrowsingContext->EnsureAttached();
return true;

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

@ -156,6 +156,7 @@ var PrintUtils = {
userContextId: browsingContext.originAttributes.userContextId,
initialBrowsingContextGroupId: browsingContext.group.id,
skipLoad: true,
initiallyActive: true,
});
browser.addEventListener("DOMWindowClose", function(e) {
// Ignore close events from printing, see the code creating browsers in

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

@ -2217,6 +2217,7 @@ STATIC_ATOMS = [
Atom("forcemessagemanager", "forcemessagemanager"),
Atom("preloadedState", "preloadedState"),
Atom("initialBrowsingContextGroupId", "initialBrowsingContextGroupId"),
Atom("initiallyactive", "initiallyactive"),
# windows media query names
Atom("windows_win7", "windows-win7"),
Atom("windows_win8", "windows-win8"),