Backed out changeset a911e7cbb478 (bug 1646498) for open-features-negative-innerwidth-innerheight.html failures CLOSED TREE

This commit is contained in:
Bogdan Tara 2021-01-26 22:40:15 +02:00
Родитель 3f8e34cb34
Коммит d8c3aca81c
4 изменённых файлов: 73 добавлений и 76 удалений

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

@ -7,14 +7,16 @@
#ifndef dom_base_AutoSuppressEventHandlingAndSuspend_h
#define dom_base_AutoSuppressEventHandlingAndSuspend_h
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/BrowsingContextGroup.h"
#include "mozilla/dom/Document.h"
#include "nsCOMPtr.h"
#include "nsPIDOMWindow.h"
#include "nsTArray.h"
namespace mozilla::dom {
class BrowsingContext;
class BrowsingContextGroup;
/**
* Suppresses event handling and suspends the active inner window for all
* in-process documents in a BrowsingContextGroup. This should be used while
@ -23,20 +25,16 @@ namespace mozilla::dom {
* group.
*/
class MOZ_RAII AutoSuppressEventHandlingAndSuspend
: private AutoWalkBrowsingContextGroup {
class MOZ_RAII AutoSuppressEventHandlingAndSuspend {
public:
explicit AutoSuppressEventHandlingAndSuspend(BrowsingContextGroup* aGroup) {
if (aGroup) {
SuppressBrowsingContextGroup(aGroup);
}
}
explicit AutoSuppressEventHandlingAndSuspend(BrowsingContextGroup* aGroup);
~AutoSuppressEventHandlingAndSuspend();
~AutoSuppressEventHandlingAndSuspend() { UnsuppressDocuments(); }
private:
void SuppressBrowsingContext(BrowsingContext* aBC);
protected:
void SuppressDocument(Document* aDocument) override;
void UnsuppressDocument(Document* aDocument) override;
AutoTArray<RefPtr<Document>, 16> mDocuments;
AutoTArray<nsCOMPtr<nsPIDOMWindowInner>, 16> mWindows;
};
} // namespace mozilla::dom

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

@ -15627,32 +15627,38 @@ already_AddRefed<Element> Document::CreateHTMLElement(nsAtom* aTag) {
return element.forget();
}
void AutoWalkBrowsingContextGroup::SuppressBrowsingContextGroup(
BrowsingContextGroup* aGroup) {
for (const auto& bc : aGroup->Toplevels()) {
bc->PreOrderWalk([&](BrowsingContext* aBC) {
if (nsCOMPtr<nsPIDOMWindowOuter> win = aBC->GetDOMWindow()) {
if (RefPtr<Document> doc = win->GetExtantDoc()) {
SuppressDocument(doc);
mDocuments.AppendElement(doc);
}
}
});
static CallState MarkDocumentTreeToBeInSyncOperation(
Document& aDoc, nsTArray<RefPtr<Document>>& aDocuments) {
aDoc.SetIsInSyncOperation(true);
if (nsCOMPtr<nsPIDOMWindowInner> window = aDoc.GetInnerWindow()) {
window->TimeoutManager().BeginSyncOperation();
}
aDocuments.AppendElement(&aDoc);
auto recurse = [&aDocuments](Document& aSubDoc) {
return MarkDocumentTreeToBeInSyncOperation(aSubDoc, aDocuments);
};
aDoc.EnumerateSubDocuments(recurse);
return CallState::Continue;
}
nsAutoSyncOperation::nsAutoSyncOperation(Document* aDoc,
SyncOperationBehavior aSyncBehavior)
: mSyncBehavior(aSyncBehavior) {
mMicroTaskLevel = 0;
if (CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get()) {
CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get();
if (ccjs) {
mMicroTaskLevel = ccjs->MicroTaskLevel();
ccjs->SetMicroTaskLevel(0);
}
if (aDoc) {
if (auto* bcg = aDoc->GetDocGroup()->GetBrowsingContextGroup()) {
SuppressBrowsingContextGroup(bcg);
if (nsPIDOMWindowOuter* win = aDoc->GetWindow()) {
if (nsCOMPtr<nsPIDOMWindowOuter> top = win->GetInProcessTop()) {
if (RefPtr<Document> doc = top->GetExtantDoc()) {
MarkDocumentTreeToBeInSyncOperation(*doc, mDocuments);
}
}
}
mBrowsingContext = aDoc->GetBrowsingContext();
if (mBrowsingContext &&
mSyncBehavior == SyncOperationBehavior::eSuspendInput &&
@ -15662,26 +15668,18 @@ nsAutoSyncOperation::nsAutoSyncOperation(Document* aDoc,
}
}
void nsAutoSyncOperation::SuppressDocument(Document* aDoc) {
if (nsCOMPtr<nsPIDOMWindowInner> win = aDoc->GetInnerWindow()) {
win->TimeoutManager().BeginSyncOperation();
}
aDoc->SetIsInSyncOperation(true);
}
void nsAutoSyncOperation::UnsuppressDocument(Document* aDoc) {
if (nsCOMPtr<nsPIDOMWindowInner> win = aDoc->GetInnerWindow()) {
win->TimeoutManager().EndSyncOperation();
}
aDoc->SetIsInSyncOperation(false);
}
nsAutoSyncOperation::~nsAutoSyncOperation() {
UnsuppressDocuments();
for (RefPtr<Document>& doc : mDocuments) {
if (nsCOMPtr<nsPIDOMWindowInner> window = doc->GetInnerWindow()) {
window->TimeoutManager().EndSyncOperation();
}
doc->SetIsInSyncOperation(false);
}
CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get();
if (ccjs) {
ccjs->SetMicroTaskLevel(mMicroTaskLevel);
}
if (mBrowsingContext &&
mSyncBehavior == SyncOperationBehavior::eSuspendInput &&
InputTaskManager::CanSuspendInputEvent()) {

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

@ -5228,33 +5228,14 @@ class MOZ_STACK_CLASS mozAutoSubtreeModified {
enum class SyncOperationBehavior { eSuspendInput, eAllowInput };
class AutoWalkBrowsingContextGroup {
public:
virtual ~AutoWalkBrowsingContextGroup() = default;
protected:
void SuppressBrowsingContextGroup(BrowsingContextGroup* aGroup);
void UnsuppressDocuments() {
for (const auto& doc : mDocuments) {
UnsuppressDocument(doc);
}
}
virtual void SuppressDocument(Document* aDocument) = 0;
virtual void UnsuppressDocument(Document* aDocument) = 0;
AutoTArray<RefPtr<Document>, 16> mDocuments;
};
class MOZ_RAII nsAutoSyncOperation : private AutoWalkBrowsingContextGroup {
class MOZ_STACK_CLASS nsAutoSyncOperation {
public:
explicit nsAutoSyncOperation(Document* aDocument,
SyncOperationBehavior aSyncBehavior);
~nsAutoSyncOperation();
protected:
void SuppressDocument(Document* aDocument) override;
void UnsuppressDocument(Document* aDocument) override;
private:
nsTArray<RefPtr<Document>> mDocuments;
uint32_t mMicroTaskLevel;
const SyncOperationBehavior mSyncBehavior;
RefPtr<BrowsingContext> mBrowsingContext;

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

@ -676,23 +676,43 @@ class SameOriginCheckerImpl final : public nsIChannelEventSink,
} // namespace
void AutoSuppressEventHandlingAndSuspend::SuppressDocument(Document* aDoc) {
// Note: Document::SuppressEventHandling will also automatically suppress
// event handling for any in-process sub-documents. However, since we need
// to deal with cases where remote BrowsingContexts may be interleaved
// with in-process ones, we still need to walk the entire tree ourselves.
// This may be slightly redundant in some cases, but since event handling
// suppressions maintain a count of current blockers, it does not cause
// any problems.
aDoc->SuppressEventHandling();
aDoc->GetInnerWindow()->Suspend();
AutoSuppressEventHandlingAndSuspend::AutoSuppressEventHandlingAndSuspend(
BrowsingContextGroup* aGroup) {
for (const auto& bc : aGroup->Toplevels()) {
SuppressBrowsingContext(bc);
}
}
void AutoSuppressEventHandlingAndSuspend::UnsuppressDocument(Document* aDoc) {
if (nsCOMPtr<nsPIDOMWindowInner> win = aDoc->GetInnerWindow()) {
void AutoSuppressEventHandlingAndSuspend::SuppressBrowsingContext(
BrowsingContext* aBC) {
if (nsCOMPtr<nsPIDOMWindowOuter> win = aBC->GetDOMWindow()) {
if (RefPtr<Document> doc = win->GetExtantDoc()) {
mDocuments.AppendElement(doc);
mWindows.AppendElement(win->GetCurrentInnerWindow());
// Note: Document::SuppressEventHandling will also automatically suppress
// event handling for any in-process sub-documents. However, since we need
// to deal with cases where remote BrowsingContexts may be interleaved
// with in-process ones, we still need to walk the entire tree ourselves.
// This may be slightly redundant in some cases, but since event handling
// suppressions maintain a count of current blockers, it does not cause
// any problems.
doc->SuppressEventHandling();
win->GetCurrentInnerWindow()->Suspend();
}
}
for (const auto& bc : aBC->Children()) {
SuppressBrowsingContext(bc);
}
}
AutoSuppressEventHandlingAndSuspend::~AutoSuppressEventHandlingAndSuspend() {
for (const auto& win : mWindows) {
win->Resume();
}
aDoc->UnsuppressEventHandlingAndFireEvents(true);
for (const auto& doc : mDocuments) {
doc->UnsuppressEventHandlingAndFireEvents(true);
}
}
/**