| 1 | /* |
| 2 | * Copyright (C) 2015 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 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. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION) |
| 29 | |
| 30 | #include "NetworkCacheStorage.h" |
| 31 | #include <WebCore/ResourceRequest.h> |
| 32 | #include <wtf/HashMap.h> |
| 33 | #include <wtf/URL.h> |
| 34 | |
| 35 | namespace WebKit { |
| 36 | namespace NetworkCache { |
| 37 | |
| 38 | class SubresourceInfo { |
| 39 | WTF_MAKE_FAST_ALLOCATED; |
| 40 | public: |
| 41 | void encode(WTF::Persistence::Encoder&) const; |
| 42 | static bool decode(WTF::Persistence::Decoder&, SubresourceInfo&); |
| 43 | |
| 44 | SubresourceInfo() = default; |
| 45 | SubresourceInfo(const Key&, const WebCore::ResourceRequest&, const SubresourceInfo* previousInfo); |
| 46 | |
| 47 | const Key& key() const { return m_key; } |
| 48 | WallTime lastSeen() const { return m_lastSeen; } |
| 49 | WallTime firstSeen() const { return m_firstSeen; } |
| 50 | |
| 51 | bool isTransient() const { return m_isTransient; } |
| 52 | const URL& firstPartyForCookies() const { ASSERT(!m_isTransient); return m_firstPartyForCookies; } |
| 53 | const WebCore::HTTPHeaderMap& () const { ASSERT(!m_isTransient); return m_requestHeaders; } |
| 54 | WebCore::ResourceLoadPriority priority() const { ASSERT(!m_isTransient); return m_priority; } |
| 55 | |
| 56 | bool isSameSite() const { ASSERT(!m_isTransient); return m_isSameSite; } |
| 57 | bool isTopSite() const { return false; } |
| 58 | |
| 59 | void setNonTransient() { m_isTransient = false; } |
| 60 | |
| 61 | private: |
| 62 | Key m_key; |
| 63 | WallTime m_lastSeen; |
| 64 | WallTime m_firstSeen; |
| 65 | bool m_isTransient { false }; |
| 66 | bool m_isSameSite { false }; |
| 67 | URL m_firstPartyForCookies; |
| 68 | WebCore::HTTPHeaderMap ; |
| 69 | WebCore::ResourceLoadPriority m_priority; |
| 70 | }; |
| 71 | |
| 72 | struct SubresourceLoad { |
| 73 | WTF_MAKE_NONCOPYABLE(SubresourceLoad); WTF_MAKE_FAST_ALLOCATED; |
| 74 | public: |
| 75 | SubresourceLoad(const WebCore::ResourceRequest& request, const Key& key) |
| 76 | : request(request) |
| 77 | , key(key) |
| 78 | { } |
| 79 | |
| 80 | WebCore::ResourceRequest request; |
| 81 | Key key; |
| 82 | }; |
| 83 | |
| 84 | class SubresourcesEntry { |
| 85 | WTF_MAKE_NONCOPYABLE(SubresourcesEntry); WTF_MAKE_FAST_ALLOCATED; |
| 86 | public: |
| 87 | SubresourcesEntry(Key&&, const Vector<std::unique_ptr<SubresourceLoad>>&); |
| 88 | explicit SubresourcesEntry(const Storage::Record&); |
| 89 | |
| 90 | Storage::Record encodeAsStorageRecord() const; |
| 91 | static std::unique_ptr<SubresourcesEntry> decodeStorageRecord(const Storage::Record&); |
| 92 | |
| 93 | const Key& key() const { return m_key; } |
| 94 | WallTime timeStamp() const { return m_timeStamp; } |
| 95 | const Vector<SubresourceInfo>& subresources() const { return m_subresources; } |
| 96 | |
| 97 | void updateSubresourceLoads(const Vector<std::unique_ptr<SubresourceLoad>>&); |
| 98 | |
| 99 | private: |
| 100 | Key m_key; |
| 101 | WallTime m_timeStamp; |
| 102 | Vector<SubresourceInfo> m_subresources; |
| 103 | }; |
| 104 | |
| 105 | } // namespace WebKit |
| 106 | } // namespace NetworkCache |
| 107 | |
| 108 | #endif // ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION) |
| 109 | |