Home | History | Annotate | Download | only in web
      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 "public/web/WebHistoryItem.h"
     33 
     34 #include "bindings/v8/SerializedScriptValue.h"
     35 #include "core/loader/HistoryItem.h"
     36 #include "platform/network/FormData.h"
     37 #include "platform/weborigin/KURL.h"
     38 #include "public/platform/WebFloatPoint.h"
     39 #include "public/platform/WebHTTPBody.h"
     40 #include "public/platform/WebPoint.h"
     41 #include "public/platform/WebString.h"
     42 #include "public/platform/WebVector.h"
     43 #include "public/web/WebSerializedScriptValue.h"
     44 #include "wtf/text/StringHash.h"
     45 
     46 using namespace WebCore;
     47 
     48 namespace blink {
     49 
     50 void WebHistoryItem::initialize()
     51 {
     52     m_private = HistoryItem::create();
     53 }
     54 
     55 void WebHistoryItem::reset()
     56 {
     57     m_private.reset();
     58 }
     59 
     60 void WebHistoryItem::assign(const WebHistoryItem& other)
     61 {
     62     m_private = other.m_private;
     63 }
     64 
     65 WebString WebHistoryItem::urlString() const
     66 {
     67     return m_private->urlString();
     68 }
     69 
     70 void WebHistoryItem::setURLString(const WebString& url)
     71 {
     72     m_private->setURLString(KURL(ParsedURLString, url).string());
     73 }
     74 
     75 WebString WebHistoryItem::referrer() const
     76 {
     77     return m_private->referrer().referrer;
     78 }
     79 
     80 WebReferrerPolicy WebHistoryItem::referrerPolicy() const
     81 {
     82     return static_cast<WebReferrerPolicy>(m_private->referrer().referrerPolicy);
     83 }
     84 
     85 void WebHistoryItem::setReferrer(const WebString& referrer, WebReferrerPolicy referrerPolicy)
     86 {
     87     m_private->setReferrer(Referrer(referrer, static_cast<ReferrerPolicy>(referrerPolicy)));
     88 }
     89 
     90 WebString WebHistoryItem::target() const
     91 {
     92     return m_private->target();
     93 }
     94 
     95 void WebHistoryItem::setTarget(const WebString& target)
     96 {
     97     m_private->setTarget(target);
     98 }
     99 
    100 WebFloatPoint WebHistoryItem::pinchViewportScrollOffset() const
    101 {
    102     return m_private->pinchViewportScrollPoint();
    103 }
    104 
    105 void WebHistoryItem::setPinchViewportScrollOffset(const WebFloatPoint& scrollOffset)
    106 {
    107     m_private->setPinchViewportScrollPoint(scrollOffset);
    108 }
    109 
    110 WebPoint WebHistoryItem::scrollOffset() const
    111 {
    112     return m_private->scrollPoint();
    113 }
    114 
    115 void WebHistoryItem::setScrollOffset(const WebPoint& scrollOffset)
    116 {
    117     m_private->setScrollPoint(scrollOffset);
    118 }
    119 
    120 float WebHistoryItem::pageScaleFactor() const
    121 {
    122     return m_private->pageScaleFactor();
    123 }
    124 
    125 void WebHistoryItem::setPageScaleFactor(float scale)
    126 {
    127     m_private->setPageScaleFactor(scale);
    128 }
    129 
    130 WebVector<WebString> WebHistoryItem::documentState() const
    131 {
    132     return m_private->documentState();
    133 }
    134 
    135 void WebHistoryItem::setDocumentState(const WebVector<WebString>& state)
    136 {
    137     // FIXME: would be nice to avoid the intermediate copy
    138     Vector<String> ds;
    139     for (size_t i = 0; i < state.size(); ++i)
    140         ds.append(state[i]);
    141     m_private->setDocumentState(ds);
    142 }
    143 
    144 long long WebHistoryItem::itemSequenceNumber() const
    145 {
    146     return m_private->itemSequenceNumber();
    147 }
    148 
    149 void WebHistoryItem::setItemSequenceNumber(long long itemSequenceNumber)
    150 {
    151     m_private->setItemSequenceNumber(itemSequenceNumber);
    152 }
    153 
    154 long long WebHistoryItem::documentSequenceNumber() const
    155 {
    156     return m_private->documentSequenceNumber();
    157 }
    158 
    159 void WebHistoryItem::setDocumentSequenceNumber(long long documentSequenceNumber)
    160 {
    161     m_private->setDocumentSequenceNumber(documentSequenceNumber);
    162 }
    163 
    164 WebSerializedScriptValue WebHistoryItem::stateObject() const
    165 {
    166     return WebSerializedScriptValue(m_private->stateObject());
    167 }
    168 
    169 void WebHistoryItem::setStateObject(const WebSerializedScriptValue& object)
    170 {
    171     m_private->setStateObject(object);
    172 }
    173 
    174 WebString WebHistoryItem::httpContentType() const
    175 {
    176     return m_private->formContentType();
    177 }
    178 
    179 void WebHistoryItem::setHTTPContentType(const WebString& httpContentType)
    180 {
    181     m_private->setFormContentType(httpContentType);
    182 }
    183 
    184 WebHTTPBody WebHistoryItem::httpBody() const
    185 {
    186     return WebHTTPBody(m_private->formData());
    187 }
    188 
    189 void WebHistoryItem::setHTTPBody(const WebHTTPBody& httpBody)
    190 {
    191     m_private->setFormData(httpBody);
    192 }
    193 
    194 WebVector<WebString> WebHistoryItem::getReferencedFilePaths() const
    195 {
    196     HashSet<String> filePaths;
    197     const FormData* formData = m_private->formData();
    198     if (formData) {
    199         for (size_t i = 0; i < formData->elements().size(); ++i) {
    200             const FormDataElement& element = formData->elements()[i];
    201             if (element.m_type == FormDataElement::encodedFile)
    202                 filePaths.add(element.m_filename);
    203         }
    204     }
    205 
    206     const Vector<String>& referencedFilePaths = m_private->getReferencedFilePaths();
    207     for (size_t i = 0; i < referencedFilePaths.size(); ++i)
    208         filePaths.add(referencedFilePaths[i]);
    209 
    210     Vector<String> results;
    211     copyToVector(filePaths, results);
    212     return results;
    213 }
    214 
    215 WebHistoryItem::WebHistoryItem(const PassRefPtr<HistoryItem>& item)
    216     : m_private(item)
    217 {
    218 }
    219 
    220 WebHistoryItem& WebHistoryItem::operator=(const PassRefPtr<HistoryItem>& item)
    221 {
    222     m_private = item;
    223     return *this;
    224 }
    225 
    226 WebHistoryItem::operator PassRefPtr<HistoryItem>() const
    227 {
    228     return m_private.get();
    229 }
    230 
    231 } // namespace blink
    232