Skip to content
This repository has been archived by the owner on Apr 30, 2023. It is now read-only.

Commit

Permalink
Allow compiling without QtWebEngine/webflow v1
Browse files Browse the repository at this point in the history
Still enabled by default

Fixes nextcloud#856 nextcloud#932
Supersedes nextcloud#1808 nextcloud#2204
  • Loading branch information
maxcrees committed May 24, 2021
1 parent 755d672 commit eb097a9
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ if(TOKEN_AUTH_ONLY)
add_definitions(-DTOKEN_AUTH_ONLY=1)
endif()

option(WITH_WEBENGINE "Enable old webflow v1 auth using webengine" ON)
if(WITH_WEBENGINE)
message("Enabling flow1 auth")
add_definitions(-DWITH_WEBENGINE=1)
endif()

option(NO_MSG_HANDLER "Don't redirect QDebug outputs to the log window/file" OFF)
if(NO_MSG_HANDLER)
add_definitions(-DNO_MSG_HANDLER=1)
Expand Down
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ include(ECMEnableSanitizers)

set(synclib_NAME ${APPLICATION_EXECUTABLE}sync)

find_package(Qt5 5.12 COMPONENTS Core Network Xml Concurrent WebEngineWidgets WebEngine REQUIRED)
find_package(Qt5 5.12 COMPONENTS Core Network Xml Concurrent REQUIRED)
if(WITH_WEBENGINE)
find_package(Qt5 5.12 COMPONENTS WebEngineWidgets WebEngine REQUIRED)
endif()
get_target_property (QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
message(STATUS "Using Qt ${Qt5Core_VERSION} (${QT_QMAKE_EXECUTABLE})")

Expand Down
17 changes: 14 additions & 3 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,18 @@ set(client_SRCS
wizard/owncloudwizardcommon.cpp
wizard/owncloudwizard.cpp
wizard/owncloudwizardresultpage.cpp
wizard/webviewpage.cpp
wizard/webview.cpp
wizard/slideshow.cpp
wizard/welcomepage.cpp
wizard/linklabel.cpp
)

IF(WITH_WEBENGINE)
list(APPEND client_SRCS
wizard/webviewpage.cpp
wizard/webview.cpp
)
endif()

IF(BUILD_UPDATER)
set(updater_SRCS
updater/ocupdater.cpp
Expand Down Expand Up @@ -255,6 +260,12 @@ endif()

add_library(nextcloudCore STATIC ${final_src})

if(WITH_WEBENGINE)
set(link_webengine "Qt5::WebEngineWidgets")
else()
set(link_webengine "")
endif()

target_link_libraries(nextcloudCore
PUBLIC
Qt5::Widgets
Expand All @@ -265,7 +276,7 @@ target_link_libraries(nextcloudCore
Qt5::Qml
Qt5::Quick
Qt5::QuickControls2
Qt5::WebEngineWidgets
${link_webengine}
${synclib_NAME}
)

Expand Down
2 changes: 2 additions & 0 deletions src/gui/creds/webflowcredentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#include "account.h"
#include "configfile.h"
#include "theme.h"
#ifdef WITH_WEBENGINE
#include "wizard/webview.h"
#endif
#include "webflowcredentialsdialog.h"

using namespace QKeychain;
Expand Down
17 changes: 14 additions & 3 deletions src/gui/creds/webflowcredentialsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
#include "owncloudgui.h"
#include "headerbanner.h"
#include "wizard/owncloudwizardcommon.h"
#ifdef WITH_WEBENGINE
#include "wizard/webview.h"
#endif
#include "wizard/flow2authwidget.h"

namespace OCC {

WebFlowCredentialsDialog::WebFlowCredentialsDialog(Account *account, bool useFlow2, QWidget *parent)
: QDialog(parent),
_useFlow2(useFlow2),
_flow2AuthWidget(nullptr),
_webView(nullptr)
_flow2AuthWidget(nullptr)
#ifdef WITH_WEBENGINE
,_webView(nullptr)
#endif
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

Expand Down Expand Up @@ -48,12 +52,15 @@ WebFlowCredentialsDialog::WebFlowCredentialsDialog(Account *account, bool useFlo
connect(this, &WebFlowCredentialsDialog::onActivate, _flow2AuthWidget, &Flow2AuthWidget::slotPollNow);

_flow2AuthWidget->startAuth(account);
} else {
}
#ifdef WITH_WEBENGINE
else {
_webView = new WebView();
_containerLayout->addWidget(_webView);

connect(_webView, &WebView::urlCatched, this, &WebFlowCredentialsDialog::urlCatched);
}
#endif

auto app = static_cast<Application *>(qApp);
connect(app, &Application::isShowingSettingsDialog, this, &WebFlowCredentialsDialog::slotShowSettingsDialog);
Expand All @@ -73,12 +80,14 @@ WebFlowCredentialsDialog::WebFlowCredentialsDialog(Account *account, bool useFlo
void WebFlowCredentialsDialog::closeEvent(QCloseEvent* e) {
Q_UNUSED(e)

#ifdef WITH_WEBENGINE
if (_webView) {
// Force calling WebView::~WebView() earlier so that _profile and _page are
// deleted in the correct order.
_webView->deleteLater();
_webView = nullptr;
}
#endif

if (_flow2AuthWidget) {
_flow2AuthWidget->resetAuth();
Expand All @@ -90,8 +99,10 @@ void WebFlowCredentialsDialog::closeEvent(QCloseEvent* e) {
}

void WebFlowCredentialsDialog::setUrl(const QUrl &url) {
#ifdef WITH_WEBENGINE
if (_webView)
_webView->setUrl(url);
#endif
}

void WebFlowCredentialsDialog::setInfo(const QString &msg) {
Expand Down
4 changes: 4 additions & 0 deletions src/gui/wizard/owncloudsetuppage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ void OwncloudSetupPage::slotLogin()
void OwncloudSetupPage::slotGotoProviderList()
{
_ocWizard->setRegistration(true);
#ifdef WITH_WEBENGINE
_ocWizard->setAuthType(DetermineAuthTypeJob::AuthType::WebViewFlow);
#else
_ocWizard->setAuthType(DetermineAuthTypeJob::AuthType::OAuth);
#endif
_authTypeKnown = true;
_checking = false;
emit completeChanged();
Expand Down
19 changes: 18 additions & 1 deletion src/gui/wizard/owncloudwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include "wizard/owncloudoauthcredspage.h"
#include "wizard/owncloudadvancedsetuppage.h"
#include "wizard/owncloudwizardresultpage.h"
#ifdef WITH_WEBENGINE
#include "wizard/webviewpage.h"
#endif
#include "wizard/flow2authcredspage.h"

#include "common/vfs.h"
Expand Down Expand Up @@ -54,7 +56,9 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
, _flow2CredsPage(new Flow2AuthCredsPage)
, _advancedSetupPage(new OwncloudAdvancedSetupPage(this))
, _resultPage(new OwncloudWizardResultPage)
#ifdef WITH_WEBENGINE
, _webViewPage(new WebViewPage(this))
#endif
{
setObjectName("owncloudWizard");

Expand All @@ -66,7 +70,9 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
setPage(WizardCommon::Page_Flow2AuthCreds, _flow2CredsPage);
setPage(WizardCommon::Page_AdvancedSetup, _advancedSetupPage);
setPage(WizardCommon::Page_Result, _resultPage);
#ifdef WITH_WEBENGINE
setPage(WizardCommon::Page_WebView, _webViewPage);
#endif

connect(this, &QDialog::finished, this, &OwncloudWizard::basicSetupFinished);

Expand All @@ -78,7 +84,9 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
connect(_httpCredsPage, &OwncloudHttpCredsPage::connectToOCUrl, this, &OwncloudWizard::connectToOCUrl);
connect(_browserCredsPage, &OwncloudOAuthCredsPage::connectToOCUrl, this, &OwncloudWizard::connectToOCUrl);
connect(_flow2CredsPage, &Flow2AuthCredsPage::connectToOCUrl, this, &OwncloudWizard::connectToOCUrl);
#ifdef WITH_WEBENGINE
connect(_webViewPage, &WebViewPage::connectToOCUrl, this, &OwncloudWizard::connectToOCUrl);
#endif
connect(_advancedSetupPage, &OwncloudAdvancedSetupPage::createLocalAndRemoteFolders,
this, &OwncloudWizard::createLocalAndRemoteFolders);
connect(this, &QWizard::customButtonClicked, this, &OwncloudWizard::skipFolderConfiguration);
Expand Down Expand Up @@ -230,9 +238,11 @@ void OwncloudWizard::successfulStep()
_flow2CredsPage->setConnected();
break;

#ifdef WITH_WEBENGINE
case WizardCommon::Page_WebView:
_webViewPage->setConnected();
break;
#endif

case WizardCommon::Page_AdvancedSetup:
_advancedSetupPage->directoriesCreated();
Expand All @@ -256,8 +266,10 @@ void OwncloudWizard::setAuthType(DetermineAuthTypeJob::AuthType type)
_credentialsPage = _browserCredsPage;
} else if (type == DetermineAuthTypeJob::LoginFlowV2) {
_credentialsPage = _flow2CredsPage;
#ifdef WITH_WEBENGINE
} else if (type == DetermineAuthTypeJob::WebViewFlow) {
_credentialsPage = _webViewPage;
#endif
} else { // try Basic auth even for "Unknown"
_credentialsPage = _httpCredsPage;
}
Expand All @@ -281,7 +293,12 @@ void OwncloudWizard::slotCurrentPageChanged(int id)
button(QWizard::NextButton)->setHidden(true);
// Need to set it from here, otherwise it has no effect
_welcomePage->setLoginButtonDefault();
} else if (id == WizardCommon::Page_WebView || id == WizardCommon::Page_Flow2AuthCreds) {
} else if (
#ifdef WITH_WEBENGINE
id == WizardCommon::Page_WebView ||
#endif
id == WizardCommon::Page_Flow2AuthCreds
) {
setButtonLayout({ QWizard::Stretch, QWizard::BackButton });
} else if (id == WizardCommon::Page_AdvancedSetup) {
setButtonLayout({ QWizard::Stretch, QWizard::CustomButton1, QWizard::BackButton, QWizard::NextButton });
Expand Down
4 changes: 4 additions & 0 deletions src/gui/wizard/owncloudwizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class OwncloudAdvancedSetupPage;
class OwncloudWizardResultPage;
class AbstractCredentials;
class AbstractCredentialsWizardPage;
#ifdef WITH_WEBENGINE
class WebViewPage;
#endif
class Flow2AuthCredsPage;

/**
Expand Down Expand Up @@ -128,7 +130,9 @@ public slots:
OwncloudAdvancedSetupPage *_advancedSetupPage;
OwncloudWizardResultPage *_resultPage;
AbstractCredentialsWizardPage *_credentialsPage = nullptr;
#ifdef WITH_WEBENGINE
WebViewPage *_webViewPage;
#endif

QStringList _setupLog;

Expand Down
8 changes: 8 additions & 0 deletions src/libsync/networkjobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ void DetermineAuthTypeJob::start()
if (statusCode == 200) {
_resultOldFlow = LoginFlowV2;

#ifdef WITH_WEBENGINE
auto data = json.object().value("ocs").toObject().value("data").toObject().value("capabilities").toObject();
auto gs = data.value("globalscale");
if (gs != QJsonValue::Undefined) {
Expand All @@ -962,6 +963,7 @@ void DetermineAuthTypeJob::start()
}
}
}
#endif
} else {
_resultOldFlow = Basic;
}
Expand All @@ -987,18 +989,24 @@ void DetermineAuthTypeJob::checkAllDone()

// WebViewFlow > OAuth > Basic
if (_account->serverVersionInt() >= Account::makeServerVersion(12, 0, 0)) {
#ifdef WITH_WEBENGINE
result = WebViewFlow;
#else
result = OAuth;
#endif
}

// LoginFlowV2 > WebViewFlow > OAuth > Basic
if (_account->serverVersionInt() >= Account::makeServerVersion(16, 0, 0)) {
result = LoginFlowV2;
}

#ifdef WITH_WEBENGINE
// If we determined that we need the webview flow (GS for example) then we switch to that
if (_resultOldFlow == WebViewFlow) {
result = WebViewFlow;
}
#endif

// If we determined that a simple get gave us an authentication required error
// then the server enforces basic auth and we got no choice but to use this
Expand Down

0 comments on commit eb097a9

Please sign in to comment.