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