Bug 1227015 P5 Remove ServiceWorkerRegistrationInfo mScriptSpec. r=ehsan

This commit is contained in:
Ben Kelly 2015-12-11 14:53:10 -05:00
parent e13ee51fe6
commit 77a6f7d49d
3 changed files with 53 additions and 61 deletions

View File

@ -318,7 +318,13 @@ PopulateRegistrationData(nsIPrincipal* aPrincipal,
}
aData.scope() = aRegistration->mScope;
aData.scriptSpec() = aRegistration->mScriptSpec;
RefPtr<ServiceWorkerInfo> newest = aRegistration->Newest();
if (NS_WARN_IF(!newest)) {
return NS_ERROR_FAILURE;
}
aData.scriptSpec() = newest->ScriptSpec();
if (aRegistration->mActiveWorker) {
aData.currentWorkerURL() = aRegistration->mActiveWorker->ScriptSpec();
@ -458,7 +464,10 @@ NS_IMETHODIMP
ServiceWorkerRegistrationInfo::GetScriptSpec(nsAString& aScriptSpec)
{
AssertIsOnMainThread();
CopyUTF8toUTF16(mScriptSpec, aScriptSpec);
RefPtr<ServiceWorkerInfo> newest = Newest();
if (newest) {
CopyUTF8toUTF16(newest->ScriptSpec(), aScriptSpec);
}
return NS_OK;
}
@ -1007,7 +1016,7 @@ protected:
// Remove the old error code so we can replace it with a TypeError.
aRv.SuppressException();
NS_ConvertUTF8toUTF16 scriptSpec(mRegistration->mScriptSpec);
NS_ConvertUTF8toUTF16 scriptSpec(mScriptSpec);
NS_ConvertUTF8toUTF16 scope(mRegistration->mScope);
// Throw the type error with a generic error message.
@ -1246,8 +1255,7 @@ public:
if (mRegistration) {
mRegistration->mPendingUninstall = false;
RefPtr<ServiceWorkerInfo> newest = mRegistration->Newest();
if (newest && mScriptSpec.Equals(newest->ScriptSpec()) &&
mScriptSpec.Equals(mRegistration->mScriptSpec)) {
if (newest && mScriptSpec.Equals(newest->ScriptSpec())) {
swm->StoreRegistration(mPrincipal, mRegistration);
Succeed();
@ -1265,8 +1273,6 @@ public:
mRegistration = swm->CreateNewRegistration(mScope, mPrincipal);
}
mRegistration->mScriptSpec = mScriptSpec;
mRegistration->NotifyListenersOnChange();
swm->StoreRegistration(mPrincipal, mRegistration);
} else {
MOZ_ASSERT(mJobType == UpdateJob);
@ -1303,7 +1309,7 @@ public:
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
nsCOMPtr<nsIURI> scriptURI;
nsresult rv = NS_NewURI(getter_AddRefs(scriptURI), mRegistration->mScriptSpec);
nsresult rv = NS_NewURI(getter_AddRefs(scriptURI), mScriptSpec);
if (NS_WARN_IF(NS_FAILED(rv))) {
Fail(NS_ERROR_DOM_SECURITY_ERR);
return;
@ -1353,8 +1359,7 @@ public:
MOZ_ASSERT(!mUpdateAndInstallInfo);
mUpdateAndInstallInfo =
new ServiceWorkerInfo(mRegistration, mRegistration->mScriptSpec,
aNewCacheName);
new ServiceWorkerInfo(mRegistration, mScriptSpec, aNewCacheName);
RefPtr<ServiceWorkerJob> upcasted = this;
nsMainThreadPtrHandle<nsISupports> handle(
@ -1388,7 +1393,7 @@ private:
if (NS_WARN_IF(!aScriptEvaluationResult)) {
ErrorResult error;
NS_ConvertUTF8toUTF16 scriptSpec(mRegistration->mScriptSpec);
NS_ConvertUTF8toUTF16 scriptSpec(mScriptSpec);
NS_ConvertUTF8toUTF16 scope(mRegistration->mScope);
error.ThrowTypeError<MSG_SW_SCRIPT_THREW>(scriptSpec, scope);
return Fail(error);
@ -1439,14 +1444,14 @@ private:
// 9.2.20 If newestWorker is not null, and newestWorker's script url is
// equal to registration's registering script url and response is a
// byte-for-byte match with the script resource of newestWorker...
if (workerInfo && workerInfo->ScriptSpec().Equals(mRegistration->mScriptSpec)) {
if (workerInfo && workerInfo->ScriptSpec().Equals(mScriptSpec)) {
cacheName = workerInfo->CacheName();
}
nsresult rv =
serviceWorkerScriptCache::Compare(mRegistration, mRegistration->mPrincipal, cacheName,
NS_ConvertUTF8toUTF16(mRegistration->mScriptSpec),
this, mLoadGroup);
NS_ConvertUTF8toUTF16(mScriptSpec), this,
mLoadGroup);
if (NS_WARN_IF(NS_FAILED(rv))) {
return Fail(rv);
}
@ -2735,14 +2740,15 @@ ServiceWorkerManager::LoadRegistration(
GetRegistration(principal, aRegistration.scope());
if (!registration) {
registration = CreateNewRegistration(aRegistration.scope(), principal);
} else if (registration->mScriptSpec == aRegistration.scriptSpec() &&
!!registration->mActiveWorker == aRegistration.currentWorkerURL().IsEmpty()) {
// No needs for updates.
return;
} else {
RefPtr<ServiceWorkerInfo> newest = registration->Newest();
if (newest && newest->ScriptSpec() == aRegistration.scriptSpec() &&
!!registration->mActiveWorker == aRegistration.currentWorkerURL().IsEmpty()) {
// No needs for updates.
return;
}
}
registration->mScriptSpec = aRegistration.scriptSpec();
const nsCString& currentWorkerURL = aRegistration.currentWorkerURL();
if (!currentWorkerURL.IsEmpty()) {
registration->mActiveWorker =
@ -3627,9 +3633,6 @@ ServiceWorkerManager::SoftUpdate(const OriginAttributes& aOriginAttributes,
return;
}
// "Set registration's registering script url to newestWorker's script url."
registration->mScriptSpec = newest->ScriptSpec();
// "If the registration queue for registration is empty, invoke Update algorithm,
// or its equivalent, with client, registration as its argument."
// TODO(catalinb): We don't implement the force bypass cache flag.
@ -3684,9 +3687,6 @@ ServiceWorkerManager::Update(nsIPrincipal* aPrincipal,
return;
}
// "Set registration's registering script url to newestWorker's script url."
registration->mScriptSpec = newest->ScriptSpec();
ServiceWorkerJobQueue* queue =
GetOrCreateJobQueue(scopeKey, aScope);
MOZ_ASSERT(queue);

View File

@ -64,9 +64,6 @@ public:
NS_DECL_NSISERVICEWORKERREGISTRATIONINFO
nsCString mScope;
// The scriptURL for the registration. This may be completely different from
// the URLs of the following three workers.
nsCString mScriptSpec;
nsCOMPtr<nsIPrincipal> mPrincipal;
@ -93,7 +90,7 @@ public:
nsIPrincipal* aPrincipal);
already_AddRefed<ServiceWorkerInfo>
Newest()
Newest() const
{
RefPtr<ServiceWorkerInfo> newest;
if (mInstallingWorker) {

View File

@ -47,43 +47,15 @@
return waitForServiceWorkerRegistrationChange(registration, function () {
is(registration.scriptSpec, EXAMPLE_URL + "worker.js");
return waitForServiceWorkerRegistrationChange(registration, function () {
ok(registration.installingWorker !== null);
ok(registration.waitingWorker === null);
ok(registration.activeWorker === null);
return waitForServiceWorkerRegistrationChange(registration, function () {
ok(registration.installingWorker === null);
ok(registration.waitingWorker !== null);
ok(registration.activeWorker === null);
return waitForServiceWorkerRegistrationChange(registration, function () {
ok(registration.installingWorker === null);
ok(registration.waitingWorker === null);
ok(registration.activeWorker !== null);
return registration;
});
});
});
});
});
iframe.contentWindow.postMessage("register", "*");
let registration = yield promise;
promise = waitForServiceWorkerRegistrationChange(registration, function () {
is(registration.scriptSpec, EXAMPLE_URL + "worker2.js");
return waitForServiceWorkerRegistrationChange(registration, function () {
ok(registration.installingWorker !== null);
is(registration.installingWorker.scriptSpec, EXAMPLE_URL + "worker.js");
ok(registration.waitingWorker === null);
ok(registration.activeWorker !== null);
ok(registration.activeWorker === null);
return waitForServiceWorkerRegistrationChange(registration, function () {
ok(registration.installingWorker === null);
ok(registration.waitingWorker !== null);
ok(registration.activeWorker !== null);
ok(registration.activeWorker === null);
return waitForServiceWorkerRegistrationChange(registration, function () {
ok(registration.installingWorker === null);
@ -93,7 +65,30 @@
return registration;
});
});
});
});
iframe.contentWindow.postMessage("register", "*");
let registration = yield promise;
promise = waitForServiceWorkerRegistrationChange(registration, function () {
is(registration.scriptSpec, EXAMPLE_URL + "worker2.js");
ok(registration.installingWorker !== null);
is(registration.installingWorker.scriptSpec, EXAMPLE_URL + "worker2.js");
ok(registration.waitingWorker === null);
ok(registration.activeWorker !== null);
return waitForServiceWorkerRegistrationChange(registration, function () {
ok(registration.installingWorker === null);
ok(registration.waitingWorker !== null);
ok(registration.activeWorker !== null);
return waitForServiceWorkerRegistrationChange(registration, function () {
ok(registration.installingWorker === null);
ok(registration.waitingWorker === null);
ok(registration.activeWorker !== null);
return registration;
});
});
});
iframe.contentWindow.postMessage("register", "*");