mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Athlete level WebEngineProfile for cookies and storage
Used by WebChart for autologin and Map charts for cache, but not for OAuth dialogs nor Python web charts. Fixes #4484
This commit is contained in:
@@ -142,7 +142,7 @@ RideMapWindow::RideMapWindow(Context *context, int mapType) : GcChartWindow(cont
|
||||
view = new QWebEngineView(this);
|
||||
// stop stealing focus!
|
||||
view->settings()->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, false);
|
||||
view->setPage(new mapWebPage());
|
||||
view->setPage(new QWebEnginePage(context->webEngineProfile));
|
||||
view->setContentsMargins(0,0,0,0);
|
||||
view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
view->setAcceptDrops(false);
|
||||
|
||||
@@ -56,12 +56,6 @@ struct PositionItem {
|
||||
};
|
||||
|
||||
|
||||
// trick the maps api into ignoring gestures by
|
||||
// pretending to be chrome. see: http://developer.qt.nokia.com/forums/viewthread/1643/P15
|
||||
class mapWebPage : public QWebEnginePage
|
||||
{
|
||||
};
|
||||
|
||||
class MapWebBridge : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <QXmlInputSource>
|
||||
#include <QXmlSimpleReader>
|
||||
#include <QMutex>
|
||||
#include <QWebEngineProfile>
|
||||
|
||||
// singleton
|
||||
static GlobalContext *globalContext = NULL;
|
||||
@@ -132,6 +133,7 @@ GlobalContext *GlobalContext::context()
|
||||
}
|
||||
|
||||
bool Context::isValid(Context *p) { return p != NULL &&_contexts.contains(p); }
|
||||
|
||||
Context::Context(MainWindow *mainWindow): mainWindow(mainWindow)
|
||||
{
|
||||
ride = NULL;
|
||||
@@ -148,6 +150,10 @@ Context::Context(MainWindow *mainWindow): mainWindow(mainWindow)
|
||||
cdbUserMetricListDialog = NULL;
|
||||
#endif
|
||||
|
||||
// WebEngineProfile - cookies and storage
|
||||
webEngineProfile = new QWebEngineProfile("Default", this);
|
||||
webEngineProfile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
|
||||
|
||||
_contexts.append(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ class AthleteTab;
|
||||
class NavigationModel;
|
||||
class RideMetadata;
|
||||
class ColorEngine;
|
||||
class QWebEngineProfile;
|
||||
|
||||
|
||||
class GlobalContext : public QObject
|
||||
@@ -161,6 +162,9 @@ class Context : public QObject
|
||||
CloudDBUserMetricListDialog *cdbUserMetricListDialog;
|
||||
#endif
|
||||
|
||||
// WebEngineProfile for this user
|
||||
QWebEngineProfile* webEngineProfile;
|
||||
|
||||
public slots:
|
||||
|
||||
// *********************************************
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <QTabBar>
|
||||
#include <QStyleFactory>
|
||||
#include <QRect>
|
||||
#include <QWebEngineProfile>
|
||||
|
||||
// DATA STRUCTURES
|
||||
#include "MainWindow.h"
|
||||
@@ -149,6 +150,9 @@ MainWindow::MainWindow(const QDir &home)
|
||||
// bootstrap
|
||||
Context *context = new Context(this);
|
||||
context->athlete = new Athlete(context, home);
|
||||
QString temp = const_cast<AthleteDirectoryStructure*>(context->athlete->directoryStructure())->temp().absolutePath();
|
||||
context->webEngineProfile->setCachePath(temp);
|
||||
context->webEngineProfile->setPersistentStoragePath(temp);
|
||||
currentAthleteTab = new AthleteTab(context);
|
||||
|
||||
setWindowIcon(QIcon(":images/gc.png"));
|
||||
|
||||
@@ -35,9 +35,6 @@
|
||||
#include "ErgFile.h"
|
||||
#include "LocationInterpolation.h"
|
||||
|
||||
//#include <QtWebChannel>
|
||||
//#include <QWebEngineProfile>
|
||||
|
||||
// overlay helper
|
||||
#include "AbstractView.h"
|
||||
#include "GcOverlayWidget.h"
|
||||
@@ -105,7 +102,7 @@ LiveMapWebPageWindow::LiveMapWebPageWindow(Context *context) : GcChartWindow(con
|
||||
|
||||
// set webview for map
|
||||
view = new QWebEngineView(this);
|
||||
webPage = view->page();
|
||||
webPage = new QWebEnginePage(context->webEngineProfile);
|
||||
view->setPage(webPage);
|
||||
|
||||
view->setContentsMargins(0,10,0,0);
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "Units.h"
|
||||
#include "LocationInterpolation.h"
|
||||
#include <QWebEngineScriptCollection>
|
||||
#include <QWebEngineProfile>
|
||||
#include <array>
|
||||
|
||||
MeterWidget::MeterWidget(QString Name, QWidget *parent, QString Source) : QWidget(parent), m_Name(Name), m_container(parent), m_Source(Source)
|
||||
@@ -516,7 +515,7 @@ LiveMapWidget::LiveMapWidget(QString Name, QWidget* parent, QString Source, Cont
|
||||
m_osmURL = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
|
||||
forceSquareRatio = false;
|
||||
liveMapView = new QWebEngineView(this);
|
||||
webPage = new QWebEnginePage(liveMapView);
|
||||
webPage = new QWebEnginePage(context->webEngineProfile);
|
||||
liveMapView->setPage(webPage);
|
||||
routeInitialized = false;
|
||||
mapInitialized = false;
|
||||
|
||||
@@ -141,32 +141,15 @@ WebPageWindow::WebPageWindow(Context *context) : GcChartWindow(context), context
|
||||
view = new QWebEngineView(this);
|
||||
connect(view, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
|
||||
|
||||
//view->page()->profile()->setHttpUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393");
|
||||
|
||||
// add a download interceptor
|
||||
WebDownloadInterceptor *interceptor = new WebDownloadInterceptor;
|
||||
view->page()->profile()->setUrlRequestInterceptor(interceptor);
|
||||
|
||||
// cookies and storage
|
||||
view->page()->profile()->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
|
||||
QString temp = const_cast<AthleteDirectoryStructure*>(context->athlete->directoryStructure())->temp().absolutePath();
|
||||
view->page()->profile()->setCachePath(temp);
|
||||
view->page()->profile()->setPersistentStoragePath(temp);
|
||||
|
||||
// web scheme handler - not needed must compile with QT 5.9 or higher
|
||||
//WebSchemeHandler *handler = new WebSchemeHandler(view);
|
||||
//view->page()->profile()->installUrlSchemeHandler("filesystem:https", handler);
|
||||
//view->page()->profile()->installUrlSchemeHandler("filesystem", handler);
|
||||
|
||||
// add some settings
|
||||
view->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
|
||||
view->settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
|
||||
|
||||
#if QT_VERSION < 0x060000
|
||||
view->setPage(new simpleWebPage());
|
||||
#else
|
||||
view->setPage(new QWebEnginePage(new QWebEngineProfile("Default")));
|
||||
#endif
|
||||
view->setPage(new QWebEnginePage(context->webEngineProfile));
|
||||
view->setContentsMargins(0,0,0,0);
|
||||
view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
view->setAcceptDrops(false);
|
||||
|
||||
@@ -54,9 +54,6 @@ class QWebEngineDownloadItem;
|
||||
#else
|
||||
class QWebEngineDownloadRequest;
|
||||
#endif
|
||||
class simpleWebPage : public QWebEnginePage
|
||||
{
|
||||
};
|
||||
|
||||
class WebPageWindow : public GcChartWindow
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user