зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1564235 - P5 Save NavigationPreload data into serviceworker.txt. r=dom-worker-reviewers,asuth
This patch implements the part of saving/loading NavigationPreload data into/from serviceworker.txt Depends on D116917 Differential Revision: https://phabricator.services.mozilla.com/D116918
This commit is contained in:
Родитель
f5b7f71fb3
Коммит
144f9f3b9c
|
@ -213,6 +213,8 @@ nsresult PopulateRegistrationData(
|
|||
|
||||
aData.lastUpdateTime() = aRegistration->GetLastUpdateTime();
|
||||
|
||||
aData.navigationPreloadState() = aRegistration->GetNavigationPreloadState();
|
||||
|
||||
MOZ_ASSERT(ServiceWorkerRegistrationDataIsValid(aData));
|
||||
|
||||
return NS_OK;
|
||||
|
@ -1474,7 +1476,8 @@ void ServiceWorkerManager::LoadRegistration(
|
|||
registration =
|
||||
CreateNewRegistration(aRegistration.scope(), principal,
|
||||
static_cast<ServiceWorkerUpdateViaCache>(
|
||||
aRegistration.updateViaCache()));
|
||||
aRegistration.updateViaCache()),
|
||||
aRegistration.navigationPreloadState());
|
||||
} else {
|
||||
// If active worker script matches our expectations for a "current worker",
|
||||
// then we are done. Since scripts with the same URL might have different
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace dom {
|
|||
namespace {
|
||||
|
||||
static const char* gSupportedRegistrarVersions[] = {
|
||||
SERVICEWORKERREGISTRAR_VERSION, "7", "6", "5", "4", "3", "2"};
|
||||
SERVICEWORKERREGISTRAR_VERSION, "8", "7", "6", "5", "4", "3", "2"};
|
||||
|
||||
static const uint32_t kInvalidGeneration = static_cast<uint32_t>(-1);
|
||||
|
||||
|
@ -128,6 +128,9 @@ nsresult CreatePrincipalInfo(nsILineInputStream* aStream,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
const IPCNavigationPreloadState gDefaultNavigationPreloadState(false,
|
||||
"true"_ns);
|
||||
|
||||
} // namespace
|
||||
|
||||
NS_IMPL_ISUPPORTS(ServiceWorkerRegistrar, nsIObserver, nsIAsyncShutdownBlocker)
|
||||
|
@ -444,8 +447,9 @@ nsresult ServiceWorkerRegistrar::ReadData() {
|
|||
entry->updateViaCache() = updateViaCache.ToInteger(&rv, 16);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
} else if (entry->updateViaCache() >
|
||||
nsIServiceWorkerRegistrationInfo::UPDATE_VIA_CACHE_NONE) {
|
||||
}
|
||||
if (entry->updateViaCache() >
|
||||
nsIServiceWorkerRegistrationInfo::UPDATE_VIA_CACHE_NONE) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
|
@ -472,6 +476,74 @@ nsresult ServiceWorkerRegistrar::ReadData() {
|
|||
return rv;
|
||||
}
|
||||
entry->lastUpdateTime() = lastUpdateTime;
|
||||
|
||||
nsAutoCString navigationPreloadEnabledStr;
|
||||
GET_LINE(navigationPreloadEnabledStr);
|
||||
bool navigationPreloadEnabled =
|
||||
navigationPreloadEnabledStr.ToInteger(&rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
entry->navigationPreloadState().enabled() = navigationPreloadEnabled;
|
||||
|
||||
GET_LINE(entry->navigationPreloadState().headerValue());
|
||||
} else if (version.EqualsLiteral("8")) {
|
||||
rv = CreatePrincipalInfo(lineInputStream, entry);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
GET_LINE(entry->currentWorkerURL());
|
||||
|
||||
nsAutoCString fetchFlag;
|
||||
GET_LINE(fetchFlag);
|
||||
if (!fetchFlag.EqualsLiteral(SERVICEWORKERREGISTRAR_TRUE) &&
|
||||
!fetchFlag.EqualsLiteral(SERVICEWORKERREGISTRAR_FALSE)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
entry->currentWorkerHandlesFetch() =
|
||||
fetchFlag.EqualsLiteral(SERVICEWORKERREGISTRAR_TRUE);
|
||||
|
||||
nsAutoCString cacheName;
|
||||
GET_LINE(cacheName);
|
||||
CopyUTF8toUTF16(cacheName, entry->cacheName());
|
||||
|
||||
nsAutoCString updateViaCache;
|
||||
GET_LINE(updateViaCache);
|
||||
entry->updateViaCache() = updateViaCache.ToInteger(&rv, 16);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
if (entry->updateViaCache() >
|
||||
nsIServiceWorkerRegistrationInfo::UPDATE_VIA_CACHE_NONE) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsAutoCString installedTimeStr;
|
||||
GET_LINE(installedTimeStr);
|
||||
int64_t installedTime = installedTimeStr.ToInteger64(&rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
entry->currentWorkerInstalledTime() = installedTime;
|
||||
|
||||
nsAutoCString activatedTimeStr;
|
||||
GET_LINE(activatedTimeStr);
|
||||
int64_t activatedTime = activatedTimeStr.ToInteger64(&rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
entry->currentWorkerActivatedTime() = activatedTime;
|
||||
|
||||
nsAutoCString lastUpdateTimeStr;
|
||||
GET_LINE(lastUpdateTimeStr);
|
||||
int64_t lastUpdateTime = lastUpdateTimeStr.ToInteger64(&rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
entry->lastUpdateTime() = lastUpdateTime;
|
||||
|
||||
entry->navigationPreloadState() = gDefaultNavigationPreloadState;
|
||||
} else if (version.EqualsLiteral("7")) {
|
||||
rv = CreatePrincipalInfo(lineInputStream, entry);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
@ -527,6 +599,8 @@ nsresult ServiceWorkerRegistrar::ReadData() {
|
|||
return rv;
|
||||
}
|
||||
entry->lastUpdateTime() = lastUpdateTime;
|
||||
|
||||
entry->navigationPreloadState() = gDefaultNavigationPreloadState;
|
||||
} else if (version.EqualsLiteral("6")) {
|
||||
rv = CreatePrincipalInfo(lineInputStream, entry);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
@ -562,6 +636,8 @@ nsresult ServiceWorkerRegistrar::ReadData() {
|
|||
entry->currentWorkerInstalledTime() = 0;
|
||||
entry->currentWorkerActivatedTime() = 0;
|
||||
entry->lastUpdateTime() = 0;
|
||||
|
||||
entry->navigationPreloadState() = gDefaultNavigationPreloadState;
|
||||
} else if (version.EqualsLiteral("5")) {
|
||||
overwrite = true;
|
||||
dedupe = true;
|
||||
|
@ -592,6 +668,8 @@ nsresult ServiceWorkerRegistrar::ReadData() {
|
|||
entry->currentWorkerInstalledTime() = 0;
|
||||
entry->currentWorkerActivatedTime() = 0;
|
||||
entry->lastUpdateTime() = 0;
|
||||
|
||||
entry->navigationPreloadState() = gDefaultNavigationPreloadState;
|
||||
} else if (version.EqualsLiteral("4")) {
|
||||
overwrite = true;
|
||||
dedupe = true;
|
||||
|
@ -616,6 +694,8 @@ nsresult ServiceWorkerRegistrar::ReadData() {
|
|||
entry->currentWorkerInstalledTime() = 0;
|
||||
entry->currentWorkerActivatedTime() = 0;
|
||||
entry->lastUpdateTime() = 0;
|
||||
|
||||
entry->navigationPreloadState() = gDefaultNavigationPreloadState;
|
||||
} else if (version.EqualsLiteral("3")) {
|
||||
overwrite = true;
|
||||
dedupe = true;
|
||||
|
@ -640,6 +720,8 @@ nsresult ServiceWorkerRegistrar::ReadData() {
|
|||
entry->currentWorkerInstalledTime() = 0;
|
||||
entry->currentWorkerActivatedTime() = 0;
|
||||
entry->lastUpdateTime() = 0;
|
||||
|
||||
entry->navigationPreloadState() = gDefaultNavigationPreloadState;
|
||||
} else if (version.EqualsLiteral("2")) {
|
||||
overwrite = true;
|
||||
dedupe = true;
|
||||
|
@ -671,6 +753,8 @@ nsresult ServiceWorkerRegistrar::ReadData() {
|
|||
entry->currentWorkerInstalledTime() = 0;
|
||||
entry->currentWorkerActivatedTime() = 0;
|
||||
entry->lastUpdateTime() = 0;
|
||||
|
||||
entry->navigationPreloadState() = gDefaultNavigationPreloadState;
|
||||
} else {
|
||||
MOZ_ASSERT_UNREACHABLE("Should never get here!");
|
||||
}
|
||||
|
@ -1073,6 +1157,13 @@ nsresult ServiceWorkerRegistrar::WriteData(
|
|||
buffer.AppendInt(aData[i].lastUpdateTime());
|
||||
buffer.Append('\n');
|
||||
|
||||
buffer.AppendInt(
|
||||
static_cast<int32_t>(aData[i].navigationPreloadState().enabled()));
|
||||
buffer.Append('\n');
|
||||
|
||||
buffer.Append(aData[i].navigationPreloadState().headerValue());
|
||||
buffer.Append('\n');
|
||||
|
||||
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR);
|
||||
buffer.Append('\n');
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "nsTArray.h"
|
||||
|
||||
#define SERVICEWORKERREGISTRAR_FILE u"serviceworker.txt"
|
||||
#define SERVICEWORKERREGISTRAR_VERSION "8"
|
||||
#define SERVICEWORKERREGISTRAR_VERSION "9"
|
||||
#define SERVICEWORKERREGISTRAR_TERMINATOR "#"
|
||||
#define SERVICEWORKERREGISTRAR_TRUE "true"
|
||||
#define SERVICEWORKERREGISTRAR_FALSE "false"
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* 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 IPCNavigationPreloadState;
|
||||
include PBackgroundSharedTypes;
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -24,6 +25,8 @@ struct ServiceWorkerRegistrationData
|
|||
int64_t currentWorkerInstalledTime;
|
||||
int64_t currentWorkerActivatedTime;
|
||||
int64_t lastUpdateTime;
|
||||
|
||||
IPCNavigationPreloadState navigationPreloadState;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
Загрузка…
Ссылка в новой задаче