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-30 10:30:06 +0000 |
commit | 93f9eed62db271ae4b8896f48df72a956f3ce7be (patch) | |
tree | dbaf7ddd410874f63e2d3e4fbaf6ef2632bd0bf7 /src/core | |
parent | 95ca17c45aea718cade487640edc63e08bc23820 (diff) |
Store Target URL in WebContentsDelegateQt::WebContentsCreated
When opening a new window, for example by using the JavaScript
method window.open('...'), the requested url is not stored
in the content::WebContents object we get in
WebContentsDelegateQt::createWindow (at this point, it should
at least be stored as pending request in the WebContents'
NavigationController, but it is not).
Because of this, the QQuickWebEngineNewViewRequest object
in QQuickWebEngineViewPrivate::adoptNewWindow never contained
the url. We have access to the target url in
WebContentsDelegateQt::WebContentsCreated, so now we store
it there in a new property m_initialTargetUrl, from where
WebContentsDelegateQt::createWindow takes it and passes it
to WebContentsAdapter::adoptNewWindow as a new parameter.
[ChangeLog][WebEngine] Fix WebEngineNewViewRequest::requestedUrl being empty when opening window from JavaScript
Task-number: QTBUG-57675
Change-Id: I7e2c7866899baade17ce2517e6be8b2b2709699e
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/web_contents_adapter_client.h | 2 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 7 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.h | 2 |
3 files changed, 9 insertions, 2 deletions
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index d4b2974fc..055cefa6f 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -330,7 +330,7 @@ public: virtual void loadFinished(bool success, const QUrl &url, bool isErrorPage = false, int errorCode = 0, const QString &errorDescription = QString()) = 0; virtual void focusContainer() = 0; virtual void unhandledKeyEvent(QKeyEvent *event) = 0; - virtual void adoptNewWindow(QSharedPointer<WebContentsAdapter> newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect & initialGeometry) = 0; + virtual void adoptNewWindow(QSharedPointer<WebContentsAdapter> newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect & initialGeometry, const QUrl &targetUrl) = 0; virtual bool isBeingAdopted() = 0; virtual void close() = 0; virtual void windowCloseRejected() = 0; diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 6c5b63960..86366abaa 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -282,6 +282,11 @@ void WebContentsDelegateQt::DidUpdateFaviconURL(const std::vector<content::Favic m_faviconManager->update(faviconCandidates); } +void WebContentsDelegateQt::WebContentsCreated(content::WebContents* /*source_contents*/, int /*opener_render_process_id*/, int /*opener_render_frame_id*/, const std::string& /*frame_name*/, const GURL& target_url, content::WebContents* new_contents) +{ + this->m_initialTargetUrl = toQt(target_url); +} + content::ColorChooser *WebContentsDelegateQt::OpenColorChooser(content::WebContents *source, SkColor color, const std::vector<content::ColorSuggestion> &suggestion) { Q_UNUSED(suggestion); @@ -422,7 +427,7 @@ QWeakPointer<WebContentsAdapter> WebContentsDelegateQt::createWindow(content::We { QSharedPointer<WebContentsAdapter> newAdapter = QSharedPointer<WebContentsAdapter>::create(new_contents); - m_viewClient->adoptNewWindow(newAdapter, static_cast<WebContentsAdapterClient::WindowOpenDisposition>(disposition), user_gesture, toQt(initial_pos)); + m_viewClient->adoptNewWindow(newAdapter, static_cast<WebContentsAdapterClient::WindowOpenDisposition>(disposition), user_gesture, toQt(initial_pos), m_initialTargetUrl); // If the client didn't reference the adapter, it will be deleted now, and the weak pointer zeroed. return newAdapter; diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h index 2e294a841..913bf356c 100644 --- a/src/core/web_contents_delegate_qt.h +++ b/src/core/web_contents_delegate_qt.h @@ -104,6 +104,7 @@ public: void LoadProgressChanged(content::WebContents* source, double progress) override; void HandleKeyboardEvent(content::WebContents *source, const content::NativeWebKeyboardEvent &event) override; content::ColorChooser *OpenColorChooser(content::WebContents *source, SkColor color, const std::vector<content::ColorSuggestion> &suggestion) override; + void WebContentsCreated(content::WebContents* source_contents, int opener_render_process_id, int opener_render_frame_id, const std::string& frame_name, const GURL& target_url, content::WebContents* new_contents) override; content::JavaScriptDialogManager *GetJavaScriptDialogManager(content::WebContents *source) override; void EnterFullscreenModeForTab(content::WebContents* web_contents, const GURL& origin) override; void ExitFullscreenModeForTab(content::WebContents*) override; @@ -156,6 +157,7 @@ private: QScopedPointer<FaviconManager> m_faviconManager; SavePageInfo m_savePageInfo; QSharedPointer<FilePickerController> m_filePickerController; + QUrl m_initialTargetUrl; }; } // namespace QtWebEngineCore |