| 1 | /* |
| 2 | * Copyright (C) 2014-2018 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 | #include "ViewSnapshotStore.h" |
| 29 | #include <WebCore/BackForwardItemIdentifier.h> |
| 30 | #include <WebCore/FloatRect.h> |
| 31 | #include <WebCore/FrameLoaderTypes.h> |
| 32 | #include <WebCore/IntRect.h> |
| 33 | #include <WebCore/SerializedScriptValue.h> |
| 34 | #include <wtf/Optional.h> |
| 35 | #include <wtf/URL.h> |
| 36 | #include <wtf/Vector.h> |
| 37 | #include <wtf/text/WTFString.h> |
| 38 | |
| 39 | namespace IPC { |
| 40 | class Decoder; |
| 41 | class Encoder; |
| 42 | } |
| 43 | |
| 44 | namespace WebKit { |
| 45 | |
| 46 | bool isValidEnum(WebCore::ShouldOpenExternalURLsPolicy); |
| 47 | |
| 48 | struct HTTPBody { |
| 49 | struct Element { |
| 50 | void encode(IPC::Encoder&) const; |
| 51 | static Optional<Element> decode(IPC::Decoder&); |
| 52 | |
| 53 | enum class Type { |
| 54 | Data, |
| 55 | File, |
| 56 | Blob, |
| 57 | }; |
| 58 | |
| 59 | // FIXME: This should be a Variant. It's also unclear why we don't just use FormDataElement here. |
| 60 | Type type = Type::Data; |
| 61 | |
| 62 | // Data. |
| 63 | Vector<char> data; |
| 64 | |
| 65 | // File. |
| 66 | String filePath; |
| 67 | int64_t fileStart; |
| 68 | Optional<int64_t> fileLength; |
| 69 | Optional<WallTime> expectedFileModificationTime; |
| 70 | |
| 71 | // Blob. |
| 72 | String blobURLString; |
| 73 | }; |
| 74 | |
| 75 | void encode(IPC::Encoder&) const; |
| 76 | static bool decode(IPC::Decoder&, HTTPBody&); |
| 77 | |
| 78 | String contentType; |
| 79 | Vector<Element> elements; |
| 80 | }; |
| 81 | |
| 82 | struct FrameState { |
| 83 | void encode(IPC::Encoder&) const; |
| 84 | static Optional<FrameState> decode(IPC::Decoder&); |
| 85 | |
| 86 | String urlString; |
| 87 | String originalURLString; |
| 88 | String referrer; |
| 89 | String target; |
| 90 | |
| 91 | Vector<String> documentState; |
| 92 | Optional<Vector<uint8_t>> stateObjectData; |
| 93 | |
| 94 | int64_t documentSequenceNumber { 0 }; |
| 95 | int64_t itemSequenceNumber { 0 }; |
| 96 | |
| 97 | WebCore::IntPoint scrollPosition; |
| 98 | bool shouldRestoreScrollPosition { true }; |
| 99 | float pageScaleFactor { 0 }; |
| 100 | |
| 101 | Optional<HTTPBody> httpBody; |
| 102 | |
| 103 | // FIXME: These should not be per frame. |
| 104 | #if PLATFORM(IOS_FAMILY) |
| 105 | WebCore::FloatRect exposedContentRect; |
| 106 | WebCore::IntRect unobscuredContentRect; |
| 107 | WebCore::FloatSize minimumLayoutSizeInScrollViewCoordinates; |
| 108 | WebCore::IntSize contentSize; |
| 109 | bool scaleIsInitial { false }; |
| 110 | WebCore::FloatBoxExtent obscuredInsets; |
| 111 | #endif |
| 112 | |
| 113 | Vector<FrameState> children; |
| 114 | }; |
| 115 | |
| 116 | struct PageState { |
| 117 | void encode(IPC::Encoder&) const; |
| 118 | static bool decode(IPC::Decoder&, PageState&); |
| 119 | |
| 120 | String title; |
| 121 | FrameState mainFrameState; |
| 122 | WebCore::ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy { WebCore::ShouldOpenExternalURLsPolicy::ShouldNotAllow }; |
| 123 | RefPtr<WebCore::SerializedScriptValue> sessionStateObject; |
| 124 | }; |
| 125 | |
| 126 | struct BackForwardListItemState { |
| 127 | void encode(IPC::Encoder&) const; |
| 128 | static Optional<BackForwardListItemState> decode(IPC::Decoder&); |
| 129 | |
| 130 | WebCore::BackForwardItemIdentifier identifier; |
| 131 | |
| 132 | PageState pageState; |
| 133 | #if PLATFORM(COCOA) || PLATFORM(GTK) |
| 134 | RefPtr<ViewSnapshot> snapshot; |
| 135 | #endif |
| 136 | }; |
| 137 | |
| 138 | struct BackForwardListState { |
| 139 | void encode(IPC::Encoder&) const; |
| 140 | static Optional<BackForwardListState> decode(IPC::Decoder&); |
| 141 | |
| 142 | Vector<BackForwardListItemState> items; |
| 143 | Optional<uint32_t> currentIndex; |
| 144 | }; |
| 145 | |
| 146 | struct SessionState { |
| 147 | BackForwardListState backForwardListState; |
| 148 | uint64_t renderTreeSize; |
| 149 | URL provisionalURL; |
| 150 | }; |
| 151 | |
| 152 | } // namespace WebKit |
| 153 | |