/* -*- 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/. */
if (aArgs.common().preloadNavigation()) { // We use synchronous task dispatch here to make sure that if the preload // response arrived before we dispatch the fetch event, then the JS preload // response promise will get resolved immediately.
mPreloadResponseAvailablePromise =
MakeRefPtr<FetchEventPreloadResponseAvailablePromise::Private>(
__func__);
mPreloadResponseAvailablePromise->UseSynchronousTaskDispatch(__func__); if (aArgs.preloadResponse().isSome()) {
mPreloadResponseAvailablePromiseResolved = true;
mPreloadResponseAvailablePromise->Resolve(
InternalResponse::FromIPC(aArgs.preloadResponse().ref()), __func__);
}
auto callback = [self](const ServiceWorkerOpResult& aResult) { // FetchEventOp could finish before NavigationPreload fetch finishes. // If NavigationPreload is available in FetchEvent, caching FetchEventOp // result until RecvPreloadResponseEnd is called, such that the preload // response could be completed. if (self->mPreloadResponseEndPromise &&
!self->mPreloadResponseEndPromiseResolved &&
self->mPreloadResponseAvailablePromiseResolved) {
self->mCachedOpResult = Some(aResult); return;
} if (!self->CanSend()) { return;
}
mozilla::ipc::IPCResult FetchEventOpProxyChild::RecvPreloadResponse(
ParentToChildInternalResponse&& aResponse) { // Receiving this message implies that navigation preload is enabled, so // Initialize() should have created this promise.
MOZ_ASSERT(mPreloadResponseAvailablePromise);
mozilla::ipc::IPCResult FetchEventOpProxyChild::RecvPreloadResponseTiming(
ResponseTiming&& aTiming) { // Receiving this message implies that navigation preload is enabled, so // Initialize() should have created this promise.
MOZ_ASSERT(mPreloadResponseTimingPromise);
mozilla::ipc::IPCResult FetchEventOpProxyChild::RecvPreloadResponseEnd(
ResponseEndArgs&& aArgs) { // Receiving this message implies that navigation preload is enabled, so // Initialize() should have created this promise.
MOZ_ASSERT(mPreloadResponseEndPromise);
mPreloadResponseEndPromiseResolved = true;
mPreloadResponseEndPromise->Resolve(std::move(aArgs), __func__); // If mCachedOpResult is not nothing, it means FetchEventOp had already done // and the operation result is cached. Continue closing IPC here. if (mCachedOpResult.isNothing()) { return IPC_OK();
}
// If mPreloadResponseAvailablePromise exists, navigation preloading response // will not be valid anymore since it is too late to respond to the // FetchEvent. Resolve the preload response promise with // NS_ERROR_DOM_ABORT_ERR. if (mPreloadResponseAvailablePromise) {
mPreloadResponseAvailablePromiseResolved = true;
mPreloadResponseAvailablePromise->Resolve(
InternalResponse::NetworkError(NS_ERROR_DOM_ABORT_ERR), __func__);
}
if (mPreloadResponseTimingPromise) {
mPreloadResponseTimingPromise->Resolve(ResponseTiming(), __func__);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.