void LoginManager::loginInteractive() { QWebEngineView* webView = new QWebEngineView; webView->setWindowModality(Qt::ApplicationModal); webView->setAttribute(Qt::WA_DeleteOnClose); QWebEnginePage* page = webView->page(); QWebEngineProfile* profile = page->profile(); // TODO: logout in editor does not log out in web view profile->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies); profile->setRequestInterceptor(new ApiWebEngineRequestInterceptor(profile)); //workaround for the crashes sometimes happend in Chromium on macOS with Qt 5.12 connect(webView, &QWebEngineView::renderProcessTerminated, this, [profile, webView](QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode) { qDebug() << "Login page loading terminated" << terminationStatus << " " << exitCode; profile->clearHttpCache(); webView->show(); }); connect(page, &QWebEnginePage::loadFinished, this, [this, page, webView](bool ok) { if (!ok) return; constexpr QUrl::FormattingOptions cmpOpt = QUrl::RemoveQuery | QUrl::RemoveFragment | QUrl::StripTrailingSlash; if (!page->url().matches(ApiInfo::loginSuccessUrl, cmpOpt)) return; page->runJavaScript("JSON.stringify(muGetAuthInfo())", [this, page, webView](const QVariant& v) { onLoginReply(nullptr, HTTP_OK, QJsonDocument::fromJson(v.toString().toUtf8()).object()); // We have retrieved an access token, do not remain logged // in with web view profile. page->profile()->cookieStore()->deleteAllCookies(); webView->close(); }); }); webView->load(ApiInfo::loginUrl); webView->show(); }
WebEngineHelpViewer::WebEngineHelpViewer(QWidget *parent) : HelpViewer(parent), m_widget(new WebView(this)) { m_widget->setPage(new WebEngineHelpPage(this)); auto layout = new QVBoxLayout; setLayout(layout); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(m_widget, 10); QPalette p = palette(); p.setColor(QPalette::Base, Qt::white); p.setColor(QPalette::Text, Qt::black); setPalette(p); connect(m_widget, &QWebEngineView::urlChanged, this, &WebEngineHelpViewer::sourceChanged); connect(m_widget, &QWebEngineView::loadStarted, this, &WebEngineHelpViewer::slotLoadStarted); connect(m_widget, &QWebEngineView::loadFinished, this, &WebEngineHelpViewer::slotLoadFinished); connect(m_widget, &QWebEngineView::titleChanged, this, &WebEngineHelpViewer::titleChanged); connect(m_widget->page(), &QWebEnginePage::linkHovered, this, &WebEngineHelpViewer::setToolTip); connect(m_widget->pageAction(QWebEnginePage::Back), &QAction::changed, this, [this]() { emit backwardAvailable(isBackwardAvailable()); }); connect(m_widget->pageAction(QWebEnginePage::Forward), &QAction::changed, this, [this]() { emit forwardAvailable(isForwardAvailable()); }); QAction* action = m_widget->pageAction(QWebEnginePage::OpenLinkInNewTab); action->setText(QCoreApplication::translate("HelpViewer", Constants::TR_OPEN_LINK_AS_NEW_PAGE)); QWebEnginePage *viewPage = m_widget->page(); QTC_ASSERT(viewPage, return); QWebEngineProfile *viewProfile = viewPage->profile(); QTC_ASSERT(viewProfile, return); if (!viewProfile->urlSchemeHandler("qthelp")) viewProfile->installUrlSchemeHandler("qthelp", helpUrlSchemeHandler()); }