Commit 500ae91a authored by Stefano Crocco's avatar Stefano Crocco Committed by David Faure
Browse files

Ensure that m_mimeType and the mimetype stored in m_request are the same and clear comments

parent c0552eff
......@@ -526,9 +526,7 @@ void KonqMainWindow::openUrl(KonqView *_view, const QUrl &_url,
QUrl url(_url);
QString mimeType(_mimeType);
KonqOpenURLRequest req(_req);
qDebug() << "VIEW" << _view;
//TODO Remove KonqRun: what's the difference between mimeType and req.args.mimeType? which should be used by UrlLoader?
if (mimeType.isEmpty()) {
mimeType = req.args.mimeType();
}
......@@ -554,7 +552,6 @@ void KonqMainWindow::openUrl(KonqView *_view, const QUrl &_url,
}
KonqView *view = _view;
qDebug() << "ORIGINAL VIEW" << view << "VIEW URL" << (view ? view->url() : QUrl());
UrlLoader *loader = new UrlLoader(this, view, url, mimeType, req, trustedSource, false);
connect(loader, &UrlLoader::finished, this, &KonqMainWindow::urlLoaderFinished);
......@@ -586,7 +583,6 @@ void KonqMainWindow::openUrl(KonqView *_view, const QUrl &_url,
}
}
loader->setView(view);
qDebug() << "VIEW" << loader->view();
loader->setOldLocationBarUrl(oldLocationBarURL);
if (!loader->isReady()) {
......@@ -610,188 +606,10 @@ void KonqMainWindow::openUrl(KonqView *_view, const QUrl &_url,
}
}
loader->goOn();
//Remove KonqRun: replaced by UrlLoader::viewForUrl
#if 0
// When clicking a 'follow active' view (e.g. view is the sidebar),
// open the URL in the active view
if (view && view->isFollowActive()) {
view = m_currentView;
}
if (!view && !req.browserArgs.newTab()) {
view = m_currentView; /* Note, this can be 0, e.g. on startup */
} else if (!view && req.browserArgs.newTab()) {
// The URL should be opened in a new tab. Let's create the tab right away,
// it gives faster user feedback (#163628). For a short while (kde-4.1-beta1)
// I removed this entire block so that we wouldn't end up with a useless tab when
// launching an external application for this mimetype. But user feedback
// in all cases is more important than empty tabs in some cases.
view = m_pViewManager->addTab(QStringLiteral("text/html"),
QString(),
false,
req.openAfterCurrentPage);
if (view) {
view->setCaption(i18nc("@title:tab", "Loading..."));
view->setLocationBarURL(_url);
if (!req.browserArgs.frameName.isEmpty()) {
view->setViewName(req.browserArgs.frameName); // #44961
}
if (req.newTabInFront) {
m_pViewManager->showTab(view);
}
updateViewActions(); //A new tab created -- we may need to enable the "remove tab" button (#56318)
} else {
req.browserArgs.setNewTab(false);
}
}
const QString oldLocationBarURL = locationBarURL();
if (view) {
if (view == m_currentView) {
//will do all the stuff below plus GUI stuff
abortLoading();
} else {
view->stop();
// Don't change location bar if not current view
}
}
// Fast mode for local files: do the stat ourselves instead of letting OpenUrlJob do it.
if (mimeType.isEmpty() && url.isLocalFile()) {
QMimeDatabase db;
mimeType = db.mimeTypeForFile(url.toLocalFile()).name();
}
const bool hasMimeType = (!mimeType.isEmpty() && mimeType != QLatin1String("application/octet-stream"));
KService::Ptr offer;
bool associatedAppIsKonqueror = false;
if (hasMimeType) {
offer = KMimeTypeTrader::self()->preferredService(mimeType, QStringLiteral("Application"));
associatedAppIsKonqueror = isMimeTypeAssociatedWithSelf(mimeType, offer);
// If the associated app is konqueror itself, then make sure we try to embed before bailing out.
if (associatedAppIsKonqueror) {
req.forceAutoEmbed = true;
}
}
//qCDebug(KONQUEROR_LOG) << "trying openView for" << url << "( mimeType" << mimeType << ")";
if (hasMimeType || KonqUrl::isValidNotBlank(url)) {
req.args.metaData().insert("urlRequestedByApp", QString());
// Built-in view ?
if (!openView(mimeType, url, view /* can be 0 */, req)) {
//qCDebug(KONQUEROR_LOG) << "openView returned false";
#endif
//TODO: Remove KonqRun: is this needed?
#if 0
// Are we following another view ? Then forget about this URL. Otherwise fire app.
if (!req.followMode) {
#endif
#if 0
//qCDebug(KONQUEROR_LOG) << "we were not following. Fire app.";
// The logic below is similar to BrowserRun::handleNonEmbeddable(),
// but we don't have a BrowserRun instance here, and since it uses
// some virtual methods [like save, for KHTMLRun], we can't just
// move all the logic to static methods... catch 22...
if (!url.isLocalFile() && !trustedSource && KonqRun::isTextExecutable(mimeType)) {
mimeType = QStringLiteral("text/plain"); // view, don't execute
}
// Remote URL: save or open ?
QString protClass = KProtocolInfo::protocolClass(url.scheme());
bool open = url.isLocalFile() || protClass == QLatin1String(":local") || KProtocolInfo::isHelperProtocol(url);
if (!open) {
KParts::BrowserOpenOrSaveQuestion dlg(this, url, mimeType);
dlg.setFeatures(KParts::BrowserOpenOrSaveQuestion::ServiceSelection);
const KParts::BrowserOpenOrSaveQuestion::Result res = dlg.askOpenOrSave();
if (res == KParts::BrowserOpenOrSaveQuestion::Save) {
KParts::BrowserRun::saveUrl(url, QString(), this, req.args);
}
open = (res == KParts::BrowserOpenOrSaveQuestion::Open);
if (open) {
offer = dlg.selectedService();
}
}
if (open) {
if (associatedAppIsKonqueror && refuseExecutingKonqueror(mimeType)) {
return;
}
//qCDebug(KONQUEROR_LOG) << "Got offer" << (offer ? offer->name() : QString("0"));
const bool allowExecution = trustedSource || KParts::BrowserRun::allowExecution(mimeType, url);
if (allowExecution) {
const bool isExecutable = KonqRun::isExecutable(mimeType);
if (isExecutable) {
setLocationBarURL(oldLocationBarURL); // Revert to previous locationbar URL
KIO::OpenUrlJob *job = new KIO::OpenUrlJob(url);
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
job->setShowOpenOrExecuteDialog(true);
job->start();
} else {
// If offer is null, it means the user clicked on "Open With..." button.
KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(offer);
job->setUrls({url});
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
if (req.tempFile) {
job->setRunFlags(KIO::ApplicationLauncherJob::DeleteTemporaryFiles);
}
job->start();
}
}
}
}
}
} else { // no known mimeType, use KonqRun
const bool hasMimeType = (!mimeType.isEmpty() && mimeType != QLatin1String("application/octet-stream"));
if (!hasMimeType) {
bool earlySetLocationBarURL = false;
if (!view && !m_currentView) { // no view yet, e.g. starting with url as argument
earlySetLocationBarURL = true;
} else if (view == m_currentView && view->url().isEmpty()) { // opening in current view
earlySetLocationBarURL = true;
}
if (req.browserArgs.newTab()) { // it's going into a new tab anyway
earlySetLocationBarURL = false;
}
if (earlySetLocationBarURL) {
// Show it for now in the location bar, but we'll need to store it in the view
// later on (can't do it yet since either view == 0 or updateHistoryEntry will be called).
qCDebug(KONQUEROR_LOG) << "url=" << url;
setLocationBarURL(url);
}
if (view == m_currentView) {
startAnimation();
}
}
qCDebug(KONQUEROR_LOG) << "Creating new konqrun for" << url << "req.typedUrl=" << req.typedUrl;
KonqRun *run = new KonqRun(this, view /* can be 0 */, url, req, trustedSource);
// Never start in external browser
run->setEnableExternalBrowser(false);
if (view) {
view->setRun(run);
}
if (view == m_currentView) {
startAnimation();
}
connect(run, &KonqRun::finished, this, &KonqMainWindow::slotRunFinished);
}
#endif
}
void KonqMainWindow::urlLoaderFinished(UrlLoader* loader)
{
//TODO Remove KonqRun: see whether this is still necessary
/*
if (!run->mailtoURL().isEmpty()) {
QDesktopServices::openUrl(run->mailtoURL());
}
*/
//TODO Remove KonqRun: see which of the things below only need to be done if loader->isAsync. In the original code,
//this function (slotRunFinished) was only called when using a KonqRun but now it's always called.
......@@ -803,7 +621,6 @@ void KonqMainWindow::urlLoaderFinished(UrlLoader* loader)
}
KonqView *childView = loader->view();
qDebug() << "VIEW" << childView;
// Check if we found a mimetype _and_ we got no error (example: cancel in openwith dialog)
if (!loader->mimeType().isEmpty() && !loader->hasError()) {
......@@ -870,7 +687,7 @@ static QString preferredService(KonqView *currentView, const QString &mimeType)
return QString();
}
//TODO Remove KonqRun: some of this becomes redundant, at least when called via UrlLoader. Can this be avoided?
//TODO After removing KonqRun: some of this becomes redundant, at least when called via UrlLoader. Can this be avoided?
bool KonqMainWindow::openView(QString mimeType, const QUrl &_url, KonqView *childView, const KonqOpenURLRequest &req)
{
// Second argument is referring URL
......@@ -890,6 +707,7 @@ bool KonqMainWindow::openView(QString mimeType, const QUrl &_url, KonqView *chil
// if (UrlLoader::isExecutable(mimeType)) {
// return false; // execute, don't open
// }
// Contract: the caller of this method should ensure the view is stopped first.
#ifndef NDEBUG
......@@ -937,13 +755,6 @@ bool KonqMainWindow::openView(QString mimeType, const QUrl &_url, KonqView *chil
QString serviceName = req.serviceName; // default: none provided
//Force use of WebEnginePart when opening a konq: URL. If the user chose a different
//default HTML engine, they would get an error because they don't know how to handle
//such scheme. As a workaround, in this case we force the use of WebEnginePart
// if (KonqUrl::hasKonqScheme(url)) {
// serviceName = "webenginepart";
// }
const QString urlStr = url.url();
if (KonqUrl::isValidNotBlank(urlStr)) {
mimeType = QStringLiteral("text/html");
......
......@@ -95,7 +95,6 @@ void UrlLoader::start()
} else {
detectSettingsForRemoteFiles();
}
qDebug()<< m_url << m_mimeType;
if (!m_mimeType.isEmpty()) {
KService::Ptr preferredService = KApplicationTrader::preferredService(m_mimeType);
......@@ -104,9 +103,6 @@ void UrlLoader::start()
}
}
qDebug() << "Should embed" << m_url << "?" << shouldEmbedThis();
qDebug() << "Is mimetype for" << m_url << "known?" << isMimeTypeKnown(m_mimeType);
if (isMimeTypeKnown(m_mimeType)) {
if (decideExecute()) {
m_action = OpenUrlAction::Execute;
......@@ -115,7 +111,6 @@ void UrlLoader::start()
if (shouldEmbedThis()) {
decideEmbedOrSave();
} else {
qDebug() << "Calling decideOpenOrSave for" << m_url;
decideOpenOrSave();
}
}
......@@ -166,7 +161,6 @@ void UrlLoader::decideEmbedOrSave()
m_action = OpenUrlAction::Embed;
} else {
m_action = askSaveOrOpen(OpenEmbedMode::Embed).first;
qDebug() << "ACTION" << m_action;
}
} else {
m_action = OpenUrlAction::Save;
......@@ -176,7 +170,6 @@ void UrlLoader::decideEmbedOrSave()
//Given that m_action is Embed, m_service must be valid
m_request.serviceName = m_service->desktopEntryName();
}
qDebug() << m_action;
m_ready = m_service || m_action != OpenUrlAction::Embed;
}
......@@ -232,6 +225,8 @@ void UrlLoader::performAction()
void UrlLoader::done(KJob *job)
{
//Ensure that m_mimeType and m_request.args.mimeType are equal, since it's not clear what will be used
m_request.args.setMimeType(m_mimeType);
if (job) {
jobFinished(job);
}
......@@ -255,7 +250,8 @@ void UrlLoader::launchOpenUrlJob(bool pauseOnMimeTypeDetermined)
m_openUrlJob->setDeleteTemporaryFile(m_request.tempFile);
if (pauseOnMimeTypeDetermined) {
//TODO Remove KonqRun: sometimes, this signal is emitted with mimetype application/octet-stream, even when the mimetype
//should be known (and, indeed, clicking again on the link gives the correct mimetype).
//should be known. It seems to happen randomly and clicking again on the URL usually gives the correct mimetype.
//Example: clicking on any of the downloads at https://www.gentoo.org/downloads
connect(m_openUrlJob, &KIO::OpenUrlJob::mimeTypeFound, this, &UrlLoader::mimetypeDeterminedByJob);
}
connect(m_openUrlJob, &KJob::finished, this, &UrlLoader::jobFinished);
......@@ -284,8 +280,7 @@ void UrlLoader::detectSettingsForRemoteFiles()
return;
}
//TODO Remove KonqRun: determine this dynamically
const QVector<QString> webengineSchemes = {"error", "konq", "tar"};
const QVector<QString> webengineSchemes = {"error", "konq"};
if (m_mimeType.isEmpty() && (m_url.scheme().startsWith(QStringLiteral("http")) || webengineSchemes.contains(m_url.scheme()))) {
m_mimeType = QLatin1String("text/html");
......@@ -340,8 +335,6 @@ void UrlLoader::detectSettingsForLocalFiles()
QMimeDatabase db;
m_mimeType = db.mimeTypeForFile(m_url.path()).name();
}
//TODO Remove KonqRun: what's the difference between m_mimeType and m_request.args.mimeType()?
// m_request.args.setMimeType(m_mimeType);
}
......@@ -392,10 +385,9 @@ void UrlLoader::saveUrlUsingKIO(const QUrl& orig, const QUrl& dest)
void UrlLoader::open()
{
// Prevention against user stupidity : if the associated app for this mimetype
// is konqueror/kfmclient, then we'll loop forever.
if (m_service && serviceIsKonqueror(m_service) && m_mainWindow->refuseExecutingKonqueror(m_mimeType)) {
qDebug() << "REFUSING EXECUTING";
// Prevention against user stupidity : if the associated app for this mimetype
// is konqueror/kfmclient, then we'll loop forever.
return;
}
KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(m_service);
......
......@@ -214,25 +214,7 @@ bool WebEnginePage::askBrowserToOpenUrl(const QUrl& url, const QString& mimetype
args.setMimeType(mimetype);
emit m_part->browserExtension()->openUrlRequest(url, args, bargs);
return true;
// KParts::BrowserInterface *bi = m_part->browserExtension()->browserInterface();
// if (bi) {
// QMetaObject::invokeMethod(bi, "openUrl", Q_ARG(QUrl, url), Q_ARG(QString, mimetype));
// return false;
// } else {
// return true;
// }
}
// bool WebEnginePage::askBrowserToOpenUrlInPart(const QUrl& url, const QString& part)
// {
// KParts::BrowserInterface *bi = m_part->browserExtension()->browserInterface();
// if (bi) {
// bool success = QMetaObject::invokeMethod(bi, "openUrlInpart", Q_ARG(QUrl, url), Q_ARG(QString, part));
// return success ? false : true;
// } else {
// return true;
// }
// }
}
bool WebEnginePage::shouldOpenLocalUrl(const QUrl& url) const
{
......@@ -250,8 +232,6 @@ bool WebEnginePage::shouldOpenLocalUrl(const QUrl& url) const
bool WebEnginePage::acceptNavigationRequest(const QUrl& url, NavigationType type, bool isMainFrame)
{
qDebug() << "ACCEPT NAVIGATION REQUEST for" << url;
if (isMainFrame && url.isLocalFile()) {
if (!shouldOpenLocalUrl(url)) {
return askBrowserToOpenUrl(url);
......
......@@ -414,22 +414,6 @@ void WebEnginePart::attemptInstallKIOSchemeHandler(const QUrl& url)
}
// bool WebEnginePart::openUrl(const QUrl &u)
// {
// // Ignore empty requests...
// if (u.isEmpty()) {
// return false;
// }
//
// UrlLoader *urlLoader = new UrlLoader(u, this);
// KParts::OpenUrlArguments args (arguments());
// qDebug() << "URL:" << u << args.mimeType();
// connect(urlLoader, &UrlLoader::finished, urlLoader, &UrlLoader::deleteLater);
//
// urlLoader->openUrl(args.mimeType(), args.metaData().value("SuggestedFileName"));
// return true;
// }
bool WebEnginePart::openUrl(const QUrl& _u)
{
if (_u.isEmpty()) {
......
......@@ -54,7 +54,6 @@ void WebEnginePartDownloadManager::removePage(QObject* page)
void WebEnginePartDownloadManager::performDownload(QWebEngineDownloadItem* it)
{
qDebug() << "DOWLOADING" << it->url();
WebEnginePage *page = qobject_cast<WebEnginePage*>(it->page());
bool forceNew = false;
//According to the documentation, QWebEngineDownloadItem::page() can return nullptr "if the download was not triggered by content in a page"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment