From e0bd650cb7f8c8fd3014541b4c49104906e0e139 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 20 Jun 2016 17:14:35 +0200 Subject: Override short-cuts to common editor commands To ensure Chromium is given a chance to handle editor commands, we must override these short-cuts. On OS X we must also perform the action afterwards as these are not handled internally by the Blink Editor. The patch solves copy/paste in flash plugins and copy/paste on OS X when no application short-cuts have been defined. The handling of short-cut override events is based on how it was handled in Qt WebKit Task-number: QTBUG-54221 Change-Id: I748671c7bfa5662aae16c6a4b9bbe5e2bce1b907 Reviewed-by: Alexandru Croitor --- src/webengine/api/qquickwebengineview.cpp | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/webengine/api/qquickwebengineview.cpp') diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 357f95bc4..6b3614fc5 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -86,6 +86,27 @@ QT_BEGIN_NAMESPACE using namespace QtWebEngineCore; +QQuickWebEngineView::WebAction editorActionForKeyEvent(QKeyEvent* event) +{ + static struct { + QKeySequence::StandardKey standardKey; + QQuickWebEngineView::WebAction action; + } editorActions[] = { + { QKeySequence::Cut, QQuickWebEngineView::Cut }, + { QKeySequence::Copy, QQuickWebEngineView::Copy }, + { QKeySequence::Paste, QQuickWebEngineView::Paste }, + { QKeySequence::Undo, QQuickWebEngineView::Undo }, + { QKeySequence::Redo, QQuickWebEngineView::Redo }, + { QKeySequence::SelectAll, QQuickWebEngineView::SelectAll }, + { QKeySequence::UnknownKey, QQuickWebEngineView::NoWebAction } + }; + for (int i = 0; editorActions[i].standardKey != QKeySequence::UnknownKey; ++i) + if (event == editorActions[i].standardKey) + return editorActions[i].action; + + return QQuickWebEngineView::NoWebAction; +} + #ifndef QT_NO_ACCESSIBILITY static QAccessibleInterface *webAccessibleFactory(const QString &, QObject *object) { @@ -489,6 +510,18 @@ void QQuickWebEngineViewPrivate::focusContainer() void QQuickWebEngineViewPrivate::unhandledKeyEvent(QKeyEvent *event) { Q_Q(QQuickWebEngineView); +#ifdef Q_OS_OSX + if (event->type() == QEvent::KeyPress) { + QQuickWebEngineView::WebAction action = editorActionForKeyEvent(event); + if (action != QQuickWebEngineView::NoWebAction) { + // Try triggering a registered short-cut + if (QGuiApplicationPrivate::instance()->shortcutMap.tryShortcut(event)) + return; + q->triggerWebAction(action); + return; + } + } +#endif if (q->parentItem()) q->window()->sendEvent(q->parentItem(), event); } -- cgit v1.2.3 From 964963f76acbcc6df8f021b5b36dbc5e726027b6 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Tue, 21 Jun 2016 16:01:03 +0200 Subject: Fix memory leak of unhandled certificateError If a user does not handle onCertificateError the instance of QQuickWebEngineCertificateError never gets to JavaScript land and never gets deleted. Create a strong reference before emitting the onCertificateError to guard against the memory leak. Change-Id: I49dbf89445d32291e2f52976f0f5e9deda201fcb Reviewed-by: Simon Hausmann Reviewed-by: Allan Sandfeld Jensen --- src/webengine/api/qquickwebengineview.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/webengine/api/qquickwebengineview.cpp') diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 6b3614fc5..ddca1b670 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -351,7 +351,8 @@ void QQuickWebEngineViewPrivate::allowCertificateError(const QSharedPointernewQObject(quickController); Q_EMIT q->certificateError(quickController); if (!quickController->deferred() && !quickController->answered()) quickController->rejectCertificate(); -- cgit v1.2.3 From 06864c75f4d009bf8fd4e9f88215bb88341ed873 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 30 Jun 2016 17:41:31 +0200 Subject: Switch WebContentsAdapter to using shared pointers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QExplicitSharedDataPointer is meant for value objects, not for shared objects. Instead switch to using QSharedPointer. Change-Id: Ib3791bbcfde627a67508f2819e141d8c538a4a50 Reviewed-by: Michael BrĂ¼ning Reviewed-by: Michal Klocek --- src/webengine/api/qquickwebengineview.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/webengine/api/qquickwebengineview.cpp') diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index ddca1b670..95aaa39e6 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -527,7 +527,7 @@ void QQuickWebEngineViewPrivate::unhandledKeyEvent(QKeyEvent *event) q->window()->sendEvent(q->parentItem(), event); } -void QQuickWebEngineViewPrivate::adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &) +void QQuickWebEngineViewPrivate::adoptNewWindow(QSharedPointer newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &) { Q_Q(QQuickWebEngineView); QQuickWebEngineNewViewRequest request; @@ -728,7 +728,7 @@ QAccessible::State QQuickWebEngineViewAccessible::state() const class WebContentsAdapterOwner : public QObject { public: - typedef QExplicitlySharedDataPointer AdapterPtr; + typedef QSharedPointer AdapterPtr; WebContentsAdapterOwner(const AdapterPtr &ptr) : adapter(ptr) {} @@ -755,9 +755,9 @@ void QQuickWebEngineViewPrivate::adoptWebContents(WebContentsAdapter *webContent // This throws away the WebContentsAdapter that has been used until now. // All its states, particularly the loading URL, are replaced by the adopted WebContentsAdapter. - WebContentsAdapterOwner *adapterOwner = new WebContentsAdapterOwner(adapter); + WebContentsAdapterOwner *adapterOwner = new WebContentsAdapterOwner(adapter->sharedFromThis()); adapterOwner->deleteLater(); - adapter = webContents; + adapter = webContents->sharedFromThis(); adapter->initialize(this); // associate the webChannel with the new adapter @@ -810,7 +810,7 @@ void QQuickWebEngineViewPrivate::ensureContentsAdapter() { Q_Q(QQuickWebEngineView); if (!adapter) { - adapter = new WebContentsAdapter(); + adapter = QSharedPointer::create(); adapter->initialize(this); if (m_backgroundColor != Qt::white) adapter->backgroundColorChanged(); @@ -970,7 +970,7 @@ void QQuickWebEngineViewPrivate::setProfile(QQuickWebEngineProfile *profile) if (adapter && adapter->browserContext() != browserContextAdapter()->browserContext()) { // When the profile changes we need to create a new WebContentAdapter and reload the active URL. QUrl activeUrl = adapter->activeUrl(); - adapter = 0; + adapter.reset(); ensureContentsAdapter(); if (!explicitUrl.isValid() && activeUrl.isValid()) -- cgit v1.2.3