diff options
Diffstat (limited to 'src/webenginewidgets/api/qwebenginepage.cpp')
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 168 |
1 files changed, 159 insertions, 9 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index c2314a1ef..b13e6b2fd 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -40,6 +40,7 @@ #include "authentication_dialog_controller.h" #include "browser_context_adapter.h" #include "certificate_error_controller.h" +#include "color_chooser_controller.h" #include "file_picker_controller.h" #include "javascript_dialog_controller.h" #include "qwebenginefullscreenrequest.h" @@ -63,6 +64,7 @@ #include <QApplication> #include <QAuthenticator> #include <QClipboard> +#include <QColorDialog> #include <QContextMenuEvent> #include <QFileDialog> #include <QKeyEvent> @@ -159,6 +161,12 @@ void QWebEnginePagePrivate::selectionChanged() Q_EMIT q->selectionChanged(); } +void QWebEnginePagePrivate::wasRecentlyAudibleChanged(bool wasRecentlyAudible) +{ + Q_Q(QWebEnginePage); + Q_EMIT q->wasRecentlyAudibleChanged(wasRecentlyAudible); +} + QRectF QWebEnginePagePrivate::viewportRect() const { return view ? view->rect() : QRectF(); @@ -313,6 +321,20 @@ void QWebEnginePagePrivate::authenticationRequired(QSharedPointer<Authentication controller->accept(networkAuth.user(), networkAuth.password()); } +void QWebEnginePagePrivate::showColorDialog(QSharedPointer<ColorChooserController> controller) +{ + QColorDialog *dialog = new QColorDialog(controller.data()->initialColor(), view); + + QColorDialog::connect(dialog, SIGNAL(colorSelected(QColor)), controller.data(), SLOT(accept(QColor))); + QColorDialog::connect(dialog, SIGNAL(rejected()), controller.data(), SLOT(reject())); + + // Delete when done + QColorDialog::connect(dialog, SIGNAL(colorSelected(QColor)), dialog, SLOT(deleteLater())); + QColorDialog::connect(dialog, SIGNAL(rejected()), dialog, SLOT(deleteLater())); + + dialog->open(); +} + void QWebEnginePagePrivate::runMediaAccessPermissionRequest(const QUrl &securityOrigin, WebContentsAdapterClient::MediaRequestFlags requestFlags) { Q_Q(QWebEnginePage); @@ -410,6 +432,18 @@ void QWebEnginePagePrivate::recreateFromSerializedHistory(QDataStream &input) } } +void QWebEnginePagePrivate::updateScrollPosition(const QPointF &position) +{ + Q_Q(QWebEnginePage); + Q_EMIT q->scrollPositionChanged(position); +} + +void QWebEnginePagePrivate::updateContentsSize(const QSizeF &size) +{ + Q_Q(QWebEnginePage); + Q_EMIT q->contentsSizeChanged(size); +} + void QWebEnginePagePrivate::setFullScreenMode(bool fullscreen) { if (fullscreenMode != fullscreen) { @@ -423,6 +457,11 @@ BrowserContextAdapter *QWebEnginePagePrivate::browserContextAdapter() return profile->d_ptr->browserContext(); } +WebContentsAdapter *QWebEnginePagePrivate::webContentsAdapter() +{ + return adapter.data(); +} + QWebEnginePage::QWebEnginePage(QObject* parent) : QObject(parent) , d_ptr(new QWebEnginePagePrivate()) @@ -471,6 +510,20 @@ QWebEnginePage::QWebEnginePage(QObject* parent) */ /*! + \property QWebEnginePage::scrollPosition + \since 5.7 + + \brief The scroll position of the page contents. +*/ + +/*! + \property QWebEnginePage::contentsSize + \since 5.7 + + The size of the page contents. +*/ + +/*! Constructs an empty web engine page in the web engine profile \a profile with the parent \a parent. @@ -512,7 +565,7 @@ QWebEngineSettings *QWebEnginePage::settings() const * that is exposed in the JavaScript context of this page as \c qt.webChannelTransport. * * \since 5.5 - * \sa QWebChannel + * \sa setWebChannel */ QWebChannel *QWebEnginePage::webChannel() const { @@ -521,20 +574,41 @@ QWebChannel *QWebEnginePage::webChannel() const } /*! + * \overload + * + * Sets the web channel instance to be used by this page to \a channel and installs + * it in the main JavaScript world. + * + * With this method the web channel can be accessed by web page content. If the content + * is not under your control and might be hostile, this could be a security issue and + * you should consider installing it in a private JavaScript world. + * + * \since 5.5 + * \sa QWebEngineScript::MainWorld + */ + +void QWebEnginePage::setWebChannel(QWebChannel *channel) +{ + setWebChannel(channel, QWebEngineScript::MainWorld); +} + +/*! * Sets the web channel instance to be used by this page to \a channel and connects it to * web engine's transport using Chromium IPC messages. The transport is exposed in the JavaScript - * context of this page as + * world \a worldId as * \c qt.webChannelTransport, which should be used when using the \l{Qt WebChannel JavaScript API}. * * \note The page does not take ownership of the channel object. + * \note Only one web channel can be installed per page, setting one even in another JavaScript + * world uninstalls any already installed web channel. * - * \since 5.5 + * \since 5.7 + * \sa QWebEngineScript::ScriptWorldId */ - -void QWebEnginePage::setWebChannel(QWebChannel *channel) +void QWebEnginePage::setWebChannel(QWebChannel *channel, uint worldId) { Q_D(QWebEnginePage); - d->adapter->setWebChannel(channel); + d->adapter->setWebChannel(channel, worldId); } /*! @@ -564,6 +638,33 @@ void QWebEnginePage::setBackgroundColor(const QColor &color) d->adapter->backgroundColorChanged(); } +/*! + \property QWebEnginePage::audioMuted + \brief the state of whether the current page audio is muted. + \since 5.7 + + The default value is false. +*/ +bool QWebEnginePage::isAudioMuted() const { + const Q_D(QWebEnginePage); + return d->adapter->isAudioMuted(); +} + +void QWebEnginePage::setAudioMuted(bool muted) { + Q_D(QWebEnginePage); + bool _isAudioMuted = isAudioMuted(); + d->adapter->setAudioMuted(muted); + if (_isAudioMuted != muted) { + Q_EMIT audioMutedChanged(muted); + } +} + +bool QWebEnginePage::wasRecentlyAudible() +{ + Q_D(QWebEnginePage); + return d->adapter->wasRecentlyAudible(); +} + void QWebEnginePage::setView(QWidget *view) { QWebEngineViewPrivate::bind(qobject_cast<QWebEngineView*>(view), this); @@ -698,6 +799,12 @@ QAction *QWebEnginePage::action(WebAction action) const case RequestClose: text = tr("Close Page"); break; + case Unselect: + text = tr("Unselect"); + break; + case SavePage: + text = tr("Save &Page"); + break; default: break; } @@ -755,6 +862,9 @@ void QWebEnginePage::triggerAction(WebAction action, bool) case PasteAndMatchStyle: d->adapter->pasteAndMatchStyle(); break; + case Unselect: + d->adapter->unselect(); + break; case OpenLinkInThisWindow: if (d->m_menuData.linkUrl.isValid()) setUrl(d->m_menuData.linkUrl); @@ -858,7 +968,8 @@ void QWebEnginePage::triggerAction(WebAction action, bool) break; case ToggleMediaMute: if (d->m_menuData.mediaUrl.isValid() && d->m_menuData.mediaFlags & WebEngineContextMenuData::MediaHasAudio) { - bool enable = (d->m_menuData.mediaFlags & WebEngineContextMenuData::MediaMuted); + // Make sure to negate the value, so that toggling actually works. + bool enable = !(d->m_menuData.mediaFlags & WebEngineContextMenuData::MediaMuted); d->adapter->executeMediaPlayerActionAt(d->m_menuData.pos, WebContentsAdapter::MediaPlayerMute, enable); } break; @@ -871,6 +982,9 @@ void QWebEnginePage::triggerAction(WebAction action, bool) case RequestClose: d->adapter->requestClose(); break; + case SavePage: + d->adapter->save(); + break; default: Q_UNREACHABLE(); } @@ -1037,6 +1151,13 @@ void QWebEnginePagePrivate::renderProcessTerminated(RenderProcessTerminationStat terminationStatus), exitCode); } +void QWebEnginePagePrivate::startDragging(const content::DropData &dropData, + Qt::DropActions allowedActions, const QPixmap &pixmap, + const QPoint &offset) +{ + adapter->startDragging(view, dropData, allowedActions, pixmap, offset); +} + QMenu *QWebEnginePage::createStandardContextMenu() { Q_D(QWebEnginePage); @@ -1063,8 +1184,12 @@ QMenu *QWebEnginePage::createStandardContextMenu() action = new QAction(QIcon::fromTheme(QStringLiteral("view-refresh")), tr("&Reload"), menu); connect(action, &QAction::triggered, d->view, &QWebEngineView::reload); menu->addAction(action); + + if (!contextMenuData.linkUrl.isValid()) + menu->addAction(QWebEnginePage::action(SavePage)); } else { menu->addAction(QWebEnginePage::action(Copy)); + menu->addAction(QWebEnginePage::action(Unselect)); } if (!contextMenuData.linkText.isEmpty() && contextMenuData.linkUrl.isValid()) { @@ -1246,13 +1371,26 @@ void QWebEnginePage::setZoomFactor(qreal factor) void QWebEnginePage::runJavaScript(const QString &scriptSource) { Q_D(QWebEnginePage); - d->adapter->runJavaScript(scriptSource); + d->adapter->runJavaScript(scriptSource, QWebEngineScript::MainWorld); } void QWebEnginePage::runJavaScript(const QString& scriptSource, const QWebEngineCallback<const QVariant &> &resultCallback) { Q_D(QWebEnginePage); - quint64 requestId = d->adapter->runJavaScriptCallbackResult(scriptSource); + quint64 requestId = d->adapter->runJavaScriptCallbackResult(scriptSource, QWebEngineScript::MainWorld); + d->m_callbacks.registerCallback(requestId, resultCallback); +} + +void QWebEnginePage::runJavaScript(const QString &scriptSource, quint32 worldId) +{ + Q_D(QWebEnginePage); + d->adapter->runJavaScript(scriptSource, worldId); +} + +void QWebEnginePage::runJavaScript(const QString& scriptSource, quint32 worldId, const QWebEngineCallback<const QVariant &> &resultCallback) +{ + Q_D(QWebEnginePage); + quint64 requestId = d->adapter->runJavaScriptCallbackResult(scriptSource, worldId); d->m_callbacks.registerCallback(requestId, resultCallback); } @@ -1373,6 +1511,18 @@ bool QWebEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType typ return true; } +QPointF QWebEnginePage::scrollPosition() const +{ + Q_D(const QWebEnginePage); + return d->adapter->lastScrollOffset(); +} + +QSizeF QWebEnginePage::contentsSize() const +{ + Q_D(const QWebEnginePage); + return d->adapter->lastContentsSize(); +} + QT_END_NAMESPACE #include "moc_qwebenginepage.cpp" |