• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/dom/Document.h"
36 #include "core/loader/FrameLoader.h"
37 #include "public/platform/WebURL.h"
38 #include "public/platform/WebURLError.h"
39 #include "public/platform/WebVector.h"
40 
41 using namespace WebCore;
42 
43 namespace blink {
44 
nextPluginLoadObserver()45 static OwnPtr<WebPluginLoadObserver>& nextPluginLoadObserver()
46 {
47     DEFINE_STATIC_LOCAL(OwnPtr<WebPluginLoadObserver>, nextPluginLoadObserver, ());
48     return nextPluginLoadObserver;
49 }
50 
create(const ResourceRequest & request,const SubstituteData & data)51 PassRefPtr<WebDataSourceImpl> WebDataSourceImpl::create(const ResourceRequest& request, const SubstituteData& data)
52 {
53     return adoptRef(new WebDataSourceImpl(request, data));
54 }
55 
originalRequest() const56 const WebURLRequest& WebDataSourceImpl::originalRequest() const
57 {
58     m_originalRequestWrapper.bind(DocumentLoader::originalRequest());
59     return m_originalRequestWrapper;
60 }
61 
request() const62 const WebURLRequest& WebDataSourceImpl::request() const
63 {
64     m_requestWrapper.bind(DocumentLoader::request());
65     return m_requestWrapper;
66 }
67 
response() const68 const WebURLResponse& WebDataSourceImpl::response() const
69 {
70     m_responseWrapper.bind(DocumentLoader::response());
71     return m_responseWrapper;
72 }
73 
hasUnreachableURL() const74 bool WebDataSourceImpl::hasUnreachableURL() const
75 {
76     return !DocumentLoader::unreachableURL().isEmpty();
77 }
78 
unreachableURL() const79 WebURL WebDataSourceImpl::unreachableURL() const
80 {
81     return DocumentLoader::unreachableURL();
82 }
83 
appendRedirect(const WebURL & url)84 void WebDataSourceImpl::appendRedirect(const WebURL& url)
85 {
86     DocumentLoader::appendRedirect(url);
87 }
88 
redirectChain(WebVector<WebURL> & result) const89 void WebDataSourceImpl::redirectChain(WebVector<WebURL>& result) const
90 {
91     result.assign(m_redirectChain);
92 }
93 
isClientRedirect() const94 bool WebDataSourceImpl::isClientRedirect() const
95 {
96     return DocumentLoader::isClientRedirect();
97 }
98 
replacesCurrentHistoryItem() const99 bool WebDataSourceImpl::replacesCurrentHistoryItem() const
100 {
101     return DocumentLoader::replacesCurrentHistoryItem();
102 }
103 
navigationType() const104 WebNavigationType WebDataSourceImpl::navigationType() const
105 {
106     return toWebNavigationType(triggeringAction().type());
107 }
108 
triggeringEventTime() const109 double WebDataSourceImpl::triggeringEventTime() const
110 {
111     if (!triggeringAction().event())
112         return 0.0;
113 
114     // DOMTimeStamp uses units of milliseconds.
115     return convertDOMTimeStampToSeconds(triggeringAction().event()->timeStamp());
116 }
117 
extraData() const118 WebDataSource::ExtraData* WebDataSourceImpl::extraData() const
119 {
120     return m_extraData.get();
121 }
122 
setExtraData(ExtraData * extraData)123 void WebDataSourceImpl::setExtraData(ExtraData* extraData)
124 {
125     // extraData can't be a PassOwnPtr because setExtraData is a WebKit API function.
126     m_extraData = adoptPtr(extraData);
127 }
128 
applicationCacheHost()129 WebApplicationCacheHost* WebDataSourceImpl::applicationCacheHost()
130 {
131     return ApplicationCacheHostInternal::toWebApplicationCacheHost(DocumentLoader::applicationCacheHost());
132 }
133 
setDeferMainResourceDataLoad(bool defer)134 void WebDataSourceImpl::setDeferMainResourceDataLoad(bool defer)
135 {
136     DocumentLoader::setDeferMainResourceDataLoad(defer);
137 }
138 
setNavigationStartTime(double navigationStart)139 void WebDataSourceImpl::setNavigationStartTime(double navigationStart)
140 {
141     timing()->setNavigationStart(navigationStart);
142 }
143 
toWebNavigationType(NavigationType type)144 WebNavigationType WebDataSourceImpl::toWebNavigationType(NavigationType type)
145 {
146     switch (type) {
147     case NavigationTypeLinkClicked:
148         return WebNavigationTypeLinkClicked;
149     case NavigationTypeFormSubmitted:
150         return WebNavigationTypeFormSubmitted;
151     case NavigationTypeBackForward:
152         return WebNavigationTypeBackForward;
153     case NavigationTypeReload:
154         return WebNavigationTypeReload;
155     case NavigationTypeFormResubmitted:
156         return WebNavigationTypeFormResubmitted;
157     case NavigationTypeOther:
158     default:
159         return WebNavigationTypeOther;
160     }
161 }
162 
setNextPluginLoadObserver(PassOwnPtr<WebPluginLoadObserver> observer)163 void WebDataSourceImpl::setNextPluginLoadObserver(PassOwnPtr<WebPluginLoadObserver> observer)
164 {
165     nextPluginLoadObserver() = observer;
166 }
167 
WebDataSourceImpl(const ResourceRequest & request,const SubstituteData & data)168 WebDataSourceImpl::WebDataSourceImpl(const ResourceRequest& request, const SubstituteData& data)
169     : DocumentLoader(request, data)
170 {
171     if (!nextPluginLoadObserver())
172         return;
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         return;
179 
180     ASSERT(nextPluginLoadObserver()->url() == WebURL(request.url()));
181     m_pluginLoadObserver = nextPluginLoadObserver().release();
182 }
183 
~WebDataSourceImpl()184 WebDataSourceImpl::~WebDataSourceImpl()
185 {
186 }
187 
188 } // namespace blink
189