Bug 1158557 - Don't throttle rAF for documents with live static clones. r=smaug

This commit is contained in:
Seth Fowler 2015-05-01 12:37:27 -07:00
parent f641de24ac
commit 5b9a952683
2 changed files with 32 additions and 1 deletions

View File

@ -1636,6 +1636,8 @@ nsIDocument::~nsIDocument()
if (mNodeInfoManager) {
mNodeInfoManager->DropDocumentReference();
}
UnlinkOriginalDocumentIfStatic();
}
@ -2093,13 +2095,14 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument)
}
tmp->mFirstChild = nullptr;
tmp->UnlinkOriginalDocumentIfStatic();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mXPathEvaluator)
tmp->mCachedRootElement = nullptr; // Avoid a dangling pointer
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDisplayDocument)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFirstBaseNodeWithHref)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDOMImplementation)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mImageMaps)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOriginalDocument)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCachedEncoder)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mUndoManager)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentTimeline)
@ -3925,6 +3928,11 @@ nsIDocument::TakeFrameRequestCallbacks(FrameRequestCallbackList& aCallbacks)
bool
nsIDocument::ShouldThrottleFrameRequests()
{
if (mStaticCloneCount > 0) {
// Even if we're not visible, a static clone may be, so run at full speed.
return false;
}
if (!mIsShowing) {
// We're not showing (probably in a background tab or the bf cache).
return true;
@ -10280,6 +10288,9 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer)
} else {
clonedDoc->mOriginalDocument = this;
}
clonedDoc->mOriginalDocument->mStaticCloneCount++;
int32_t sheetsCount = GetNumberOfStyleSheets();
for (int32_t i = 0; i < sheetsCount; ++i) {
nsRefPtr<CSSStyleSheet> sheet = do_QueryObject(GetStyleSheetAt(i));
@ -10317,6 +10328,17 @@ nsIDocument::CreateStaticClone(nsIDocShell* aCloneContainer)
return clonedDoc.forget();
}
void
nsIDocument::UnlinkOriginalDocumentIfStatic()
{
if (IsStaticDocument() && mOriginalDocument) {
MOZ_ASSERT(mOriginalDocument->mStaticCloneCount > 0);
mOriginalDocument->mStaticCloneCount--;
mOriginalDocument = nullptr;
}
MOZ_ASSERT(!mOriginalDocument);
}
nsresult
nsIDocument::ScheduleFrameRequestCallback(const FrameRequestCallbackHolder& aCallback,
int32_t *aHandle)

View File

@ -1937,6 +1937,12 @@ public:
return mOriginalDocument;
}
/**
* If this document is a static clone, let the original document know that
* we're going away and then release our reference to it.
*/
void UnlinkOriginalDocumentIfStatic();
/**
* These are called by the parser as it encounters <picture> tags, the end of
* said tags, and possible picture <source srcset> sources respectively. These
@ -2861,6 +2867,9 @@ protected:
*/
int32_t mFrameRequestCallbackCounter;
// Count of live static clones of this document.
uint32_t mStaticCloneCount;
// Array of nodes that have been blocked to prevent user tracking.
// They most likely have had their nsIChannel canceled by the URL
// classifier. (Safebrowsing)