summaryrefslogtreecommitdiffstats
path: root/src/webengine
diff options
context:
space:
mode:
authorViktor Engelmann <Viktor.Engelmann@qt.io>2017-03-13 14:30:02 +0100
committerViktor Engelmann <viktor.engelmann@qt.io>2017-05-24 08:03:01 +0000
commitb0324c5e020b98cbc0caf8176bbdfc5cd80b545e (patch)
tree8227937e524c862e0f8d72a2a16924f6d906fd13 /src/webengine
parentac34e49473d731b068c7782674069cb9fcc95328 (diff)
Handle ViewHostMsg_Focus message from chromium
Calling the method window.focus() in javascript causes chromium to send a ViewHostMsg_Focus message, which is received by RenderViewHost, which then calls RenderViewHost::OnFocus. This calls WebContentsDelegate::ActivateContents, which does nothing in the default implementation. We now override this method in WebContentsDelegateQt::ActivateContents and call Focus() on the WebContents object IF the new WebEngineSettings value AllowWindowActivationFromJavaScript is true (by default, it is false). This in turn calls QWebEnginePagePrivate::focusContainer. The WebEnginePage now calls QWidget::activateWindow() in addition to QWidget::setFocus, to make sure the window is also activated (which it might not be, if multiple windows are open). For the QML side, a new boolean Property allowWindowActivationFromJavaScript was added. Task-number: QTBUG-58800 Change-Id: Iabf5d4d15236c77838a3886de81e9dafcaf49f5d Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/webengine')
-rw-r--r--src/webengine/api/qquickwebenginesettings.cpp18
-rw-r--r--src/webengine/api/qquickwebenginesettings_p.h4
-rw-r--r--src/webengine/api/qquickwebengineview.cpp3
-rw-r--r--src/webengine/plugin/plugin.cpp1
-rw-r--r--src/webengine/plugin/plugin.pro2
-rw-r--r--src/webengine/plugin/plugins.qmltypes9
6 files changed, 33 insertions, 4 deletions
diff --git a/src/webengine/api/qquickwebenginesettings.cpp b/src/webengine/api/qquickwebenginesettings.cpp
index ff2541376..cdbb25e4c 100644
--- a/src/webengine/api/qquickwebenginesettings.cpp
+++ b/src/webengine/api/qquickwebenginesettings.cpp
@@ -363,6 +363,16 @@ bool QQuickWebEngineSettings::allowGeolocationOnInsecureOrigins() const
}
/*!
+ \qmlproperty bool WebEngineSettings::allowWindowActivationFromJavaScript
+ \since QtWebEngine 1.6
+ Allows the window.focus() method in JavaScript. Disallowed by default.
+*/
+bool QQuickWebEngineSettings::allowWindowActivationFromJavaScript() const
+{
+ return d_ptr->testAttribute(WebEngineSettings::AllowWindowActivationFromJavaScript);
+}
+
+/*!
\qmlproperty string WebEngineSettings::defaultTextEncoding
\since QtWebEngine 1.2
@@ -564,6 +574,14 @@ void QQuickWebEngineSettings::setAllowGeolocationOnInsecureOrigins(bool on)
Q_EMIT allowGeolocationOnInsecureOriginsChanged();
}
+void QQuickWebEngineSettings::setAllowWindowActivationFromJavaScript(bool on)
+{
+ bool wasOn = d_ptr->testAttribute(WebEngineSettings::AllowWindowActivationFromJavaScript);
+ d_ptr->setAttribute(WebEngineSettings::AllowWindowActivationFromJavaScript, on);
+ if (wasOn != on)
+ Q_EMIT allowWindowActivationFromJavaScriptChanged();
+}
+
void QQuickWebEngineSettings::setParentSettings(QQuickWebEngineSettings *parentSettings)
{
d_ptr->setParentSettings(parentSettings->d_ptr.data());
diff --git a/src/webengine/api/qquickwebenginesettings_p.h b/src/webengine/api/qquickwebenginesettings_p.h
index 10217c678..1b9988bce 100644
--- a/src/webengine/api/qquickwebenginesettings_p.h
+++ b/src/webengine/api/qquickwebenginesettings_p.h
@@ -86,6 +86,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineSettings : public QObject {
Q_PROPERTY(bool printElementBackgrounds READ printElementBackgrounds WRITE setPrintElementBackgrounds NOTIFY printElementBackgroundsChanged REVISION 3 FINAL)
Q_PROPERTY(bool allowRunningInsecureContent READ allowRunningInsecureContent WRITE setAllowRunningInsecureContent NOTIFY allowRunningInsecureContentChanged REVISION 3 FINAL)
Q_PROPERTY(bool allowGeolocationOnInsecureOrigins READ allowGeolocationOnInsecureOrigins WRITE setAllowGeolocationOnInsecureOrigins NOTIFY allowGeolocationOnInsecureOriginsChanged REVISION 4 FINAL)
+ Q_PROPERTY(bool allowWindowActivationFromJavaScript READ allowWindowActivationFromJavaScript WRITE setAllowWindowActivationFromJavaScript NOTIFY allowWindowActivationFromJavaScriptChanged REVISION 5 FINAL)
public:
~QQuickWebEngineSettings();
@@ -113,6 +114,7 @@ public:
bool printElementBackgrounds() const;
bool allowRunningInsecureContent() const;
bool allowGeolocationOnInsecureOrigins() const;
+ bool allowWindowActivationFromJavaScript() const;
void setAutoLoadImages(bool on);
void setJavascriptEnabled(bool on);
@@ -137,6 +139,7 @@ public:
void setPrintElementBackgrounds(bool on);
void setAllowRunningInsecureContent(bool on);
void setAllowGeolocationOnInsecureOrigins(bool on);
+ void setAllowWindowActivationFromJavaScript(bool on);
signals:
void autoLoadImagesChanged();
@@ -162,6 +165,7 @@ signals:
Q_REVISION(3) void printElementBackgroundsChanged();
Q_REVISION(3) void allowRunningInsecureContentChanged();
Q_REVISION(4) void allowGeolocationOnInsecureOriginsChanged();
+ Q_REVISION(5) void allowWindowActivationFromJavaScriptChanged();
private:
explicit QQuickWebEngineSettings(QQuickWebEngineSettings *parentSettings = 0);
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index 45f65e49b..dac844fdb 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -564,6 +564,9 @@ void QQuickWebEngineViewPrivate::loadFinished(bool success, const QUrl &url, boo
void QQuickWebEngineViewPrivate::focusContainer()
{
Q_Q(QQuickWebEngineView);
+ QQuickWindow *window = q->window();
+ if (window)
+ window->requestActivate();
q->forceActiveFocus();
}
diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp
index 3c8991ff7..668d55458 100644
--- a/src/webengine/plugin/plugin.cpp
+++ b/src/webengine/plugin/plugin.cpp
@@ -109,6 +109,7 @@ public:
qmlRegisterUncreatableType<QQuickWebEngineSettings, 2>(uri, 1, 3, "WebEngineSettings", tr("Cannot create a separate instance of WebEngineSettings"));
qmlRegisterUncreatableType<QQuickWebEngineSettings, 3>(uri, 1, 4, "WebEngineSettings", tr("Cannot create a separate instance of WebEngineSettings"));
qmlRegisterUncreatableType<QQuickWebEngineSettings, 4>(uri, 1, 5, "WebEngineSettings", tr("Cannot create a separate instance of WebEngineSettings"));
+ qmlRegisterUncreatableType<QQuickWebEngineSettings, 5>(uri, 1, 6, "WebEngineSettings", tr("Cannot create a separate instance of WebEngineSettings"));
qmlRegisterSingletonType<QQuickWebEngineSingleton>(uri, 1, 1, "WebEngine", webEngineSingletonProvider);
qmlRegisterUncreatableType<QQuickWebEngineHistory>(uri, 1, 1, "NavigationHistory",
tr("Cannot create a separate instance of NavigationHistory"));
diff --git a/src/webengine/plugin/plugin.pro b/src/webengine/plugin/plugin.pro
index 68404b4f8..1f9ef00c5 100644
--- a/src/webengine/plugin/plugin.pro
+++ b/src/webengine/plugin/plugin.pro
@@ -1,7 +1,7 @@
CXX_MODULE = qml
TARGET = qtwebengineplugin
TARGETPATH = QtWebEngine
-IMPORT_VERSION = 1.5
+IMPORT_VERSION = 1.6
QT += webengine qml quick
QT_PRIVATE += webengine-private
diff --git a/src/webengine/plugin/plugins.qmltypes b/src/webengine/plugin/plugins.qmltypes
index 81ff25a63..0cfa2d25b 100644
--- a/src/webengine/plugin/plugins.qmltypes
+++ b/src/webengine/plugin/plugins.qmltypes
@@ -4,7 +4,7 @@ import QtQuick.tooling 1.2
// It is used for QML tooling purposes only.
//
// This file was auto-generated by:
-// 'qmlplugindump -defaultplatform -dependencies dependencies.json -nonrelocatable QtWebEngine 1.5'
+// 'qmlplugindump -defaultplatform -dependencies dependencies.json -nonrelocatable QtWebEngine 1.6'
Module {
dependencies: ["QtQuick 2.6"]
@@ -509,10 +509,11 @@ Module {
"QtWebEngine/WebEngineSettings 1.2",
"QtWebEngine/WebEngineSettings 1.3",
"QtWebEngine/WebEngineSettings 1.4",
- "QtWebEngine/WebEngineSettings 1.5"
+ "QtWebEngine/WebEngineSettings 1.5",
+ "QtWebEngine/WebEngineSettings 1.6"
]
isCreatable: false
- exportMetaObjectRevisions: [0, 1, 2, 3, 4]
+ exportMetaObjectRevisions: [0, 1, 2, 3, 4, 5]
Property { name: "autoLoadImages"; type: "bool" }
Property { name: "javascriptEnabled"; type: "bool" }
Property { name: "javascriptCanOpenWindows"; type: "bool" }
@@ -536,6 +537,7 @@ Module {
Property { name: "printElementBackgrounds"; revision: 3; type: "bool" }
Property { name: "allowRunningInsecureContent"; revision: 3; type: "bool" }
Property { name: "allowGeolocationOnInsecureOrigins"; revision: 4; type: "bool" }
+ Property { name: "allowWindowActivationFromJavaScript"; revision: 5; type: "bool" }
Signal { name: "fullScreenSupportEnabledChanged"; revision: 1 }
Signal { name: "screenCaptureEnabledChanged"; revision: 2 }
Signal { name: "webGLEnabledChanged"; revision: 2 }
@@ -546,6 +548,7 @@ Module {
Signal { name: "printElementBackgroundsChanged"; revision: 3 }
Signal { name: "allowRunningInsecureContentChanged"; revision: 3 }
Signal { name: "allowGeolocationOnInsecureOriginsChanged"; revision: 4 }
+ Signal { name: "allowWindowActivationFromJavaScriptChanged"; revision: 5 }
}
Component {
name: "QQuickWebEngineSingleton"