diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-08-27 16:36:03 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-09-02 12:18:24 +0200 |
commit | 7146fcc14dcd69f39f20a3e49a9b371bd306bb53 (patch) | |
tree | 708cbbe9e6fa39edcccd334b09eba9ec123224c9 /lib/widgets | |
parent | b7210ab328438038bbf1c0e03f19616d6ce56c76 (diff) |
Implement window creation through QWebEnginePage::createWindow.
This makes the necessary changes to handle
WebContentsDelegateQt::AddNewContents and funnel the callback
through createWindow in QWebEnginePage and QWebEngineView.
- Expose the AddNewContents callback through WebContentsAdapterClient
- Allow creating a WebContentsAdapter attached only on the Chromium side,
leaving the choice to QWebEnginePage to either adopt it and call
WebContentsAdapter::initialize to attach itself as the client, or
destroy it if the application isn't handling the call.
- Delay the InitAsChild handling in RenderWidgetHostViewQt when
it is called before an adapter client has been attached.
- Since WebContentsAdapterClient::CreateRenderWidgetHostViewQtDelegate
is only a factory method, not creating any link with the callee client,
allow using the creating window's adapter client to create the RWHVQtDelegate.
This allows an unparented delegate to be created instead of needing to
add numerous null-checks in RWHVQt.
Use content::WebContents::CreateParams::context for this purpose,
which can be used both when creating a WebContents ourselves and when
a new window's WebContents is created for us.
Change-Id: I032262e867931dc40a7c2eca0c993027a555f56e
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'lib/widgets')
-rw-r--r-- | lib/widgets/Api/qwebenginepage.cpp | 25 | ||||
-rw-r--r-- | lib/widgets/Api/qwebenginepage.h | 2 | ||||
-rw-r--r-- | lib/widgets/Api/qwebenginepage_p.h | 1 | ||||
-rw-r--r-- | lib/widgets/Api/qwebengineview.cpp | 6 | ||||
-rw-r--r-- | lib/widgets/Api/qwebengineview.h | 4 |
5 files changed, 35 insertions, 3 deletions
diff --git a/lib/widgets/Api/qwebenginepage.cpp b/lib/widgets/Api/qwebenginepage.cpp index 0bc6d85e1..f3f046675 100644 --- a/lib/widgets/Api/qwebenginepage.cpp +++ b/lib/widgets/Api/qwebenginepage.cpp @@ -36,11 +36,12 @@ QWebEnginePagePrivate::QWebEnginePagePrivate() : QObjectPrivate(QObjectPrivateVersion) - , adapter(new WebContentsAdapter(this)) + , adapter(new WebContentsAdapter) , history(new QWebEngineHistory(new QWebEngineHistoryPrivate(adapter.data()))) , view(0) , m_isLoading(false) { + adapter->initialize(this); memset(actions, 0, sizeof(actions)); } @@ -96,6 +97,17 @@ void QWebEnginePagePrivate::focusContainer() view->setFocus(); } +void QWebEnginePagePrivate::adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition) +{ + Q_Q(QWebEnginePage); + QWebEnginePage *newPage = q->createWindow(disposition == WebContentsAdapterClient::NewPopupDisposition ? QWebEnginePage::WebModalDialog : QWebEnginePage::WebBrowserWindow); + // Overwrite the new page's WebContents with ours. + if (newPage) { + newPage->d_func()->adapter = newWebContents; + newWebContents->initialize(newPage->d_func()); + } +} + void QWebEnginePagePrivate::updateAction(QWebEnginePage::WebAction action) const { #ifdef QT_NO_ACTION @@ -267,4 +279,15 @@ QUrl QWebEnginePage::url() const return d->adapter->activeUrl(); } +QWebEnginePage *QWebEnginePage::createWindow(WebWindowType type) +{ + Q_D(const QWebEnginePage); + if (d->view) { + QWebEngineView *newView = d->view->createWindow(type); + if (newView) + return newView->page(); + } + return 0; +} + #include "moc_qwebenginepage.cpp" diff --git a/lib/widgets/Api/qwebenginepage.h b/lib/widgets/Api/qwebenginepage.h index 0a664edf8..808ce8435 100644 --- a/lib/widgets/Api/qwebenginepage.h +++ b/lib/widgets/Api/qwebenginepage.h @@ -535,7 +535,7 @@ Q_SIGNALS: void pageChanged(); protected: - virtual QWebEnginePage *createWindow(WebWindowType type) { Q_UNUSED(type); Q_UNREACHABLE(); return 0; }; + virtual QWebEnginePage *createWindow(WebWindowType type); virtual QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues) { Q_UNUSED(classid); Q_UNUSED(url); Q_UNUSED(paramNames); Q_UNUSED(paramValues); Q_UNREACHABLE(); return 0; } virtual bool acceptNavigationRequest(QWebEngineFrame *frame, const QNetworkRequest &request, NavigationType type) { Q_UNUSED(frame); Q_UNUSED(request); Q_UNUSED(type); Q_UNREACHABLE(); return false; } diff --git a/lib/widgets/Api/qwebenginepage_p.h b/lib/widgets/Api/qwebenginepage_p.h index f43ed9522..79c40db02 100644 --- a/lib/widgets/Api/qwebenginepage_p.h +++ b/lib/widgets/Api/qwebenginepage_p.h @@ -69,6 +69,7 @@ public: virtual QRectF viewportRect() const Q_DECL_OVERRIDE; virtual void loadFinished(bool success) Q_DECL_OVERRIDE; virtual void focusContainer() Q_DECL_OVERRIDE; + virtual void adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition) Q_DECL_OVERRIDE; void updateAction(QWebEnginePage::WebAction) const; void updateNavigationActions(); diff --git a/lib/widgets/Api/qwebengineview.cpp b/lib/widgets/Api/qwebengineview.cpp index 6ae19ca75..298ddac43 100644 --- a/lib/widgets/Api/qwebengineview.cpp +++ b/lib/widgets/Api/qwebengineview.cpp @@ -166,4 +166,10 @@ void QWebEngineView::reload() page()->triggerAction(QWebEnginePage::Reload); } +QWebEngineView *QWebEngineView::createWindow(QWebEnginePage::WebWindowType type) +{ + Q_UNUSED(type) + return 0; +} + #include "moc_qwebengineview.cpp" diff --git a/lib/widgets/Api/qwebengineview.h b/lib/widgets/Api/qwebengineview.h index 8cef6a4a7..40af695bb 100644 --- a/lib/widgets/Api/qwebengineview.h +++ b/lib/widgets/Api/qwebengineview.h @@ -125,10 +125,12 @@ Q_SIGNALS: void urlChanged(const QUrl&); protected: - virtual QWebEngineView *createWindow(QWebEnginePage::WebWindowType type) { Q_UNUSED(type); return 0; } + virtual QWebEngineView *createWindow(QWebEnginePage::WebWindowType type); private: Q_DECLARE_PRIVATE(QWebEngineView); + + friend class QWebEnginePage; }; #endif // QWEBENGINEVIEW_H |