From 26f7428c9f917d5c558eedc770a5dcd392be6080 Mon Sep 17 00:00:00 2001 From: Fredrik Johansson Date: Mon, 7 Jan 2019 20:26:49 +0100 Subject: [PATCH] Fix local paths for windows --- src/Mod/Web/Gui/BrowserView.cpp | 22 +++++++++++++++------- src/Mod/Web/Gui/BrowserView.h | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Mod/Web/Gui/BrowserView.cpp b/src/Mod/Web/Gui/BrowserView.cpp index ac1c02087d..af9bd387ae 100644 --- a/src/Mod/Web/Gui/BrowserView.cpp +++ b/src/Mod/Web/Gui/BrowserView.cpp @@ -51,7 +51,7 @@ #endif -#if QT_VERSION >= 0x050700 and defined(QTWEBENGINE) +#if QT_VERSION >= 0x050700 && defined(QTWEBENGINE) # include # include # include @@ -61,7 +61,7 @@ # include # define QWEBVIEW QWebEngineView # define QWEBPAGE QWebEnginePage -#elif QT_VERSION >= 0x040400 and defined(QTWEBKIT) +#elif QT_VERSION >= 0x040400 && defined(QTWEBKIT) # include # include # include @@ -69,6 +69,8 @@ # define QWEBPAGE QWebPage #endif +#include +#include #include "BrowserView.h" #include "CookieJar.h" #include @@ -103,11 +105,18 @@ public: void interceptRequest(QWebEngineUrlRequestInfo &info) { + // do something with this resource, click or get img for example if (info.navigationType() == QWebEngineUrlRequestInfo::NavigationTypeLink) { - // invoke thread safe. - QMetaObject::invokeMethod(m_parent, "urlFilter", - Q_ARG(QUrl, info.requestUrl())); + // wash out windows file:///C:/something ->file://C:/something + QUrl url = info.requestUrl(); + QRegExp re(QLatin1String("^/([a-zA-Z]\\:.*)")); // match & catch drive letter forward + if (url.host().isEmpty() && url.isLocalFile() && re.exactMatch(url.path())) + // clip / in file urs ie /C:/something -> C:/something + url.setPath(re.cap(1)); + + // invoke thread safe. + QMetaObject::invokeMethod(m_parent, "urlFilter", Q_ARG(QUrl, url)); } } @@ -256,7 +265,7 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) menu.exec(mapToGlobal(event->pos())); return; } -#if QT_VERSION >= 0x050800 and defined(QTWEBENGINE) +#if QT_VERSION >= 0x050800 && defined(QTWEBENGINE) else { // for view source // QWebEngine caches standardContextMenu, guard so we only add signlmapper once static bool firstRun = true; @@ -671,6 +680,5 @@ PyObject* BrowserView::getPyObject(void) return new BrowserViewPy(this); } - #include "moc_BrowserView.cpp" diff --git a/src/Mod/Web/Gui/BrowserView.h b/src/Mod/Web/Gui/BrowserView.h index 7a80857987..871c5c0743 100644 --- a/src/Mod/Web/Gui/BrowserView.h +++ b/src/Mod/Web/Gui/BrowserView.h @@ -28,12 +28,12 @@ #include #include -#if QT_VERSION >= 0x050700 and defined(QTWEBENGINE) +#if QT_VERSION >= 0x050700 && defined(QTWEBENGINE) #include namespace WebGui { class WebEngineUrlRequestInterceptor; }; -#elif QT_VERSION >= 0x040400 and defined(QTWEBKIT) +#elif QT_VERSION >= 0x040400 && defined(QTWEBKIT) #include #endif