From 66077d5616709ab836b2e07f88b3a7aefe41c8b7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 1 May 2014 12:18:40 -0700 Subject: [PATCH] present the OAuth webview only every 5 seconds --- interface/src/ui/OAuthWebViewHandler.cpp | 19 ++++++++++++++++++- interface/src/ui/OAuthWebViewHandler.h | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/OAuthWebViewHandler.cpp b/interface/src/ui/OAuthWebViewHandler.cpp index 6ef7bebdce..3ba2a1115a 100644 --- a/interface/src/ui/OAuthWebViewHandler.cpp +++ b/interface/src/ui/OAuthWebViewHandler.cpp @@ -38,8 +38,10 @@ void OAuthWebViewHandler::addHighFidelityRootCAToSSLConfig() { QSslConfiguration::setDefaultConfiguration(sslConfig); } +const int WEB_VIEW_REDISPLAY_ELAPSED_MSECS = 5 * 1000; + void OAuthWebViewHandler::displayWebviewForAuthorizationURL(const QUrl& authorizationURL) { - if (!_activeWebView) { + if (!_activeWebView && _webViewRedisplayTimer.elapsed() >= WEB_VIEW_REDISPLAY_ELAPSED_MSECS) { _activeWebView = new QWebView; // keep the window on top and delete it when it closes @@ -52,9 +54,24 @@ void OAuthWebViewHandler::displayWebviewForAuthorizationURL(const QUrl& authoriz connect(_activeWebView->page()->networkAccessManager(), &QNetworkAccessManager::sslErrors, this, &OAuthWebViewHandler::handleSSLErrors); + connect(_activeWebView, &QWebView::loadFinished, this, &OAuthWebViewHandler::handleLoadFinished); + + // connect to the destroyed signal so after the web view closes we can start a timer + connect(_activeWebView, &QWebView::destroyed, this, &OAuthWebViewHandler::handleWebViewDestroyed); } } void OAuthWebViewHandler::handleSSLErrors(QNetworkReply* networkReply, const QList& errorList) { qDebug() << "SSL Errors:" << errorList; } + +void OAuthWebViewHandler::handleLoadFinished(bool success) { + if (success && _activeWebView->url().host() == NodeList::getInstance()->getDomainHandler().getHostname()) { + qDebug() << "OAuth authorization code passed successfully to domain-server."; + _activeWebView->close(); + } +} + +void OAuthWebViewHandler::handleWebViewDestroyed(QObject* destroyedObject) { + _webViewRedisplayTimer.restart(); +} diff --git a/interface/src/ui/OAuthWebViewHandler.h b/interface/src/ui/OAuthWebViewHandler.h index 692a31dc75..b3a865ce07 100644 --- a/interface/src/ui/OAuthWebViewHandler.h +++ b/interface/src/ui/OAuthWebViewHandler.h @@ -28,8 +28,11 @@ public slots: private slots: void handleSSLErrors(QNetworkReply* networkReply, const QList& errorList); + void handleLoadFinished(bool success); + void handleWebViewDestroyed(QObject* destroyedObject); private: QPointer _activeWebView; + QElapsedTimer _webViewRedisplayTimer; }; #endif // hifi_OAuthWebviewHandler_h \ No newline at end of file