Backed out 4 changesets (bug 1702055) for causing failures on /browser_UsageTelemetry_private_and_restore.js. CLOSED TREE

Backed out changeset af21e2d8324e (bug 1702055)
Backed out changeset ff67df9befe5 (bug 1702055)
Backed out changeset b5f0638dcbc4 (bug 1702055)
Backed out changeset bffaa2c203b3 (bug 1702055)
This commit is contained in:
Butkovits Atila
2021-04-28 04:42:09 +03:00
parent 7326bf4b22
commit 80c415a4fc
18 changed files with 186 additions and 416 deletions

View File

@@ -182,6 +182,14 @@ void CanonicalBrowsingContext::ReplacedBy(
}
aNewContext->mWebProgress = std::move(mWebProgress);
bool hasRestoreData = !!mRestoreData && !mRestoreData->IsEmpty();
aNewContext->mRestoreData = std::move(mRestoreData);
aNewContext->mRequestedContentRestores = mRequestedContentRestores;
aNewContext->mCompletedContentRestores = mCompletedContentRestores;
SetRestoreData(nullptr);
mRequestedContentRestores = 0;
mCompletedContentRestores = 0;
// Use the Transaction for the fields which need to be updated whether or not
// the new context has been attached before.
// SetWithoutSyncing can be used if context hasn't been attached.
@@ -189,16 +197,13 @@ void CanonicalBrowsingContext::ReplacedBy(
txn.SetBrowserId(GetBrowserId());
txn.SetHistoryID(GetHistoryID());
txn.SetExplicitActive(GetExplicitActive());
txn.SetHasRestoreData(GetHasRestoreData());
txn.SetHasRestoreData(hasRestoreData);
if (aNewContext->EverAttached()) {
MOZ_ALWAYS_SUCCEEDS(txn.Commit(aNewContext));
} else {
txn.CommitWithoutSyncing(aNewContext);
}
aNewContext->mRestoreState = mRestoreState.forget();
MOZ_ALWAYS_SUCCEEDS(SetHasRestoreData(false));
// XXXBFCache name handling is still a bit broken in Fission in general,
// at least in case name should be cleared.
if (aRemotenessOptions.mTryUseBFCache) {
@@ -1908,103 +1913,49 @@ void CanonicalBrowsingContext::ResetScalingZoom() {
}
}
void CanonicalBrowsingContext::SetRestoreData(SessionStoreRestoreData* aData,
ErrorResult& aError) {
MOZ_DIAGNOSTIC_ASSERT(aData);
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
RefPtr<Promise> promise = Promise::Create(global, aError);
if (aError.Failed()) {
return;
}
if (NS_WARN_IF(NS_FAILED(SetHasRestoreData(true)))) {
aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
mRestoreState = new RestoreState();
mRestoreState->mData = aData;
mRestoreState->mPromise = promise;
}
already_AddRefed<Promise> CanonicalBrowsingContext::GetRestorePromise() {
if (mRestoreState) {
return do_AddRef(mRestoreState->mPromise);
}
return nullptr;
}
void CanonicalBrowsingContext::ClearRestoreState() {
if (!mRestoreState) {
MOZ_DIAGNOSTIC_ASSERT(!GetHasRestoreData());
return;
}
if (mRestoreState->mPromise) {
mRestoreState->mPromise->MaybeRejectWithUndefined();
mRestoreState->mPromise = nullptr;
}
mRestoreState = nullptr;
MOZ_ALWAYS_SUCCEEDS(SetHasRestoreData(false));
}
void CanonicalBrowsingContext::ResolveAndClearRestoreState(
RestoreState* aState) {
MOZ_DIAGNOSTIC_ASSERT(aState->mPromise);
aState->mPromise->MaybeResolveWithUndefined();
aState->mPromise = nullptr;
// We may have started a new restore before the previous one had resolved.
// This ensures that we aren't clearing state for the new restore.
if (aState == mRestoreState) {
ClearRestoreState();
}
void CanonicalBrowsingContext::SetRestoreData(SessionStoreRestoreData* aData) {
MOZ_DIAGNOSTIC_ASSERT(!mRestoreData || !aData,
"must either be clearing or initializing");
MOZ_DIAGNOSTIC_ASSERT(
!aData || mCompletedContentRestores == mRequestedContentRestores,
"must not start restore in an unstable state");
mRestoreData = aData;
MOZ_ALWAYS_SUCCEEDS(SetHasRestoreData(mRestoreData));
}
void CanonicalBrowsingContext::RequestRestoreTabContent(
WindowGlobalParent* aWindow) {
MOZ_DIAGNOSTIC_ASSERT(IsTop());
if (IsDiscarded() || !mRestoreState || !mRestoreState->mData) {
if (IsDiscarded() || !mRestoreData || mRestoreData->IsEmpty()) {
return;
}
CanonicalBrowsingContext* context = aWindow->GetBrowsingContext();
MOZ_DIAGNOSTIC_ASSERT(!context->IsDiscarded());
RefPtr<SessionStoreRestoreData> data =
mRestoreState->mData->FindDataForChild(context);
RefPtr<SessionStoreRestoreData> data = mRestoreData->FindChild(context);
// We'll only arrive here for a toplevel context after we've already sent
// down data for any out-of-process descendants, so it's fine to clear our
// data now.
if (context->IsTop()) {
MOZ_DIAGNOSTIC_ASSERT(context == this);
// We need to wait until the appropriate load event has fired before we
// can "complete" the restore process, so if we're holding an empty data
// object, just resolve the promise immediately.
if (mRestoreState->mData->IsEmpty()) {
MOZ_DIAGNOSTIC_ASSERT(!data || data->IsEmpty());
ResolveAndClearRestoreState(mRestoreState);
return;
}
// Since we're following load event order, we'll only arrive here for a
// toplevel context after we've already sent down data for all child frames,
// so it's safe to clear this reference now. The completion callback below
// relies on the mData field being null to determine if all requests have
// been sent out.
mRestoreState->ClearData();
MOZ_ALWAYS_SUCCEEDS(SetHasRestoreData(false));
SetRestoreData(nullptr);
}
if (data && !data->IsEmpty()) {
auto onTabRestoreComplete = [self = RefPtr{this},
state = RefPtr{mRestoreState}](auto) {
state->mResolves++;
if (!state->mData && state->mRequests == state->mResolves) {
self->ResolveAndClearRestoreState(state);
auto onTabRestoreComplete = [self = RefPtr{this}](auto) {
self->mCompletedContentRestores++;
if (!self->mRestoreData &&
self->mCompletedContentRestores == self->mRequestedContentRestores) {
if (Element* browser = self->GetEmbedderElement()) {
SessionStoreUtils::CallRestoreTabContentComplete(browser);
}
}
};
mRestoreState->mRequests++;
mRequestedContentRestores++;
if (data->CanRestoreInto(aWindow->GetDocumentURI())) {
if (!aWindow->IsInProcess()) {