diff options
Diffstat (limited to 'src/core/web_contents_delegate_qt.cpp')
-rw-r--r-- | src/core/web_contents_delegate_qt.cpp | 75 |
1 files changed, 53 insertions, 22 deletions
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index db05fae4b..09cca943e 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -76,6 +76,7 @@ #include <QDesktopServices> #include <QTimer> +#include <QWindow> namespace QtWebEngineCore { @@ -225,16 +226,6 @@ void WebContentsDelegateQt::DidStartNavigation(content::NavigationHandle *naviga if (!navigation_handle->IsInMainFrame()) return; - // Suppress extra loadStarted signal for data URL with specified base URL. - if (navigation_handle->GetURL().SchemeIs(url::kDataScheme)) { - content::NavigationEntry *pending_entry = navigation_handle->GetWebContents()->GetController().GetPendingEntry(); - - if (pending_entry && !pending_entry->GetBaseURLForDataURL().is_empty() && - navigation_handle->GetURL() == pending_entry->GetURL()) { - return; - } - } - // Error-pages are not reported as separate started navigations. Q_ASSERT(!navigation_handle->IsErrorPage()); @@ -301,9 +292,8 @@ void WebContentsDelegateQt::didFailLoad(const QUrl &url, int errorCode, const QS EmitLoadFinished(false /* success */ , url, false /* isErrorPage */, errorCode, errorDescription); } -void WebContentsDelegateQt::DidFailLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url, int error_code, const base::string16& error_description, bool was_ignored_by_handler) +void WebContentsDelegateQt::DidFailLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url, int error_code, const base::string16& error_description) { - Q_UNUSED(was_ignored_by_handler); if (render_frame_host->GetParent()) return; @@ -444,8 +434,13 @@ void WebContentsDelegateQt::RequestMediaAccessPermission(content::WebContents *w void WebContentsDelegateQt::MoveContents(content::WebContents *source, const gfx::Rect &pos) { - Q_UNUSED(source) - m_viewClient->requestGeometryChange(toQt(pos)); + QRect frameGeometry(toQt(pos)); + QRect geometry; + if (RenderWidgetHostViewQt *rwhv = static_cast<RenderWidgetHostViewQt*>(web_contents()->GetRenderWidgetHostView())) { + if (rwhv->delegate() && rwhv->delegate()->window()) + geometry = frameGeometry.marginsRemoved(rwhv->delegate()->window()->frameMargins()); + } + m_viewClient->requestGeometryChange(geometry, frameGeometry); } bool WebContentsDelegateQt::IsPopupOrPanel(const content::WebContents *source) const @@ -461,7 +456,7 @@ void WebContentsDelegateQt::UpdateTargetURL(content::WebContents* source, const void WebContentsDelegateQt::WasShown() { - web_cache::WebCacheManager::GetInstance()->ObserveActivity(web_contents()->GetRenderProcessHost()->GetID()); + web_cache::WebCacheManager::GetInstance()->ObserveActivity(web_contents()->GetMainFrame()->GetProcess()->GetID()); } void WebContentsDelegateQt::DidFirstVisuallyNonEmptyPaint() @@ -496,9 +491,9 @@ void WebContentsDelegateQt::RequestToLockMouse(content::WebContents *web_content m_viewClient->runMouseLockPermissionRequest(toQt(web_contents->GetVisibleURL())); } -void WebContentsDelegateQt::overrideWebPreferences(content::WebContents *, content::WebPreferences *webPreferences) +void WebContentsDelegateQt::overrideWebPreferences(content::WebContents *webContents, content::WebPreferences *webPreferences) { - m_viewClient->webEngineSettings()->overrideWebPreferences(webPreferences); + m_viewClient->webEngineSettings()->overrideWebPreferences(webContents, webPreferences); } QWeakPointer<WebContentsAdapter> WebContentsDelegateQt::createWindow(content::WebContents *new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture) @@ -523,14 +518,45 @@ void WebContentsDelegateQt::requestGeolocationPermission(const QUrl &requestingO extern WebContentsAdapterClient::NavigationType pageTransitionToNavigationType(ui::PageTransition transition); -void WebContentsDelegateQt::launchExternalURL(const QUrl &url, ui::PageTransition page_transition, bool is_main_frame) +void WebContentsDelegateQt::launchExternalURL(const QUrl &url, ui::PageTransition page_transition, bool is_main_frame, bool has_user_gesture) { - int navigationRequestAction = WebContentsAdapterClient::AcceptRequest; - m_viewClient->navigationRequested(pageTransitionToNavigationType(page_transition), url, navigationRequestAction, is_main_frame); + WebEngineSettings *settings = m_viewClient->webEngineSettings(); + bool navigationAllowedByPolicy = false; + bool navigationRequestAccepted = true; + + switch (settings->unknownUrlSchemePolicy()) { + case WebEngineSettings::DisallowUnknownUrlSchemes: + break; + case WebEngineSettings::AllowUnknownUrlSchemesFromUserInteraction: + navigationAllowedByPolicy = has_user_gesture; + break; + case WebEngineSettings::AllowAllUnknownUrlSchemes: + navigationAllowedByPolicy = true; + break; + default: + Q_UNREACHABLE(); + } + + if (navigationAllowedByPolicy) { + int navigationRequestAction = WebContentsAdapterClient::AcceptRequest; + m_viewClient->navigationRequested(pageTransitionToNavigationType(page_transition), url, navigationRequestAction, is_main_frame); + navigationRequestAccepted = navigationRequestAction == WebContentsAdapterClient::AcceptRequest; #ifndef QT_NO_DESKTOPSERVICES - if (navigationRequestAction == WebContentsAdapterClient::AcceptRequest) - QDesktopServices::openUrl(url); + if (navigationRequestAccepted) + QDesktopServices::openUrl(url); #endif + } + + if (!navigationAllowedByPolicy || !navigationRequestAccepted) { + if (!navigationAllowedByPolicy) + didFailLoad(url, 420, QStringLiteral("Launching external protocol forbidden by WebEngineSettings::UnknownUrlSchemePolicy")); + else + didFailLoad(url, 420, QStringLiteral("Launching external protocol suppressed by WebContentsAdapterClient::navigationRequested")); + if (settings->testAttribute(WebEngineSettings::ErrorPageEnabled)) { + EmitLoadStarted(toQt(GURL(content::kUnreachableWebDataURL)), true); + m_viewClient->webContentsAdapter()->load(toQt(GURL(content::kUnreachableWebDataURL))); + } + } } void WebContentsDelegateQt::ShowValidationMessage(content::WebContents *web_contents, const gfx::Rect &anchor_in_root_view, const base::string16 &main_text, const base::string16 &sub_text) @@ -591,4 +617,9 @@ WebEngineSettings *WebContentsDelegateQt::webEngineSettings() const { return m_viewClient->webEngineSettings(); } +WebContentsAdapter *WebContentsDelegateQt::webContentsAdapter() const +{ + return m_viewClient->webContentsAdapter(); +} + } // namespace QtWebEngineCore |