summaryrefslogtreecommitdiffstats
path: root/src/core/web_contents_delegate_qt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/web_contents_delegate_qt.cpp')
-rw-r--r--src/core/web_contents_delegate_qt.cpp115
1 files changed, 67 insertions, 48 deletions
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index aae7f4a43..4bde93fd3 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -43,22 +43,21 @@
#include "web_contents_delegate_qt.h"
-#include "browser_context_adapter.h"
-#include "browser_context_qt.h"
-#include "color_chooser_qt.h"
+#include "profile_adapter.h"
#include "color_chooser_controller.h"
+#include "color_chooser_qt.h"
#include "favicon_manager.h"
-#include "favicon_manager_p.h"
#include "file_picker_controller.h"
#include "media_capture_devices_dispatcher.h"
#include "net/network_delegate_qt.h"
+#include "profile_qt.h"
#include "qwebengineregisterprotocolhandlerrequest.h"
#include "register_protocol_handler_request_controller_impl.h"
#include "render_widget_host_view_qt.h"
#include "type_conversion.h"
#include "visited_links_manager_qt.h"
#include "web_contents_adapter_client.h"
-#include "web_contents_adapter_p.h"
+#include "web_contents_adapter.h"
#include "web_engine_context.h"
#include "web_engine_settings.h"
@@ -88,7 +87,8 @@
namespace QtWebEngineCore {
// Maps the LogSeverity defines in base/logging.h to the web engines message levels.
-static WebContentsAdapterClient::JavaScriptConsoleMessageLevel mapToJavascriptConsoleMessageLevel(int32_t messageLevel) {
+static WebContentsAdapterClient::JavaScriptConsoleMessageLevel mapToJavascriptConsoleMessageLevel(int32_t messageLevel)
+{
if (messageLevel < 1)
return WebContentsAdapterClient::Info;
else if (messageLevel > 1)
@@ -100,7 +100,7 @@ static WebContentsAdapterClient::JavaScriptConsoleMessageLevel mapToJavascriptCo
WebContentsDelegateQt::WebContentsDelegateQt(content::WebContents *webContents, WebContentsAdapterClient *adapterClient)
: m_viewClient(adapterClient)
, m_lastReceivedFindReply(0)
- , m_faviconManager(new FaviconManager(new FaviconManagerPrivate(webContents, adapterClient)))
+ , m_faviconManager(new FaviconManager(webContents, adapterClient))
, m_lastLoadProgress(-1)
{
webContents->SetDelegate(this);
@@ -122,7 +122,7 @@ content::WebContents *WebContentsDelegateQt::OpenURLFromTab(content::WebContents
if (params.disposition != WindowOpenDisposition::CURRENT_TAB) {
QSharedPointer<WebContentsAdapter> targetAdapter = createWindow(0, params.disposition, gfx::Rect(), params.user_gesture);
if (targetAdapter) {
- if (targetAdapter->browserContext() != source->GetBrowserContext()) {
+ if (targetAdapter->profile() != source->GetBrowserContext()) {
target_site_instance = nullptr;
referrer = content::Referrer();
}
@@ -215,14 +215,14 @@ void WebContentsDelegateQt::NavigationStateChanged(content::WebContents* source,
// Make sure to only emit the signal when loading isn't in progress, because it causes multiple
// false signals to be emitted.
if ((changed_flags & content::INVALIDATE_TYPE_TAB) && !(changed_flags & content::INVALIDATE_TYPE_LOAD)) {
- m_viewClient->recentlyAudibleChanged(source->WasRecentlyAudible());
+ m_viewClient->recentlyAudibleChanged(source->IsCurrentlyAudible());
}
}
-void WebContentsDelegateQt::AddNewContents(content::WebContents* source, content::WebContents* new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture, bool* was_blocked)
+void WebContentsDelegateQt::AddNewContents(content::WebContents* source, std::unique_ptr<content::WebContents> new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture, bool* was_blocked)
{
Q_UNUSED(source)
- QSharedPointer<WebContentsAdapter> newAdapter = createWindow(new_contents, disposition, initial_pos, user_gesture);
+ QSharedPointer<WebContentsAdapter> newAdapter = createWindow(std::move(new_contents), disposition, initial_pos, user_gesture);
if (newAdapter && !newAdapter->isInitialized())
newAdapter->loadDefault();
if (was_blocked)
@@ -258,11 +258,20 @@ void WebContentsDelegateQt::RenderFrameDeleted(content::RenderFrameHost *render_
m_loadingErrorFrameList.removeOne(render_frame_host->GetRoutingID());
}
+void WebContentsDelegateQt::RenderViewHostChanged(content::RenderViewHost *, content::RenderViewHost *newHost)
+{
+ if (newHost && newHost->GetWidget() && newHost->GetWidget()->GetView()) {
+ auto rwhv = static_cast<RenderWidgetHostViewQt *>(newHost->GetWidget()->GetView());
+ m_viewClient->widgetChanged(rwhv->delegate());
+ }
+}
+
void WebContentsDelegateQt::EmitLoadStarted(const QUrl &url, bool isErrorPage)
{
if (m_lastLoadProgress >= 0 && m_lastLoadProgress < 100) // already running
return;
m_viewClient->loadStarted(url, isErrorPage);
+ m_viewClient->updateNavigationActions();
m_viewClient->loadProgressChanged(0);
m_lastLoadProgress = 0;
}
@@ -287,6 +296,16 @@ void WebContentsDelegateQt::EmitLoadFinished(bool success, const QUrl &url, bool
m_lastLoadProgress = -1;
m_viewClient->loadProgressChanged(100);
m_viewClient->loadFinished(success, url, isErrorPage, errorCode, errorDescription);
+ m_viewClient->updateNavigationActions();
+}
+
+void WebContentsDelegateQt::EmitLoadCommitted()
+{
+ // Make sure that we don't set the findNext WebFindOptions on a new frame.
+ m_lastSearchedString = QString();
+
+ m_viewClient->loadCommitted();
+ m_viewClient->updateNavigationActions();
}
void WebContentsDelegateQt::DidFinishNavigation(content::NavigationHandle *navigation_handle)
@@ -295,18 +314,14 @@ void WebContentsDelegateQt::DidFinishNavigation(content::NavigationHandle *navig
return;
if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) {
- BrowserContextAdapter *browserContextAdapter = m_viewClient->browserContextAdapter().data();
+ ProfileAdapter *profileAdapter = m_viewClient->profileAdapter();
// VisistedLinksMaster asserts !IsOffTheRecord().
- if (navigation_handle->ShouldUpdateHistory() && browserContextAdapter->trackVisitedLinks()) {
+ if (navigation_handle->ShouldUpdateHistory() && profileAdapter->trackVisitedLinks()) {
for (const GURL &url : navigation_handle->GetRedirectChain())
- browserContextAdapter->visitedLinksManager()->addUrl(url);
+ profileAdapter->visitedLinksManager()->addUrl(url);
}
- // Make sure that we don't set the findNext WebFindOptions on a new frame.
- m_lastSearchedString = QString();
-
- // This is currently used for canGoBack/Forward values, which is flattened across frames. For other purposes we might have to pass is_main_frame.
- m_viewClient->loadCommitted();
+ EmitLoadCommitted();
}
// Success is reported by DidFinishLoad, but DidFailLoad is now dead code and needs to be handled below
if (navigation_handle->GetNetErrorCode() == net::OK)
@@ -325,10 +340,8 @@ void WebContentsDelegateQt::DidFinishNavigation(content::NavigationHandle *navig
EmitLoadStarted(toQt(GURL(content::kUnreachableWebDataURL)), true);
// If it is already committed we will not see another DidFinishNavigation call or a DidFinishLoad call.
- if (navigation_handle->HasCommitted()) {
- m_lastSearchedString = QString();
- m_viewClient->loadCommitted();
- }
+ if (navigation_handle->HasCommitted())
+ EmitLoadCommitted();
}
}
@@ -340,7 +353,7 @@ void WebContentsDelegateQt::didFailLoad(const QUrl &url, int errorCode, const QS
void WebContentsDelegateQt::DidFailLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url, int error_code, const base::string16& error_description)
{
- if (render_frame_host->GetParent())
+ if (render_frame_host != web_contents()->GetMainFrame())
return;
if (validated_url.spec() == content::kUnreachableWebDataURL) {
@@ -376,7 +389,11 @@ void WebContentsDelegateQt::DidFinishLoad(content::RenderFrameHost* render_frame
if (!m_faviconManager->hasCandidate())
m_viewClient->iconChanged(QUrl());
- EmitLoadFinished(true, toQt(validated_url));
+ content::NavigationEntry *entry = web_contents()->GetController().GetActiveEntry();
+ int http_statuscode = 0;
+ if (entry)
+ http_statuscode = entry->GetHttpStatusCode();
+ EmitLoadFinished(true /* success */ , toQt(validated_url), false /* isErrorPage */, http_statuscode);
}
void WebContentsDelegateQt::DidUpdateFaviconURL(const std::vector<content::FaviconURL> &candidates)
@@ -415,7 +432,7 @@ content::JavaScriptDialogManager *WebContentsDelegateQt::GetJavaScriptDialogMana
return JavaScriptDialogManagerQt::GetInstance();
}
-void WebContentsDelegateQt::EnterFullscreenModeForTab(content::WebContents *web_contents, const GURL& origin)
+void WebContentsDelegateQt::EnterFullscreenModeForTab(content::WebContents *web_contents, const GURL& origin, const blink::WebFullscreenOptions &)
{
Q_UNUSED(web_contents);
if (!m_viewClient->isFullScreenMode())
@@ -473,14 +490,17 @@ void WebContentsDelegateQt::FindReply(content::WebContents *source, int request_
}
}
-void WebContentsDelegateQt::RequestMediaAccessPermission(content::WebContents *web_contents, const content::MediaStreamRequest &request, const content::MediaResponseCallback &callback)
+void WebContentsDelegateQt::RequestMediaAccessPermission(content::WebContents *web_contents, const content::MediaStreamRequest &request, content::MediaResponseCallback callback)
{
- MediaCaptureDevicesDispatcher::GetInstance()->processMediaAccessRequest(m_viewClient, web_contents, request, callback);
+ MediaCaptureDevicesDispatcher::GetInstance()->processMediaAccessRequest(m_viewClient, web_contents, request, std::move(callback));
}
-void WebContentsDelegateQt::MoveContents(content::WebContents *source, const gfx::Rect &pos)
+void WebContentsDelegateQt::SetContentsBounds(content::WebContents *source, const gfx::Rect &bounds)
{
- QRect frameGeometry(toQt(pos));
+ if (!source->HasOpener()) // is popup
+ return;
+
+ QRect frameGeometry(toQt(bounds));
QRect geometry;
if (RenderWidgetHostViewQt *rwhv = static_cast<RenderWidgetHostViewQt*>(web_contents()->GetRenderWidgetHostView())) {
if (rwhv->delegate() && rwhv->delegate()->window())
@@ -489,20 +509,16 @@ void WebContentsDelegateQt::MoveContents(content::WebContents *source, const gfx
m_viewClient->requestGeometryChange(geometry, frameGeometry);
}
-bool WebContentsDelegateQt::IsPopupOrPanel(const content::WebContents *source) const
-{
- return source->HasOpener();
-}
-
void WebContentsDelegateQt::UpdateTargetURL(content::WebContents* source, const GURL& url)
{
Q_UNUSED(source)
m_viewClient->didUpdateTargetURL(toQt(url));
}
-void WebContentsDelegateQt::WasShown()
+void WebContentsDelegateQt::OnVisibilityChanged(content::Visibility visibility)
{
- web_cache::WebCacheManager::GetInstance()->ObserveActivity(web_contents()->GetMainFrame()->GetProcess()->GetID());
+ if (visibility != content::Visibility::HIDDEN)
+ web_cache::WebCacheManager::GetInstance()->ObserveActivity(web_contents()->GetMainFrame()->GetProcess()->GetID());
}
void WebContentsDelegateQt::DidFirstVisuallyNonEmptyPaint()
@@ -542,9 +558,9 @@ void WebContentsDelegateQt::overrideWebPreferences(content::WebContents *webCont
m_viewClient->webEngineSettings()->overrideWebPreferences(webContents, webPreferences);
}
-QWeakPointer<WebContentsAdapter> WebContentsDelegateQt::createWindow(content::WebContents *new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture)
+QWeakPointer<WebContentsAdapter> WebContentsDelegateQt::createWindow(std::unique_ptr<content::WebContents> new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture)
{
- QSharedPointer<WebContentsAdapter> newAdapter = QSharedPointer<WebContentsAdapter>::create(new_contents);
+ QSharedPointer<WebContentsAdapter> newAdapter = QSharedPointer<WebContentsAdapter>::create(std::move(new_contents));
m_viewClient->adoptNewWindow(newAdapter, static_cast<WebContentsAdapterClient::WindowOpenDisposition>(disposition), user_gesture, toQt(initial_pos), m_initialTargetUrl);
@@ -557,6 +573,11 @@ void WebContentsDelegateQt::allowCertificateError(const QSharedPointer<Certifica
m_viewClient->allowCertificateError(errorController);
}
+void WebContentsDelegateQt::selectClientCert(const QSharedPointer<ClientCertSelectController> &selectController)
+{
+ m_viewClient->selectClientCert(selectController);
+}
+
void WebContentsDelegateQt::requestGeolocationPermission(const QUrl &requestingOrigin)
{
m_viewClient->runGeolocationPermissionRequest(requestingOrigin);
@@ -594,14 +615,12 @@ void WebContentsDelegateQt::launchExternalURL(const QUrl &url, ui::PageTransitio
}
if (!navigationAllowedByPolicy || !navigationRequestAccepted) {
+ QString errorDescription;
if (!navigationAllowedByPolicy)
- didFailLoad(url, 420, QStringLiteral("Launching external protocol forbidden by WebEngineSettings::UnknownUrlSchemePolicy"));
+ errorDescription = 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)));
- }
+ errorDescription = QStringLiteral("Launching external protocol suppressed by WebContentsAdapterClient::navigationRequested");
+ didFailLoad(url, net::Error::ERR_ABORTED, errorDescription);
}
}
@@ -618,13 +637,13 @@ void WebContentsDelegateQt::BeforeUnloadFired(const base::TimeTicks &proceed_tim
Q_UNUSED(proceed_time);
}
-bool WebContentsDelegateQt::CheckMediaAccessPermission(content::WebContents *web_contents, const GURL& security_origin, content::MediaStreamType type)
+bool WebContentsDelegateQt::CheckMediaAccessPermission(content::RenderFrameHost *, const GURL& security_origin, content::MediaStreamType type)
{
switch (type) {
case content::MEDIA_DEVICE_AUDIO_CAPTURE:
- return m_viewClient->browserContextAdapter()->checkPermission(toQt(security_origin), BrowserContextAdapter::AudioCapturePermission);
+ return m_viewClient->profileAdapter()->checkPermission(toQt(security_origin), ProfileAdapter::AudioCapturePermission);
case content::MEDIA_DEVICE_VIDEO_CAPTURE:
- return m_viewClient->browserContextAdapter()->checkPermission(toQt(security_origin), BrowserContextAdapter::VideoCapturePermission);
+ return m_viewClient->profileAdapter()->checkPermission(toQt(security_origin), ProfileAdapter::VideoCapturePermission);
default:
LOG(INFO) << "WebContentsDelegateQt::CheckMediaAccessPermission: "
<< "Unsupported media stream type checked" << type;