present QWebView for OAuth authorization in interface

This commit is contained in:
Stephen Birarda 2014-05-01 11:09:35 -07:00
parent 2f0e311a99
commit 56c24ce8b7
5 changed files with 76 additions and 3 deletions

View file

@ -454,7 +454,6 @@ QUrl DomainServer::oauthAuthorizationURL() {
authorizationQuery.addQueryItem(OAUTH_RESPONSE_TYPE_QUERY_KEY, OAUTH_REPSONSE_TYPE_QUERY_VALUE);
QString redirectURL = QString("https://%1:%2/oauth").arg(_hostname).arg(_httpsManager->serverPort());
qDebug() << "redirect URL is" << redirectURL;
const QString OAUTH_REDIRECT_URI_QUERY_KEY = "redirect_uri";
authorizationQuery.addQueryItem(OAUTH_REDIRECT_URI_QUERY_KEY, redirectURL);

View file

@ -79,9 +79,10 @@
#include "scripting/SettingsScriptingInterface.h"
#include "ui/InfoView.h"
#include "ui/OAuthWebviewHandler.h"
#include "ui/Snapshot.h"
#include "ui/TextRenderer.h"
#include "ui/Stats.h"
#include "ui/TextRenderer.h"
using namespace std;
@ -354,6 +355,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
}
//When -url in command line, teleport to location
urlGoTo(argc, constArgv);
// call the OAuthWebviewHandler static getter so that its instance lives in our thread
OAuthWebViewHandler::getInstance();
}
Application::~Application() {

View file

@ -15,6 +15,7 @@
#include "Application.h"
#include "Menu.h"
#include "ui/OAuthWebviewHandler.h"
#include "DatagramProcessor.h"
@ -118,7 +119,8 @@ void DatagramProcessor::processDatagrams() {
QUrl authorizationURL;
readStream >> authorizationURL;
qDebug() << "the authorization URL sent from the server is" << authorizationURL;
QMetaObject::invokeMethod(&OAuthWebViewHandler::getInstance(), "displayWebviewForAuthorizationURL",
Q_ARG(const QUrl&, authorizationURL));
break;
}

View file

@ -0,0 +1,36 @@
//
// OAuthWebViewHandler.cpp
// interface/src/ui
//
// Created by Stephen Birarda on 2014-05-01.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QtWebkitWidgets/QWebView>
#include "Application.h"
#include "OAuthWebviewHandler.h"
OAuthWebViewHandler& OAuthWebViewHandler::getInstance() {
static OAuthWebViewHandler sharedInstance;
return sharedInstance;
}
OAuthWebViewHandler::OAuthWebViewHandler() :
_activeWebView(NULL)
{
}
void OAuthWebViewHandler::displayWebviewForAuthorizationURL(const QUrl& authorizationURL) {
if (!_activeWebView) {
_activeWebView = new QWebView();
_activeWebView->setWindowFlags(Qt::WindowStaysOnTopHint);
_activeWebView->load(authorizationURL);
_activeWebView->show();
}
}

View file

@ -0,0 +1,32 @@
//
// OAuthWebviewHandler.h
// interface/src/ui
//
// Created by Stephen Birarda on 2014-05-01.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_OAuthWebviewHandler_h
#define hifi_OAuthWebviewHandler_h
#include <QtCore/QUrl>
class QWebView;
class OAuthWebViewHandler : public QObject {
Q_OBJECT
public:
OAuthWebViewHandler();
static OAuthWebViewHandler& getInstance();
public slots:
void displayWebviewForAuthorizationURL(const QUrl& authorizationURL);
private:
QWebView* _activeWebView;
};
#endif // hifi_OAuthWebviewHandler_h