• 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 "web/WebDataSourceImpl.h"
33 
34 #include "core/dom/Document.h"
35 #include "public/platform/WebURL.h"
36 #include "public/platform/WebURLError.h"
37 #include "public/platform/WebVector.h"
38 
39 namespace blink {
40 
nextPluginLoadObserver()41 static OwnPtr<WebPluginLoadObserver>& nextPluginLoadObserver()
42 {
43     DEFINE_STATIC_LOCAL(OwnPtr<WebPluginLoadObserver>, nextPluginLoadObserver, ());
44     return nextPluginLoadObserver;
45 }
46 
create(LocalFrame * frame,const ResourceRequest & request,const SubstituteData & data)47 PassRefPtr<WebDataSourceImpl> WebDataSourceImpl::create(LocalFrame* frame, const ResourceRequest& request, const SubstituteData& data)
48 {
49     return adoptRef(new WebDataSourceImpl(frame, request, data));
50 }
51 
originalRequest() const52 const WebURLRequest& WebDataSourceImpl::originalRequest() const
53 {
54     m_originalRequestWrapper.bind(DocumentLoader::originalRequest());
55     return m_originalRequestWrapper;
56 }
57 
request() const58 const WebURLRequest& WebDataSourceImpl::request() const
59 {
60     m_requestWrapper.bind(DocumentLoader::request());
61     return m_requestWrapper;
62 }
63 
response() const64 const WebURLResponse& WebDataSourceImpl::response() const
65 {
66     m_responseWrapper.bind(DocumentLoader::response());
67     return m_responseWrapper;
68 }
69 
hasUnreachableURL() const70 bool WebDataSourceImpl::hasUnreachableURL() const
71 {
72     return !DocumentLoader::unreachableURL().isEmpty();
73 }
74 
unreachableURL() const75 WebURL WebDataSourceImpl::unreachableURL() const
76 {
77     return DocumentLoader::unreachableURL();
78 }
79 
appendRedirect(const WebURL & url)80 void WebDataSourceImpl::appendRedirect(const WebURL& url)
81 {
82     DocumentLoader::appendRedirect(url);
83 }
84 
redirectChain(WebVector<WebURL> & result) const85 void WebDataSourceImpl::redirectChain(WebVector<WebURL>& result) const
86 {
87     result.assign(m_redirectChain);
88 }
89 
isClientRedirect() const90 bool WebDataSourceImpl::isClientRedirect() const
91 {
92     return DocumentLoader::isClientRedirect();
93 }
94 
replacesCurrentHistoryItem() const95 bool WebDataSourceImpl::replacesCurrentHistoryItem() const
96 {
97     return DocumentLoader::replacesCurrentHistoryItem();
98 }
99 
navigationType() const100 WebNavigationType WebDataSourceImpl::navigationType() const
101 {
102     return toWebNavigationType(triggeringAction().type());
103 }
104 
triggeringEventTime() const105 double WebDataSourceImpl::triggeringEventTime() const
106 {
107     // DOMTimeStamp uses units of milliseconds.
108     return convertDOMTimeStampToSeconds(triggeringAction().eventTimeStamp());
109 }
110 
extraData() const111 WebDataSource::ExtraData* WebDataSourceImpl::extraData() const
112 {
113     return m_extraData.get();
114 }
115 
setExtraData(ExtraData * extraData)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 
setNavigationStartTime(double navigationStart)122 void WebDataSourceImpl::setNavigationStartTime(double navigationStart)
123 {
124     timing()->setNavigationStart(navigationStart);
125 }
126 
toWebNavigationType(NavigationType type)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 
setNextPluginLoadObserver(PassOwnPtr<WebPluginLoadObserver> observer)146 void WebDataSourceImpl::setNextPluginLoadObserver(PassOwnPtr<WebPluginLoadObserver> observer)
147 {
148     nextPluginLoadObserver() = observer;
149 }
150 
WebDataSourceImpl(LocalFrame * frame,const ResourceRequest & request,const SubstituteData & data)151 WebDataSourceImpl::WebDataSourceImpl(LocalFrame* frame, const ResourceRequest& request, const SubstituteData& data)
152     : DocumentLoader(frame, request, data)
153 {
154     if (!nextPluginLoadObserver())
155         return;
156     // When a new frame is created, it initially gets a data source for an
157     // empty document. Then it is navigated to the source URL of the
158     // frame, which results in a second data source being created. We want
159     // to wait to attach the WebPluginLoadObserver to that data source.
160     if (request.url().isEmpty())
161         return;
162 
163     ASSERT(nextPluginLoadObserver()->url() == WebURL(request.url()));
164     m_pluginLoadObserver = nextPluginLoadObserver().release();
165 }
166 
~WebDataSourceImpl()167 WebDataSourceImpl::~WebDataSourceImpl()
168 {
169 }
170 
171 } // namespace blink
172