Commit 5bc62241 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

PageInfo: prevent the crashes of instantiating with non-tab webContents

If PageInfo is instantiated with a webContents that is not from a tab,
a crash would happen. This CL is to allow for such a webContents in
this case.

How would it crash? The webContents not coming from a tab does not
have TabSpecificContentSettings attached to it. If PageInfo is
initiated with this webContents, PageInfo tries to use
TabSpecificContentSettings and causes a null pointer exception.

The general idea of this CL is that, for each PageInfo instantiation,
create TabSpecificContentSettings for WebContents who does not have
it.

This CL belongs to a larger change of extending the usage of PageInfo
dialog to the webContents of PaymentHandler UI.

Bug: 999196

Change-Id: Ifdcf15e61193d93f9a669d93111507b32dc91b0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1944627
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721801}
parent e4d72b79
...@@ -59,6 +59,9 @@ ConnectionInfoPopupAndroid::ConnectionInfoPopupAndroid( ...@@ -59,6 +59,9 @@ ConnectionInfoPopupAndroid::ConnectionInfoPopupAndroid(
SecurityStateTabHelper::FromWebContents(web_contents); SecurityStateTabHelper::FromWebContents(web_contents);
DCHECK(helper); DCHECK(helper);
// When |web_contents| is not from a Tab, |web_contents| does not have a
// |TabSpecificContentSettings| and need to create one; otherwise, noop.
TabSpecificContentSettings::CreateForWebContents(web_contents);
presenter_ = std::make_unique<PageInfo>( presenter_ = std::make_unique<PageInfo>(
this, Profile::FromBrowserContext(web_contents->GetBrowserContext()), this, Profile::FromBrowserContext(web_contents->GetBrowserContext()),
TabSpecificContentSettings::FromWebContents(web_contents), web_contents, TabSpecificContentSettings::FromWebContents(web_contents), web_contents,
......
...@@ -62,6 +62,9 @@ PageInfoControllerAndroid::PageInfoControllerAndroid( ...@@ -62,6 +62,9 @@ PageInfoControllerAndroid::PageInfoControllerAndroid(
SecurityStateTabHelper::FromWebContents(web_contents); SecurityStateTabHelper::FromWebContents(web_contents);
DCHECK(helper); DCHECK(helper);
// When |web_contents| is not from a Tab, |web_contents| does not have a
// |TabSpecificContentSettings| and need to create one; otherwise, noop.
TabSpecificContentSettings::CreateForWebContents(web_contents);
presenter_ = std::make_unique<PageInfo>( presenter_ = std::make_unique<PageInfo>(
this, Profile::FromBrowserContext(web_contents->GetBrowserContext()), this, Profile::FromBrowserContext(web_contents->GetBrowserContext()),
TabSpecificContentSettings::FromWebContents(web_contents), web_contents, TabSpecificContentSettings::FromWebContents(web_contents), web_contents,
......
...@@ -507,6 +507,9 @@ PageInfoBubbleView::PageInfoBubbleView( ...@@ -507,6 +507,9 @@ PageInfoBubbleView::PageInfoBubbleView(
// before PageInfo updates trigger child layouts. // before PageInfo updates trigger child layouts.
SetSize(GetPreferredSize()); SetSize(GetPreferredSize());
// When |web_contents| is not from a Tab, |web_contents| does not have a
// |TabSpecificContentSettings| and need to create one; otherwise, noop.
TabSpecificContentSettings::CreateForWebContents(web_contents);
presenter_ = std::make_unique<PageInfo>( presenter_ = std::make_unique<PageInfo>(
this, profile, TabSpecificContentSettings::FromWebContents(web_contents), this, profile, TabSpecificContentSettings::FromWebContents(web_contents),
web_contents, url, security_level, visible_security_state); web_contents, url, security_level, visible_security_state);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment