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

View File

@ -64,9 +64,6 @@ public:
NS_DECL_NSISERVICEWORKERREGISTRATIONINFO NS_DECL_NSISERVICEWORKERREGISTRATIONINFO
nsCString mScope; 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; nsCOMPtr<nsIPrincipal> mPrincipal;
@ -93,7 +90,7 @@ public:
nsIPrincipal* aPrincipal); nsIPrincipal* aPrincipal);
already_AddRefed<ServiceWorkerInfo> already_AddRefed<ServiceWorkerInfo>
Newest() Newest() const
{ {
RefPtr<ServiceWorkerInfo> newest; RefPtr<ServiceWorkerInfo> newest;
if (mInstallingWorker) { if (mInstallingWorker) {

View File

@ -47,43 +47,15 @@
return waitForServiceWorkerRegistrationChange(registration, function () { return waitForServiceWorkerRegistrationChange(registration, function () {
is(registration.scriptSpec, EXAMPLE_URL + "worker.js"); 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); ok(registration.installingWorker !== null);
is(registration.installingWorker.scriptSpec, EXAMPLE_URL + "worker.js");
ok(registration.waitingWorker === null); ok(registration.waitingWorker === null);
ok(registration.activeWorker !== null); ok(registration.activeWorker === null);
return waitForServiceWorkerRegistrationChange(registration, function () { return waitForServiceWorkerRegistrationChange(registration, function () {
ok(registration.installingWorker === null); ok(registration.installingWorker === null);
ok(registration.waitingWorker !== null); ok(registration.waitingWorker !== null);
ok(registration.activeWorker !== null); ok(registration.activeWorker === null);
return waitForServiceWorkerRegistrationChange(registration, function () { return waitForServiceWorkerRegistrationChange(registration, function () {
ok(registration.installingWorker === null); ok(registration.installingWorker === null);
@ -93,7 +65,30 @@
return registration; 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", "*"); iframe.contentWindow.postMessage("register", "*");