зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1186810 (part 5) - Replace nsBaseHashtable::EnumerateRead() calls in dom/workers/ with iterators. r=nsm.
--HG-- extra : rebase_source : f4a67d4bca37fbec566a3b110a9f7002df0af7f6
This commit is contained in:
Родитель
5068308113
Коммит
06aaac230d
|
@ -3652,97 +3652,6 @@ HasRootDomain(nsIURI* aURI, const nsACString& aDomain)
|
|||
return prevChar == '.';
|
||||
}
|
||||
|
||||
struct UnregisterIfMatchesUserData final
|
||||
{
|
||||
UnregisterIfMatchesUserData(
|
||||
ServiceWorkerManager::RegistrationDataPerPrincipal* aRegistrationData,
|
||||
void* aUserData)
|
||||
: mRegistrationData(aRegistrationData)
|
||||
, mUserData(aUserData)
|
||||
{}
|
||||
|
||||
ServiceWorkerManager::RegistrationDataPerPrincipal* mRegistrationData;
|
||||
void *mUserData;
|
||||
};
|
||||
|
||||
PLDHashOperator
|
||||
UnregisterIfMatchesClearOriginParams(const nsACString& aScope,
|
||||
ServiceWorkerRegistrationInfo* aReg,
|
||||
void* aPtr)
|
||||
{
|
||||
UnregisterIfMatchesUserData* data =
|
||||
static_cast<UnregisterIfMatchesUserData*>(aPtr);
|
||||
MOZ_ASSERT(data);
|
||||
|
||||
if (data->mUserData) {
|
||||
OriginAttributes* params = static_cast<OriginAttributes*>(data->mUserData);
|
||||
MOZ_ASSERT(params);
|
||||
MOZ_ASSERT(aReg);
|
||||
MOZ_ASSERT(aReg->mPrincipal);
|
||||
|
||||
bool equals = false;
|
||||
|
||||
if (params->mInBrowser) {
|
||||
// When we do a system wide "clear cookies and stored data" on B2G we get
|
||||
// the "clear-origin-data" notification with the System app appID and
|
||||
// the browserOnly flag set to true.
|
||||
// Web sites registering a service worker on B2G have a principal with the
|
||||
// following information: web site origin + System app appId + inBrowser=1
|
||||
// So we need to check if the service worker registration info contains
|
||||
// the System app appID and the enabled inBrowser flag and in that case
|
||||
// remove it from the registry.
|
||||
OriginAttributes attrs =
|
||||
mozilla::BasePrincipal::Cast(aReg->mPrincipal)->OriginAttributesRef();
|
||||
equals = attrs == *params;
|
||||
} else {
|
||||
// If we get the "clear-origin-data" notification because of an app
|
||||
// uninstallation, we need to check the full principal to get the match
|
||||
// in the service workers registry. If we find a match, we unregister the
|
||||
// worker.
|
||||
nsCOMPtr<nsIAppsService> appsService =
|
||||
do_GetService(APPS_SERVICE_CONTRACTID);
|
||||
if (NS_WARN_IF(!appsService)) {
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
nsCOMPtr<mozIApplication> app;
|
||||
appsService->GetAppByLocalId(params->mAppId, getter_AddRefs(app));
|
||||
if (NS_WARN_IF(!app)) {
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
app->GetPrincipal(getter_AddRefs(principal));
|
||||
if (NS_WARN_IF(!principal)) {
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
aReg->mPrincipal->Equals(principal, &equals);
|
||||
}
|
||||
|
||||
if (equals) {
|
||||
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
||||
swm->ForceUnregister(data->mRegistrationData, aReg);
|
||||
}
|
||||
}
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
PLDHashOperator
|
||||
UnregisterIfMatchesClearOriginParams(const nsACString& aKey,
|
||||
ServiceWorkerManager::RegistrationDataPerPrincipal* aData,
|
||||
void* aUserData)
|
||||
{
|
||||
UnregisterIfMatchesUserData data(aData, aUserData);
|
||||
// We can use EnumerateRead because ForceUnregister (and Unregister) are async.
|
||||
// Otherwise doing some R/W operations on an hashtable during an EnumerateRead
|
||||
// will crash.
|
||||
aData->mInfos.EnumerateRead(UnregisterIfMatchesClearOriginParams,
|
||||
&data);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NS_IMPL_ISUPPORTS(ServiceWorkerDataInfo, nsIServiceWorkerInfo)
|
||||
|
@ -3852,8 +3761,7 @@ ServiceWorkerManager::GetAllRegistrations(nsIArray** aResult)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// MUST ONLY BE CALLED FROM Remove(), RemoveAll() and
|
||||
// UnregisterIfMatchesClearOriginParams()!
|
||||
// MUST ONLY BE CALLED FROM Remove(), RemoveAll() and RemoveAllRegistrations()!
|
||||
void
|
||||
ServiceWorkerManager::ForceUnregister(RegistrationDataPerPrincipal* aRegistrationData,
|
||||
ServiceWorkerRegistrationInfo* aRegistration)
|
||||
|
@ -3959,8 +3867,63 @@ ServiceWorkerManager::RemoveAllRegistrations(OriginAttributes* aParams)
|
|||
|
||||
MOZ_ASSERT(aParams);
|
||||
|
||||
mRegistrationInfos.EnumerateRead(UnregisterIfMatchesClearOriginParams,
|
||||
aParams);
|
||||
for (auto it1 = mRegistrationInfos.Iter(); !it1.Done(); it1.Next()) {
|
||||
ServiceWorkerManager::RegistrationDataPerPrincipal* data = it1.UserData();
|
||||
|
||||
// We can use iteration because ForceUnregister (and Unregister) are
|
||||
// async. Otherwise doing some R/W operations on an hashtable during
|
||||
// iteration will crash.
|
||||
for (auto it2 = data->mInfos.Iter(); !it2.Done(); it2.Next()) {
|
||||
ServiceWorkerRegistrationInfo* reg = it2.UserData();
|
||||
|
||||
MOZ_ASSERT(reg);
|
||||
MOZ_ASSERT(reg->mPrincipal);
|
||||
|
||||
bool equals = false;
|
||||
|
||||
if (aParams->mInBrowser) {
|
||||
// When we do a system wide "clear cookies and stored data" on B2G we
|
||||
// get the "clear-origin-data" notification with the System app appID
|
||||
// and the browserOnly flag set to true. Web sites registering a
|
||||
// service worker on B2G have a principal with the following
|
||||
// information: web site origin + System app appId + inBrowser=1 So
|
||||
// we need to check if the service worker registration info contains
|
||||
// the System app appID and the enabled inBrowser flag and in that
|
||||
// case remove it from the registry.
|
||||
OriginAttributes attrs =
|
||||
mozilla::BasePrincipal::Cast(reg->mPrincipal)->OriginAttributesRef();
|
||||
equals = attrs == *aParams;
|
||||
} else {
|
||||
// If we get the "clear-origin-data" notification because of an app
|
||||
// uninstallation, we need to check the full principal to get the
|
||||
// match in the service workers registry. If we find a match, we
|
||||
// unregister the worker.
|
||||
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
|
||||
if (NS_WARN_IF(!appsService)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nsCOMPtr<mozIApplication> app;
|
||||
appsService->GetAppByLocalId(aParams->mAppId, getter_AddRefs(app));
|
||||
if (NS_WARN_IF(!app)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
app->GetPrincipal(getter_AddRefs(principal));
|
||||
if (NS_WARN_IF(!principal)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
reg->mPrincipal->Equals(principal, &equals);
|
||||
}
|
||||
|
||||
if (equals) {
|
||||
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
||||
swm->ForceUnregister(data, reg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
Загрузка…
Ссылка в новой задаче