Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2009 Google 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 are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include "config.h"
     32 #include "WebHistoryItem.h"
     33 
     34 #include "FormData.h"
     35 #include "HistoryItem.h"
     36 #include "KURL.h"
     37 
     38 #include "WebHTTPBody.h"
     39 #include "WebPoint.h"
     40 #include "WebSerializedScriptValue.h"
     41 #include "WebString.h"
     42 #include "WebVector.h"
     43 
     44 using namespace WebCore;
     45 
     46 namespace WebKit {
     47 
     48 void WebHistoryItem::initialize()
     49 {
     50     m_private = HistoryItem::create();
     51 }
     52 
     53 void WebHistoryItem::reset()
     54 {
     55     m_private.reset();
     56 }
     57 
     58 void WebHistoryItem::assign(const WebHistoryItem& other)
     59 {
     60     m_private = other.m_private;
     61 }
     62 
     63 WebString WebHistoryItem::urlString() const
     64 {
     65     return m_private->urlString();
     66 }
     67 
     68 void WebHistoryItem::setURLString(const WebString& url)
     69 {
     70     ensureMutable();
     71     m_private->setURLString(KURL(ParsedURLString, url).string());
     72 }
     73 
     74 WebString WebHistoryItem::originalURLString() const
     75 {
     76     return m_private->originalURLString();
     77 }
     78 
     79 void WebHistoryItem::setOriginalURLString(const WebString& originalURLString)
     80 {
     81     ensureMutable();
     82     m_private->setOriginalURLString(originalURLString);
     83 }
     84 
     85 WebString WebHistoryItem::referrer() const
     86 {
     87     return m_private->referrer();
     88 }
     89 
     90 void WebHistoryItem::setReferrer(const WebString& referrer)
     91 {
     92     ensureMutable();
     93     m_private->setReferrer(referrer);
     94 }
     95 
     96 WebString WebHistoryItem::target() const
     97 {
     98     return m_private->target();
     99 }
    100 
    101 void WebHistoryItem::setTarget(const WebString& target)
    102 {
    103     ensureMutable();
    104     m_private->setTarget(target);
    105 }
    106 
    107 WebString WebHistoryItem::parent() const
    108 {
    109     return m_private->parent();
    110 }
    111 
    112 void WebHistoryItem::setParent(const WebString& parent)
    113 {
    114     ensureMutable();
    115     m_private->setParent(parent);
    116 }
    117 
    118 WebString WebHistoryItem::title() const
    119 {
    120     return m_private->title();
    121 }
    122 
    123 void WebHistoryItem::setTitle(const WebString& title)
    124 {
    125     ensureMutable();
    126     m_private->setTitle(title);
    127 }
    128 
    129 WebString WebHistoryItem::alternateTitle() const
    130 {
    131     return m_private->alternateTitle();
    132 }
    133 
    134 void WebHistoryItem::setAlternateTitle(const WebString& alternateTitle)
    135 {
    136     ensureMutable();
    137     m_private->setAlternateTitle(alternateTitle);
    138 }
    139 
    140 double WebHistoryItem::lastVisitedTime() const
    141 {
    142     return m_private->lastVisitedTime();
    143 }
    144 
    145 void WebHistoryItem::setLastVisitedTime(double lastVisitedTime)
    146 {
    147     ensureMutable();
    148     // FIXME: setLastVisitedTime increments the visit count, so we have to
    149     // correct for that.  Instead, we should have a back-door to just mutate
    150     // the last visited time directly.
    151     int count = m_private->visitCount();
    152     m_private->setLastVisitedTime(lastVisitedTime);
    153     m_private->setVisitCount(count);
    154 }
    155 
    156 WebPoint WebHistoryItem::scrollOffset() const
    157 {
    158     return m_private->scrollPoint();
    159 }
    160 
    161 void WebHistoryItem::setScrollOffset(const WebPoint& scrollOffset)
    162 {
    163     ensureMutable();
    164     m_private->setScrollPoint(scrollOffset);
    165 }
    166 
    167 bool WebHistoryItem::isTargetItem() const
    168 {
    169     return m_private->isTargetItem();
    170 }
    171 
    172 void WebHistoryItem::setIsTargetItem(bool isTargetItem)
    173 {
    174     ensureMutable();
    175     m_private->setIsTargetItem(isTargetItem);
    176 }
    177 
    178 int WebHistoryItem::visitCount() const
    179 {
    180     return m_private->visitCount();
    181 }
    182 
    183 void WebHistoryItem::setVisitCount(int count)
    184 {
    185     ensureMutable();
    186     m_private->setVisitCount(count);
    187 }
    188 
    189 WebVector<WebString> WebHistoryItem::documentState() const
    190 {
    191     return m_private->documentState();
    192 }
    193 
    194 void WebHistoryItem::setDocumentState(const WebVector<WebString>& state)
    195 {
    196     ensureMutable();
    197     // FIXME: would be nice to avoid the intermediate copy
    198     Vector<String> ds;
    199     for (size_t i = 0; i < state.size(); ++i)
    200         ds.append(state[i]);
    201     m_private->setDocumentState(ds);
    202 }
    203 
    204 long long WebHistoryItem::itemSequenceNumber() const
    205 {
    206     return m_private->itemSequenceNumber();
    207 }
    208 
    209 void WebHistoryItem::setItemSequenceNumber(long long itemSequenceNumber)
    210 {
    211     ensureMutable();
    212     m_private->setItemSequenceNumber(itemSequenceNumber);
    213 }
    214 
    215 long long WebHistoryItem::documentSequenceNumber() const
    216 {
    217     return m_private->documentSequenceNumber();
    218 }
    219 
    220 void WebHistoryItem::setDocumentSequenceNumber(long long documentSequenceNumber)
    221 {
    222     ensureMutable();
    223     m_private->setDocumentSequenceNumber(documentSequenceNumber);
    224 }
    225 
    226 WebSerializedScriptValue WebHistoryItem::stateObject() const
    227 {
    228     return WebSerializedScriptValue(m_private->stateObject());
    229 }
    230 
    231 void WebHistoryItem::setStateObject(const WebSerializedScriptValue& object)
    232 {
    233     ensureMutable();
    234     m_private->setStateObject(object);
    235 }
    236 
    237 WebString WebHistoryItem::httpContentType() const
    238 {
    239     return m_private->formContentType();
    240 }
    241 
    242 void WebHistoryItem::setHTTPContentType(const WebString& httpContentType)
    243 {
    244     ensureMutable();
    245     m_private->setFormContentType(httpContentType);
    246 }
    247 
    248 WebHTTPBody WebHistoryItem::httpBody() const
    249 {
    250     return WebHTTPBody(m_private->formData());
    251 }
    252 
    253 void WebHistoryItem::setHTTPBody(const WebHTTPBody& httpBody)
    254 {
    255     ensureMutable();
    256     m_private->setFormData(httpBody);
    257 }
    258 
    259 WebVector<WebHistoryItem> WebHistoryItem::children() const
    260 {
    261     return m_private->children();
    262 }
    263 
    264 void WebHistoryItem::setChildren(const WebVector<WebHistoryItem>& items)
    265 {
    266     ensureMutable();
    267     m_private->clearChildren();
    268     for (size_t i = 0; i < items.size(); ++i)
    269         m_private->addChildItem(items[i]);
    270 }
    271 
    272 void WebHistoryItem::appendToChildren(const WebHistoryItem& item)
    273 {
    274     ensureMutable();
    275     m_private->addChildItem(item);
    276 }
    277 
    278 WebHistoryItem::WebHistoryItem(const PassRefPtr<HistoryItem>& item)
    279     : m_private(item)
    280 {
    281 }
    282 
    283 WebHistoryItem& WebHistoryItem::operator=(const PassRefPtr<HistoryItem>& item)
    284 {
    285     m_private = item;
    286     return *this;
    287 }
    288 
    289 WebHistoryItem::operator PassRefPtr<HistoryItem>() const
    290 {
    291     return m_private.get();
    292 }
    293 
    294 void WebHistoryItem::ensureMutable()
    295 {
    296     if (!m_private->hasOneRef())
    297         m_private = m_private->copy();
    298 }
    299 
    300 } // namespace WebKit
    301