1/* 2 * Copyright (C) 2014 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#include "config.h" 27#include "SessionState.h" 28 29#include "WebCoreArgumentCoders.h" 30 31namespace WebKit { 32 33void HTTPBody::Element::encode(IPC::ArgumentEncoder& encoder) const 34{ 35 encoder.encodeEnum(type); 36 encoder << data; 37 encoder << filePath; 38 encoder << fileStart; 39 encoder << fileLength; 40 encoder << expectedFileModificationTime; 41 encoder << blobURLString; 42} 43 44static bool isValidEnum(HTTPBody::Element::Type type) 45{ 46 switch (type) { 47 case HTTPBody::Element::Type::Data: 48 case HTTPBody::Element::Type::File: 49 case HTTPBody::Element::Type::Blob: 50 return true; 51 } 52 53 return false; 54} 55 56bool HTTPBody::Element::decode(IPC::ArgumentDecoder& decoder, Element& result) 57{ 58 if (!decoder.decodeEnum(result.type) || !isValidEnum(result.type)) 59 return false; 60 if (!decoder.decode(result.data)) 61 return false; 62 if (!decoder.decode(result.filePath)) 63 return false; 64 if (!decoder.decode(result.fileStart)) 65 return false; 66 if (!decoder.decode(result.fileLength)) 67 return false; 68 if (!decoder.decode(result.expectedFileModificationTime)) 69 return false; 70 if (!decoder.decode(result.blobURLString)) 71 return false; 72 73 return true; 74} 75 76void HTTPBody::encode(IPC::ArgumentEncoder& encoder) const 77{ 78 encoder << contentType; 79 encoder << elements; 80} 81 82bool HTTPBody::decode(IPC::ArgumentDecoder& decoder, HTTPBody& result) 83{ 84 if (!decoder.decode(result.contentType)) 85 return false; 86 if (!decoder.decode(result.elements)) 87 return false; 88 89 return true; 90} 91 92void FrameState::encode(IPC::ArgumentEncoder& encoder) const 93{ 94 encoder << urlString; 95 encoder << originalURLString; 96 encoder << referrer; 97 encoder << target; 98 99 encoder << documentState; 100 encoder << stateObjectData; 101 102 encoder << documentSequenceNumber; 103 encoder << itemSequenceNumber; 104 105 encoder << scrollPoint; 106 encoder << pageScaleFactor; 107 108 encoder << httpBody; 109 110#if PLATFORM(IOS) 111 encoder << exposedContentRect; 112 encoder << unobscuredContentRect; 113 encoder << minimumLayoutSizeInScrollViewCoordinates; 114 encoder << contentSize; 115 encoder << scaleIsInitial; 116#endif 117 118 encoder << children; 119} 120 121bool FrameState::decode(IPC::ArgumentDecoder& decoder, FrameState& result) 122{ 123 if (!decoder.decode(result.urlString)) 124 return false; 125 if (!decoder.decode(result.originalURLString)) 126 return false; 127 if (!decoder.decode(result.referrer)) 128 return false; 129 if (!decoder.decode(result.target)) 130 return false; 131 132 if (!decoder.decode(result.documentState)) 133 return false; 134 if (!decoder.decode(result.stateObjectData)) 135 return false; 136 137 if (!decoder.decode(result.documentSequenceNumber)) 138 return false; 139 if (!decoder.decode(result.itemSequenceNumber)) 140 return false; 141 142 if (!decoder.decode(result.scrollPoint)) 143 return false; 144 if (!decoder.decode(result.pageScaleFactor)) 145 return false; 146 147 if (!decoder.decode(result.httpBody)) 148 return false; 149 150#if PLATFORM(IOS) 151 if (!decoder.decode(result.exposedContentRect)) 152 return false; 153 if (!decoder.decode(result.unobscuredContentRect)) 154 return false; 155 if (!decoder.decode(result.minimumLayoutSizeInScrollViewCoordinates)) 156 return false; 157 if (!decoder.decode(result.contentSize)) 158 return false; 159 if (!decoder.decode(result.scaleIsInitial)) 160 return false; 161#endif 162 163 if (!decoder.decode(result.children)) 164 return false; 165 166 return true; 167} 168 169void PageState::encode(IPC::ArgumentEncoder& encoder) const 170{ 171 encoder << title; 172 encoder << mainFrameState; 173} 174 175bool PageState::decode(IPC::ArgumentDecoder& decoder, PageState& result) 176{ 177 if (!decoder.decode(result.title)) 178 return false; 179 if (!decoder.decode(result.mainFrameState)) 180 return false; 181 182 return true; 183} 184 185void BackForwardListItemState::encode(IPC::ArgumentEncoder& encoder) const 186{ 187 encoder << identifier; 188 encoder << pageState; 189} 190 191bool BackForwardListItemState::decode(IPC::ArgumentDecoder& decoder, BackForwardListItemState& result) 192{ 193 if (!decoder.decode(result.identifier)) 194 return false; 195 196 if (!decoder.decode(result.pageState)) 197 return false; 198 199 return true; 200} 201 202void BackForwardListState::encode(IPC::ArgumentEncoder& encoder) const 203{ 204 encoder << items; 205 encoder << currentIndex; 206} 207 208bool BackForwardListState::decode(IPC::ArgumentDecoder& decoder, BackForwardListState& result) 209{ 210 if (!decoder.decode(result.items)) 211 return false; 212 if (!decoder.decode(result.currentIndex)) 213 return false; 214 215 return true; 216} 217 218} // namespace WebKit 219