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;
String referrerPolicy;
ResourceError scriptError;
ServiceWorkerFetchResult isolatedCopy() const { return { jobDataIdentifier, registrationKey.isolatedCopy(), script.isolatedCopy(), contentSecurityPolicy.isolatedCopy(), referrerPolicy.isolatedCopy(), scriptError.isolatedCopy() }; }
template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static bool decode(Decoder&, ServiceWorkerFetchResult&);
};
inline ServiceWorkerFetchResult serviceWorkerFetchError(ServiceWorkerJobDataIdentifier jobDataIdentifier, ServiceWorkerRegistrationKey&& registrationKey, ResourceError&& error)
{
return { jobDataIdentifier, WTFMove(registrationKey), { }, { }, { }, WTFMove(error) };
}
template<class Encoder>
void ServiceWorkerFetchResult::encode(Encoder& encoder) const
{
encoder << jobDataIdentifier << registrationKey << script << contentSecurityPolicy << referrerPolicy << scriptError;
}
template<class Decoder>
bool ServiceWorkerFetchResult::decode(Decoder& decoder, ServiceWorkerFetchResult& result)
{
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.referrerPolicy))
return false;
if (!decoder.decode(result.scriptError))
return false;
return true;
}
}
#endif // ENABLE(SERVICE_WORKER)