diff options
Diffstat (limited to 'src/webenginewidgets/api')
-rw-r--r-- | src/webenginewidgets/api/qwebenginecontextmenudata.cpp | 3 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem.cpp | 87 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem.h | 4 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem_p.h | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 86 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.h | 16 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.cpp | 7 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile_p.h | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginesettings.cpp | 2 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginesettings.h | 3 |
10 files changed, 185 insertions, 25 deletions
diff --git a/src/webenginewidgets/api/qwebenginecontextmenudata.cpp b/src/webenginewidgets/api/qwebenginecontextmenudata.cpp index 5d68ed0ec..63e11175b 100644 --- a/src/webenginewidgets/api/qwebenginecontextmenudata.cpp +++ b/src/webenginewidgets/api/qwebenginecontextmenudata.cpp @@ -148,10 +148,11 @@ QString QWebEngineContextMenuData::linkText() const /*! Returns the URL of a link if the context is a link. + It is not guaranteed to be a valid URL. */ QUrl QWebEngineContextMenuData::linkUrl() const { - return d ? d->linkUrl() : QUrl(); + return d ? d->unfilteredLinkUrl() : QUrl(); } /*! diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp index c1d9a3698..a5569e408 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp +++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp @@ -38,10 +38,12 @@ ****************************************************************************/ #include "qwebenginedownloaditem.h" - #include "qwebenginedownloaditem_p.h" + +#include "browser_context_adapter.h" #include "qwebengineprofile_p.h" + QT_BEGIN_NAMESPACE using QtWebEngineCore::BrowserContextAdapterClient; @@ -116,6 +118,7 @@ QWebEngineDownloadItemPrivate::QWebEngineDownloadItemPrivate(QWebEngineProfilePr , type(QWebEngineDownloadItem::Attachment) , interruptReason(QWebEngineDownloadItem::NoReason) , downloadUrl(url) + , downloadPaused(false) , totalBytes(-1) , receivedBytes(0) { @@ -145,10 +148,16 @@ void QWebEngineDownloadItemPrivate::update(const BrowserContextAdapterClient::Do Q_EMIT q->downloadProgress(receivedBytes, totalBytes); } - downloadFinished = downloadState != QWebEngineDownloadItem::DownloadInProgress; + if (info.done != downloadFinished) { + downloadFinished = info.done; + if (downloadFinished) + Q_EMIT q->finished(); + } - if (downloadFinished) - Q_EMIT q->finished(); + if (downloadPaused != info.paused) { + downloadPaused = info.paused; + Q_EMIT q->isPausedChanged(downloadPaused); + } } /*! @@ -184,13 +193,50 @@ void QWebEngineDownloadItem::cancel() || state == QWebEngineDownloadItem::DownloadCancelled) return; - d->downloadState = QWebEngineDownloadItem::DownloadCancelled; - Q_EMIT stateChanged(d->downloadState); - // We directly cancel the download request if the user cancels // before it even started, so no need to notify the profile here. if (state == QWebEngineDownloadItem::DownloadInProgress) - d->profile->cancelDownload(d->downloadId); + d->profile->browserContext()->cancelDownload(d->downloadId); + else { + d->downloadState = QWebEngineDownloadItem::DownloadCancelled; + Q_EMIT stateChanged(d->downloadState); + } +} + +/*! + \since 5.10 + Pauses the current download. Has no effect if the state is not \c DownloadInProgress. + + \sa resume() +*/ + +void QWebEngineDownloadItem::pause() +{ + Q_D(QWebEngineDownloadItem); + + QWebEngineDownloadItem::DownloadState state = d->downloadState; + + if (state != QWebEngineDownloadItem::DownloadInProgress) + return; + + d->profile->browserContext()->pauseDownload(d->downloadId); +} + +/*! + \since 5.10 + Resumes the current download if it was paused or interrupted. + + \sa pause(), isPaused(), state() +*/ +void QWebEngineDownloadItem::resume() +{ + Q_D(QWebEngineDownloadItem); + + QWebEngineDownloadItem::DownloadState state = d->downloadState; + + if (d->downloadFinished || (state != QWebEngineDownloadItem::DownloadInProgress && state != QWebEngineDownloadItem::DownloadInterrupted)) + return; + d->profile->browserContext()->resumeDownload(d->downloadId); } /*! @@ -206,12 +252,21 @@ quint32 QWebEngineDownloadItem::id() const /*! \fn QWebEngineDownloadItem::finished() - This signal is emitted whenever the download finishes. + This signal is emitted when the download finishes. \sa state(), isFinished() */ /*! + \fn QWebEngineDownloadItem::isPausedChanged(bool isPaused) + \since 5.10 + + This signal is emitted whenever \a isPaused changes. + + \sa pause(), isPaused() +*/ + +/*! \fn QWebEngineDownloadItem::stateChanged(DownloadState state) This signal is emitted whenever the download's \a state changes. @@ -407,7 +462,7 @@ void QWebEngineDownloadItem::setPath(QString path) } /*! - Returns whether this download is finished (not in progress). + Returns whether this download is finished (completed, cancelled, or non-resumable interrupted state). \sa finished(), state(), */ @@ -419,6 +474,18 @@ bool QWebEngineDownloadItem::isFinished() const } /*! + Returns whether this download is paused. + + \sa pause() +*/ + +bool QWebEngineDownloadItem::isPaused() const +{ + Q_D(const QWebEngineDownloadItem); + return d->downloadPaused; +} + +/*! Returns the format the web page will be saved in if this is a download request for a web page. \since 5.7 diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.h b/src/webenginewidgets/api/qwebenginedownloaditem.h index a4b6c08aa..2aca2bb2a 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.h +++ b/src/webenginewidgets/api/qwebenginedownloaditem.h @@ -120,6 +120,7 @@ public: QString path() const; void setPath(QString path); bool isFinished() const; + bool isPaused() const; SavePageFormat savePageFormat() const; void setSavePageFormat(SavePageFormat format); DownloadType type() const; @@ -129,11 +130,14 @@ public: public Q_SLOTS: void accept(); void cancel(); + void pause(); + void resume(); Q_SIGNALS: void finished(); void stateChanged(QWebEngineDownloadItem::DownloadState state); void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); + void isPausedChanged(bool isPaused); private: Q_DISABLE_COPY(QWebEngineDownloadItem) diff --git a/src/webenginewidgets/api/qwebenginedownloaditem_p.h b/src/webenginewidgets/api/qwebenginedownloaditem_p.h index 038332da3..da765e5c5 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem_p.h +++ b/src/webenginewidgets/api/qwebenginedownloaditem_p.h @@ -77,6 +77,7 @@ public: QString downloadPath; const QUrl downloadUrl; QString mimeType; + bool downloadPaused; qint64 totalBytes; qint64 receivedBytes; diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 6042b9fdc..d0305f81a 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -60,6 +60,7 @@ #include "render_widget_host_view_qt_delegate_widget.h" #include "web_contents_adapter.h" #include "web_engine_settings.h" +#include "qwebenginescript.h" #ifdef QT_UI_DELEGATES #include "ui/messagebubblewidget_p.h" @@ -352,7 +353,6 @@ void QWebEnginePagePrivate::loadFinished(bool success, const QUrl &url, bool isE if (isErrorPage) { Q_ASSERT(settings->testAttribute(QWebEngineSettings::ErrorPageEnabled)); - Q_ASSERT(success); Q_EMIT q->loadFinished(false); return; } @@ -376,8 +376,10 @@ void QWebEnginePagePrivate::didPrintPageToPdf(const QString &filePath, bool succ void QWebEnginePagePrivate::focusContainer() { - if (view) + if (view) { + view->activateWindow(); view->setFocus(); + } } void QWebEnginePagePrivate::unhandledKeyEvent(QKeyEvent *event) @@ -1140,6 +1142,42 @@ QAction *QWebEnginePage::action(WebAction action) const case ViewSource: text = tr("&View Page Source"); break; + case ToggleBold: + text = tr("&Bold"); + break; + case ToggleItalic: + text = tr("&Italic"); + break; + case ToggleUnderline: + text = tr("&Underline"); + break; + case ToggleStrikethrough: + text = tr("&Strikethrough"); + break; + case AlignLeft: + text = tr("Align &Left"); + break; + case AlignCenter: + text = tr("Align &Center"); + break; + case AlignRight: + text = tr("Align &Right"); + break; + case AlignJustified: + text = tr("Align &Justified"); + break; + case Indent: + text = tr("&Indent"); + break; + case Outdent: + text = tr("&Outdent"); + break; + case InsertOrderedList: + text = tr("Insert &Ordered List"); + break; + case InsertUnorderedList: + text = tr("Insert &Unordered List"); + break; case NoWebAction: case WebActionCount: Q_UNREACHABLE(); @@ -1229,14 +1267,14 @@ void QWebEnginePage::triggerAction(WebAction action, bool) } break; case CopyLinkToClipboard: - if (menuData.linkUrl().isValid()) { - QString urlString = menuData.linkUrl().toString(QUrl::FullyEncoded); + if (!menuData.unfilteredLinkUrl().isEmpty()) { + QString urlString = menuData.unfilteredLinkUrl().toString(QUrl::FullyEncoded); QString title = menuData.linkText().toHtmlEscaped(); QMimeData *data = new QMimeData(); data->setText(urlString); QString html = QStringLiteral("<a href=\"") + urlString + QStringLiteral("\">") + title + QStringLiteral("</a>"); data->setHtml(html); - data->setUrls(QList<QUrl>() << menuData.linkUrl()); + data->setUrls(QList<QUrl>() << menuData.unfilteredLinkUrl()); qApp->clipboard()->setMimeData(data); } break; @@ -1341,6 +1379,42 @@ void QWebEnginePage::triggerAction(WebAction action, bool) // the viewSource() call after the QMenu's destruction. QTimer::singleShot(0, this, [d](){ d->adapter->viewSource(); }); break; + case ToggleBold: + runJavaScript(QStringLiteral("document.execCommand('bold');"), QWebEngineScript::ApplicationWorld); + break; + case ToggleItalic: + runJavaScript(QStringLiteral("document.execCommand('italic');"), QWebEngineScript::ApplicationWorld); + break; + case ToggleUnderline: + runJavaScript(QStringLiteral("document.execCommand('underline');"), QWebEngineScript::ApplicationWorld); + break; + case ToggleStrikethrough: + runJavaScript(QStringLiteral("document.execCommand('strikethrough');"), QWebEngineScript::ApplicationWorld); + break; + case AlignLeft: + runJavaScript(QStringLiteral("document.execCommand('justifyLeft');"), QWebEngineScript::ApplicationWorld); + break; + case AlignCenter: + runJavaScript(QStringLiteral("document.execCommand('justifyCenter');"), QWebEngineScript::ApplicationWorld); + break; + case AlignRight: + runJavaScript(QStringLiteral("document.execCommand('justifyRight');"), QWebEngineScript::ApplicationWorld); + break; + case AlignJustified: + runJavaScript(QStringLiteral("document.execCommand('justifyFull');"), QWebEngineScript::ApplicationWorld); + break; + case Indent: + runJavaScript(QStringLiteral("document.execCommand('indent');"), QWebEngineScript::ApplicationWorld); + break; + case Outdent: + runJavaScript(QStringLiteral("document.execCommand('outdent');"), QWebEngineScript::ApplicationWorld); + break; + case InsertOrderedList: + runJavaScript(QStringLiteral("document.execCommand('insertOrderedList');"), QWebEngineScript::ApplicationWorld); + break; + case InsertUnorderedList: + runJavaScript(QStringLiteral("document.execCommand('insertUnorderedList');"), QWebEngineScript::ApplicationWorld); + break; case NoWebAction: break; case WebActionCount: @@ -1605,7 +1679,7 @@ QMenu *QWebEnginePage::createStandardContextMenu() menu->addAction(QWebEnginePage::action(Unselect)); } - if (!contextMenuData.linkText().isEmpty() && contextMenuData.linkUrl().isValid()) { + if (!contextMenuData.linkText().isEmpty() && !contextMenuData.unfilteredLinkUrl().isEmpty()) { menu->addAction(QWebEnginePage::action(CopyLinkToClipboard)); } if (contextMenuData.mediaUrl().isValid()) { diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h index 5619639c7..74ebd0a35 100644 --- a/src/webenginewidgets/api/qwebenginepage.h +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -128,6 +128,22 @@ public: SavePage, OpenLinkInNewBackgroundTab, ViewSource, + + ToggleBold, + ToggleItalic, + ToggleUnderline, + ToggleStrikethrough, + + AlignLeft, + AlignCenter, + AlignRight, + AlignJustified, + Indent, + Outdent, + + InsertOrderedList, + InsertUnorderedList, + WebActionCount }; Q_ENUM(WebAction) diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index cd4fc8b02..73998030c 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -151,7 +151,7 @@ QWebEngineProfilePrivate::QWebEngineProfilePrivate(QSharedPointer<BrowserContext , m_browserContextRef(browserContext) { m_browserContextRef->addClient(this); - m_settings->d_ptr->initDefaults(browserContext->isOffTheRecord()); + m_settings->d_ptr->initDefaults(); } QWebEngineProfilePrivate::~QWebEngineProfilePrivate() @@ -172,11 +172,6 @@ QWebEngineProfilePrivate::~QWebEngineProfilePrivate() m_ongoingDownloads.clear(); } -void QWebEngineProfilePrivate::cancelDownload(quint32 downloadId) -{ - browserContext()->cancelDownload(downloadId); -} - void QWebEngineProfilePrivate::downloadDestroyed(quint32 downloadId) { m_ongoingDownloads.remove(downloadId); diff --git a/src/webenginewidgets/api/qwebengineprofile_p.h b/src/webenginewidgets/api/qwebengineprofile_p.h index 4d31c5a81..c5a75f6d4 100644 --- a/src/webenginewidgets/api/qwebengineprofile_p.h +++ b/src/webenginewidgets/api/qwebengineprofile_p.h @@ -76,7 +76,6 @@ public: QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext() const { return m_browserContextRef; } QWebEngineSettings *settings() const { return m_settings; } - void cancelDownload(quint32 downloadId); void downloadDestroyed(quint32 downloadId); void downloadRequested(DownloadItemInfo &info) Q_DECL_OVERRIDE; diff --git a/src/webenginewidgets/api/qwebenginesettings.cpp b/src/webenginewidgets/api/qwebenginesettings.cpp index 65c77a54d..6e24b4b51 100644 --- a/src/webenginewidgets/api/qwebenginesettings.cpp +++ b/src/webenginewidgets/api/qwebenginesettings.cpp @@ -97,6 +97,8 @@ static WebEngineSettings::Attribute toWebEngineAttribute(QWebEngineSettings::Web return WebEngineSettings::AllowRunningInsecureContent; case QWebEngineSettings::AllowGeolocationOnInsecureOrigins: return WebEngineSettings::AllowGeolocationOnInsecureOrigins; + case QWebEngineSettings::AllowWindowActivationFromJavaScript: + return WebEngineSettings::AllowWindowActivationFromJavaScript; default: return WebEngineSettings::UnsupportedInCoreSettings; diff --git a/src/webenginewidgets/api/qwebenginesettings.h b/src/webenginewidgets/api/qwebenginesettings.h index 73995a457..4b997f0ac 100644 --- a/src/webenginewidgets/api/qwebenginesettings.h +++ b/src/webenginewidgets/api/qwebenginesettings.h @@ -89,7 +89,8 @@ public: FocusOnNavigationEnabled, PrintElementBackgrounds, AllowRunningInsecureContent, - AllowGeolocationOnInsecureOrigins + AllowGeolocationOnInsecureOrigins, + AllowWindowActivationFromJavaScript }; enum FontSize { |