Commit 65bd7e54 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[WebLayer] SecurityLevel+VisibleSecurityState from delegate.

Update PageInfo to get SecurityLevel and VisibleSecurityState from the
delegate, which moves a lot of duplicated logic from wherever PageInfo
is constructed into the delegate, and will also make componentizing
ConnectionInfoPopup and PageInfoController easier, because the
dependency on SecurityStateTabHelper won't be necessary.

UpdateSecurityState and ComputeUIInputs don't need SecurityLevel and
VisibleSecurityState, and have been updated to get them directly from
the delegate instead.

PageInfoTest was setting custom values for these, and so a test-only
method to set security state has been added.

Bug: 1052375
Change-Id: Icf09eba58654d46ca9f9bf075364c1f00793db91
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2128107
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755050}
parent bb4cacc3
......@@ -34,7 +34,6 @@
#include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ssl/security_state_tab_helper.h"
#include "chrome/browser/ui/page_info/chrome_page_info_delegate.h"
#include "chrome/browser/vr/assets_loader.h"
#include "chrome/browser/vr/browser_renderer.h"
......@@ -1204,12 +1203,9 @@ std::unique_ptr<PageInfo> VrShell::CreatePageInfo() {
if (!entry)
return nullptr;
SecurityStateTabHelper* helper =
SecurityStateTabHelper::FromWebContents(web_contents_);
auto page_info = std::make_unique<PageInfo>(
std::make_unique<ChromePageInfoDelegate>(web_contents_), web_contents_,
entry->GetVirtualURL(), helper->GetSecurityLevel(),
*helper->GetVisibleSecurityState());
entry->GetVirtualURL());
page_info->InitializeUiState(this);
return page_info;
}
......
......@@ -10,7 +10,6 @@
#include "chrome/android/chrome_jni_headers/ConnectionInfoPopup_jni.h"
#include "chrome/browser/android/resource_mapper.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/ssl/security_state_tab_helper.h"
#include "chrome/browser/ui/page_info/chrome_page_info_delegate.h"
#include "components/page_info/page_info.h"
#include "components/security_state/core/security_state.h"
......@@ -55,14 +54,9 @@ ConnectionInfoPopupAndroid::ConnectionInfoPopupAndroid(
popup_jobject_.Reset(env, java_page_info_pop);
SecurityStateTabHelper* helper =
SecurityStateTabHelper::FromWebContents(web_contents);
DCHECK(helper);
presenter_ = std::make_unique<PageInfo>(
std::make_unique<ChromePageInfoDelegate>(web_contents), web_contents,
nav_entry->GetURL(), helper->GetSecurityLevel(),
*helper->GetVisibleSecurityState());
nav_entry->GetURL());
presenter_->InitializeUiState(this);
}
......
......@@ -11,7 +11,6 @@
#include "base/stl_util.h"
#include "chrome/android/chrome_jni_headers/PageInfoController_jni.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/ssl/security_state_tab_helper.h"
#include "chrome/browser/ui/page_info/chrome_page_info_delegate.h"
#include "chrome/common/chrome_features.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
......@@ -59,14 +58,9 @@ PageInfoControllerAndroid::PageInfoControllerAndroid(
controller_jobject_.Reset(env, java_page_info_pop);
SecurityStateTabHelper* helper =
SecurityStateTabHelper::FromWebContents(web_contents);
DCHECK(helper);
presenter_ = std::make_unique<PageInfo>(
std::make_unique<ChromePageInfoDelegate>(web_contents), web_contents,
nav_entry->GetURL(), helper->GetSecurityLevel(),
*helper->GetVisibleSecurityState());
nav_entry->GetURL());
presenter_->InitializeUiState(this);
}
......
......@@ -14,6 +14,7 @@
#include "chrome/browser/permissions/permission_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
#include "chrome/browser/ssl/security_state_tab_helper.h"
#include "chrome/browser/ssl/stateful_ssl_host_state_delegate_factory.h"
#include "chrome/browser/usb/usb_chooser_context.h"
#include "chrome/browser/usb/usb_chooser_context_factory.h"
......@@ -207,3 +208,38 @@ HostContentSettingsMap* ChromePageInfoDelegate::GetContentSettings() {
bool ChromePageInfoDelegate::IsContentDisplayedInVrHeadset() {
return vr::VrTabHelper::IsContentDisplayedInHeadset(web_contents_);
}
security_state::SecurityLevel ChromePageInfoDelegate::GetSecurityLevel() {
if (security_state_for_tests_set_)
return security_level_for_tests_;
// This is a no-op if a SecurityStateTabHelper already exists for
// |web_contents|.
SecurityStateTabHelper::CreateForWebContents(web_contents_);
auto* helper = SecurityStateTabHelper::FromWebContents(web_contents_);
DCHECK(helper);
return helper->GetSecurityLevel();
}
security_state::VisibleSecurityState
ChromePageInfoDelegate::GetVisibleSecurityState() {
if (security_state_for_tests_set_)
return visible_security_state_for_tests_;
// This is a no-op if a SecurityStateTabHelper already exists for
// |web_contents|.
SecurityStateTabHelper::CreateForWebContents(web_contents_);
auto* helper = SecurityStateTabHelper::FromWebContents(web_contents_);
DCHECK(helper);
return *helper->GetVisibleSecurityState();
}
void ChromePageInfoDelegate::SetSecurityStateForTests(
security_state::SecurityLevel security_level,
security_state::VisibleSecurityState visible_security_state) {
security_state_for_tests_set_ = true;
security_level_for_tests_ = security_level;
visible_security_state_for_tests_ = visible_security_state;
}
......@@ -35,6 +35,10 @@ class ChromePageInfoDelegate : public PageInfoDelegate {
explicit ChromePageInfoDelegate(content::WebContents* web_contents);
~ChromePageInfoDelegate() override = default;
void SetSecurityStateForTests(
security_state::SecurityLevel security_level,
security_state::VisibleSecurityState visible_security_state);
// PageInfoDelegate implementation
permissions::ChooserContextBase* GetChooserContext(
ContentSettingsType type) override;
......@@ -65,6 +69,8 @@ class ChromePageInfoDelegate : public PageInfoDelegate {
StatefulSSLHostStateDelegate* GetStatefulSSLHostStateDelegate() override;
HostContentSettingsMap* GetContentSettings() override;
bool IsContentDisplayedInVrHeadset() override;
security_state::SecurityLevel GetSecurityLevel() override;
security_state::VisibleSecurityState GetVisibleSecurityState() override;
private:
TabSpecificContentSettings* GetTabSpecificContentSettings() const;
......@@ -76,6 +82,9 @@ class ChromePageInfoDelegate : public PageInfoDelegate {
GetChromePasswordProtectionService() const;
#endif
content::WebContents* web_contents_;
security_state::SecurityLevel security_level_for_tests_;
security_state::VisibleSecurityState visible_security_state_for_tests_;
bool security_state_for_tests_set_ = false;
};
#endif // CHROME_BROWSER_UI_PAGE_INFO_CHROME_PAGE_INFO_DELEGATE_H_
......@@ -26,11 +26,8 @@ bool ShowPageInfoDialog(content::WebContents* web_contents,
if (!entry)
return false;
SecurityStateTabHelper* helper =
SecurityStateTabHelper::FromWebContents(web_contents);
ShowPageInfoDialogImpl(
browser, web_contents, entry->GetVirtualURL(), helper->GetSecurityLevel(),
*helper->GetVisibleSecurityState(), anchor, std::move(closing_callback));
ShowPageInfoDialogImpl(browser, web_contents, entry->GetVirtualURL(), anchor,
std::move(closing_callback));
if (GetPageInfoDialogCreatedCallbackForTesting())
std::move(GetPageInfoDialogCreatedCallbackForTesting()).Run();
......
......@@ -39,8 +39,6 @@ void ShowPageInfoDialogImpl(
Browser* browser,
content::WebContents* web_contents,
const GURL& virtual_url,
security_state::SecurityLevel security_level,
const security_state::VisibleSecurityState& visible_security_state,
bubble_anchor_util::Anchor,
PageInfoClosingCallback closing_callback);
......
......@@ -199,10 +199,6 @@ class PageInfoTest : public ChromeRenderViewHostTestHarness {
const url::Origin& origin() const { return origin_; }
scoped_refptr<net::X509Certificate> cert() { return cert_; }
MockPageInfoUI* mock_ui() { return mock_ui_.get(); }
security_state::SecurityLevel security_level() { return security_level_; }
const security_state::VisibleSecurityState& visible_security_state() {
return visible_security_state_;
}
const std::vector<std::unique_ptr<PageInfoUI::ChosenObjectInfo>>&
last_chosen_object_info() {
return last_chosen_object_info_;
......@@ -216,9 +212,11 @@ class PageInfoTest : public ChromeRenderViewHostTestHarness {
PageInfo* page_info() {
if (!page_info_.get()) {
page_info_ = std::make_unique<PageInfo>(
std::make_unique<ChromePageInfoDelegate>(web_contents()),
web_contents(), url(), security_level(), visible_security_state());
auto delegate = std::make_unique<ChromePageInfoDelegate>(web_contents());
delegate->SetSecurityStateForTests(security_level_,
visible_security_state_);
page_info_ = std::make_unique<PageInfo>(std::move(delegate),
web_contents(), url());
page_info_->InitializeUiState(mock_ui());
}
return page_info_.get();
......
......@@ -1145,16 +1145,11 @@ bool LocationBarView::ShowPageInfoDialog() {
if (!entry)
return false;
SecurityStateTabHelper* helper =
SecurityStateTabHelper::FromWebContents(contents);
DCHECK(helper);
DCHECK(GetWidget());
views::BubbleDialogDelegateView* bubble =
PageInfoBubbleView::CreatePageInfoBubble(
this, gfx::Rect(), GetWidget()->GetNativeWindow(), profile_, contents,
entry->GetVirtualURL(), helper->GetSecurityLevel(),
*helper->GetVisibleSecurityState(),
entry->GetVirtualURL(),
base::BindOnce(&LocationBarView::OnPageInfoBubbleClosed,
weak_factory_.GetWeakPtr()));
bubble->SetHighlightedButton(location_icon_view_);
......
......@@ -424,8 +424,6 @@ views::BubbleDialogDelegateView* PageInfoBubbleView::CreatePageInfoBubble(
Profile* profile,
content::WebContents* web_contents,
const GURL& url,
security_state::SecurityLevel security_level,
const security_state::VisibleSecurityState& visible_security_state,
PageInfoClosingCallback closing_callback) {
gfx::NativeView parent_view = platform_util::GetViewForWindow(parent_window);
......@@ -439,9 +437,8 @@ views::BubbleDialogDelegateView* PageInfoBubbleView::CreatePageInfoBubble(
web_contents, url);
}
return new PageInfoBubbleView(
anchor_view, anchor_rect, parent_view, profile, web_contents, url,
security_level, visible_security_state, std::move(closing_callback));
return new PageInfoBubbleView(anchor_view, anchor_rect, parent_view, profile,
web_contents, url, std::move(closing_callback));
}
PageInfoBubbleView::PageInfoBubbleView(
......@@ -451,8 +448,6 @@ PageInfoBubbleView::PageInfoBubbleView(
Profile* profile,
content::WebContents* web_contents,
const GURL& url,
security_state::SecurityLevel security_level,
const security_state::VisibleSecurityState& visible_security_state,
PageInfoClosingCallback closing_callback)
: PageInfoBubbleViewBase(anchor_view,
anchor_rect,
......@@ -522,8 +517,8 @@ PageInfoBubbleView::PageInfoBubbleView(
// |TabSpecificContentSettings| and need to create one; otherwise, noop.
TabSpecificContentSettings::CreateForWebContents(web_contents);
presenter_ = std::make_unique<PageInfo>(
std::make_unique<ChromePageInfoDelegate>(web_contents), web_contents, url,
security_level, visible_security_state);
std::make_unique<ChromePageInfoDelegate>(web_contents), web_contents,
url);
presenter_->InitializeUiState(this);
}
......@@ -923,16 +918,7 @@ void PageInfoBubbleView::LayoutPermissionsLikeUiRow(views::GridLayout* layout,
}
void PageInfoBubbleView::DidChangeVisibleSecurityState() {
content::WebContents* contents = web_contents();
if (!contents)
return;
SecurityStateTabHelper* helper =
SecurityStateTabHelper::FromWebContents(contents);
DCHECK(helper);
presenter_->UpdateSecurityState(helper->GetSecurityLevel(),
*helper->GetVisibleSecurityState());
presenter_->UpdateSecurityState();
}
#if BUILDFLAG(FULL_SAFE_BROWSING)
......@@ -1030,14 +1016,11 @@ void PageInfoBubbleView::StyledLabelLinkClicked(views::StyledLabel* label,
}
}
void ShowPageInfoDialogImpl(
Browser* browser,
content::WebContents* web_contents,
const GURL& virtual_url,
security_state::SecurityLevel security_level,
const security_state::VisibleSecurityState& visible_security_state,
bubble_anchor_util::Anchor anchor,
PageInfoClosingCallback closing_callback) {
void ShowPageInfoDialogImpl(Browser* browser,
content::WebContents* web_contents,
const GURL& virtual_url,
bubble_anchor_util::Anchor anchor,
PageInfoClosingCallback closing_callback) {
AnchorConfiguration configuration =
GetPageInfoAnchorConfiguration(browser, anchor);
gfx::Rect anchor_rect =
......@@ -1046,8 +1029,8 @@ void ShowPageInfoDialogImpl(
views::BubbleDialogDelegateView* bubble =
PageInfoBubbleView::CreatePageInfoBubble(
configuration.anchor_view, anchor_rect, parent_window,
browser->profile(), web_contents, virtual_url, security_level,
visible_security_state, std::move(closing_callback));
browser->profile(), web_contents, virtual_url,
std::move(closing_callback));
bubble->SetHighlightedButton(configuration.highlighted_button);
bubble->SetArrow(configuration.bubble_arrow);
bubble->GetWidget()->Show();
......
......@@ -98,8 +98,6 @@ class PageInfoBubbleView : public PageInfoBubbleViewBase,
Profile* profile,
content::WebContents* web_contents,
const GURL& url,
security_state::SecurityLevel security_level,
const security_state::VisibleSecurityState& visible_security_state,
PageInfoClosingCallback closing_callback);
protected:
......@@ -117,8 +115,6 @@ class PageInfoBubbleView : public PageInfoBubbleViewBase,
Profile* profile,
content::WebContents* web_contents,
const GURL& url,
security_state::SecurityLevel security_level,
const security_state::VisibleSecurityState& visible_security_state,
PageInfoClosingCallback closing_callback);
// PageInfoBubbleViewBase:
......
......@@ -79,7 +79,6 @@ class PageInfoBubbleViewTestApi {
views::View* anchor_view = nullptr;
view_ = new PageInfoBubbleView(
anchor_view, gfx::Rect(), parent_, profile_, web_contents_, GURL(kUrl),
security_state::NONE, security_state::VisibleSecurityState(),
base::BindOnce(&PageInfoBubbleViewTestApi::OnPageInfoBubbleClosed,
base::Unretained(this), run_loop_.QuitClosure()));
}
......
......@@ -301,12 +301,9 @@ const char kPageInfoTimeNoActionPrefix[] =
} // namespace
PageInfo::PageInfo(
std::unique_ptr<PageInfoDelegate> delegate,
content::WebContents* web_contents,
const GURL& url,
security_state::SecurityLevel security_level,
const security_state::VisibleSecurityState& visible_security_state)
PageInfo::PageInfo(std::unique_ptr<PageInfoDelegate> delegate,
content::WebContents* web_contents,
const GURL& url)
: content::WebContentsObserver(web_contents),
delegate_(std::move(delegate)),
show_info_bar_(false),
......@@ -317,11 +314,11 @@ PageInfo::PageInfo(
site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
show_ssl_decision_revoke_button_(false),
did_revoke_user_ssl_decisions_(false),
security_level_(security_level),
visible_security_state_for_metrics_(visible_security_state),
show_change_password_buttons_(false),
did_perform_action_(false) {
DCHECK(delegate_);
security_level_ = delegate_->GetSecurityLevel();
visible_security_state_for_metrics_ = delegate_->GetVisibleSecurityState();
}
PageInfo::~PageInfo() {
......@@ -399,8 +396,7 @@ void PageInfo::InitializeUiState(PageInfoUI* ui) {
ui_ = ui;
DCHECK(ui_);
ComputeUIInputs(site_url_, security_level_,
visible_security_state_for_metrics_);
ComputeUIInputs(site_url_);
PresentSitePermissions();
PresentSiteIdentity();
PresentSiteData();
......@@ -415,11 +411,8 @@ void PageInfo::InitializeUiState(PageInfoUI* ui) {
start_time_ = base::TimeTicks::Now();
}
void PageInfo::UpdateSecurityState(
security_state::SecurityLevel security_level,
const security_state::VisibleSecurityState& visible_security_state) {
visible_security_state_for_metrics_ = visible_security_state;
ComputeUIInputs(site_url_, security_level, visible_security_state);
void PageInfo::UpdateSecurityState() {
ComputeUIInputs(site_url_);
PresentSiteIdentity();
}
......@@ -618,10 +611,9 @@ permissions::ChooserContextBase* PageInfo::GetChooserContextFromUIInfo(
return delegate_->GetChooserContext(ui_info.content_settings_type);
}
void PageInfo::ComputeUIInputs(
const GURL& url,
security_state::SecurityLevel security_level,
const security_state::VisibleSecurityState& visible_security_state) {
void PageInfo::ComputeUIInputs(const GURL& url) {
auto security_level = delegate_->GetSecurityLevel();
auto visible_security_state = delegate_->GetVisibleSecurityState();
#if !defined(OS_ANDROID)
// On desktop, internal URLs aren't handled by this class. Instead, a
// custom and simpler bubble is shown.
......@@ -636,8 +628,6 @@ void PageInfo::ComputeUIInputs(
is_chrome_ui_native_scheme = url.SchemeIs(browser_ui::kChromeUINativeScheme);
#endif
security_level_ = security_level;
if (url.SchemeIs(url::kAboutScheme)) {
// All about: URLs except about:blank are redirected.
DCHECK_EQ(url::kAboutBlankURL, url.spec());
......
......@@ -143,9 +143,7 @@ class PageInfo : public content::WebContentsObserver {
// object to determine the status of the site's connection.
PageInfo(std::unique_ptr<PageInfoDelegate> delegate,
content::WebContents* web_contents,
const GURL& url,
security_state::SecurityLevel security_level,
const security_state::VisibleSecurityState& visible_security_state);
const GURL& url);
~PageInfo() override;
// Initializes UI state that is dependent on having access to the PageInfoUI
......@@ -159,9 +157,7 @@ class PageInfo : public content::WebContentsObserver {
// This method is called to update the presenter's security state and forwards
// that change on to the UI to be redrawn.
void UpdateSecurityState(
security_state::SecurityLevel security_level,
const security_state::VisibleSecurityState& visible_security_state);
void UpdateSecurityState();
void RecordPageInfoAction(PageInfoAction action);
......@@ -217,10 +213,7 @@ class PageInfo : public content::WebContentsObserver {
friend class PageInfoBubbleViewBrowserTest;
// Populates this object's UI state with provided security context. This
// function does not update visible UI-- that's part of Present*().
void ComputeUIInputs(
const GURL& url,
const security_state::SecurityLevel security_level,
const security_state::VisibleSecurityState& visible_security_state);
void ComputeUIInputs(const GURL& url);
// Sets (presents) the information about the site's permissions in the |ui_|.
void PresentSitePermissions();
......
......@@ -12,6 +12,7 @@
#include "components/permissions/permission_uma_util.h"
#include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/content/password_protection/metrics_util.h"
#include "components/security_state/core/security_state.h"
namespace safe_browsing {
class PasswordProtectionService;
......@@ -86,6 +87,8 @@ class PageInfoDelegate {
virtual HostContentSettingsMap* GetContentSettings() = 0;
virtual bool IsContentDisplayedInVrHeadset() = 0;
virtual security_state::SecurityLevel GetSecurityLevel() = 0;
virtual security_state::VisibleSecurityState GetVisibleSecurityState() = 0;
};
#endif // COMPONENTS_PAGE_INFO_PAGE_INFO_DELEGATE_H_
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