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     return title();
     86 }
     87 
     88 WebNavigationType WebDataSourceImpl::navigationType() const
     89 {
     90     return toWebNavigationType(triggeringAction().type());
     91 }
     92 
     93 double WebDataSourceImpl::triggeringEventTime() const
     94 {
     95     if (!triggeringAction().event())
     96         return 0.0;
     97 
     98     // DOMTimeStamp uses units of milliseconds.
     99     return triggeringAction().event()->timeStamp() / 1000.0;
    100 }
    101 
    102 WebDataSource::ExtraData* WebDataSourceImpl::extraData() const
    103 {
    104     return m_extraData.get();
    105 }
    106 
    107 void WebDataSourceImpl::setExtraData(ExtraData* extraData)
    108 {
    109     m_extraData.set(extraData);
    110 }
    111 
    112 WebApplicationCacheHost* WebDataSourceImpl::applicationCacheHost() {
    113 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
    114     return ApplicationCacheHostInternal::toWebApplicationCacheHost(DocumentLoader::applicationCacheHost());
    115 #else
    116     return 0;
    117 #endif
    118 }
    119 
    120 WebNavigationType WebDataSourceImpl::toWebNavigationType(NavigationType type)
    121 {
    122     switch (type) {
    123     case NavigationTypeLinkClicked:
    124         return WebNavigationTypeLinkClicked;
    125     case NavigationTypeFormSubmitted:
    126         return WebNavigationTypeFormSubmitted;
    127     case NavigationTypeBackForward:
    128         return WebNavigationTypeBackForward;
    129     case NavigationTypeReload:
    130         return WebNavigationTypeReload;
    131     case NavigationTypeFormResubmitted:
    132         return WebNavigationTypeFormResubmitted;
    133     case NavigationTypeOther:
    134     default:
    135         return WebNavigationTypeOther;
    136     }
    137 }
    138 
    139 const KURL& WebDataSourceImpl::endOfRedirectChain() const
    140 {
    141     ASSERT(!m_redirectChain.isEmpty());
    142     return m_redirectChain.last();
    143 }
    144 
    145 void WebDataSourceImpl::clearRedirectChain()
    146 {
    147     m_redirectChain.clear();
    148 }
    149 
    150 void WebDataSourceImpl::appendRedirect(const KURL& url)
    151 {
    152     m_redirectChain.append(url);
    153 }
    154 
    155 void WebDataSourceImpl::setNextPluginLoadObserver(PassOwnPtr<WebPluginLoadObserver> observer)
    156 {
    157     // This call should always be followed up with the creation of a
    158     // WebDataSourceImpl, so we should never leak this object.
    159     m_nextPluginLoadObserver = observer.release();
    160 }
    161 
    162 WebDataSourceImpl::WebDataSourceImpl(const ResourceRequest& request, const SubstituteData& data)
    163     : DocumentLoader(request, data)
    164 {
    165     if (m_nextPluginLoadObserver) {
    166         // When a new frame is created, it initially gets a data source for an
    167         // empty document.  Then it is navigated to the source URL of the
    168         // frame, which results in a second data source being created.  We want
    169         // to wait to attach the WebPluginLoadObserver to that data source.
    170         if (!request.url().isEmpty()) {
    171             ASSERT(m_nextPluginLoadObserver->url() == request.url());
    172             m_pluginLoadObserver.set(m_nextPluginLoadObserver);
    173             m_nextPluginLoadObserver = 0;
    174         }
    175     }
    176 }
    177 
    178 WebDataSourceImpl::~WebDataSourceImpl()
    179 {
    180 }
    181 
    182 } // namespace WebKit
    183