Backed out changeset ab6c012704b9 (bug 1315105) for failing on own test

This commit is contained in:
Carsten "Tomcat" Book 2016-12-19 16:34:18 +01:00
parent 97d9339674
commit 72f817124f
9 changed files with 39 additions and 280 deletions

View File

@ -21,11 +21,6 @@ interface nsIGroupedSHistory : nsISupports
// The total number of entries of all its partial session histories.
[infallible] readonly attribute unsigned long count;
/**
* The currently active frameloader controlled by this nsIGroupedSHistory.
*/
readonly attribute nsIFrameLoader activeFrameLoader;
/**
* Remove all partial histories after currently active one (if any) and then
* append the given partial session history to the end of the list.
@ -62,22 +57,4 @@ interface nsIGroupedSHistory : nsISupports
* This does not remove the PartialSHistories from the GroupedSHistory.
*/
void closeInactiveFrameLoaderOwners();
/**
* Add a partialSHistory as a "prerendering" partialSHistory. This
* partialSHistory's tab will have its lifetime managed by the
* GroupedSHistory, and will be closed when closeInactiveFrameLoaderOwners is
* called, or whenever a SHistory update is received.
*/
void addPrerenderingPartialSHistory(in nsIPartialSHistory aPrerendering, in long aId);
/**
* Switch to the prerendering partialSHistory identified by aId, appending it after the current partialSHistory.
*/
[implicit_jscontext] nsISupports activatePrerendering(in long aId);
/**
* Cancel the prerendering with the given ID.
*/
void cancelPrerendering(in long aId);
};

View File

@ -5,7 +5,6 @@
#include "nsISupports.idl"
interface nsIGroupedSHistory;
interface nsIFrameLoader;
/**
@ -28,29 +27,14 @@ interface nsIPartialSHistory : nsISupports
// The frameloader which owns this partial session history.
readonly attribute nsIFrameLoader ownerFrameLoader;
// The groupedSHistory which this partialSHistory is a part of, or null.
readonly attribute nsIGroupedSHistory groupedSHistory;
// The current state of the nsIPartialSHistory, whether it is active,
// inactive, or currently prerendering.
const long STATE_INACTIVE = 0;
const long STATE_ACTIVE = 1;
const long STATE_PRERENDER = 2;
[infallible] attribute long activeState;
/**
* Notify that it's been added to a grouped session history. It also implies
* it's becoming the active partial history of the group.
*
* @param aGroup The GroupedSHistory which this partialSHistory
* is joining.
*
* @param aOffset The number of entries in preceding partial
* session histories.
*/
void onAttachGroupedSessionHistory(in nsIGroupedSHistory aGroup,
in unsigned long aOffset);
void onAttachGroupedSessionHistory(in unsigned long aOffset);
/**
* This method is used by the TabParent to notify the PartialSHistory

View File

@ -11,20 +11,7 @@
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_CLASS(GroupedSHistory)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(GroupedSHistory)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPartialHistories)
tmp->mPrerenderingHistories.Clear();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(GroupedSHistory)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPartialHistories)
for (GroupedSHistory::PrerenderingHistory& h : tmp->mPrerenderingHistories) {
ImplCycleCollectionTraverse(cb, h.mPartialHistory, "mPrerenderingHistories[i]->mPartialHistory", 0);
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION(GroupedSHistory, mPartialHistories)
NS_IMPL_CYCLE_COLLECTING_ADDREF(GroupedSHistory)
NS_IMPL_CYCLE_COLLECTING_RELEASE(GroupedSHistory)
@ -76,12 +63,9 @@ GroupedSHistory::AppendPartialSessionHistory(nsIPartialSHistory* aPartialHistory
uint32_t offset = mCount;
mCount += partialHistory->GetCount();
mPartialHistories.AppendElement(partialHistory);
partialHistory->OnAttachGroupedSessionHistory(this, offset);
partialHistory->OnAttachGroupedSessionHistory(offset);
mIndexOfActivePartialHistory = mPartialHistories.Count() - 1;
// Remove the prerendered documents, as there was a history navigation
PurgePrerendering();
return NS_OK;
}
@ -117,9 +101,6 @@ GroupedSHistory::HandleSHistoryUpdate(nsIPartialSHistory* aPartial, bool aTrunca
}
}
// Remove the prerendered documents, as there was a history navigation
PurgePrerendering();
// If we should be truncating, make sure to purge any partialSHistories which
// follow the one being updated.
if (aTruncate) {
@ -228,114 +209,16 @@ GroupedSHistory::GroupedHistoryEnabled() {
return Preferences::GetBool("browser.groupedhistory.enabled", false);
}
void
GroupedSHistory::PurgePrerendering()
{
nsTArray<PrerenderingHistory> histories = Move(mPrerenderingHistories);
// Remove the frameloaders which are owned by the prerendering history, and
// remove them from mPrerenderingHistories.
for (uint32_t i = 0; i < histories.Length(); ++i) {
nsCOMPtr<nsIFrameLoader> loader;
histories[i].mPartialHistory->GetOwnerFrameLoader(getter_AddRefs(loader));
if (loader) {
loader->RequestFrameLoaderClose();
}
}
MOZ_ASSERT(mPrerenderingHistories.IsEmpty());
}
NS_IMETHODIMP
GroupedSHistory::CloseInactiveFrameLoaderOwners()
{
MOZ_ASSERT(mIndexOfActivePartialHistory >= 0);
// Remove inactive frameloaders which are participating in the grouped shistory
for (uint32_t i = 0; i < mPartialHistories.Length(); ++i) {
if (i != static_cast<uint32_t>(mIndexOfActivePartialHistory)) {
for (int32_t i = 0; i < mPartialHistories.Count(); ++i) {
if (i != mIndexOfActivePartialHistory) {
nsCOMPtr<nsIFrameLoader> loader;
mPartialHistories[i]->GetOwnerFrameLoader(getter_AddRefs(loader));
loader->RequestFrameLoaderClose();
}
}
PurgePrerendering();
return NS_OK;
}
NS_IMETHODIMP
GroupedSHistory::AddPrerenderingPartialSHistory(nsIPartialSHistory* aPrerendering, int32_t aId)
{
NS_ENSURE_TRUE(aPrerendering && aId, NS_ERROR_UNEXPECTED);
aPrerendering->SetActiveState(nsIPartialSHistory::STATE_PRERENDER);
PrerenderingHistory history = { aPrerendering, aId };
mPrerenderingHistories.AppendElement(history);
return NS_OK;
}
NS_IMETHODIMP
GroupedSHistory::GetActiveFrameLoader(nsIFrameLoader** aFrameLoader)
{
if (mIndexOfActivePartialHistory >= 0) {
return mPartialHistories[mIndexOfActivePartialHistory]->GetOwnerFrameLoader(aFrameLoader);
}
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
GroupedSHistory::ActivatePrerendering(int32_t aId, JSContext* aCx, nsISupports** aPromise)
{
NS_ENSURE_TRUE(aId && aCx && aPromise, NS_ERROR_UNEXPECTED);
// Look for an entry with the given aId in mPrerenderingHistories.
for (uint32_t i = 0; i < mPrerenderingHistories.Length(); ++i) {
if (mPrerenderingHistories[i].mId == aId) {
nsCOMPtr<nsIPartialSHistory> partialHistory = mPrerenderingHistories[i].mPartialHistory;
mPrerenderingHistories.RemoveElementAt(i);
nsCOMPtr<nsIFrameLoader> fl;
partialHistory->GetOwnerFrameLoader(getter_AddRefs(fl));
NS_ENSURE_TRUE(fl, NS_ERROR_FAILURE);
nsCOMPtr<nsIFrameLoader> activeFl;
GetActiveFrameLoader(getter_AddRefs(activeFl));
NS_ENSURE_TRUE(activeFl, NS_ERROR_FAILURE);
nsresult rv = fl->MakePrerenderedLoaderActive();
NS_ENSURE_SUCCESS(rv, rv);
return activeFl->AppendPartialSessionHistoryAndSwap(fl, aPromise);
}
}
// Generate a rejected promise as the entry was not found.
nsCOMPtr<nsIGlobalObject> go = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx));
if (NS_WARN_IF(!go)) {
return NS_ERROR_FAILURE;
}
ErrorResult rv;
RefPtr<Promise> promise = Promise::Reject(go, aCx, JS::UndefinedHandleValue, rv);
if (NS_WARN_IF(rv.Failed())) {
return NS_ERROR_FAILURE;
}
promise.forget(aPromise);
return NS_OK;
}
NS_IMETHODIMP
GroupedSHistory::CancelPrerendering(int32_t aId)
{
for (uint32_t i = 0; i < mPrerenderingHistories.Length(); ++i) {
if (mPrerenderingHistories[i].mId == aId) {
nsCOMPtr<nsIPartialSHistory> partialHistory = mPrerenderingHistories[i].mPartialHistory;
nsCOMPtr<nsIFrameLoader> fl;
partialHistory->GetOwnerFrameLoader(getter_AddRefs(fl));
if (fl) {
fl->RequestFrameLoaderClose();
}
mPrerenderingHistories.RemoveElementAt(i);
}
}
return NS_OK;
}

View File

@ -88,12 +88,6 @@ private:
*/
void PurgePartialHistories(uint32_t aLastPartialIndexToKeep);
/**
* Remove the frameloaders which are owned by the prerendering history, and
* remove them from mPrerenderingHistories.
*/
void PurgePrerendering();
// The total number of entries in all partial histories.
uint32_t mCount;
@ -103,14 +97,6 @@ private:
// All participating nsIPartialSHistory objects.
nsCOMArray<nsIPartialSHistory> mPartialHistories;
// All nsIPartialSHistories which are being prerendered.
struct PrerenderingHistory
{
nsCOMPtr<nsIPartialSHistory> mPartialHistory;
int32_t mId;
};
nsTArray<PrerenderingHistory> mPrerenderingHistories;
};
} // namespace dom

View File

@ -11,7 +11,7 @@
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION(PartialSHistory, mOwnerFrameLoader, mGroupedSHistory)
NS_IMPL_CYCLE_COLLECTION(PartialSHistory, mOwnerFrameLoader)
NS_IMPL_CYCLE_COLLECTING_ADDREF(PartialSHistory)
NS_IMPL_CYCLE_COLLECTING_RELEASE(PartialSHistory)
@ -26,7 +26,6 @@ NS_INTERFACE_MAP_END
PartialSHistory::PartialSHistory(nsIFrameLoader* aOwnerFrameLoader)
: mCount(0),
mGlobalIndexOffset(0),
mActive(nsIPartialSHistory::STATE_ACTIVE),
mOwnerFrameLoader(aOwnerFrameLoader)
{
MOZ_ASSERT(aOwnerFrameLoader);
@ -145,13 +144,9 @@ PartialSHistory::GetOwnerFrameLoader(nsIFrameLoader** aResult)
}
NS_IMETHODIMP
PartialSHistory::OnAttachGroupedSessionHistory(nsIGroupedSHistory* aGroup, uint32_t aOffset)
PartialSHistory::OnAttachGroupedSessionHistory(uint32_t aOffset)
{
MOZ_ASSERT(!mGroupedSHistory, "Only may join a single GroupedSHistory");
mActive = nsIPartialSHistory::STATE_ACTIVE;
mGlobalIndexOffset = aOffset;
mGroupedSHistory = aGroup;
// If we have direct reference to nsISHistory, simply pass through.
nsCOMPtr<nsISHistory> shistory(GetSessionHistory());
@ -192,23 +187,21 @@ PartialSHistory::SHistoryDidUpdate(bool aTruncate /* = false */)
return NS_ERROR_UNEXPECTED;
}
if (!mGroupedSHistory) {
// It's OK if we don't have a grouped history, that just means that we
// aren't in a grouped shistory, so we don't need to do anything.
return NS_OK;
nsCOMPtr<nsIGroupedSHistory> groupedHistory;
mOwnerFrameLoader->GetGroupedSessionHistory(getter_AddRefs(groupedHistory));
if (NS_WARN_IF(!groupedHistory)) {
// Maybe we're not the active partial history, but in this case we shouldn't
// receive any update from session history object either.
return NS_ERROR_FAILURE;
}
mGroupedSHistory->HandleSHistoryUpdate(this, aTruncate);
groupedHistory->HandleSHistoryUpdate(this, aTruncate);
return NS_OK;
}
NS_IMETHODIMP
PartialSHistory::OnActive(uint32_t aGlobalLength, uint32_t aTargetLocalIndex)
{
MOZ_ASSERT(mGroupedSHistory);
mActive = nsIPartialSHistory::STATE_ACTIVE;
// In-process case.
nsCOMPtr<nsISHistory> shistory(GetSessionHistory());
if (shistory) {
@ -236,10 +229,6 @@ PartialSHistory::OnActive(uint32_t aGlobalLength, uint32_t aTargetLocalIndex)
NS_IMETHODIMP
PartialSHistory::OnDeactive()
{
MOZ_ASSERT(mGroupedSHistory);
mActive = nsIPartialSHistory::STATE_INACTIVE;
// In-process case.
nsCOMPtr<nsISHistory> shistory(GetSessionHistory());
if (shistory) {
@ -260,28 +249,6 @@ PartialSHistory::OnDeactive()
return NS_OK;
}
NS_IMETHODIMP
PartialSHistory::GetActiveState(int32_t* aActive)
{
*aActive = mActive;
return NS_OK;
}
NS_IMETHODIMP
PartialSHistory::SetActiveState(int32_t aActive)
{
mActive = aActive;
return NS_OK;
}
NS_IMETHODIMP
PartialSHistory::GetGroupedSHistory(nsIGroupedSHistory** aGrouped)
{
nsCOMPtr<nsIGroupedSHistory> shistory = mGroupedSHistory;
shistory.forget(aGrouped);
return NS_OK;
}
/*******************************************************************************
* nsIPartialSHistoryListener
******************************************************************************/

View File

@ -56,14 +56,8 @@ private:
// used for remote process case.
uint32_t mGlobalIndexOffset;
// One of the possible active states from nsIPartialSHistory
int32_t mActive;
// The frameloader which owns this PartialSHistory.
nsCOMPtr<nsIFrameLoader> mOwnerFrameLoader;
// The GroupedSHistory which this PartialSHistory is part of, or null.
nsCOMPtr<nsIGroupedSHistory> mGroupedSHistory;
};
} // namespace dom

View File

@ -141,7 +141,8 @@ NS_IMPL_CYCLE_COLLECTION(nsFrameLoader,
mMessageManager,
mChildMessageManager,
mOpener,
mPartialSessionHistory)
mPartialSessionHistory,
mGroupedSessionHistory)
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFrameLoader)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFrameLoader)
@ -377,38 +378,12 @@ nsFrameLoader::GetPartialSessionHistory(nsIPartialSHistory** aResult)
return NS_OK;
}
NS_IMETHODIMP
nsFrameLoader::EnsureGroupedSHistory(nsIGroupedSHistory** aResult)
{
nsCOMPtr<nsIPartialSHistory> partialHistory;
GetPartialSessionHistory(getter_AddRefs(partialHistory));
MOZ_ASSERT(partialHistory);
nsCOMPtr<nsIGroupedSHistory> groupedHistory;
partialHistory->GetGroupedSHistory(getter_AddRefs(groupedHistory));
if (!groupedHistory) {
groupedHistory = new GroupedSHistory();
groupedHistory->AppendPartialSessionHistory(partialHistory);
#ifdef DEBUG
nsCOMPtr<nsIGroupedSHistory> test;
GetGroupedSessionHistory(getter_AddRefs(test));
MOZ_ASSERT(test == groupedHistory, "GroupedHistory must match");
#endif
}
groupedHistory.forget(aResult);
return NS_OK;
}
NS_IMETHODIMP
nsFrameLoader::GetGroupedSessionHistory(nsIGroupedSHistory** aResult)
{
nsCOMPtr<nsIGroupedSHistory> groupedSHistory;
if (mPartialSessionHistory) {
mPartialSessionHistory->GetGroupedSHistory(getter_AddRefs(groupedSHistory));
}
groupedSHistory.forget(aResult);
nsCOMPtr<nsIGroupedSHistory> groupedHistory(mGroupedSessionHistory);
groupedHistory.forget(aResult);
return NS_OK;
}
@ -432,6 +407,9 @@ nsFrameLoader::SwapBrowsersAndNotify(nsFrameLoader* aOther)
return false;
}
// Swap the GroupedSessionHistory
mGroupedSessionHistory.swap(aOther->mGroupedSessionHistory);
// Dispatch the BrowserChangedProcess event to tell JS that the process swap
// has occurred.
GroupedHistoryEventInit eventInit;
@ -474,17 +452,21 @@ public:
// Append ourselves.
nsresult rv;
nsCOMPtr<nsIGroupedSHistory> groupedSHistory;
rv = mThis->EnsureGroupedSHistory(getter_AddRefs(groupedSHistory));
if (NS_WARN_IF(NS_FAILED(rv))) {
mPromise->MaybeRejectWithUndefined();
return;
if (!mThis->mGroupedSessionHistory) {
mThis->mGroupedSessionHistory = new GroupedSHistory();
nsCOMPtr<nsIPartialSHistory> partialSHistory;
MOZ_ALWAYS_SUCCEEDS(mThis->GetPartialSessionHistory(getter_AddRefs(partialSHistory)));
rv = mThis->mGroupedSessionHistory->AppendPartialSessionHistory(partialSHistory);
if (NS_WARN_IF(NS_FAILED(rv))) {
mPromise->MaybeRejectWithUndefined();
return;
}
}
// Append the other.
nsCOMPtr<nsIPartialSHistory> otherPartialSHistory;
MOZ_ALWAYS_SUCCEEDS(mOther->GetPartialSessionHistory(getter_AddRefs(otherPartialSHistory)));
rv = groupedSHistory->AppendPartialSessionHistory(otherPartialSHistory);
rv = mThis->mGroupedSessionHistory->AppendPartialSessionHistory(otherPartialSHistory);
if (NS_WARN_IF(NS_FAILED(rv))) {
mPromise->MaybeRejectWithUndefined();
return;
@ -538,16 +520,10 @@ public:
return;
}
nsCOMPtr<nsIGroupedSHistory> groupedSHistory;
mThis->GetGroupedSessionHistory(getter_AddRefs(groupedSHistory));
if (NS_WARN_IF(!groupedSHistory)) {
mPromise->MaybeRejectWithUndefined();
return;
}
// Navigate the loader to the new index
nsCOMPtr<nsIFrameLoader> otherLoader;
nsresult rv = groupedSHistory->GotoIndex(mGlobalIndex, getter_AddRefs(otherLoader));
nsresult rv = mThis->mGroupedSessionHistory->
GotoIndex(mGlobalIndex, getter_AddRefs(otherLoader));
// Check if the gotoIndex failed because the target frameloader is dead. We
// need to perform a navigateAndRestoreByIndex and then return to recover.
@ -710,6 +686,9 @@ nsFrameLoader::AppendPartialSessionHistoryAndSwap(nsIFrameLoader* aOther, nsISup
NS_IMETHODIMP
nsFrameLoader::RequestGroupedHistoryNavigation(uint32_t aGlobalIndex, nsISupports** aPromise)
{
if (!mGroupedSessionHistory) {
return NS_ERROR_UNEXPECTED;
}
RefPtr<Promise> ready = FireWillChangeProcessEvent();
if (NS_WARN_IF(!ready)) {
@ -2010,15 +1989,8 @@ nsFrameLoader::StartDestroy()
}
// Destroy the other frame loader owners now that we are being destroyed.
if (mPartialSessionHistory &&
mPartialSessionHistory->GetActiveState() == nsIPartialSHistory::STATE_ACTIVE) {
nsCOMPtr<nsIGroupedSHistory> groupedSHistory;
GetGroupedSessionHistory(getter_AddRefs(groupedSHistory));
if (groupedSHistory) {
NS_DispatchToCurrentThread(NS_NewRunnableFunction([groupedSHistory] () {
groupedSHistory->CloseInactiveFrameLoaderOwners();
}));
}
if (mGroupedSessionHistory) {
mGroupedSessionHistory->CloseInactiveFrameLoaderOwners();
}
nsCOMPtr<nsIRunnable> destroyRunnable = new nsFrameLoaderDestroyRunnable(this);

View File

@ -351,6 +351,7 @@ private:
mozilla::ScreenIntSize mLazySize;
nsCOMPtr<nsIPartialSHistory> mPartialSessionHistory;
nsCOMPtr<nsIGroupedSHistory> mGroupedSessionHistory;
// A stack-maintained reference to an array of promises which are blocking
// grouped history navigation

View File

@ -170,11 +170,6 @@ interface nsIFrameLoader : nsISupports
in nsIPrintSettings aPrintSettings,
in nsIWebProgressListener aProgressListener);
/**
* Ensure that the current nsIFrameLoader has a GroupedSHistory.
*/
nsIGroupedSHistory ensureGroupedSHistory();
/**
* The default event mode automatically forwards the events
* handled in EventStateManager::HandleCrossProcessEvent to