2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "FrameQtClient.h"
34 #include "FrameTree.h"
35 #include "ResourceHandle.h"
36 #include "LoaderFunctions.h"
37 #include "ResourceHandleInternal.h"
40 #include <kstdguiitem.h>
41 #include <kmessagebox.h>
42 #include <kinputdialog.h>
44 #include <QInputDialog>
45 #include <QMessageBox>
50 FrameQtClientDefault::FrameQtClientDefault()
52 , ResourceHandleClient()
54 , m_assignedMimetype(false)
58 FrameQtClientDefault::~FrameQtClientDefault()
62 void FrameQtClientDefault::setFrame(const FrameQt* frame)
65 m_frame = const_cast<FrameQt*>(frame);
68 void FrameQtClientDefault::openURL(const KURL& url)
72 m_frame->didOpenURL(url);
73 m_assignedMimetype = false;
75 if (!m_frame->document())
76 m_frame->createEmptyDocument();
78 ASSERT(m_frame->document());
80 ResourceRequest request(url);
81 RefPtr<ResourceHandle> loader = ResourceHandle::create(request, this, m_frame->document()->docLoader());
84 void FrameQtClientDefault::submitForm(const String& method, const KURL& url, const FormData* postData)
88 m_assignedMimetype = false;
90 ResourceRequest request(url);
91 request.setHTTPMethod(method);
92 request.setHTTPBody(*postData);
94 RefPtr<ResourceHandle> loader = ResourceHandle::create(request, this, m_frame->document() ? m_frame->document()->docLoader() : 0);
97 void FrameQtClientDefault::checkLoaded()
99 ASSERT(m_frame && m_frame->document() && m_frame->document()->docLoader());
101 // Recursively check the frame tree for open requests...
102 int num = numPendingOrLoadingRequests(true);
107 void FrameQtClientDefault::runJavaScriptAlert(String const& message)
110 KMessageBox::error(m_frame->view()->qwidget(), message, "JavaScript");
112 QMessageBox::warning(m_frame->view()->qwidget(), "JavaScript", message);
116 bool FrameQtClientDefault::runJavaScriptConfirm(const String& message)
119 return KMessageBox::warningYesNo(m_frame->view()->qwidget(), message,
120 "JavaScript", KStdGuiItem::ok(), KStdGuiItem::cancel())
123 return QMessageBox::warning(m_frame->view()->qwidget(), "JavaScript", message,
124 QMessageBox::Yes | QMessageBox::No)
129 bool FrameQtClientDefault::runJavaScriptPrompt(const String& message, const String& defaultValue, String& result)
133 result = KInputDialog::getText("JavaScript", message, defaultValue, &ok, m_frame->view()->qwidget());
135 result = QInputDialog::getText(m_frame->view()->qwidget(), "JavaScript", message,
136 QLineEdit::Normal, defaultValue, &ok);
142 bool FrameQtClientDefault::menubarVisible() const
147 bool FrameQtClientDefault::toolbarVisible() const
152 bool FrameQtClientDefault::statusbarVisible() const
157 bool FrameQtClientDefault::personalbarVisible() const
162 bool FrameQtClientDefault::locationbarVisible() const
167 void FrameQtClientDefault::loadFinished() const
172 void FrameQtClientDefault::receivedResponse(ResourceHandle*, PlatformResponse)
177 void FrameQtClientDefault::didReceiveData(ResourceHandle* job, const char* data, int length)
179 ResourceHandleInternal* d = job->getInternal();
182 if (!m_assignedMimetype) {
183 m_assignedMimetype = true;
185 // Assign correct mimetype _before_ calling begin()!
186 m_frame->setResponseMIMEType(d->m_mimetype);
189 // TODO: Allow user overrides of the encoding...
190 // This calls begin() for us, despite the misleading name
191 m_frame->setEncoding(d->m_charset, false);
193 // Feed with new data
194 m_frame->write(data, length);
197 FrameQt* FrameQtClientDefault::traverseNextFrameStayWithin(FrameQt* frame) const
199 return QtFrame(m_frame->tree()->traverseNext(frame));
202 static int numRequests(Document* document)
205 return cache()->loader()->numRequests(document->docLoader());
210 int FrameQtClientDefault::numPendingOrLoadingRequests(bool recurse) const
213 return numRequests(m_frame->document());
216 for (FrameQt* frame = m_frame; frame != 0; frame = traverseNextFrameStayWithin(frame))
217 num += numRequests(frame->document());
222 void FrameQtClientDefault::receivedAllData(ResourceHandle* job, PlatformData data)
227 m_assignedMimetype = false;