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 "WebDataSourceImpl.h"
     33 
     34 #include "ApplicationCacheHostInternal.h"
     35 #include "WebURL.h"
     36 #include "WebURLError.h"
     37 #include "WebVector.h"
     38 
     39 using namespace WebCore;
     40 
     41 namespace WebKit {
     42 
     43 WebPluginLoadObserver* WebDataSourceImpl::m_nextPluginLoadObserver = 0;
     44 
     45 PassRefPtr<WebDataSourceImpl> WebDataSourceImpl::create(const ResourceRequest& request, const SubstituteData& data)
     46 {
     47     return adoptRef(new WebDataSourceImpl(request, data));
     48 }
     49 
     50 const WebURLRequest& WebDataSourceImpl::originalRequest() const
     51 {
     52     m_originalRequestWrapper.bind(DocumentLoader::originalRequest());
     53     return m_originalRequestWrapper;
     54 }
     55 
     56 const WebURLRequest& WebDataSourceImpl::request() const
     57 {
     58     m_requestWrapper.bind(DocumentLoader::request());
     59     return m_requestWrapper;
     60 }
     61 
     62 const WebURLResponse& WebDataSourceImpl::response() const
     63 {
     64     m_responseWrapper.bind(DocumentLoader::response());
     65     return m_responseWrapper;
     66 }
     67 
     68 bool WebDataSourceImpl::hasUnreachableURL() const
     69 {
     70     return !DocumentLoader::unreachableURL().isEmpty();
     71 }
     72 
     73 WebURL WebDataSourceImpl::unreachableURL() const
     74 {
     75     return DocumentLoader::unreachableURL();
     76 }
     77 
     78 void WebDataSourceImpl::redirectChain(WebVector<WebURL>& result) const
     79 {
     80     result.assign(m_redirectChain);
     81 }
     82 
     83 WebString WebDataSourceImpl::pageTitle() const
     84 {
     85     // FIXME: use direction of title as well.
     86     return title().string();
     87 }
     88 
     89 WebNavigationType WebDataSourceImpl::navigationType() const
     90 {
     91     return toWebNavigationType(triggeringAction().type());
     92 }
     93 
     94 double WebDataSourceImpl::triggeringEventTime() const
     95 {
     96     if (!triggeringAction().event())
     97         return 0.0;
     98 
     99     // DOMTimeStamp uses units of milliseconds.
    100     return convertDOMTimeStampToSeconds(triggeringAction().event()->timeStamp());
    101 }
    102 
    103 WebDataSource::ExtraData* WebDataSourceImpl::extraData() const
    104 {
    105     return m_extraData.get();
    106 }
    107 
    108 void WebDataSourceImpl::setExtraData(ExtraData* extraData)
    109 {
    110     m_extraData.set(extraData);
    111 }
    112 
    113 WebApplicationCacheHost* WebDataSourceImpl::applicationCacheHost()
    114 {
    115 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
    116     return ApplicationCacheHostInternal::toWebApplicationCacheHost(DocumentLoader::applicationCacheHost());
    117 #else
    118     return 0;
    119 #endif
    120 }
    121 
    122 void WebDataSourceImpl::setDeferMainResourceDataLoad(bool defer)
    123 {
    124     DocumentLoader::setDeferMainResourceDataLoad(defer);
    125 }
    126 
    127 WebNavigationType WebDataSourceImpl::toWebNavigationType(NavigationType type)
    128 {
    129     switch (type) {
    130     case NavigationTypeLinkClicked:
    131         return WebNavigationTypeLinkClicked;
    132     case NavigationTypeFormSubmitted:
    133         return WebNavigationTypeFormSubmitted;
    134     case NavigationTypeBackForward:
    135         return WebNavigationTypeBackForward;
    136     case NavigationTypeReload:
    137         return WebNavigationTypeReload;
    138     case NavigationTypeFormResubmitted:
    139         return WebNavigationTypeFormResubmitted;
    140     case NavigationTypeOther:
    141     default:
    142         return WebNavigationTypeOther;
    143     }
    144 }
    145 
    146 const KURL& WebDataSourceImpl::endOfRedirectChain() const
    147 {
    148     ASSERT(!m_redirectChain.isEmpty());
    149     return m_redirectChain.last();
    150 }
    151 
    152 void WebDataSourceImpl::clearRedirectChain()
    153 {
    154     m_redirectChain.clear();
    155 }
    156 
    157 void WebDataSourceImpl::appendRedirect(const KURL& url)
    158 {
    159     m_redirectChain.append(url);
    160 }
    161 
    162 void WebDataSourceImpl::setNextPluginLoadObserver(PassOwnPtr<WebPluginLoadObserver> observer)
    163 {
    164     // This call should always be followed up with the creation of a
    165     // WebDataSourceImpl, so we should never leak this object.
    166     m_nextPluginLoadObserver = observer.leakPtr();
    167 }
    168 
    169 WebDataSourceImpl::WebDataSourceImpl(const ResourceRequest& request, const SubstituteData& data)
    170     : DocumentLoader(request, data)
    171 {
    172     if (m_nextPluginLoadObserver) {
    173         // When a new frame is created, it initially gets a data source for an
    174         // empty document.  Then it is navigated to the source URL of the
    175         // frame, which results in a second data source being created.  We want
    176         // to wait to attach the WebPluginLoadObserver to that data source.
    177         if (!request.url().isEmpty()) {
    178             ASSERT(m_nextPluginLoadObserver->url() == WebURL(request.url()));
    179             m_pluginLoadObserver.set(m_nextPluginLoadObserver);
    180             m_nextPluginLoadObserver = 0;
    181         }
    182     }
    183 }
    184 
    185 WebDataSourceImpl::~WebDataSourceImpl()
    186 {
    187 }
    188 
    189 } // namespace WebKit
    190