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