Bug 1509466 - Pass frame request callbacks along with their handles to nsRefreshDriver; r=farre

In the next patch in this series we want to compare the handle of frame
callbacks we are about to run,  with a set of canceled handles stored on the
document. This patch makes us pass the handles along with the callbacks so we
can do that.

Incidentally doing this allows us to just swap array elements when building up
the refresh driver's set of callbacks to run. That is hopefully a little more
efficient than running the implicit conversion operator on each item and then
appending to an array.

Differential Revision: https://phabricator.services.mozilla.com/D20973

--HG--
extra : rebase_source : f014605ece1c8e3495b2927621fb9f72ff8e57d7
This commit is contained in:
Brian Birtles 2019-02-25 15:02:12 +09:00
Родитель 75b2169450
Коммит 80fb21495c
3 изменённых файлов: 39 добавлений и 38 удалений

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

@ -1128,22 +1128,9 @@ void Document::SelectorCache::NotifyExpired(SelectorCacheKey* aSelector) {
delete aSelector;
}
struct Document::FrameRequest {
FrameRequest(FrameRequestCallback& aCallback, int32_t aHandle)
: mCallback(&aCallback), mHandle(aHandle) {}
// Conversion operator so that we can append these to a
// FrameRequestCallbackList
operator const RefPtr<FrameRequestCallback>&() const { return mCallback; }
// Comparator operators to allow RemoveElementSorted with an
// integer argument on arrays of FrameRequest
bool operator==(int32_t aHandle) const { return mHandle == aHandle; }
bool operator<(int32_t aHandle) const { return mHandle < aHandle; }
RefPtr<FrameRequestCallback> mCallback;
int32_t mHandle;
};
Document::FrameRequest::FrameRequest(FrameRequestCallback& aCallback,
int32_t aHandle)
: mCallback(&aCallback), mHandle(aHandle) {}
// ==================================================================
// =
@ -3743,9 +3730,9 @@ void Document::UpdateFrameRequestCallbackSchedulingState(
mFrameRequestCallbacksScheduled = shouldBeScheduled;
}
void Document::TakeFrameRequestCallbacks(FrameRequestCallbackList& aCallbacks) {
aCallbacks.AppendElements(mFrameRequestCallbacks);
mFrameRequestCallbacks.Clear();
void Document::TakeFrameRequestCallbacks(nsTArray<FrameRequest>& aCallbacks) {
MOZ_ASSERT(aCallbacks.IsEmpty());
aCallbacks.SwapElements(mFrameRequestCallbacks);
// No need to manually remove ourselves from the refresh driver; it will
// handle that part. But we do have to update our state.
mFrameRequestCallbacksScheduled = false;
@ -12623,19 +12610,20 @@ already_AddRefed<mozilla::dom::Promise> Document::RequestStorageAccess(
AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor(
NodePrincipal(), inner, AntiTrackingCommon::eStorageAccessAPI,
performFinalChecks)
->Then(GetCurrentThreadSerialEventTarget(), __func__,
[outer, promise] {
// Step 10. Grant the document access to cookies and store
// that fact for
// the purposes of future calls to
// hasStorageAccess() and requestStorageAccess().
outer->SetHasStorageAccess(true);
promise->MaybeResolveWithUndefined();
},
[outer, promise] {
outer->SetHasStorageAccess(false);
promise->MaybeRejectWithUndefined();
});
->Then(
GetCurrentThreadSerialEventTarget(), __func__,
[outer, promise] {
// Step 10. Grant the document access to cookies and store
// that fact for
// the purposes of future calls to
// hasStorageAccess() and requestStorageAccess().
outer->SetHasStorageAccess(true);
promise->MaybeResolveWithUndefined();
},
[outer, promise] {
outer->SetHasStorageAccess(false);
promise->MaybeRejectWithUndefined();
});
return promise.forget();
}

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

@ -2950,16 +2950,27 @@ class Document : public nsINode,
SVGSVGElement* GetSVGRootElement() const;
struct FrameRequest {
FrameRequest(FrameRequestCallback& aCallback, int32_t aHandle);
// Comparator operators to allow RemoveElementSorted with an
// integer argument on arrays of FrameRequest
bool operator==(int32_t aHandle) const { return mHandle == aHandle; }
bool operator<(int32_t aHandle) const { return mHandle < aHandle; }
RefPtr<FrameRequestCallback> mCallback;
int32_t mHandle;
};
nsresult ScheduleFrameRequestCallback(FrameRequestCallback& aCallback,
int32_t* aHandle);
void CancelFrameRequestCallback(int32_t aHandle);
typedef nsTArray<RefPtr<FrameRequestCallback>> FrameRequestCallbackList;
/**
* Put this document's frame request callbacks into the provided
* list, and forget about them.
*/
void TakeFrameRequestCallbacks(FrameRequestCallbackList& aCallbacks);
void TakeFrameRequestCallbacks(nsTArray<FrameRequest>& aCallbacks);
/**
* @return true if this document's frame request callbacks should be
@ -4417,8 +4428,6 @@ class Document : public nsINode,
nsCOMPtr<nsIDocumentEncoder> mCachedEncoder;
struct FrameRequest;
nsTArray<FrameRequest> mFrameRequestCallbacks;
// This object allows us to evict ourself from the back/forward cache. The

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

@ -29,6 +29,7 @@
#include "mozilla/AnimationEventDispatcher.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/IntegerRange.h"
@ -1496,7 +1497,7 @@ struct DocumentFrameCallbacks {
explicit DocumentFrameCallbacks(Document* aDocument) : mDocument(aDocument) {}
RefPtr<Document> mDocument;
Document::FrameRequestCallbackList mCallbacks;
nsTArray<Document::FrameRequest> mCallbacks;
};
static nsDocShell* GetDocShell(nsPresContext* aPresContext) {
@ -1688,7 +1689,10 @@ void nsRefreshDriver::RunFrameRequestCallbacks(TimeStamp aNowTime) {
// else window is partially torn down already
}
for (auto& callback : docCallbacks.mCallbacks) {
callback->Call(timeStamp);
// MOZ_KnownLive is OK, because the stack array frameRequestCallbacks
// keeps callback alive and the mCallback strong reference can't be
// mutated by the call.
MOZ_KnownLive(callback.mCallback)->Call(timeStamp);
}
}
}