ServiceWorkerFetchResult.h [plain text]
#pragma once
#if ENABLE(SERVICE_WORKER)
#include "ContentSecurityPolicyResponseHeaders.h"
#include "ResourceError.h"
#include "ServiceWorkerRegistrationKey.h"
#include "ServiceWorkerTypes.h"
namespace WebCore {
struct ServiceWorkerFetchResult {
ServiceWorkerJobDataIdentifier jobDataIdentifier;
ServiceWorkerRegistrationKey registrationKey;
String script;
ContentSecurityPolicyResponseHeaders contentSecurityPolicy;
ResourceError scriptError;
template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static bool decode(Decoder&, ServiceWorkerFetchResult&);
};
template<class Encoder>
void ServiceWorkerFetchResult::encode(Encoder& encoder) const
{
encoder << jobDataIdentifier << registrationKey << script << contentSecurityPolicy << scriptError;
}
template<class Decoder>
bool ServiceWorkerFetchResult::decode(Decoder& decoder, ServiceWorkerFetchResult& result)
{
std::optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier;
decoder >> jobDataIdentifier;
if (!jobDataIdentifier)
return false;
result.jobDataIdentifier = WTFMove(*jobDataIdentifier);
auto registrationKey = ServiceWorkerRegistrationKey::decode(decoder);
if (!registrationKey)
return false;
std::swap(*registrationKey, result.registrationKey);
if (!decoder.decode(result.script))
return false;
if (!decoder.decode(result.contentSecurityPolicy))
return false;
if (!decoder.decode(result.scriptError))
return false;
return true;
}
}
#endif // ENABLE(SERVICE_WORKER)