Skip to content

Commit

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

Fixes: #856 #932
Supersedes: #1808 #2204
Signed-off-by: Max Rees <maxcrees@me.com>
  • Loading branch information
maxcrees committed May 25, 2021
1 parent 755d672 commit de9f403
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 8 deletions.
4 changes: 3 additions & 1 deletion NEXTCLOUD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ option( WITH_CRASHREPORTER "Build crashreporter" OFF )
## Updater options
option( BUILD_UPDATER "Build updater" OFF )

option( WITH_PROVIDERS "Build with providers list" ON )
option( WITH_WEBFLOWV1 "Enable old webflow v1 authentication (requires QtWebEngine)" ON )
include( CMakeDependentOption )
cmake_dependent_option ( WITH_PROVIDERS "Build with providers list (requires webflow v1)" ON "WITH_WEBFLOWV1" OFF )


## Theming options
Expand Down
1 change: 1 addition & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#cmakedefine WITH_QTKEYCHAIN 1
#cmakedefine WITH_CRASHREPORTER
#cmakedefine WITH_PROVIDERS "@WITH_PROVIDERS@"
#cmakedefine WITH_WEBFLOWV1
#cmakedefine CRASHREPORTER_EXECUTABLE "@CRASHREPORTER_EXECUTABLE@"
#define SOCKETAPI_TEAM_IDENTIFIER_PREFIX "@SOCKETAPI_TEAM_IDENTIFIER_PREFIX@"

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_WEBFLOWV1)
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_WEBFLOWV1)
list(APPEND client_SRCS
wizard/webviewpage.cpp
wizard/webview.cpp
)
endif()

IF(BUILD_UPDATER)
set(updater_SRCS
updater/ocupdater.cpp
Expand Down Expand Up @@ -265,10 +270,16 @@ target_link_libraries(nextcloudCore
Qt5::Qml
Qt5::Quick
Qt5::QuickControls2
Qt5::WebEngineWidgets
${synclib_NAME}
)

if(WITH_WEBFLOWV1)
target_link_libraries(nextcloudCore
PUBLIC
Qt5::WebEngineWidgets
)
endif()

set_target_properties(nextcloudCore
PROPERTIES
AUTOUIC ON
Expand Down
6 changes: 6 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_WEBFLOWV1
#include "wizard/webview.h"
#endif
#include "webflowcredentialsdialog.h"

using namespace QKeychain;
Expand Down Expand Up @@ -145,7 +147,11 @@ void WebFlowCredentials::askFromUser() {
auto job = new DetermineAuthTypeJob(_account->sharedFromThis(), this);
connect(job, &DetermineAuthTypeJob::authType, [this](DetermineAuthTypeJob::AuthType type) {
// LoginFlowV2 > WebViewFlow > OAuth > Shib > Basic
#ifdef WITH_WEBFLOWV1
bool useFlow2 = (type != DetermineAuthTypeJob::WebViewFlow);
#else
bool useFlow2 = true;
#endif

_askDialog = new WebFlowCredentialsDialog(_account, useFlow2);

Expand Down
14 changes: 12 additions & 2 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_WEBFLOWV1
#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_WEBFLOWV1
,_webView(nullptr)
#endif
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

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

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

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

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

#ifdef WITH_WEBFLOWV1
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 +98,10 @@ void WebFlowCredentialsDialog::closeEvent(QCloseEvent* e) {
}

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

void WebFlowCredentialsDialog::setInfo(const QString &msg) {
Expand Down
2 changes: 2 additions & 0 deletions src/gui/wizard/owncloudsetuppage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@ int OwncloudSetupPage::nextId() const
return WizardCommon::Page_OAuthCreds;
case DetermineAuthTypeJob::LoginFlowV2:
return WizardCommon::Page_Flow2AuthCreds;
#ifdef WITH_WEBFLOWV1
case DetermineAuthTypeJob::WebViewFlow:
return WizardCommon::Page_WebView;
#endif
}
return WizardCommon::Page_HttpCreds;
}
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_WEBFLOWV1
#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_WEBFLOWV1
, _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_WEBFLOWV1
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_WEBFLOWV1
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_WEBFLOWV1
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_WEBFLOWV1
} 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_WEBFLOWV1
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_WEBFLOWV1
class WebViewPage;
#endif
class Flow2AuthCredsPage;

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

QStringList _setupLog;

Expand Down
2 changes: 2 additions & 0 deletions src/gui/wizard/owncloudwizardcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ namespace WizardCommon {
Page_HttpCreds,
Page_OAuthCreds,
Page_Flow2AuthCreds,
#ifdef WITH_WEBFLOWV1
Page_WebView,
#endif
Page_AdvancedSetup,
Page_Result
};
Expand Down
2 changes: 2 additions & 0 deletions src/gui/wizard/welcomepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ void WelcomePage::setupLoginButton()

void WelcomePage::setupCreateAccountButton()
{
#ifdef WITH_WEBFLOWV1
connect(_ui->createAccountButton, &QPushButton::clicked, this, [this](bool /*checked*/) {
_ocWizard->setRegistration(true);
_nextPage = WizardCommon::Page_WebView;
_ocWizard->next();
});
#endif
}

void WelcomePage::setupHostYourOwnServerLabel()
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_WEBFLOWV1
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_WEBFLOWV1
result = WebViewFlow;
#else
result = OAuth;
#endif
}

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

#ifdef WITH_WEBFLOWV1
// 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
2 changes: 2 additions & 0 deletions src/libsync/networkjobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ class OWNCLOUDSYNC_EXPORT DetermineAuthTypeJob : public QObject
NoAuthType, // used only before we got a chance to probe the server
Basic, // also the catch-all fallback for backwards compatibility reasons
OAuth,
#ifdef WITH_WEBFLOWV1
WebViewFlow,
#endif
LoginFlowV2
};
Q_ENUM(AuthType)
Expand Down

0 comments on commit de9f403

Please sign in to comment.