Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / WebDataSourceImpl.cpp
blob4b7bbd809aaca47d0c081cdfee0d344e455127a2
1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
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.
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.
31 #include "config.h"
32 #include "web/WebDataSourceImpl.h"
34 #include "core/dom/Document.h"
35 #include "public/platform/WebURL.h"
36 #include "public/platform/WebURLError.h"
37 #include "public/platform/WebVector.h"
39 namespace blink {
41 static OwnPtr<WebPluginLoadObserver>& nextPluginLoadObserver()
43 DEFINE_STATIC_LOCAL(OwnPtr<WebPluginLoadObserver>, nextPluginLoadObserver, ());
44 return nextPluginLoadObserver;
47 PassRefPtrWillBeRawPtr<WebDataSourceImpl> WebDataSourceImpl::create(LocalFrame* frame, const ResourceRequest& request, const SubstituteData& data)
49 return adoptRefWillBeNoop(new WebDataSourceImpl(frame, request, data));
52 const WebURLRequest& WebDataSourceImpl::originalRequest() const
54 m_originalRequestWrapper.bind(DocumentLoader::originalRequest());
55 return m_originalRequestWrapper;
58 const WebURLRequest& WebDataSourceImpl::request() const
60 m_requestWrapper.bind(DocumentLoader::request());
61 return m_requestWrapper;
64 const WebURLResponse& WebDataSourceImpl::response() const
66 m_responseWrapper.bind(DocumentLoader::response());
67 return m_responseWrapper;
70 bool WebDataSourceImpl::hasUnreachableURL() const
72 return !DocumentLoader::unreachableURL().isEmpty();
75 WebURL WebDataSourceImpl::unreachableURL() const
77 return DocumentLoader::unreachableURL();
80 void WebDataSourceImpl::appendRedirect(const WebURL& url)
82 DocumentLoader::appendRedirect(url);
85 void WebDataSourceImpl::redirectChain(WebVector<WebURL>& result) const
87 result.assign(m_redirectChain);
90 bool WebDataSourceImpl::isClientRedirect() const
92 return DocumentLoader::isClientRedirect();
95 bool WebDataSourceImpl::replacesCurrentHistoryItem() const
97 return DocumentLoader::replacesCurrentHistoryItem();
100 WebNavigationType WebDataSourceImpl::navigationType() const
102 return toWebNavigationType(DocumentLoader::navigationType());
105 WebDataSource::ExtraData* WebDataSourceImpl::extraData() const
107 return m_extraData.get();
110 void WebDataSourceImpl::setExtraData(ExtraData* extraData)
112 // extraData can't be a PassOwnPtr because setExtraData is a WebKit API function.
113 m_extraData = adoptPtr(extraData);
116 void WebDataSourceImpl::setNavigationStartTime(double navigationStart)
118 timing().setNavigationStart(navigationStart);
121 WebNavigationType WebDataSourceImpl::toWebNavigationType(NavigationType type)
123 switch (type) {
124 case NavigationTypeLinkClicked:
125 return WebNavigationTypeLinkClicked;
126 case NavigationTypeFormSubmitted:
127 return WebNavigationTypeFormSubmitted;
128 case NavigationTypeBackForward:
129 return WebNavigationTypeBackForward;
130 case NavigationTypeReload:
131 return WebNavigationTypeReload;
132 case NavigationTypeFormResubmitted:
133 return WebNavigationTypeFormResubmitted;
134 case NavigationTypeOther:
135 default:
136 return WebNavigationTypeOther;
140 void WebDataSourceImpl::setNextPluginLoadObserver(PassOwnPtr<WebPluginLoadObserver> observer)
142 nextPluginLoadObserver() = observer;
145 WebDataSourceImpl::WebDataSourceImpl(LocalFrame* frame, const ResourceRequest& request, const SubstituteData& data)
146 : DocumentLoader(frame, request, data)
148 if (!nextPluginLoadObserver())
149 return;
150 // When a new frame is created, it initially gets a data source for an
151 // empty document. Then it is navigated to the source URL of the
152 // frame, which results in a second data source being created. We want
153 // to wait to attach the WebPluginLoadObserver to that data source.
154 if (request.url().isEmpty())
155 return;
157 ASSERT(nextPluginLoadObserver()->url() == WebURL(request.url()));
158 m_pluginLoadObserver = nextPluginLoadObserver().release();
161 WebDataSourceImpl::~WebDataSourceImpl()
163 // Verify that detachFromFrame() has been called.
164 ASSERT(!m_extraData);
167 void WebDataSourceImpl::detachFromFrame()
169 RefPtrWillBeRawPtr<DocumentLoader> protect(this);
171 DocumentLoader::detachFromFrame();
172 m_extraData.clear();
173 m_pluginLoadObserver.clear();
176 DEFINE_TRACE(WebDataSourceImpl)
178 DocumentLoader::trace(visitor);
181 } // namespace blink