File indexing completed on 2023-05-30 09:09:56
0001 /* This file is part of the KDE project 0002 * 0003 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 0004 * 1999 Lars Knoll <knoll@kde.org> 0005 * 1999 Antti Koivisto <koivisto@kde.org> 0006 * 2000 Simon Hausmann <hausmann@kde.org> 0007 * 0008 * This library is free software; you can redistribute it and/or 0009 * modify it under the terms of the GNU Library General Public 0010 * License as published by the Free Software Foundation; either 0011 * version 2 of the License, or (at your option) any later version. 0012 * 0013 * This library is distributed in the hope that it will be useful, 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 * Library General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU Library General Public License 0019 * along with this library; see the file COPYING.LIB. If not, write to 0020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 * Boston, MA 02110-1301, USA. 0022 */ 0023 #include "khtml_run.h" 0024 #include "khtmlpart_p.h" 0025 #include <kio/job.h> 0026 #include "khtml_debug.h" 0027 #include <klocalizedstring.h> 0028 #include "khtml_ext.h" 0029 #include <QImage> 0030 0031 KHTMLRun::KHTMLRun(KHTMLPart *part, khtml::ChildFrame *child, const QUrl &url, 0032 const KParts::OpenUrlArguments &args, 0033 const KParts::BrowserArguments &browserArgs, 0034 bool hideErrorDialog) 0035 : KParts::BrowserRun(url, args, browserArgs, part, part->widget() ? part->widget()->topLevelWidget() : nullptr, 0036 false, false, hideErrorDialog), 0037 m_child(child) 0038 { 0039 // Don't use an external browser for parts of a webpage we are rendering. (iframes at least are one example) 0040 setEnableExternalBrowser(false); 0041 0042 // get the wheel to start spinning 0043 part->started(nullptr); 0044 } 0045 0046 //KHTMLPart *KHTMLRun::htmlPart() const 0047 //{ return static_cast<KHTMLPart *>(part()); } 0048 0049 void KHTMLRun::foundMimeType(const QString &_type) 0050 { 0051 //qCDebug(KHTML_LOG) << this << _type; 0052 Q_ASSERT(!hasFinished()); 0053 QString mimeType = _type; // this ref comes from the job, we lose it when using KIO again 0054 0055 bool requestProcessed = static_cast<KHTMLPart *>(part())->processObjectRequest(m_child, KRun::url(), mimeType); 0056 0057 if (requestProcessed) { 0058 setFinished(true); 0059 } else { 0060 if (hasFinished()) { // abort was called (this happens with the activex fallback for instance) 0061 return; 0062 } 0063 // Couldn't embed -> call BrowserRun::handleNonEmbeddable() 0064 KService::Ptr selectedService; 0065 KParts::BrowserRun::NonEmbeddableResult res = handleNonEmbeddable(mimeType, &selectedService); 0066 if (res == KParts::BrowserRun::Delayed) { 0067 return; 0068 } 0069 setFinished(res == KParts::BrowserRun::Handled); 0070 if (hasFinished()) { // saved or canceled -> flag completed 0071 m_child->m_bCompleted = true; 0072 static_cast<KHTMLPart *>(part())->checkCompleted(); 0073 } else { 0074 // "Open" selected, possible with a specific application 0075 if (selectedService) { 0076 KRun::setPreferredService(selectedService->desktopEntryName()); 0077 } else { 0078 KRun::displayOpenWithDialog(QList<QUrl>() << url(), part()->widget(), false /*tempfile*/, suggestedFileName()); 0079 setFinished(true); 0080 } 0081 } 0082 } 0083 0084 if (hasFinished()) { 0085 // qCDebug(KHTML_LOG) << "finished"; 0086 return; 0087 } 0088 0089 //qCDebug(KHTML_LOG) << _type << " couldn't open"; 0090 KRun::foundMimeType(mimeType); 0091 0092 // "open" is finished -> flag completed 0093 m_child->m_bCompleted = true; 0094 static_cast<KHTMLPart *>(part())->checkCompleted(); 0095 } 0096 0097 void KHTMLRun::handleError(KJob *) 0098 { 0099 // Tell KHTML that loading failed. 0100 static_cast<KHTMLPart *>(part())->processObjectRequest(m_child, QUrl(), QString()); 0101 setJob(nullptr); 0102 } 0103 0104 void KHTMLRun::save(const QUrl &url, const QString &suggestedFilename) 0105 { 0106 KHTMLPopupGUIClient::saveURL(part()->widget(), i18n("Save As"), url, arguments().metaData(), QString(), 0, suggestedFilename); 0107 } 0108