summaryrefslogtreecommitdiffstats
path: root/src/core/web_contents_adapter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/web_contents_adapter.cpp')
-rw-r--r--src/core/web_contents_adapter.cpp86
1 files changed, 49 insertions, 37 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index 21540f5da..607412e16 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -43,15 +43,14 @@
#include "web_contents_adapter.h"
-#include "browser_accessibility_qt.h"
-#include "profile_adapter_client.h"
-#include "profile_adapter.h"
#include "devtools_frontend_qt.h"
#include "download_manager_delegate_qt.h"
#include "media_capture_devices_dispatcher.h"
#if QT_CONFIG(webengine_printing_and_pdf)
#include "printing/print_view_manager_qt.h"
#endif
+#include "profile_adapter_client.h"
+#include "profile_adapter.h"
#include "profile_qt.h"
#include "qwebenginecallback_p.h"
#include "render_view_observer_host_qt.h"
@@ -63,9 +62,11 @@
#include "base/command_line.h"
#include "base/run_loop.h"
+#include "base/task/post_task.h"
#include "base/values.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
+#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/download_manager.h"
@@ -83,7 +84,9 @@
#include "content/public/common/url_constants.h"
#include "content/public/common/web_preferences.h"
#include "content/public/common/webrtc_ip_handling_policy.h"
-#include "third_party/blink/public/web/web_find_options.h"
+#include "extensions/buildflags/buildflags.h"
+#include "third_party/blink/public/mojom/frame/find_in_page.mojom.h"
+//#include "third_party/blink/public/web/web_find_options.h"
#include "third_party/blink/public/web/web_media_player_action.h"
#include "printing/buildflags/buildflags.h"
#include "ui/base/clipboard/clipboard.h"
@@ -95,6 +98,10 @@
#include <QtWebChannel/QWebChannel>
#endif
+#if BUILDFLAG(ENABLE_EXTENSIONS)
+#include "extensions/extension_web_contents_observer_qt.h"
+#endif
+
#include <QDir>
#include <QGuiApplication>
#include <QPageLayout>
@@ -105,10 +112,14 @@
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qmimedata.h>
#include <QtCore/qtemporarydir.h>
-#include <QtGui/qaccessible.h>
#include <QtGui/qdrag.h>
#include <QtGui/qpixmap.h>
+// Can't include headers as qaccessible.h conflicts with Chromium headers.
+namespace content {
+extern QAccessibleInterface *toQAccessibleInterface(BrowserAccessibility *acc);
+}
+
namespace QtWebEngineCore {
#define CHECK_INITIALIZED(return_value) \
@@ -117,7 +128,7 @@ namespace QtWebEngineCore {
#define CHECK_VALID_RENDER_WIDGET_HOST_VIEW(render_view_host) \
if (!render_view_host->IsRenderViewLive() && render_view_host->GetWidget()->GetView()) { \
- qWarning("Ignore navigation due to terminated render process with invalid RenderWidgetHostView."); \
+ LOG(WARNING) << "Ignore navigation due to terminated render process with invalid RenderWidgetHostView."; \
return; \
}
@@ -190,7 +201,7 @@ static QVariant fromJSValue(const base::Value *result)
}
case base::Value::Type::BINARY:
{
- QByteArray data(result->GetBlob().data(), result->GetBlob().size());
+ QByteArray data(reinterpret_cast<const char *>(result->GetBlob().data()), result->GetBlob().size());
ret.setValue(data);
break;
}
@@ -210,10 +221,10 @@ static void callbackOnEvaluateJS(WebContentsAdapterClient *adapterClient, quint6
#if QT_CONFIG(webengine_printing_and_pdf)
static void callbackOnPrintingFinished(WebContentsAdapterClient *adapterClient,
int requestId,
- const std::vector<char>& result)
+ QSharedPointer<QByteArray> result)
{
if (requestId)
- adapterClient->didPrintPage(requestId, QByteArray(result.data(), result.size()));
+ adapterClient->didPrintPage(requestId, result);
}
static void callbackOnPdfSavingFinished(WebContentsAdapterClient *adapterClient,
@@ -229,9 +240,13 @@ static std::unique_ptr<content::WebContents> createBlankWebContents(WebContentsA
content::WebContents::CreateParams create_params(browserContext, NULL);
create_params.routing_id = MSG_ROUTING_NONE;
create_params.initial_size = gfx::Size(kTestWindowWidth, kTestWindowHeight);
- create_params.context = reinterpret_cast<gfx::NativeView>(adapterClient);
create_params.initially_hidden = true;
- return content::WebContents::Create(create_params);
+
+ std::unique_ptr<content::WebContents> webContents = content::WebContents::Create(create_params);
+ WebContentsViewQt* contentsView = static_cast<WebContentsViewQt*>(static_cast<content::WebContentsImpl*>(webContents.get())->GetView());
+ contentsView->setClient(adapterClient);
+
+ return webContents;
}
static void serializeNavigationHistory(const content::NavigationController &controller, QDataStream &output)
@@ -457,7 +472,6 @@ void WebContentsAdapter::initialize(content::SiteInstance *site)
if (!m_webContents) {
content::WebContents::CreateParams create_params(m_profileAdapter->profile(), site);
create_params.initial_size = gfx::Size(kTestWindowWidth, kTestWindowHeight);
- create_params.context = reinterpret_cast<gfx::NativeView>(m_adapterClient);
create_params.initially_hidden = true;
m_webContents = content::WebContents::Create(create_params);
}
@@ -495,7 +509,7 @@ void WebContentsAdapter::initialize(content::SiteInstance *site)
// Let the WebContent's view know about the WebContentsAdapterClient.
WebContentsViewQt* contentsView = static_cast<WebContentsViewQt*>(static_cast<content::WebContentsImpl*>(m_webContents.get())->GetView());
- contentsView->initialize(m_adapterClient);
+ contentsView->setClient(m_adapterClient);
// This should only be necessary after having restored the history to a new WebContentsAdapter.
m_webContents->GetController().LoadIfNecessary();
@@ -503,6 +517,9 @@ void WebContentsAdapter::initialize(content::SiteInstance *site)
#if QT_CONFIG(webengine_printing_and_pdf)
PrintViewManagerQt::CreateForWebContents(webContents());
#endif
+#if BUILDFLAG(ENABLE_EXTENSIONS)
+ extensions::ExtensionWebContentsObserverQt::CreateForWebContents(webContents());
+#endif
// Create an instance of WebEngineVisitedLinksManager to catch the first
// content::NOTIFICATION_RENDERER_PROCESS_CREATED event. This event will
@@ -630,13 +647,12 @@ void WebContentsAdapter::load(const QWebEngineHttpRequest &request)
"HTTP-POST data can only be sent over HTTP(S) protocol"));
return;
}
+ params.post_data = network::ResourceRequestBody::CreateFromBytes(
+ (const char*)request.postData().constData(),
+ request.postData().length());
break;
}
- params.post_data = network::ResourceRequestBody::CreateFromBytes(
- (const char*)request.postData().constData(),
- request.postData().length());
-
// convert the custom headers into the format that chromium expects
QVector<QByteArray> headers = request.headers();
for (QVector<QByteArray>::const_iterator it = headers.cbegin(); it != headers.cend(); ++it) {
@@ -662,8 +678,8 @@ void WebContentsAdapter::load(const QWebEngineHttpRequest &request)
if (resizeNeeded) {
// Schedule navigation on the event loop.
- content::BrowserThread::PostTask(
- content::BrowserThread::UI, FROM_HERE, base::BindOnce(navigate, this, std::move(params)));
+ base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI},
+ base::BindOnce(navigate, this, std::move(params)));
} else {
navigate(this, params);
}
@@ -800,7 +816,7 @@ void WebContentsAdapter::selectAll()
void WebContentsAdapter::requestClose()
{
CHECK_INITIALIZED();
- m_webContents->DispatchBeforeUnload();
+ m_webContents->DispatchBeforeUnload(false /* auto_cancel */);
}
void WebContentsAdapter::unselect()
@@ -932,8 +948,8 @@ QAccessibleInterface *WebContentsAdapter::browserAccessible()
if (!manager) // FIXME!
return nullptr;
content::BrowserAccessibility *acc = manager->GetRoot();
- content::BrowserAccessibilityQt *accQt = static_cast<content::BrowserAccessibilityQt*>(acc);
- return accQt;
+
+ return content::toQAccessibleInterface(acc);
}
#endif // QT_NO_ACCESSIBILITY
@@ -990,16 +1006,16 @@ quint64 WebContentsAdapter::findText(const QString &subString, bool caseSensitiv
m_adapterClient->didFindText(m_lastFindRequestId, 0);
}
- blink::WebFindOptions options;
- options.forward = !findBackward;
- options.match_case = caseSensitively;
- options.find_next = subString == m_webContentsDelegate->lastSearchedString();
+ blink::mojom::FindOptionsPtr options = blink::mojom::FindOptions::New();
+ options->forward = !findBackward;
+ options->match_case = caseSensitively;
+ options->find_next = subString == m_webContentsDelegate->lastSearchedString();
m_webContentsDelegate->setLastSearchedString(subString);
// Find already allows a request ID as input, but only as an int.
// Use the same counter but mod it to MAX_INT, this keeps the same likeliness of request ID clashing.
int shrunkRequestId = m_nextRequestId++ & 0x7fffffff;
- m_webContents->Find(shrunkRequestId, toString16(subString), options);
+ m_webContents->Find(shrunkRequestId, toString16(subString), std::move(options));
m_lastFindRequestId = shrunkRequestId;
return shrunkRequestId;
}
@@ -1257,6 +1273,12 @@ void WebContentsAdapter::runGeolocationRequestCallback(const QUrl &securityOrigi
m_profileAdapter->permissionRequestReply(securityOrigin, ProfileAdapter::GeolocationPermission, allowed);
}
+void WebContentsAdapter::runUserNotificationRequestCallback(const QUrl &securityOrigin, bool allowed)
+{
+ CHECK_INITIALIZED();
+ m_profileAdapter->permissionRequestReply(securityOrigin, ProfileAdapter::NotificationPermission, allowed);
+}
+
void WebContentsAdapter::grantMouseLockPermission(bool granted)
{
CHECK_INITIALIZED();
@@ -1271,16 +1293,6 @@ void WebContentsAdapter::grantMouseLockPermission(bool granted)
m_webContents->GotResponseToLockMouseRequest(granted);
}
-void WebContentsAdapter::dpiScaleChanged()
-{
- CHECK_INITIALIZED();
- content::RenderWidgetHostImpl* impl = NULL;
- if (m_webContents->GetRenderViewHost())
- impl = content::RenderWidgetHostImpl::From(m_webContents->GetRenderViewHost()->GetWidget());
- if (impl)
- impl->NotifyScreenInfoChanged();
-}
-
void WebContentsAdapter::setBackgroundColor(const QColor &color)
{
CHECK_INITIALIZED();