2016-04-06 23:27:22 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "ServiceWorkerRegisterJob.h"
|
|
|
|
|
2018-01-31 10:25:30 +03:00
|
|
|
#include "mozilla/dom/WorkerCommon.h"
|
2018-06-25 17:03:18 +03:00
|
|
|
#include "ServiceWorkerManager.h"
|
2016-04-06 23:27:22 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2017-08-16 09:18:52 +03:00
|
|
|
ServiceWorkerRegisterJob::ServiceWorkerRegisterJob(
|
|
|
|
nsIPrincipal* aPrincipal, const nsACString& aScope,
|
2019-02-15 07:56:12 +03:00
|
|
|
const nsACString& aScriptSpec, ServiceWorkerUpdateViaCache aUpdateViaCache)
|
2016-04-06 23:27:23 +03:00
|
|
|
: ServiceWorkerUpdateJob(Type::Register, aPrincipal, aScope, aScriptSpec,
|
2019-02-15 07:56:12 +03:00
|
|
|
aUpdateViaCache) {}
|
2016-04-06 23:27:22 +03:00
|
|
|
|
2016-04-06 23:27:23 +03:00
|
|
|
void ServiceWorkerRegisterJob::AsyncExecute() {
|
2018-01-27 00:08:59 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-04-06 23:27:22 +03:00
|
|
|
|
2017-01-13 01:00:36 +03:00
|
|
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
|
|
|
if (Canceled() || !swm) {
|
2016-04-06 23:27:22 +03:00
|
|
|
FailUpdateJob(NS_ERROR_DOM_ABORT_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ServiceWorkerRegistrationInfo> registration =
|
|
|
|
swm->GetRegistration(mPrincipal, mScope);
|
|
|
|
|
|
|
|
if (registration) {
|
2017-08-16 09:18:52 +03:00
|
|
|
bool sameUVC = GetUpdateViaCache() == registration->GetUpdateViaCache();
|
|
|
|
registration->SetUpdateViaCache(GetUpdateViaCache());
|
2017-01-04 12:08:51 +03:00
|
|
|
|
2016-04-06 23:27:22 +03:00
|
|
|
RefPtr<ServiceWorkerInfo> newest = registration->Newest();
|
2017-08-16 09:18:52 +03:00
|
|
|
if (newest && mScriptSpec.Equals(newest->ScriptSpec()) && sameUVC) {
|
2016-04-06 23:27:22 +03:00
|
|
|
SetRegistration(registration);
|
|
|
|
Finish(NS_OK);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2017-01-04 12:08:58 +03:00
|
|
|
registration =
|
|
|
|
swm->CreateNewRegistration(mScope, mPrincipal, GetUpdateViaCache());
|
2017-02-14 18:06:38 +03:00
|
|
|
if (!registration) {
|
|
|
|
FailUpdateJob(NS_ERROR_DOM_ABORT_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2016-04-06 23:27:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
SetRegistration(registration);
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2016-04-06 23:27:23 +03:00
|
|
|
ServiceWorkerRegisterJob::~ServiceWorkerRegisterJob() {}
|
2016-04-06 23:27:22 +03:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|