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