From f24f885eeb7fe358a41e5544e29d76f74210c787 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 4 May 2018 16:42:02 +0200 Subject: [PATCH] Fix DCHECK due to unreliable is_main_frame state on XHR requests (issue #2433) --- libcef/browser/browser_host_impl.cc | 15 +++++++++------ libcef/browser/browser_host_impl.h | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index d65a78ada..320dd2438 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -1590,10 +1590,13 @@ CefRefPtr CefBrowserHostImpl::GetFrameForRequest( content::ResourceRequestInfo::ForRequest(request); if (!info) return nullptr; - // The value of |IsMainFrame| is unreliable when |IsDownload| returns true. + // The value of |IsMainFrame| is unreliable in these cases. + const bool is_main_frame_state_flaky = + info->IsDownload() || + info->GetResourceType() == content::RESOURCE_TYPE_XHR; return GetOrCreateFrame(info->GetRenderFrameID(), info->GetFrameTreeNodeId(), CefFrameHostImpl::kUnspecifiedFrameId, - info->IsMainFrame(), info->IsDownload(), + info->IsMainFrame(), is_main_frame_state_flaky, base::string16(), GURL()); } @@ -3224,7 +3227,7 @@ CefRefPtr CefBrowserHostImpl::GetOrCreateFrame( int frame_tree_node_id, int64 parent_frame_id, bool is_main_frame, - bool is_download, + bool is_main_frame_state_flaky, base::string16 frame_name, const GURL& frame_url) { // We need either a valid |frame_id| or a valid |frame_tree_node_id|. @@ -3245,13 +3248,13 @@ CefRefPtr CefBrowserHostImpl::GetOrCreateFrame( if (frame_id < 0) { // With PlzNavigate the renderer process representation might not exist yet. - if ((is_main_frame || is_download) && + if ((is_main_frame || is_main_frame_state_flaky) && main_frame_id_ != CefFrameHostImpl::kInvalidFrameId) { // Operating in the main frame. Continue using the existing main frame // object until the new renderer process representation is created. frame_id = main_frame_id_; } else { - if (is_main_frame || is_download) { + if (is_main_frame || is_main_frame_state_flaky) { // Always use the same pending object for the main frame. frame_tree_node_id = kMainFrameTreeNodeId; } @@ -3319,7 +3322,7 @@ CefRefPtr CefBrowserHostImpl::GetOrCreateFrame( } } - if (!frame_created && !is_download) + if (!frame_created && !is_main_frame_state_flaky) frame->SetAttributes(is_main_frame, url, name, parent_frame_id); #if DCHECK_IS_ON() diff --git a/libcef/browser/browser_host_impl.h b/libcef/browser/browser_host_impl.h index d09a082ed..da7e94132 100644 --- a/libcef/browser/browser_host_impl.h +++ b/libcef/browser/browser_host_impl.h @@ -586,13 +586,13 @@ class CefBrowserHostImpl : public CefBrowserHost, // if PlzNavigate is disabled; or >= 0 otherwise. |parent_frame_id| will be // CefFrameHostImpl::kUnspecifiedFrameId if unknown. In cases where |frame_id| // is < 0 either the existing main frame object or a pending object will be - // returned depending on current state. If |is_download| is true then the - // value of |is_main_frame| cannot be relied on. + // returned depending on current state. If |is_main_frame_state_flaky| is true + // then the value of |is_main_frame| cannot be relied on. CefRefPtr GetOrCreateFrame(int64 frame_id, int frame_tree_node_id, int64 parent_frame_id, bool is_main_frame, - bool is_download, + bool is_main_frame_state_flaky, base::string16 frame_name, const GURL& frame_url);