diff options
author | Viktor Engelmann <Viktor.Engelmann@qt.io> | 2017-03-13 14:30:02 +0100 |
---|---|---|
committer | Viktor Engelmann <viktor.engelmann@qt.io> | 2017-05-24 08:03:01 +0000 |
commit | b0324c5e020b98cbc0caf8176bbdfc5cd80b545e (patch) | |
tree | 8227937e524c862e0f8d72a2a16924f6d906fd13 /src/core | |
parent | ac34e49473d731b068c7782674069cb9fcc95328 (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/core')
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 7 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.h | 1 | ||||
-rw-r--r-- | src/core/web_engine_settings.cpp | 1 | ||||
-rw-r--r-- | src/core/web_engine_settings.h | 3 |
4 files changed, 11 insertions, 1 deletions
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 6c5b63960..3e09df340 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -403,6 +403,13 @@ void WebContentsDelegateQt::DidFirstVisuallyNonEmptyPaint() } } +void WebContentsDelegateQt::ActivateContents(content::WebContents* contents) +{ + WebEngineSettings *settings = m_viewClient->webEngineSettings(); + if (settings->testAttribute(settings->Attribute::AllowWindowActivationFromJavaScript)) + contents->Focus(); +} + void WebContentsDelegateQt::RequestToLockMouse(content::WebContents *web_contents, bool user_gesture, bool last_unlocked_by_target) { Q_UNUSED(user_gesture); diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h index 2e294a841..8b5f5fd80 100644 --- a/src/core/web_contents_delegate_qt.h +++ b/src/core/web_contents_delegate_qt.h @@ -136,6 +136,7 @@ public: void DidNavigateAnyFrame(content::RenderFrameHost *render_frame_host, const content::LoadCommittedDetails &details, const content::FrameNavigateParams ¶ms) override; void WasShown() override; void DidFirstVisuallyNonEmptyPaint() override; + void ActivateContents(content::WebContents* contents) override; void overrideWebPreferences(content::WebContents *, content::WebPreferences*); void allowCertificateError(const QSharedPointer<CertificateErrorController> &) ; diff --git a/src/core/web_engine_settings.cpp b/src/core/web_engine_settings.cpp index 58f0a3e2c..ca051397b 100644 --- a/src/core/web_engine_settings.cpp +++ b/src/core/web_engine_settings.cpp @@ -243,6 +243,7 @@ void WebEngineSettings::initDefaults(bool offTheRecord) s_defaultAttributes.insert(PrintElementBackgrounds, true); s_defaultAttributes.insert(AllowRunningInsecureContent, allowRunningInsecureContent); s_defaultAttributes.insert(AllowGeolocationOnInsecureOrigins, false); + s_defaultAttributes.insert(AllowWindowActivationFromJavaScript, false); } if (offTheRecord) m_attributes.insert(LocalStorageEnabled, false); diff --git a/src/core/web_engine_settings.h b/src/core/web_engine_settings.h index 4b0ce7b39..7cfb9434f 100644 --- a/src/core/web_engine_settings.h +++ b/src/core/web_engine_settings.h @@ -83,7 +83,8 @@ public: FocusOnNavigationEnabled, PrintElementBackgrounds, AllowRunningInsecureContent, - AllowGeolocationOnInsecureOrigins + AllowGeolocationOnInsecureOrigins, + AllowWindowActivationFromJavaScript }; // Must match the values from the public API in qwebenginesettings.h. |