mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 03:24:07 +02:00
PR feedback
This commit is contained in:
parent
5a6e2e5daf
commit
af22ab55bb
2 changed files with 21 additions and 14 deletions
|
@ -10,19 +10,20 @@
|
|||
//
|
||||
|
||||
#include "ContextAwareProfile.h"
|
||||
#if !defined(Q_OS_ANDROID)
|
||||
|
||||
#include <cassert>
|
||||
#include <QtCore/QThread>
|
||||
#include <QtQml/QQmlContext>
|
||||
|
||||
#include <shared/QtHelpers.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
|
||||
static const QString RESTRICTED_FLAG_PROPERTY = "RestrictFileAccess";
|
||||
|
||||
ContextAwareProfile::ContextAwareProfile(QQmlContext* context) :
|
||||
QQuickWebEngineProfile(context), _context(context) { }
|
||||
QQuickWebEngineProfile(context), _context(context) {
|
||||
assert(context);
|
||||
}
|
||||
|
||||
|
||||
void ContextAwareProfile::restrictContext(QQmlContext* context, bool restrict) {
|
||||
|
@ -40,12 +41,9 @@ bool ContextAwareProfile::isRestrictedInternal() {
|
|||
|
||||
bool ContextAwareProfile::isRestricted() {
|
||||
auto now = usecTimestampNow();
|
||||
auto cacheAge = now - _lastCacheCheck;
|
||||
if (cacheAge > MAX_CACHE_AGE) {
|
||||
if (now > _cacheExpiry) {
|
||||
_cachedValue = isRestrictedInternal();
|
||||
_lastCacheCheck = now;
|
||||
_cacheExpiry = now + MAX_CACHE_AGE;
|
||||
}
|
||||
return _cachedValue;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -16,11 +16,21 @@
|
|||
#if !defined(Q_OS_ANDROID)
|
||||
#include <QtWebEngine/QQuickWebEngineProfile>
|
||||
#include <QtWebEngineCore/QWebEngineUrlRequestInterceptor>
|
||||
|
||||
using ContextAwareProfileParent = QQuickWebEngineProfile;
|
||||
using RequestInterceptorParent = QWebEngineUrlRequestInterceptor;
|
||||
#else
|
||||
#include <QtCore/QObject>
|
||||
|
||||
using ContextAwareProfileParent = QObject;
|
||||
using RequestInterceptorParent = QObject;
|
||||
#endif
|
||||
|
||||
#include <NumericalConstants.h>
|
||||
|
||||
class QQmlContext;
|
||||
|
||||
class ContextAwareProfile : public QQuickWebEngineProfile {
|
||||
class ContextAwareProfile : public ContextAwareProfileParent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static void restrictContext(QQmlContext* context, bool restrict = true);
|
||||
|
@ -28,9 +38,9 @@ public:
|
|||
Q_INVOKABLE bool isRestrictedInternal();
|
||||
protected:
|
||||
|
||||
class RequestInterceptor : public QWebEngineUrlRequestInterceptor {
|
||||
class RequestInterceptor : public RequestInterceptorParent {
|
||||
public:
|
||||
RequestInterceptor(ContextAwareProfile* parent) : QWebEngineUrlRequestInterceptor(parent), _profile(parent) {}
|
||||
RequestInterceptor(ContextAwareProfile* parent) : RequestInterceptorParent(parent), _profile(parent) { }
|
||||
bool isRestricted() { return _profile->isRestricted(); }
|
||||
protected:
|
||||
ContextAwareProfile* _profile;
|
||||
|
@ -39,9 +49,8 @@ protected:
|
|||
ContextAwareProfile(QQmlContext* parent);
|
||||
QQmlContext* _context{ nullptr };
|
||||
bool _cachedValue{ false };
|
||||
quint64 _lastCacheCheck{ 0 };
|
||||
static const quint64 MAX_CACHE_AGE = MSECS_PER_SECOND;
|
||||
quint64 _cacheExpiry{ 0 };
|
||||
constexpr static quint64 MAX_CACHE_AGE = MSECS_PER_SECOND;
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // hifi_FileTypeProfile_h
|
||||
|
|
Loading…
Reference in a new issue