2 * Copyright (C) 2012 Google, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "CachedResource.h"
30 #include "ResourceLoadPriority.h"
31 #include "ResourceLoaderOptions.h"
32 #include "ResourceRequest.h"
33 #include "SecurityOrigin.h"
34 #include <wtf/RefPtr.h>
35 #include <wtf/text/AtomicString.h>
39 namespace ContentExtensions {
45 enum class ReferrerPolicy;
47 bool isRequestCrossOrigin(SecurityOrigin*, const URL& requestURL, const ResourceLoaderOptions&);
49 class CachedResourceRequest {
51 CachedResourceRequest(ResourceRequest&&, const ResourceLoaderOptions&, std::optional<ResourceLoadPriority> = std::nullopt, String&& charset = String());
53 ResourceRequest&& releaseResourceRequest() { return WTFMove(m_resourceRequest); }
54 const ResourceRequest& resourceRequest() const { return m_resourceRequest; }
55 const String& charset() const { return m_charset; }
56 void setCharset(const String& charset) { m_charset = charset; }
57 const ResourceLoaderOptions& options() const { return m_options; }
58 void setOptions(const ResourceLoaderOptions& options) { m_options = options; }
59 const std::optional<ResourceLoadPriority>& priority() const { return m_priority; }
60 void setInitiator(Element&);
61 void setInitiator(const AtomicString& name);
62 const AtomicString& initiatorName() const;
63 bool allowsCaching() const { return m_options.cachingPolicy == CachingPolicy::AllowCaching; }
64 void setCachingPolicy(CachingPolicy policy) { m_options.cachingPolicy = policy; }
66 // Whether this request should impact request counting and delay window.onload.
67 bool ignoreForRequestCount() const { return m_ignoreForRequestCount; }
68 void setIgnoreForRequestCount(bool ignoreForRequestCount) { m_ignoreForRequestCount = ignoreForRequestCount; }
70 void setAsPotentiallyCrossOrigin(const String&, Document&);
71 void updateForAccessControl(Document&);
73 void updateReferrerOriginAndUserAgentHeaders(FrameLoader&, ReferrerPolicy);
74 void upgradeInsecureRequestIfNeeded(Document&);
75 void setAcceptHeaderIfNone(CachedResource::Type);
76 void updateAccordingCacheMode();
77 void removeFragmentIdentifierIfNeeded();
78 #if ENABLE(CONTENT_EXTENSIONS)
79 void applyBlockedStatus(const ContentExtensions::BlockedStatus&);
81 void setDomainForCachePartition(Document&);
82 void setDomainForCachePartition(const String&);
83 bool isLinkPreload() const { return m_isLinkPreload; }
84 void setIsLinkPreload() { m_isLinkPreload = true; }
86 void setOrigin(Ref<SecurityOrigin>&& origin) { m_origin = WTFMove(origin); }
87 RefPtr<SecurityOrigin> releaseOrigin() { return WTFMove(m_origin); }
88 SecurityOrigin* origin() const { return m_origin.get(); }
90 String&& releaseFragmentIdentifier() { return WTFMove(m_fragmentIdentifier); }
91 void clearFragmentIdentifier() { m_fragmentIdentifier = { }; }
93 static String splitFragmentIdentifierFromRequestURL(ResourceRequest&);
96 ResourceRequest m_resourceRequest;
98 ResourceLoaderOptions m_options;
99 std::optional<ResourceLoadPriority> m_priority;
100 RefPtr<Element> m_initiatorElement;
101 AtomicString m_initiatorName;
102 RefPtr<SecurityOrigin> m_origin;
103 String m_fragmentIdentifier;
104 bool m_isLinkPreload { false };
105 bool m_ignoreForRequestCount { false };
108 void upgradeInsecureResourceRequestIfNeeded(ResourceRequest&, Document&);
110 } // namespace WebCore