summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSzabolcs David <davidsz@inf.u-szeged.hu>2023-12-04 16:05:55 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-02-26 18:01:18 +0000
commit3daf7aed13281bc5df72cdcc67ab0b066f05dae1 (patch)
treecc8ef47979d0ee81d851626a72146b0df776c45c
parentd452147ca742ac77f22efd2aa1653a41baad88fe (diff)
Show guest WebContents in DevTools if possible
Chrome's DevTools has different behavior for PDF content: - If it was opened for the PDF viewer, it closes itself when the guest view has gone (e.g. by navigating away), but it shows the inner content of the plugin. - If it was opened for another site and then navigated to the PDF plugin it won't show the inner content, but the embedding HTML of the parent and it allows navigating away from the plugin. Make our inspector match the behavior of Chrome and allow DevTools to look into the plugin. It helps debugging PDF viewer related issues. Change-Id: I218d4fcf47d6b1f0101fa1d7f36758e04a1dd7b0 Reviewed-by: Anu Aliyas <anu.aliyas@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> (cherry picked from commit 6acf981aae2165cde6829f309f3792fc34852fd2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit c503b50b189c7446b91edfede083100b206370fb)
-rw-r--r--src/core/devtools_frontend_qt.cpp7
-rw-r--r--src/core/devtools_frontend_qt.h1
-rw-r--r--src/core/web_contents_adapter.cpp5
3 files changed, 11 insertions, 2 deletions
diff --git a/src/core/devtools_frontend_qt.cpp b/src/core/devtools_frontend_qt.cpp
index 047026826..ff0596a3d 100644
--- a/src/core/devtools_frontend_qt.cpp
+++ b/src/core/devtools_frontend_qt.cpp
@@ -78,6 +78,7 @@ DevToolsFrontendQt::DevToolsFrontendQt(QSharedPointer<WebContentsAdapter> webCon
: content::WebContentsObserver(webContentsAdapter->webContents())
, m_frontendAdapter(webContentsAdapter)
, m_inspectedContents(inspectedContents)
+ , m_outermostContents(inspectedContents->GetOutermostWebContents())
, m_bindings(new DevToolsUIBindings(webContentsAdapter->webContents()))
{
// bindings take ownership over devtools
@@ -147,8 +148,10 @@ void DevToolsFrontendQt::ColorPickedInEyeDropper(int r, int g, int b, int a)
// content::WebContentsObserver implementation
void DevToolsFrontendQt::WebContentsDestroyed()
{
+ // If m_inspectedContents was a guest view it was probably already destroyed,
+ // but its embedder still lives.
WebContentsAdapter *inspectedAdapter =
- static_cast<WebContentsDelegateQt *>(m_inspectedContents->GetDelegate())
+ static_cast<WebContentsDelegateQt *>(m_outermostContents->GetDelegate())
->webContentsAdapter();
if (inspectedAdapter)
inspectedAdapter->devToolsFrontendDestroyed(this);
@@ -201,6 +204,8 @@ bool DevToolsFrontendQt::IsValidFrontendURL(const GURL &url)
void DevToolsFrontendQt::InspectedContentsClosing()
{
+ // Called for already destroyed guest views
+ m_inspectedContents = nullptr;
web_contents()->ClosePage();
}
diff --git a/src/core/devtools_frontend_qt.h b/src/core/devtools_frontend_qt.h
index ec7ccce83..b867d4af1 100644
--- a/src/core/devtools_frontend_qt.h
+++ b/src/core/devtools_frontend_qt.h
@@ -76,6 +76,7 @@ private:
// We shouldn't be keeping it alive
QWeakPointer<WebContentsAdapter> m_frontendAdapter;
content::WebContents *m_inspectedContents;
+ content::WebContents *m_outermostContents;
std::unique_ptr<DevToolsEyeDropper> m_eyeDropper;
DevToolsUIBindings *m_bindings;
};
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index f44675171..0f1162b25 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -1272,7 +1272,10 @@ void WebContentsAdapter::openDevToolsFrontend(QSharedPointer<WebContentsAdapter>
setLifecycleState(LifecycleState::Active);
- m_devToolsFrontend = DevToolsFrontendQt::Show(frontendAdapter, m_webContents.get());
+ content::WebContents *webContents = m_webContents.get();
+ if (content::WebContents *guest = guestWebContents())
+ webContents = guest;
+ m_devToolsFrontend = DevToolsFrontendQt::Show(frontendAdapter, webContents);
updateRecommendedState();
}