summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2021-11-16 16:05:27 +0100
committerMichal Klocek <michal.klocek@qt.io>2021-11-25 12:34:59 +0100
commit1b8aa58a618eee23c4fd23b4fb51667fd8a3f2b8 (patch)
treecf2f294ce3e7e92a48397a6ab05340e7479d33ba /src
parentee3252238c200d84461d5da71bb413b798c117f3 (diff)
Fix race condition on layoutHEADdev
Calling some methods without 'meaningful' layout when render frame is visible tiggers at the best some DCHECKS. Therefore if frame is visible wait for 'meaningful' layout. This fixes some flaky tests on toPlainTextSync call. Pick-to: 6.2 Change-Id: I746a1c436798b440c59f9b8b4a1d297e3fa7e56d Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/core/renderer/web_engine_page_render_frame.cpp36
-rw-r--r--src/core/renderer/web_engine_page_render_frame.h4
2 files changed, 35 insertions, 5 deletions
diff --git a/src/core/renderer/web_engine_page_render_frame.cpp b/src/core/renderer/web_engine_page_render_frame.cpp
index e230e7fa..ad5aa4b9 100644
--- a/src/core/renderer/web_engine_page_render_frame.cpp
+++ b/src/core/renderer/web_engine_page_render_frame.cpp
@@ -53,7 +53,7 @@
namespace QtWebEngineCore {
WebEnginePageRenderFrame::WebEnginePageRenderFrame(content::RenderFrame *render_frame)
- : content::RenderFrameObserver(render_frame), m_binding(this)
+ : content::RenderFrameObserver(render_frame), m_binding(this), m_needsLayout(false)
{
render_frame->GetAssociatedInterfaceRegistry()->AddInterface(
base::BindRepeating(&WebEnginePageRenderFrame::BindReceiver, base::Unretained(this)));
@@ -68,16 +68,21 @@ void WebEnginePageRenderFrame::BindReceiver(
void WebEnginePageRenderFrame::FetchDocumentMarkup(uint64_t requestId,
FetchDocumentMarkupCallback callback)
{
- blink::WebString markup = blink::WebFrameContentDumper::DumpAsMarkup(
- render_frame()->GetWebFrame()) ;
+ blink::WebLocalFrame *frame = render_frame()->GetWebFrame();
+ blink::WebString markup;
+ if (!m_needsLayout)
+ markup = blink::WebFrameContentDumper::DumpAsMarkup(frame);
std::move(callback).Run(requestId, markup.Utf8());
}
void WebEnginePageRenderFrame::FetchDocumentInnerText(uint64_t requestId,
FetchDocumentInnerTextCallback callback)
{
- blink::WebString text = blink::WebFrameContentDumper::DumpFrameTreeAsText(
- render_frame()->GetWebFrame(), std::numeric_limits<std::size_t>::max());
+ blink::WebLocalFrame *frame = render_frame()->GetWebFrame();
+ blink::WebString text;
+ if (!m_needsLayout)
+ text = blink::WebFrameContentDumper::DumpFrameTreeAsText(
+ frame, std::numeric_limits<std::size_t>::max());
std::move(callback).Run(requestId, text.Utf8());
}
@@ -91,4 +96,25 @@ void WebEnginePageRenderFrame::OnDestruct()
delete this;
}
+void WebEnginePageRenderFrame::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type)
+{
+ switch (layout_type) {
+ case blink::WebMeaningfulLayout::kFinishedParsing:
+ case blink::WebMeaningfulLayout::kFinishedLoading:
+ m_needsLayout = false;
+ break;
+ default:
+ break;
+ }
+}
+
+void WebEnginePageRenderFrame::WasShown()
+{
+ m_needsLayout = true;
+}
+
+void WebEnginePageRenderFrame::WasHidden()
+{
+ m_needsLayout = false;
+}
}
diff --git a/src/core/renderer/web_engine_page_render_frame.h b/src/core/renderer/web_engine_page_render_frame.h
index 3fb4657c..f2ae8fd2 100644
--- a/src/core/renderer/web_engine_page_render_frame.h
+++ b/src/core/renderer/web_engine_page_render_frame.h
@@ -63,12 +63,16 @@ private:
FetchDocumentInnerTextCallback callback) override;
void SetBackgroundColor(uint32_t color) override;
void OnDestruct() override;
+ void DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) override;
+ void WasShown() override;
+ void WasHidden() override;
void
BindReceiver(mojo::PendingAssociatedReceiver<qtwebenginepage::mojom::WebEnginePageRenderFrame>
receiver);
private:
mojo::AssociatedReceiver<qtwebenginepage::mojom::WebEnginePageRenderFrame> m_binding;
+ bool m_needsLayout;
};
} // namespace