2
* Copyright (C) 2010, 2011 Apple 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
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
* THE POSSIBILITY OF SUCH DAMAGE.
27
#include "WebFrameProxy.h"
29
#include "WebCertificateInfo.h"
30
#include "WebContext.h"
31
#include "WebFormSubmissionListenerProxy.h"
32
#include "WebFramePolicyListenerProxy.h"
33
#include "WebPageMessages.h"
34
#include "WebPageProxy.h"
35
#include <WebCore/DOMImplementation.h>
36
#include <WebCore/Image.h>
38
#include <wtf/text/WTFString.h>
40
using namespace WebCore;
45
WebFrameProxy::WebFrameProxy(WebPageProxy* page, uint64_t frameID)
49
, m_previousSibling(0)
52
, m_loadState(LoadStateFinished)
56
WebContext::statistics().wkFrameCount++;
59
WebFrameProxy::~WebFrameProxy()
61
WebContext::statistics().wkFrameCount--;
64
void WebFrameProxy::disconnect()
69
m_previousSibling = 0;
73
if (m_activeListener) {
74
m_activeListener->invalidate();
79
bool WebFrameProxy::isMainFrame() const
84
return this == m_page->mainFrame();
87
void WebFrameProxy::stopLoading() const
92
if (!m_page->isValid())
95
m_page->process()->send(Messages::WebPage::StopLoadingFrame(m_frameID), m_page->pageID());
98
bool WebFrameProxy::canProvideSource() const
100
return isDisplayingMarkupDocument();
103
bool WebFrameProxy::canShowMIMEType(const String& mimeType) const
108
if (m_page->canShowMIMEType(mimeType))
112
// On Mac, we can show PDFs.
113
if (!mimeType.isEmpty())
114
return WebContext::pdfAndPostScriptMIMETypes().contains(mimeType) && !WebContext::omitPDFSupport();
120
bool WebFrameProxy::isDisplayingStandaloneImageDocument() const
122
return Image::supportsType(m_MIMEType);
125
bool WebFrameProxy::isDisplayingMarkupDocument() const
127
// FIXME: This check should be moved to somewhere in WebCore.
128
// FIXME: This returns false when displaying a web archive.
129
return m_MIMEType == "text/html" || m_MIMEType == "image/svg+xml" || DOMImplementation::isXMLMIMEType(m_MIMEType);
132
bool WebFrameProxy::isDisplayingPDFDocument() const
134
if (m_MIMEType.isEmpty())
137
return WebContext::pdfAndPostScriptMIMETypes().contains(m_MIMEType);
140
void WebFrameProxy::didStartProvisionalLoad(const String& url)
142
ASSERT(m_loadState == LoadStateFinished);
143
ASSERT(m_provisionalURL.isEmpty());
144
m_loadState = LoadStateProvisional;
145
m_provisionalURL = url;
148
void WebFrameProxy::didReceiveServerRedirectForProvisionalLoad(const String& url)
150
ASSERT(m_loadState == LoadStateProvisional);
151
m_provisionalURL = url;
154
void WebFrameProxy::didFailProvisionalLoad()
156
ASSERT(m_loadState == LoadStateProvisional);
157
m_loadState = LoadStateFinished;
158
m_provisionalURL = String();
159
m_unreachableURL = m_lastUnreachableURL;
162
void WebFrameProxy::didCommitLoad(const String& contentType, const PlatformCertificateInfo& certificateInfo)
164
ASSERT(m_loadState == LoadStateProvisional);
165
m_loadState = LoadStateCommitted;
166
m_url = m_provisionalURL;
167
m_provisionalURL = String();
169
m_MIMEType = contentType;
170
m_isFrameSet = false;
171
m_certificateInfo = WebCertificateInfo::create(certificateInfo);
174
void WebFrameProxy::didFinishLoad()
176
ASSERT(m_loadState == LoadStateCommitted);
177
ASSERT(m_provisionalURL.isEmpty());
178
m_loadState = LoadStateFinished;
181
void WebFrameProxy::didFailLoad()
183
ASSERT(m_loadState == LoadStateCommitted);
184
ASSERT(m_provisionalURL.isEmpty());
185
m_loadState = LoadStateFinished;
189
void WebFrameProxy::didSameDocumentNavigation(const String& url)
194
void WebFrameProxy::didChangeTitle(const String& title)
199
void WebFrameProxy::appendChild(WebFrameProxy* child)
201
ASSERT(child->page() == page());
202
ASSERT(!child->m_parentFrame);
203
ASSERT(!child->m_nextSibling);
204
ASSERT(!child->m_previousSibling);
206
child->m_parentFrame = this;
208
WebFrameProxy* oldLast = m_lastChild;
212
ASSERT(!oldLast->m_nextSibling);
213
child->m_previousSibling = oldLast;
214
oldLast->m_nextSibling = child;
216
m_firstChild = child;
219
void WebFrameProxy::removeChild(WebFrameProxy* child)
221
child->m_parentFrame = 0;
223
WebFrameProxy*& newLocationForNext = m_firstChild == child ? m_firstChild : child->m_previousSibling->m_nextSibling;
224
WebFrameProxy*& newLocationForPrevious = m_lastChild == child ? m_lastChild : child->m_nextSibling->m_previousSibling;
225
swap(newLocationForNext, child->m_nextSibling);
226
swap(newLocationForPrevious, child->m_previousSibling);
227
child->m_previousSibling = 0;
228
child->m_nextSibling = 0;
231
bool WebFrameProxy::isDescendantOf(const WebFrameProxy* ancestor) const
236
if (m_page != ancestor->m_page)
239
for (const WebFrameProxy* frame = this; frame; frame = frame->m_parentFrame) {
240
if (frame == ancestor)
247
void WebFrameProxy::dumpFrameTreeToSTDOUT(unsigned indent)
249
if (!indent && m_parentFrame)
250
printf("NOTE: Printing subtree.\n");
252
for (unsigned i = 0; i < indent; ++i)
254
printf("| FRAME %d %s\n", (int)m_frameID, m_url.utf8().data());
256
for (WebFrameProxy* child = m_firstChild; child; child = child->m_nextSibling)
257
child->dumpFrameTreeToSTDOUT(indent + 4);
260
void WebFrameProxy::didRemoveFromHierarchy()
263
m_parentFrame->removeChild(this);
266
PassRefPtr<ImmutableArray> WebFrameProxy::childFrames()
269
return ImmutableArray::create();
271
Vector<RefPtr<APIObject> > vector;
272
for (WebFrameProxy* child = m_firstChild; child; child = child->m_nextSibling)
273
vector.append(child);
275
return ImmutableArray::adopt(vector);
278
void WebFrameProxy::receivedPolicyDecision(WebCore::PolicyAction action, uint64_t listenerID)
283
ASSERT(m_activeListener);
284
ASSERT(m_activeListener->listenerID() == listenerID);
285
m_page->receivedPolicyDecision(action, this, listenerID);
288
WebFramePolicyListenerProxy* WebFrameProxy::setUpPolicyListenerProxy(uint64_t listenerID)
290
if (m_activeListener)
291
m_activeListener->invalidate();
292
m_activeListener = WebFramePolicyListenerProxy::create(this, listenerID);
293
return static_cast<WebFramePolicyListenerProxy*>(m_activeListener.get());
296
WebFormSubmissionListenerProxy* WebFrameProxy::setUpFormSubmissionListenerProxy(uint64_t listenerID)
298
if (m_activeListener)
299
m_activeListener->invalidate();
300
m_activeListener = WebFormSubmissionListenerProxy::create(this, listenerID);
301
return static_cast<WebFormSubmissionListenerProxy*>(m_activeListener.get());
304
void WebFrameProxy::getWebArchive(PassRefPtr<DataCallback> callback)
307
callback->invalidate();
311
m_page->getWebArchiveOfFrame(this, callback);
314
void WebFrameProxy::getMainResourceData(PassRefPtr<DataCallback> callback)
317
callback->invalidate();
321
m_page->getMainResourceDataOfFrame(this, callback);
324
void WebFrameProxy::getResourceData(WebURL* resourceURL, PassRefPtr<DataCallback> callback)
327
callback->invalidate();
331
m_page->getResourceDataFromFrame(this, resourceURL, callback);
334
void WebFrameProxy::setUnreachableURL(const String& unreachableURL)
336
m_lastUnreachableURL = m_unreachableURL;
337
m_unreachableURL = unreachableURL;
340
} // namespace WebKit