diff options
Diffstat (limited to 'src/webenginewidgets/api/qwebenginepage.cpp')
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 102 |
1 files changed, 61 insertions, 41 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index b22d47916..7e02130c9 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -178,7 +178,6 @@ QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile) wasShownTimer.setSingleShot(true); QObject::connect(&wasShownTimer, &QTimer::timeout, [this](){ ensureInitialized(); - adapter->setVisible(true); }); profile->d_ptr->addWebContentsAdapterClient(this); @@ -231,11 +230,14 @@ void QWebEnginePagePrivate::titleChanged(const QString &title) Q_EMIT q->titleChanged(title); } -void QWebEnginePagePrivate::urlChanged(const QUrl &url) +void QWebEnginePagePrivate::urlChanged() { Q_Q(QWebEnginePage); - explicitUrl = QUrl(); - Q_EMIT q->urlChanged(url); + QUrl qurl = adapter->activeUrl(); + if (url != qurl) { + url = qurl; + Q_EMIT q->urlChanged(qurl); + } } void QWebEnginePagePrivate::iconChanged(const QUrl &url) @@ -314,8 +316,6 @@ void QWebEnginePagePrivate::loadFinished(bool success, const QUrl &url, bool isE } isLoading = false; - if (success) - explicitUrl = QUrl(); // Delay notifying failure until the error-page is done loading. // Error-pages are not loaded on failures due to abort. if (success || errorCode == -3 /* ERR_ABORTED*/ || !settings->testAttribute(QWebEngineSettings::ErrorPageEnabled)) { @@ -442,7 +442,7 @@ void QWebEnginePagePrivate::didPrintPage(quint64 requestId, QSharedPointer<QByte printerThread->start(); PrinterWorker *printerWorker = new PrinterWorker(result, currentPrinter); - QObject::connect(printerWorker, &PrinterWorker::resultReady, q, [=](bool success) { + QObject::connect(printerWorker, &PrinterWorker::resultReady, q, [requestId, this](bool success) { currentPrinter = nullptr; m_callbacks.invoke(requestId, success); }); @@ -1427,10 +1427,14 @@ void QWebEnginePage::triggerAction(WebAction action, bool) case CopyLinkToClipboard: if (menuData && !menuData->unfilteredLinkUrl().isEmpty()) { QString urlString = menuData->unfilteredLinkUrl().toString(QUrl::FullyEncoded); - QString title = menuData->linkText().toHtmlEscaped(); + QString linkText = menuData->linkText().toHtmlEscaped(); + QString title = menuData->titleText(); + if (!title.isEmpty()) + title = QStringLiteral(" title=\"%1\"").arg(title.toHtmlEscaped()); QMimeData *data = new QMimeData(); data->setText(urlString); - QString html = QStringLiteral("<a href=\"") + urlString + QStringLiteral("\">") + title + QStringLiteral("</a>"); + QString html = QStringLiteral("<a href=\"") + urlString + QStringLiteral("\"") + title + QStringLiteral(">") + + linkText + QStringLiteral("</a>"); data->setHtml(html); data->setUrls(QList<QUrl>() << menuData->unfilteredLinkUrl()); qApp->clipboard()->setMimeData(data); @@ -1453,12 +1457,15 @@ void QWebEnginePage::triggerAction(WebAction action, bool) case CopyImageUrlToClipboard: if (menuData && menuData->mediaUrl().isValid() && menuData->mediaType() == WebEngineContextMenuData::MediaTypeImage) { QString urlString = menuData->mediaUrl().toString(QUrl::FullyEncoded); - QString title = menuData->linkText(); + QString alt = menuData->altText(); + if (!alt.isEmpty()) + alt = QStringLiteral(" alt=\"%1\"").arg(alt.toHtmlEscaped()); + QString title = menuData->titleText(); if (!title.isEmpty()) - title = QStringLiteral(" alt=\"%1\"").arg(title.toHtmlEscaped()); + title = QStringLiteral(" title=\"%1\"").arg(title.toHtmlEscaped()); QMimeData *data = new QMimeData(); data->setText(urlString); - QString html = QStringLiteral("<img src=\"") + urlString + QStringLiteral("\"") + title + QStringLiteral("></img>"); + QString html = QStringLiteral("<img src=\"") + urlString + QStringLiteral("\"") + title + alt + QStringLiteral("></img>"); data->setHtml(html); data->setUrls(QList<QUrl>() << menuData->mediaUrl()); qApp->clipboard()->setMimeData(data); @@ -1476,12 +1483,17 @@ void QWebEnginePage::triggerAction(WebAction action, bool) menuData->mediaType() == WebEngineContextMenuData::MediaTypeVideo)) { QString urlString = menuData->mediaUrl().toString(QUrl::FullyEncoded); + QString title = menuData->titleText(); + if (!title.isEmpty()) + title = QStringLiteral(" title=\"%1\"").arg(title.toHtmlEscaped()); QMimeData *data = new QMimeData(); data->setText(urlString); if (menuData->mediaType() == WebEngineContextMenuData::MediaTypeAudio) - data->setHtml(QStringLiteral("<audio src=\"") + urlString + QStringLiteral("\"></audio>")); + data->setHtml(QStringLiteral("<audio src=\"") + urlString + QStringLiteral("\"") + title + + QStringLiteral("></audio>")); else - data->setHtml(QStringLiteral("<video src=\"") + urlString + QStringLiteral("\"></video>")); + data->setHtml(QStringLiteral("<video src=\"") + urlString + QStringLiteral("\"") + title + + QStringLiteral("></video>")); data->setUrls(QList<QUrl>() << menuData->mediaUrl()); qApp->clipboard()->setMimeData(data); } @@ -1720,8 +1732,8 @@ void QWebEnginePagePrivate::allowCertificateError(const QSharedPointer<Certifica accepted = q->certificateError(error); if (error.deferred() && !error.answered()) m_certificateErrorControllers.append(controller); - else if (!error.answered() && error.isOverridable()) - controller->accept(accepted); + else if (!error.answered()) + controller->accept(error.isOverridable() && accepted); } void QWebEnginePagePrivate::selectClientCert(const QSharedPointer<ClientCertSelectController> &controller) @@ -1817,7 +1829,7 @@ void QWebEnginePagePrivate::setToolTip(const QString &toolTipText) } // Update tooltip if text was changed. - QString wrappedTip = QLatin1String("<p style=\"white-space:pre\">") + QString wrappedTip = QLatin1String("<p style=\"white-space:pre-wrap\">") % toolTipText.toHtmlEscaped().left(MaxTooltipLength) % QLatin1String("</p>"); if (view->toolTip() != wrappedTip) @@ -1858,13 +1870,12 @@ void QWebEnginePagePrivate::visibleChanged(bool visible) Registers the request interceptor \a interceptor to intercept URL requests. The page does not take ownership of the pointer. This interceptor is called - after any interceptors on the profile, and unlike profile interceptors, is run - on the UI thread, making it thread-safer. Only URL requests from this page are - intercepted. + after any interceptors on the profile, and unlike profile interceptors, only + URL requests from this page are intercepted. To unset the request interceptor, set a \c nullptr. - \sa QWebEngineUrlRequestInfo, QWebEngineProfile::setRequestInterceptor() + \sa QWebEngineUrlRequestInfo, QWebEngineProfile::setUrlRequestInterceptor() */ void QWebEnginePage::setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor) @@ -2066,14 +2077,17 @@ QString QWebEnginePage::title() const void QWebEnginePage::setUrl(const QUrl &url) { Q_D(QWebEnginePage); - d->explicitUrl = url; + if (d->url != url) { + d->url = url; + emit urlChanged(url); + } load(url); } QUrl QWebEnginePage::url() const { Q_D(const QWebEnginePage); - return d->explicitUrl.isValid() ? d->explicitUrl : d->adapter->activeUrl(); + return d->url; } QUrl QWebEnginePage::requestedUrl() const @@ -2178,7 +2192,7 @@ void QWebEnginePage::runJavaScript(const QString& scriptSource, quint32 worldId, In addition, a page might also execute scripts added through QWebEngineProfile::scripts(). - \sa QWebEngineScriptCollection, QWebEngineScript + \sa QWebEngineScriptCollection, QWebEngineScript, {Script Injection} */ QWebEngineScriptCollection &QWebEnginePage::scripts() @@ -2293,14 +2307,12 @@ ASSERT_ENUMS_MATCH(FilePickerController::OpenMultiple, QWebEnginePage::FileSelec QStringList QWebEnginePage::chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes) { #if QT_CONFIG(filedialog) - // FIXME: Should we expose this in QWebPage's API ? Right now it is very open and can contain a mix and match of file extensions (which QFileDialog - // can work with) and mimetypes ranging from text/plain or images/* to application/vnd.openxmlformats-officedocument.spreadsheetml.sheet - Q_UNUSED(acceptedMimeTypes); + const QStringList &filter = FilePickerController::nameFilters(acceptedMimeTypes); QStringList ret; QString str; switch (static_cast<FilePickerController::FileChooserMode>(mode)) { case FilePickerController::OpenMultiple: - ret = QFileDialog::getOpenFileNames(view(), QString()); + ret = QFileDialog::getOpenFileNames(view(), QString(), QString(), filter.join(";;"), nullptr, QFileDialog::HideNameFilterDetails); break; // Chromium extension, not exposed as part of the public API for now. case FilePickerController::UploadFolder: @@ -2314,7 +2326,7 @@ QStringList QWebEnginePage::chooseFiles(FileSelectionMode mode, const QStringLis ret << str; break; case FilePickerController::Open: - str = QFileDialog::getOpenFileName(view(), QString(), oldFiles.first()); + str = QFileDialog::getOpenFileName(view(), QString(), oldFiles.first(), filter.join(";;"), nullptr, QFileDialog::HideNameFilterDetails); if (!str.isNull()) ret << str; break; @@ -2333,7 +2345,9 @@ void QWebEnginePage::javaScriptAlert(const QUrl &securityOrigin, const QString & { Q_UNUSED(securityOrigin); #if QT_CONFIG(messagebox) - QMessageBox::information(view(), QStringLiteral("Javascript Alert - %1").arg(url().toString()), msg); + QMessageBox::information(view(), + QStringLiteral("Javascript Alert - %1").arg(url().toString()), + msg.toHtmlEscaped()); #else Q_UNUSED(msg); #endif // QT_CONFIG(messagebox) @@ -2343,7 +2357,11 @@ bool QWebEnginePage::javaScriptConfirm(const QUrl &securityOrigin, const QString { Q_UNUSED(securityOrigin); #if QT_CONFIG(messagebox) - return (QMessageBox::information(view(), QStringLiteral("Javascript Confirm - %1").arg(url().toString()), msg, QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok); + return (QMessageBox::information(view(), + QStringLiteral("Javascript Confirm - %1").arg(url().toString()), + msg.toHtmlEscaped(), + QMessageBox::Ok, + QMessageBox::Cancel) == QMessageBox::Ok); #else Q_UNUSED(msg); return false; @@ -2356,7 +2374,12 @@ bool QWebEnginePage::javaScriptPrompt(const QUrl &securityOrigin, const QString #if QT_CONFIG(inputdialog) bool ret = false; if (result) - *result = QInputDialog::getText(view(), QStringLiteral("Javascript Prompt - %1").arg(url().toString()), msg, QLineEdit::Normal, defaultValue, &ret); + *result = QInputDialog::getText(view(), + QStringLiteral("Javascript Prompt - %1").arg(url().toString()), + msg.toHtmlEscaped(), + QLineEdit::Normal, + defaultValue.toHtmlEscaped(), + &ret); return ret; #else Q_UNUSED(msg); @@ -2544,7 +2567,7 @@ const QWebEngineContextMenuData &QWebEnginePage::contextMenuData() const \value Discarded Very low resource usage state where the entire browsing context is discarded. - \sa lifecycleState, {WebEngine Lifecycle Example} + \sa lifecycleState, {Page Lifecycle API}, {WebEngine Lifecycle Example} */ /*! @@ -2566,7 +2589,7 @@ const QWebEngineContextMenuData &QWebEnginePage::contextMenuData() const These are the only hard limits on the lifecycle state, but see also \l{recommendedState} for the recommended soft limits. - \sa recommendedState, {WebEngine Lifecycle Example} + \sa recommendedState, {Page Lifecycle API}, {WebEngine Lifecycle Example} */ QWebEnginePage::LifecycleState QWebEnginePage::lifecycleState() const @@ -2592,7 +2615,7 @@ void QWebEnginePage::setLifecycleState(LifecycleState state) playback or loss of HTML form input. Setting the lifecycle state to a higher resource state is however completely safe. - \sa lifecycleState + \sa lifecycleState, {Page Lifecycle API}, {WebEngine Lifecycle Example} */ QWebEnginePage::LifecycleState QWebEnginePage::recommendedState() const @@ -2672,16 +2695,13 @@ void QContextMenuBuilder::addMenuItem(ContextMenuItem menuItem) switch (menuItem) { case ContextMenuItem::Back: - action = new QAction(QIcon::fromTheme(QStringLiteral("go-previous")), QWebEnginePage::tr("&Back"), m_menu); - QObject::connect(action, &QAction::triggered, thisRef->d_ptr->view, &QWebEngineView::back); + action = thisRef->action(QWebEnginePage::Back); break; case ContextMenuItem::Forward: - action = new QAction(QIcon::fromTheme(QStringLiteral("go-next")), QWebEnginePage::tr("&Forward"), m_menu); - QObject::connect(action, &QAction::triggered, thisRef->d_ptr->view, &QWebEngineView::forward); + action = thisRef->action(QWebEnginePage::Forward); break; case ContextMenuItem::Reload: - action = new QAction(QIcon::fromTheme(QStringLiteral("view-refresh")), QWebEnginePage::tr("&Reload"), m_menu); - QObject::connect(action, &QAction::triggered, thisRef->d_ptr->view, &QWebEngineView::reload); + action = thisRef->action(QWebEnginePage::Reload); break; case ContextMenuItem::Cut: action = thisRef->action(QWebEnginePage::Cut); |