Commit 26012454 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[WebLayer] Refactor PageInfoUI.

Refactor PageInfoUI so it can be moved to components easily.
This extracts out chrome dependencies from PageInfoUI into
ChromePageInfoUiDelegate.

The only dependencies now in PageInfoUI are resources which can be moved
to components and shared.

Bug: 1052375
Change-Id: Ibb50b9252af3f87586a4c9d22697be74a992d765
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2109915
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751857}
parent e615c808
......@@ -124,10 +124,13 @@ jumbo_static_library("ui") {
"native_file_system_dialogs.h",
"navigation_correction_tab_observer.cc",
"navigation_correction_tab_observer.h",
"page_info/chrome_page_info_ui_delegate.cc",
"page_info/chrome_page_info_ui_delegate.h",
"page_info/page_info.cc",
"page_info/page_info.h",
"page_info/page_info_ui.cc",
"page_info/page_info_ui.h",
"page_info/page_info_ui_delegate.h",
"passwords/account_avatar_fetcher.cc",
"passwords/account_avatar_fetcher.h",
"passwords/manage_passwords_state.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/page_info/chrome_page_info_ui_delegate.h"
#include "build/build_config.h"
#include "chrome/browser/permissions/permission_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/permissions/permission_manager.h"
#include "components/prefs/pref_service.h"
#include "url/gurl.h"
ChromePageInfoUiDelegate::ChromePageInfoUiDelegate(Profile* profile)
: profile_(profile) {}
permissions::PermissionResult ChromePageInfoUiDelegate::GetPermissionStatus(
ContentSettingsType type,
const GURL& url) {
return PermissionManagerFactory::GetForProfile(profile_)->GetPermissionStatus(
type, url, url);
}
#if !defined(OS_ANDROID)
bool ChromePageInfoUiDelegate::IsBlockAutoPlayEnabled() {
return profile_->GetPrefs()->GetBoolean(prefs::kBlockAutoplayEnabled);
}
#endif
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_PAGE_INFO_CHROME_PAGE_INFO_UI_DELEGATE_H_
#define CHROME_BROWSER_UI_PAGE_INFO_CHROME_PAGE_INFO_UI_DELEGATE_H_
#include "build/build_config.h"
#include "chrome/browser/ui/page_info/page_info_ui_delegate.h"
class Profile;
class ChromePageInfoUiDelegate : public PageInfoUiDelegate {
public:
explicit ChromePageInfoUiDelegate(Profile* profile);
~ChromePageInfoUiDelegate() = default;
// PageInfoUiDelegate implementation
#if !defined(OS_ANDROID)
bool IsBlockAutoPlayEnabled() override;
#endif
permissions::PermissionResult GetPermissionStatus(ContentSettingsType type,
const GURL& url) override;
private:
Profile* profile_;
};
#endif // CHROME_BROWSER_UI_PAGE_INFO_CHROME_PAGE_INFO_UI_DELEGATE_H_
......@@ -12,10 +12,7 @@
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/permissions/permission_manager_factory.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/browser/ui/page_info/page_info_ui_delegate.h"
#include "chrome/grit/generated_resources.h"
#include "components/permissions/permission_manager.h"
#include "components/permissions/permission_result.h"
......@@ -34,8 +31,6 @@
#include "chrome/browser/android/android_theme_resources.h"
#else
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "media/base/media_switches.h"
#include "ui/gfx/color_palette.h"
......@@ -225,8 +220,7 @@ CreateSecurityDescriptionForLookalikeSafetyTip(const GURL& safe_url) {
// Gets the actual setting for a ContentSettingType, taking into account what
// the default setting value is and whether Html5ByDefault is enabled.
ContentSetting GetEffectiveSetting(Profile* profile,
ContentSettingsType type,
ContentSetting GetEffectiveSetting(ContentSettingsType type,
ContentSetting setting,
ContentSetting default_setting) {
ContentSetting effective_setting = setting;
......@@ -388,13 +382,13 @@ base::string16 PageInfoUI::PermissionTypeToUIString(ContentSettingsType type) {
// static
base::string16 PageInfoUI::PermissionActionToUIString(
Profile* profile,
PageInfoUiDelegate* delegate,
ContentSettingsType type,
ContentSetting setting,
ContentSetting default_setting,
content_settings::SettingSource source) {
ContentSetting effective_setting =
GetEffectiveSetting(profile, type, setting, default_setting);
GetEffectiveSetting(type, setting, default_setting);
const int* button_text_ids = NULL;
switch (source) {
case content_settings::SETTING_SOURCE_USER:
......@@ -406,7 +400,7 @@ base::string16 PageInfoUI::PermissionActionToUIString(
// sound default setting is ALLOW, we will return a custom string
// indicating that Chrome is controlling autoplay and sound
// automatically.
if (profile->GetPrefs()->GetBoolean(prefs::kBlockAutoplayEnabled) &&
if (delegate->IsBlockAutoPlayEnabled() &&
effective_setting == ContentSetting::CONTENT_SETTING_ALLOW) {
return l10n_util::GetStringUTF16(
IDS_PAGE_INFO_BUTTON_TEXT_AUTOMATIC_BY_DEFAULT);
......@@ -446,11 +440,11 @@ base::string16 PageInfoUI::PermissionActionToUIString(
// static
base::string16 PageInfoUI::PermissionDecisionReasonToUIString(
Profile* profile,
PageInfoUiDelegate* delegate,
const PageInfoUI::PermissionInfo& permission,
const GURL& url) {
ContentSetting effective_setting = GetEffectiveSetting(
profile, permission.type, permission.setting, permission.default_setting);
permission.type, permission.setting, permission.default_setting);
int message_id = kInvalidResourceID;
switch (permission.source) {
case content_settings::SettingSource::SETTING_SOURCE_POLICY:
......@@ -466,8 +460,7 @@ base::string16 PageInfoUI::PermissionDecisionReasonToUIString(
if (permission.setting == CONTENT_SETTING_BLOCK &&
permissions::PermissionUtil::IsPermission(permission.type)) {
permissions::PermissionResult permission_result =
PermissionManagerFactory::GetForProfile(profile)->GetPermissionStatus(
permission.type, url, url);
delegate->GetPermissionStatus(permission.type, url);
switch (permission_result.source) {
case permissions::PermissionStatusSource::MULTIPLE_DISMISSALS:
message_id = IDS_PAGE_INFO_PERMISSION_AUTOMATICALLY_BLOCKED;
......
......@@ -23,8 +23,8 @@
#endif
class GURL;
class Profile;
class PageInfo;
class PageInfoUiDelegate;
namespace net {
class X509Certificate;
......@@ -97,7 +97,7 @@ class PageInfoUI {
ContentSetting default_setting;
// The settings source e.g. user, extensions, policy, ... .
content_settings::SettingSource source;
// Whether the profile is off the record.
// Whether we're in incognito mode.
bool is_incognito;
};
......@@ -179,7 +179,7 @@ class PageInfoUI {
// "Blocked by default". If |setting| is default, specify the actual default
// setting using |default_setting|.
static base::string16 PermissionActionToUIString(
Profile* profile,
PageInfoUiDelegate* delegate,
ContentSettingsType type,
ContentSetting setting,
ContentSetting default_setting,
......@@ -188,7 +188,7 @@ class PageInfoUI {
// Returns a string indicating whether the permission was blocked via an
// extension, enterprise policy, or embargo.
static base::string16 PermissionDecisionReasonToUIString(
Profile* profile,
PageInfoUiDelegate* delegate,
const PermissionInfo& permission,
const GURL& url);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_PAGE_INFO_PAGE_INFO_UI_DELEGATE_H_
#define CHROME_BROWSER_UI_PAGE_INFO_PAGE_INFO_UI_DELEGATE_H_
#include "build/build_config.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/permissions/permission_result.h"
#include "url/gurl.h"
class PageInfoUiDelegate {
public:
~PageInfoUiDelegate() = default;
#if !defined(OS_ANDROID)
virtual bool IsBlockAutoPlayEnabled() = 0;
#endif
virtual permissions::PermissionResult GetPermissionStatus(
ContentSettingsType type,
const GURL& url) = 0;
};
#endif // CHROME_BROWSER_UI_PAGE_INFO_PAGE_INFO_UI_DELEGATE_H_
......@@ -21,6 +21,7 @@
#include "chrome/browser/infobars/mock_infobar_service.h"
#include "chrome/browser/ssl/stateful_ssl_host_state_delegate_factory.h"
#include "chrome/browser/ssl/tls_deprecation_test_utils.h"
#include "chrome/browser/ui/page_info/chrome_page_info_ui_delegate.h"
#include "chrome/browser/ui/page_info/page_info_ui.h"
#include "chrome/browser/usb/usb_chooser_context.h"
#include "chrome/browser/usb/usb_chooser_context_factory.h"
......@@ -1435,14 +1436,16 @@ class UnifiedAutoplaySoundSettingsPageInfoTest
}
base::string16 GetDefaultSoundSettingString() {
auto delegate = ChromePageInfoUiDelegate(profile());
return PageInfoUI::PermissionActionToUIString(
profile(), ContentSettingsType::SOUND, CONTENT_SETTING_DEFAULT,
&delegate, ContentSettingsType::SOUND, CONTENT_SETTING_DEFAULT,
default_setting_, content_settings::SettingSource::SETTING_SOURCE_USER);
}
base::string16 GetSoundSettingString(ContentSetting setting) {
auto delegate = ChromePageInfoUiDelegate(profile());
return PageInfoUI::PermissionActionToUIString(
profile(), ContentSettingsType::SOUND, setting, default_setting_,
&delegate, ContentSettingsType::SOUND, setting, default_setting_,
content_settings::SettingSource::SETTING_SOURCE_USER);
}
......@@ -1530,10 +1533,11 @@ TEST_F(UnifiedAutoplaySoundSettingsPageInfoTest, DefaultBlock_PrefOff) {
// This test checks that the string for a permission dropdown that is not the
// sound setting is unaffected.
TEST_F(UnifiedAutoplaySoundSettingsPageInfoTest, NotSoundSetting_Noop) {
auto delegate = ChromePageInfoUiDelegate(profile());
EXPECT_EQ(
l10n_util::GetStringUTF16(IDS_PAGE_INFO_BUTTON_TEXT_ALLOWED_BY_DEFAULT),
PageInfoUI::PermissionActionToUIString(
profile(), ContentSettingsType::ADS, CONTENT_SETTING_DEFAULT,
&delegate, ContentSettingsType::ADS, CONTENT_SETTING_DEFAULT,
CONTENT_SETTING_ALLOW,
content_settings::SettingSource::SETTING_SOURCE_USER));
}
......
......@@ -6,6 +6,7 @@
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/page_info/chrome_page_info_ui_delegate.h"
#include "chrome/common/chrome_features.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/common/origin_util.h"
......@@ -29,8 +30,9 @@ PermissionMenuModel::PermissionMenuModel(Profile* profile,
// The Material UI for site settings uses comboboxes instead of menubuttons,
// which means the elements of the menu themselves have to be shorter, instead
// of simply setting a shorter label on the menubutton.
auto delegate = ChromePageInfoUiDelegate(profile);
label = PageInfoUI::PermissionActionToUIString(
profile, permission_.type, CONTENT_SETTING_DEFAULT,
&delegate, permission_.type, CONTENT_SETTING_DEFAULT,
permission_.default_setting, permission_.source);
AddCheckItem(CONTENT_SETTING_DEFAULT, label);
......@@ -38,14 +40,15 @@ PermissionMenuModel::PermissionMenuModel(Profile* profile,
// Retrieve the string to show for allowing the permission.
if (ShouldShowAllow(url)) {
label = PageInfoUI::PermissionActionToUIString(
profile, permission_.type, CONTENT_SETTING_ALLOW,
&delegate, permission_.type, CONTENT_SETTING_ALLOW,
permission_.default_setting, permission_.source);
AddCheckItem(CONTENT_SETTING_ALLOW, label);
}
// Retrieve the string to show for blocking the permission.
label = PageInfoUI::PermissionActionToUIString(
profile, info.type, CONTENT_SETTING_BLOCK, permission_.default_setting,
&delegate, info.type, CONTENT_SETTING_BLOCK, permission_.default_setting,
info.source);
AddCheckItem(CONTENT_SETTING_BLOCK, label);
......@@ -53,7 +56,7 @@ PermissionMenuModel::PermissionMenuModel(Profile* profile,
// permission.
if (ShouldShowAsk(url)) {
label = PageInfoUI::PermissionActionToUIString(
profile, info.type, CONTENT_SETTING_ASK, permission_.default_setting,
&delegate, info.type, CONTENT_SETTING_ASK, permission_.default_setting,
info.source);
AddCheckItem(CONTENT_SETTING_ASK, label);
}
......
......@@ -8,6 +8,7 @@
#include "base/i18n/rtl.h"
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/page_info/chrome_page_info_ui_delegate.h"
#include "chrome/browser/ui/page_info/page_info_ui.h"
#include "chrome/browser/ui/page_info/permission_menu_model.h"
#include "chrome/browser/ui/views/accessibility/non_accessible_image_view.h"
......@@ -185,8 +186,9 @@ PermissionSelectorRow::PermissionSelectorRow(
InitializeComboboxView(layout, permission);
// Show the permission decision reason, if it was not the user.
base::string16 reason =
PageInfoUI::PermissionDecisionReasonToUIString(profile, permission, url);
auto delegate = ChromePageInfoUiDelegate(profile);
base::string16 reason = PageInfoUI::PermissionDecisionReasonToUIString(
&delegate, permission, url);
if (!reason.empty()) {
layout->StartRow(1.0, PageInfoBubbleView::kPermissionColumnSetId);
layout->SkipColumns(1);
......
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