mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 12:20:56 +00:00
Bug 1472005 Don't resolve ready promise until the registration has reached the right state version. r=mrbkap
This commit is contained in:
parent
4405c076b5
commit
d2e065fc4e
@ -544,7 +544,14 @@ ServiceWorkerContainer::GetReady(ErrorResult& aRv)
|
||||
RefPtr<ServiceWorkerRegistration> reg =
|
||||
global->GetOrCreateServiceWorkerRegistration(aDescriptor);
|
||||
NS_ENSURE_TRUE_VOID(reg);
|
||||
outer->MaybeResolve(reg);
|
||||
|
||||
// Don't resolve the ready promise until the registration has
|
||||
// reached the right version. This ensures that the active
|
||||
// worker property is set correctly on the registration.
|
||||
reg->WhenVersionReached(aDescriptor.Version(),
|
||||
[outer, reg] (bool aResult) {
|
||||
outer->MaybeResolve(reg);
|
||||
});
|
||||
}, [self, outer] (ErrorResult& aRv) {
|
||||
outer->MaybeReject(aRv);
|
||||
});
|
||||
|
@ -158,6 +158,17 @@ ServiceWorkerRegistration::UpdateState(const ServiceWorkerRegistrationDescriptor
|
||||
UpdateStateInternal(aDescriptor.GetInstalling(),
|
||||
aDescriptor.GetWaiting(),
|
||||
aDescriptor.GetActive());
|
||||
|
||||
nsTArray<UniquePtr<VersionCallback>> callbackList;
|
||||
mVersionCallbackList.SwapElements(callbackList);
|
||||
for (auto& cb : callbackList) {
|
||||
if (cb->mVersion > mDescriptor.Version()) {
|
||||
mVersionCallbackList.AppendElement(std::move(cb));
|
||||
continue;
|
||||
}
|
||||
|
||||
cb->mFunc(cb->mVersion == mDescriptor.Version());
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
@ -343,6 +354,19 @@ ServiceWorkerRegistration::Descriptor() const
|
||||
return mDescriptor;
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistration::WhenVersionReached(uint64_t aVersion,
|
||||
ServiceWorkerBoolCallback&& aCallback)
|
||||
{
|
||||
if (aVersion <= mDescriptor.Version()) {
|
||||
aCallback(aVersion == mDescriptor.Version());
|
||||
return;
|
||||
}
|
||||
|
||||
mVersionCallbackList.AppendElement(
|
||||
MakeUnique<VersionCallback>(aVersion, std::move(aCallback)));
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistration::MaybeScheduleUpdateFound(const Maybe<ServiceWorkerDescriptor>& aInstallingDescriptor)
|
||||
{
|
||||
|
@ -119,6 +119,9 @@ public:
|
||||
const ServiceWorkerRegistrationDescriptor&
|
||||
Descriptor() const;
|
||||
|
||||
void
|
||||
WhenVersionReached(uint64_t aVersion, ServiceWorkerBoolCallback&& aCallback);
|
||||
|
||||
private:
|
||||
ServiceWorkerRegistration(nsIGlobalObject* aGlobal,
|
||||
const ServiceWorkerRegistrationDescriptor& aDescriptor,
|
||||
@ -148,6 +151,20 @@ private:
|
||||
RefPtr<ServiceWorker> mActiveWorker;
|
||||
RefPtr<PushManager> mPushManager;
|
||||
|
||||
struct VersionCallback
|
||||
{
|
||||
uint64_t mVersion;
|
||||
ServiceWorkerBoolCallback mFunc;
|
||||
|
||||
VersionCallback(uint64_t aVersion, ServiceWorkerBoolCallback&& aFunc)
|
||||
: mVersion(aVersion)
|
||||
, mFunc(std::move(aFunc))
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mFunc);
|
||||
}
|
||||
};
|
||||
nsTArray<UniquePtr<VersionCallback>> mVersionCallbackList;
|
||||
|
||||
uint64_t mScheduledUpdateFoundId;
|
||||
uint64_t mDispatchedUpdateFoundId;
|
||||
uint32_t mPendingUpdatePromises;
|
||||
|
Loading…
x
Reference in New Issue
Block a user