Ignore load of excluded PDF renderer frames

Starting with M125 we get WebContentsObserver callbacks for speculative
PDF renderer frames. These callbacks should be ignored.
This commit is contained in:
Marshall Greenblatt 2024-04-24 15:38:49 -04:00
parent b67cbc47e3
commit 65234a6830
5 changed files with 47 additions and 6 deletions

View File

@ -569,6 +569,10 @@ void CefBrowserContentsDelegate::DidFinishLoad(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
const GURL& validated_url) { const GURL& validated_url) {
auto frame = browser_info_->GetFrameForHost(render_frame_host); auto frame = browser_info_->GetFrameForHost(render_frame_host);
if (!frame) {
return;
}
frame->RefreshAttributes(); frame->RefreshAttributes();
int http_status_code = 0; int http_status_code = 0;

View File

@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "libcef/browser/browser_host_base.h" #include "libcef/browser/browser_host_base.h"
#include "libcef/browser/browser_info_manager.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/frame_util.h" #include "libcef/common/frame_util.h"
#include "libcef/common/values_impl.h" #include "libcef/common/values_impl.h"
@ -98,6 +99,11 @@ void CefBrowserInfo::MaybeCreateFrame(content::RenderFrameHost* host,
bool is_guest_view) { bool is_guest_view) {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
if (CefBrowserInfoManager::IsExcludedFrameHost(host)) {
// Don't create a FrameHost for an excluded type.
return;
}
const auto global_id = host->GetGlobalId(); const auto global_id = host->GetGlobalId();
const bool is_main_frame = (host->GetParent() == nullptr); const bool is_main_frame = (host->GetParent() == nullptr);
@ -212,10 +218,11 @@ void CefBrowserInfo::FrameHostStateChanged(
base::AutoLock lock_scope(lock_); base::AutoLock lock_scope(lock_);
auto it = frame_id_map_.find(host->GetGlobalId()); auto it = frame_id_map_.find(host->GetGlobalId());
DCHECK(it != frame_id_map_.end()); if (it != frame_id_map_.end()) {
DCHECK((!it->second->is_in_bfcache_ && added_to_bfcache) || DCHECK((!it->second->is_in_bfcache_ && added_to_bfcache) ||
(it->second->is_in_bfcache_ && removed_from_bfcache)); (it->second->is_in_bfcache_ && removed_from_bfcache));
it->second->is_in_bfcache_ = added_to_bfcache; it->second->is_in_bfcache_ = added_to_bfcache;
}
} }
void CefBrowserInfo::RemoveFrame(content::RenderFrameHost* host) { void CefBrowserInfo::RemoveFrame(content::RenderFrameHost* host) {
@ -225,7 +232,9 @@ void CefBrowserInfo::RemoveFrame(content::RenderFrameHost* host) {
const auto global_id = host->GetGlobalId(); const auto global_id = host->GetGlobalId();
auto it = frame_id_map_.find(global_id); auto it = frame_id_map_.find(global_id);
DCHECK(it != frame_id_map_.end()); if (it == frame_id_map_.end()) {
return;
}
auto frame_info = it->second; auto frame_info = it->second;

View File

@ -551,6 +551,31 @@ CefRefPtr<CefFrameHostImpl> CefBrowserInfoManager::GetFrameHost(
return frame; return frame;
} }
// static
bool CefBrowserInfoManager::IsExcludedFrameHost(content::RenderFrameHost* rfh) {
CEF_REQUIRE_UIT();
DCHECK(rfh);
const bool is_pdf_process = rfh->GetProcess()->IsPdf();
if (is_pdf_process) {
return true;
}
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
const bool is_browser_process_guest =
extensions::IsBrowserPluginGuest(web_contents);
if (is_browser_process_guest) {
return true;
}
const bool is_print_preview_dialog =
extensions::IsPrintPreviewDialog(web_contents);
if (is_print_preview_dialog) {
return true;
}
return false;
}
CefBrowserInfoManager::BrowserInfoList CefBrowserInfoManager::BrowserInfoList
CefBrowserInfoManager::GetBrowserInfoList() { CefBrowserInfoManager::GetBrowserInfoList() {
base::AutoLock lock_scope(browser_info_lock_); base::AutoLock lock_scope(browser_info_lock_);

View File

@ -160,6 +160,9 @@ class CefBrowserInfoManager : public content::RenderProcessHostObserver {
CefBrowserInfo** browser_info, CefBrowserInfo** browser_info,
bool* excluded_type); bool* excluded_type);
// Returns true if |rfh| should be excluded (no FrameHost created).
static bool IsExcludedFrameHost(content::RenderFrameHost* rfh);
private: private:
// RenderProcessHostObserver methods: // RenderProcessHostObserver methods:
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;

View File

@ -92,7 +92,7 @@ class PdfViewerTestHandler : public TestHandler, public CefContextMenuHandler {
int httpStatusCode) override { int httpStatusCode) override {
bool is_pdf1 = false; bool is_pdf1 = false;
const std::string& url = frame->GetURL(); const std::string& url = frame->GetURL();
if (url == "about:blank") { if (url == "about:blank" || url.find("chrome-extension://") == 0) {
return; return;
} }