1/* 2 * Copyright (C) 2005, 2006, 2008, 2011 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 COMPUTER, 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 COMPUTER, 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. 24 */ 25 26#include "config.h" 27#include "core/loader/HistoryItem.h" 28 29#include "core/dom/Document.h" 30#include "core/html/forms/FormController.h" 31#include "platform/network/ResourceRequest.h" 32#include "wtf/CurrentTime.h" 33#include "wtf/text/CString.h" 34 35namespace blink { 36 37static long long generateSequenceNumber() 38{ 39 // Initialize to the current time to reduce the likelihood of generating 40 // identifiers that overlap with those from past/future browser sessions. 41 static long long next = static_cast<long long>(currentTime() * 1000000.0); 42 return ++next; 43} 44 45HistoryItem::HistoryItem() 46 : m_pageScaleFactor(0) 47 , m_itemSequenceNumber(generateSequenceNumber()) 48 , m_documentSequenceNumber(generateSequenceNumber()) 49 , m_frameSequenceNumber(generateSequenceNumber()) 50{ 51} 52 53HistoryItem::~HistoryItem() 54{ 55} 56 57void HistoryItem::generateNewItemSequenceNumber() 58{ 59 m_itemSequenceNumber = generateSequenceNumber(); 60} 61 62void HistoryItem::generateNewDocumentSequenceNumber() 63{ 64 m_documentSequenceNumber = generateSequenceNumber(); 65} 66 67const String& HistoryItem::urlString() const 68{ 69 return m_urlString; 70} 71 72KURL HistoryItem::url() const 73{ 74 return KURL(ParsedURLString, m_urlString); 75} 76 77const Referrer& HistoryItem::referrer() const 78{ 79 return m_referrer; 80} 81 82const String& HistoryItem::target() const 83{ 84 return m_target; 85} 86 87void HistoryItem::setURLString(const String& urlString) 88{ 89 if (m_urlString != urlString) 90 m_urlString = urlString; 91} 92 93void HistoryItem::setURL(const KURL& url) 94{ 95 setURLString(url.string()); 96} 97 98void HistoryItem::setReferrer(const Referrer& referrer) 99{ 100 m_referrer = referrer; 101} 102 103void HistoryItem::setTarget(const String& target) 104{ 105 m_target = target; 106} 107 108const FloatPoint& HistoryItem::pinchViewportScrollPoint() const 109{ 110 return m_pinchViewportScrollPoint; 111} 112 113void HistoryItem::setPinchViewportScrollPoint(const FloatPoint& point) 114{ 115 m_pinchViewportScrollPoint = point; 116} 117 118const IntPoint& HistoryItem::scrollPoint() const 119{ 120 return m_scrollPoint; 121} 122 123void HistoryItem::setScrollPoint(const IntPoint& point) 124{ 125 m_scrollPoint = point; 126} 127 128void HistoryItem::clearScrollPoint() 129{ 130 m_scrollPoint = IntPoint(); 131 m_pinchViewportScrollPoint = FloatPoint(); 132} 133 134float HistoryItem::pageScaleFactor() const 135{ 136 return m_pageScaleFactor; 137} 138 139void HistoryItem::setPageScaleFactor(float scaleFactor) 140{ 141 m_pageScaleFactor = scaleFactor; 142} 143 144void HistoryItem::setDocumentState(const Vector<String>& state) 145{ 146 ASSERT(!m_documentState); 147 m_documentStateVector = state; 148} 149 150void HistoryItem::setDocumentState(DocumentState* state) 151{ 152 m_documentState = state; 153} 154 155const Vector<String>& HistoryItem::documentState() 156{ 157 if (m_documentState) 158 m_documentStateVector = m_documentState->toStateVector(); 159 return m_documentStateVector; 160} 161 162Vector<String> HistoryItem::getReferencedFilePaths() 163{ 164 return FormController::getReferencedFilePaths(documentState()); 165} 166 167void HistoryItem::clearDocumentState() 168{ 169 m_documentState.clear(); 170 m_documentStateVector.clear(); 171} 172 173void HistoryItem::setStateObject(PassRefPtr<SerializedScriptValue> object) 174{ 175 m_stateObject = object; 176} 177 178const AtomicString& HistoryItem::formContentType() const 179{ 180 return m_formContentType; 181} 182 183void HistoryItem::setFormInfoFromRequest(const ResourceRequest& request) 184{ 185 if (equalIgnoringCase(request.httpMethod(), "POST")) { 186 // FIXME: Eventually we have to make this smart enough to handle the case where 187 // we have a stream for the body to handle the "data interspersed with files" feature. 188 m_formData = request.httpBody(); 189 m_formContentType = request.httpContentType(); 190 } else { 191 m_formData = nullptr; 192 m_formContentType = nullAtom; 193 } 194} 195 196void HistoryItem::setFormData(PassRefPtr<FormData> formData) 197{ 198 m_formData = formData; 199} 200 201void HistoryItem::setFormContentType(const AtomicString& formContentType) 202{ 203 m_formContentType = formContentType; 204} 205 206FormData* HistoryItem::formData() 207{ 208 return m_formData.get(); 209} 210 211bool HistoryItem::isCurrentDocument(Document* doc) const 212{ 213 // FIXME: We should find a better way to check if this is the current document. 214 return equalIgnoringFragmentIdentifier(url(), doc->url()); 215} 216 217} // namespace blink 218 219