# Copyright (C) 2023 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1.  Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
# 2.  Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

headers: "NetworkResourceLoadParameters.h"

enum class WebKit::PreconnectOnly : bool;
enum class WebKit::NavigatingToAppBoundDomain : bool;

[RValue] struct WebKit::NetworkResourceLoadParameters {
    WebKit::WebPageProxyIdentifier webPageProxyID;
    WebCore::PageIdentifier webPageID;
    WebCore::FrameIdentifier webFrameID;
    [EncodeRequestBody] WebCore::ResourceRequest request;

    RefPtr<WebCore::SecurityOrigin> topOrigin;
    RefPtr<WebCore::SecurityOrigin> sourceOrigin;
    WTF::ProcessID parentPID;
    
    WebCore::ContentSniffingPolicy contentSniffingPolicy;
    WebCore::ContentEncodingSniffingPolicy contentEncodingSniffingPolicy;
    WebCore::StoredCredentialsPolicy storedCredentialsPolicy;
    WebCore::ClientCredentialPolicy clientCredentialPolicy;
    
    bool shouldClearReferrerOnHTTPSToHTTPRedirect;
    bool needsCertificateInfo;
    bool isMainFrameNavigation;
    std::optional<WebKit::NavigationActionData> mainResourceNavigationDataForAnyFrame;
    WebKit::PreconnectOnly shouldPreconnectOnly;
    std::optional<WebKit::NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain;
    bool hadMainFrameMainResourcePrivateRelayed;
    bool allowPrivacyProxy;
    OptionSet<WebCore::AdvancedPrivacyProtections> advancedPrivacyProtections;
    uint64_t requiredCookiesVersion;

    Markable<WebCore::ResourceLoaderIdentifier> identifier;

    Vector<WebKit::SandboxExtensionHandle> requestBodySandboxExtensions;
    std::optional<WebKit::SandboxExtensionHandle> resourceSandboxExtension;

    Seconds maximumBufferingTime;
    
    WebCore::FetchOptions options;
    std::optional<WebCore::ContentSecurityPolicyResponseHeaders> cspResponseHeaders;
    URL parentFrameURL;
    URL frameURL;
    WebCore::CrossOriginEmbedderPolicy parentCrossOriginEmbedderPolicy;
    WebCore::CrossOriginEmbedderPolicy crossOriginEmbedderPolicy;
    WebCore::HTTPHeaderMap originalRequestHeaders;
    
    bool shouldRestrictHTTPResponseAccess;
    
    WebCore::PreflightPolicy preflightPolicy;
    
    bool shouldEnableCrossOriginResourcePolicy;
    
    Vector<Ref<WebCore::SecurityOrigin>> frameAncestorOrigins;
    bool pageHasResourceLoadClient;
    std::optional<WebCore::FrameIdentifier> parentFrameID;
    bool crossOriginAccessControlCheckEnabled;
    
    URL documentURL;

    bool isCrossOriginOpenerPolicyEnabled;
    bool isClearSiteDataHeaderEnabled;
    bool isClearSiteDataExecutionContextEnabled;
    bool isDisplayingInitialEmptyDocument;
    WebCore::SandboxFlags effectiveSandboxFlags;
    URL openerURL;
    WebCore::CrossOriginOpenerPolicy sourceCrossOriginOpenerPolicy;
    
    std::optional<WebCore::NavigationIdentifier> navigationID;
    std::optional<WebCore::NavigationRequester> navigationRequester;
    
    WebCore::ServiceWorkersMode serviceWorkersMode;
    std::optional<WebCore::ServiceWorkerRegistrationIdentifier> serviceWorkerRegistrationIdentifier;
    OptionSet<WebCore::HTTPHeadersToKeepFromCleaning> httpHeadersToKeep;
    std::optional<WebCore::FetchIdentifier> navigationPreloadIdentifier;
    WebCore::FetchingWorkerIdentifier workerIdentifier;

#if ENABLE(CONTENT_EXTENSIONS)
    URL mainDocumentURL;
    std::optional<WebKit::UserContentControllerIdentifier> userContentControllerIdentifier;
#endif

#if ENABLE(WK_WEB_EXTENSIONS)
    bool pageHasLoadedWebExtensions;
#endif

    bool linkPreconnectEarlyHintsEnabled;
    bool shouldRecordFrameLoadForStorageAccess;

    bool isInitiatorPrefetch;
    bool isInitiatedByDedicatedWorker;
};

using WebCore::FetchingWorkerIdentifier = Variant<std::monostate, WebCore::SharedWorkerIdentifier, WebCore::ServiceWorkerIdentifier>;
