From 7753f12a5449a3ec934e833619380e91f97a6db1 Mon Sep 17 00:00:00 2001
From: Pierre Rossi <pierre.rossi@digia.com>
Date: Tue, 14 Jan 2014 15:56:06 +0100
Subject: [PATCH] Pre-start the render process upon initialiazing the adapter

This should provide us with an initial empty document, which our
imported autotests tend to assume all over the place.

Initialization of the adapter is moved further down in
QQuickWebEngineView's constructor so that the value of
q_ptr is set and valid by the time we end up in
WebContentsViewQt::CreateViewForWidget.

Change-Id: I45d8d61e65caa3a690461b6da44adea9f8981e7e
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
---
 src/core/web_contents_adapter.cpp         | 8 +++++++-
 src/webengine/api/qquickwebengineview.cpp | 5 ++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index 24da23016..4c197090c 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -52,9 +52,9 @@
 
 #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/navigation_entry.h"
 #include "content/public/browser/render_view_host.h"
-#include "content/public/browser/web_contents.h"
 #include "content/public/common/page_zoom.h"
 #include "content/public/common/renderer_preferences.h"
 #include "ui/shell_dialogs/selected_file_info.h"
@@ -220,6 +220,12 @@ void WebContentsAdapter::initialize(WebContentsAdapterClient *adapterClient)
     // Let the WebContent's view know about the WebContentsAdapterClient.
     WebContentsViewQt* contentsView = static_cast<WebContentsViewQt*>(d->webContents->GetView());
     contentsView->initialize(adapterClient);
+
+    // Create a RenderView with the initial empty document
+    content::RenderViewHost *rvh = d->webContents->GetRenderViewHost();
+    Q_ASSERT(rvh);
+    static_cast<content::WebContentsImpl*>(d->webContents.get())->CreateRenderViewForRenderManager(rvh, MSG_ROUTING_NONE);
+
 }
 
 void WebContentsAdapter::reattachRWHV()
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index a99707730..68e64ee4e 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -89,8 +89,6 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate()
         // 1x, 2x, 3x etc assets that fit an integral number of pixels.
         setDevicePixelRatio(qMax(1, qRound(webPixelRatio)));
     }
-
-    adapter->initialize(this);
 }
 
 QQuickWebEngineViewExperimental *QQuickWebEngineViewPrivate::experimental() const
@@ -324,8 +322,9 @@ void QQuickWebEngineViewPrivate::setDevicePixelRatio(qreal devicePixelRatio)
 QQuickWebEngineView::QQuickWebEngineView(QQuickItem *parent)
     : QQuickItem(*(new QQuickWebEngineViewPrivate), parent)
 {
-    Q_D(const QQuickWebEngineView);
+    Q_D(QQuickWebEngineView);
     d->e->q_ptr = this;
+    d->adapter->initialize(d);
 }
 
 QQuickWebEngineView::~QQuickWebEngineView()
-- 
GitLab