Fix DCHECK due to unreliable is_main_frame state on XHR requests (issue #2433)

This commit is contained in:
Marshall Greenblatt 2018-05-04 16:42:02 +02:00
parent a3c55f1d26
commit f24f885eeb
2 changed files with 12 additions and 9 deletions

View File

@ -1590,10 +1590,13 @@ CefRefPtr<CefFrame> CefBrowserHostImpl::GetFrameForRequest(
content::ResourceRequestInfo::ForRequest(request); content::ResourceRequestInfo::ForRequest(request);
if (!info) if (!info)
return nullptr; 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(), return GetOrCreateFrame(info->GetRenderFrameID(), info->GetFrameTreeNodeId(),
CefFrameHostImpl::kUnspecifiedFrameId, CefFrameHostImpl::kUnspecifiedFrameId,
info->IsMainFrame(), info->IsDownload(), info->IsMainFrame(), is_main_frame_state_flaky,
base::string16(), GURL()); base::string16(), GURL());
} }
@ -3224,7 +3227,7 @@ CefRefPtr<CefFrame> CefBrowserHostImpl::GetOrCreateFrame(
int frame_tree_node_id, int frame_tree_node_id,
int64 parent_frame_id, int64 parent_frame_id,
bool is_main_frame, bool is_main_frame,
bool is_download, bool is_main_frame_state_flaky,
base::string16 frame_name, base::string16 frame_name,
const GURL& frame_url) { const GURL& frame_url) {
// We need either a valid |frame_id| or a valid |frame_tree_node_id|. // We need either a valid |frame_id| or a valid |frame_tree_node_id|.
@ -3245,13 +3248,13 @@ CefRefPtr<CefFrame> CefBrowserHostImpl::GetOrCreateFrame(
if (frame_id < 0) { if (frame_id < 0) {
// With PlzNavigate the renderer process representation might not exist yet. // 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) { main_frame_id_ != CefFrameHostImpl::kInvalidFrameId) {
// Operating in the main frame. Continue using the existing main frame // Operating in the main frame. Continue using the existing main frame
// object until the new renderer process representation is created. // object until the new renderer process representation is created.
frame_id = main_frame_id_; frame_id = main_frame_id_;
} else { } 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. // Always use the same pending object for the main frame.
frame_tree_node_id = kMainFrameTreeNodeId; frame_tree_node_id = kMainFrameTreeNodeId;
} }
@ -3319,7 +3322,7 @@ CefRefPtr<CefFrame> 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); frame->SetAttributes(is_main_frame, url, name, parent_frame_id);
#if DCHECK_IS_ON() #if DCHECK_IS_ON()

View File

@ -586,13 +586,13 @@ class CefBrowserHostImpl : public CefBrowserHost,
// if PlzNavigate is disabled; or >= 0 otherwise. |parent_frame_id| will be // if PlzNavigate is disabled; or >= 0 otherwise. |parent_frame_id| will be
// CefFrameHostImpl::kUnspecifiedFrameId if unknown. In cases where |frame_id| // CefFrameHostImpl::kUnspecifiedFrameId if unknown. In cases where |frame_id|
// is < 0 either the existing main frame object or a pending object will be // 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 // returned depending on current state. If |is_main_frame_state_flaky| is true
// value of |is_main_frame| cannot be relied on. // then the value of |is_main_frame| cannot be relied on.
CefRefPtr<CefFrame> GetOrCreateFrame(int64 frame_id, CefRefPtr<CefFrame> GetOrCreateFrame(int64 frame_id,
int frame_tree_node_id, int frame_tree_node_id,
int64 parent_frame_id, int64 parent_frame_id,
bool is_main_frame, bool is_main_frame,
bool is_download, bool is_main_frame_state_flaky,
base::string16 frame_name, base::string16 frame_name,
const GURL& frame_url); const GURL& frame_url);