Commit 70c68c35 authored by Ehimare Okoyomon's avatar Ehimare Okoyomon Committed by Commit Bot

[Android] Show permissions in page info with non-factory default

Create two page info static helpers to determine if we are on an
internal page and if a permission is factory default. Change references.

Bug: 1077766
Change-Id: Ica6e13b5438b0d18a5fe9e424cd3017bb4ce1b3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2395756
Commit-Queue: Ehimare Okoyomon <eokoyomon@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808321}
parent c11c8757
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
PermissionMenuModel::PermissionMenuModel(Profile* profile, PermissionMenuModel::PermissionMenuModel(Profile* profile,
const GURL& url, const GURL& url,
const PageInfoUI::PermissionInfo& info, const PageInfo::PermissionInfo& info,
const ChangeCallback& callback) const ChangeCallback& callback)
: ui::SimpleMenuModel(this), : ui::SimpleMenuModel(this),
host_content_settings_map_( host_content_settings_map_(
......
...@@ -18,13 +18,12 @@ class Profile; ...@@ -18,13 +18,12 @@ class Profile;
class PermissionMenuModel : public ui::SimpleMenuModel, class PermissionMenuModel : public ui::SimpleMenuModel,
public ui::SimpleMenuModel::Delegate { public ui::SimpleMenuModel::Delegate {
public: public:
typedef base::Callback<void(const PageInfoUI::PermissionInfo&)> typedef base::Callback<void(const PageInfo::PermissionInfo&)> ChangeCallback;
ChangeCallback;
// Create a new menu model for permission settings. // Create a new menu model for permission settings.
PermissionMenuModel(Profile* profile, PermissionMenuModel(Profile* profile,
const GURL& url, const GURL& url,
const PageInfoUI::PermissionInfo& info, const PageInfo::PermissionInfo& info,
const ChangeCallback& callback); const ChangeCallback& callback);
~PermissionMenuModel() override; ~PermissionMenuModel() override;
...@@ -40,7 +39,7 @@ class PermissionMenuModel : public ui::SimpleMenuModel, ...@@ -40,7 +39,7 @@ class PermissionMenuModel : public ui::SimpleMenuModel,
HostContentSettingsMap* host_content_settings_map_; HostContentSettingsMap* host_content_settings_map_;
// The permission info represented by the menu model. // The permission info represented by the menu model.
PageInfoUI::PermissionInfo permission_; PageInfo::PermissionInfo permission_;
// Callback to be called when the permission's setting is changed. // Callback to be called when the permission's setting is changed.
ChangeCallback callback_; ChangeCallback callback_;
......
...@@ -19,7 +19,7 @@ class TestCallback { ...@@ -19,7 +19,7 @@ class TestCallback {
PermissionMenuModel::ChangeCallback callback() { PermissionMenuModel::ChangeCallback callback() {
return base::Bind(&TestCallback::PermissionChanged, base::Unretained(this)); return base::Bind(&TestCallback::PermissionChanged, base::Unretained(this));
} }
void PermissionChanged(const PageInfoUI::PermissionInfo& permission) { void PermissionChanged(const PageInfo::PermissionInfo& permission) {
current_ = permission.setting; current_ = permission.setting;
} }
...@@ -39,7 +39,7 @@ class PermissionMenuModelTest : public testing::Test { ...@@ -39,7 +39,7 @@ class PermissionMenuModelTest : public testing::Test {
TEST_F(PermissionMenuModelTest, TestDefault) { TEST_F(PermissionMenuModelTest, TestDefault) {
TestCallback callback; TestCallback callback;
PageInfoUI::PermissionInfo permission; PageInfo::PermissionInfo permission;
permission.type = ContentSettingsType::COOKIES; permission.type = ContentSettingsType::COOKIES;
permission.setting = CONTENT_SETTING_ALLOW; permission.setting = CONTENT_SETTING_ALLOW;
permission.default_setting = CONTENT_SETTING_ALLOW; permission.default_setting = CONTENT_SETTING_ALLOW;
...@@ -56,7 +56,7 @@ TEST_F(PermissionMenuModelTest, TestDefaultMediaHttp) { ...@@ -56,7 +56,7 @@ TEST_F(PermissionMenuModelTest, TestDefaultMediaHttp) {
ContentSettingsType type = i ? ContentSettingsType::MEDIASTREAM_MIC ContentSettingsType type = i ? ContentSettingsType::MEDIASTREAM_MIC
: ContentSettingsType::MEDIASTREAM_CAMERA; : ContentSettingsType::MEDIASTREAM_CAMERA;
TestCallback callback; TestCallback callback;
PageInfoUI::PermissionInfo permission; PageInfo::PermissionInfo permission;
permission.type = type; permission.type = type;
permission.setting = CONTENT_SETTING_ALLOW; permission.setting = CONTENT_SETTING_ALLOW;
permission.default_setting = CONTENT_SETTING_ALLOW; permission.default_setting = CONTENT_SETTING_ALLOW;
...@@ -70,7 +70,7 @@ TEST_F(PermissionMenuModelTest, TestDefaultMediaHttp) { ...@@ -70,7 +70,7 @@ TEST_F(PermissionMenuModelTest, TestDefaultMediaHttp) {
TEST_F(PermissionMenuModelTest, TestIncognitoNotifications) { TEST_F(PermissionMenuModelTest, TestIncognitoNotifications) {
TestCallback callback; TestCallback callback;
PageInfoUI::PermissionInfo permission; PageInfo::PermissionInfo permission;
permission.type = ContentSettingsType::NOTIFICATIONS; permission.type = ContentSettingsType::NOTIFICATIONS;
permission.setting = CONTENT_SETTING_ASK; permission.setting = CONTENT_SETTING_ASK;
permission.default_setting = CONTENT_SETTING_ASK; permission.default_setting = CONTENT_SETTING_ASK;
...@@ -89,7 +89,7 @@ TEST_F(PermissionMenuModelTest, TestIncognitoNotifications) { ...@@ -89,7 +89,7 @@ TEST_F(PermissionMenuModelTest, TestIncognitoNotifications) {
TEST_F(PermissionMenuModelTest, TestUsbGuard) { TEST_F(PermissionMenuModelTest, TestUsbGuard) {
TestCallback callback; TestCallback callback;
PageInfoUI::PermissionInfo permission; PageInfo::PermissionInfo permission;
permission.type = ContentSettingsType::USB_GUARD; permission.type = ContentSettingsType::USB_GUARD;
permission.setting = CONTENT_SETTING_ASK; permission.setting = CONTENT_SETTING_ASK;
permission.default_setting = CONTENT_SETTING_ASK; permission.default_setting = CONTENT_SETTING_ASK;
...@@ -104,7 +104,7 @@ TEST_F(PermissionMenuModelTest, TestUsbGuard) { ...@@ -104,7 +104,7 @@ TEST_F(PermissionMenuModelTest, TestUsbGuard) {
TEST_F(PermissionMenuModelTest, TestSerialGuard) { TEST_F(PermissionMenuModelTest, TestSerialGuard) {
const GURL kUrl("http://www.google.com"); const GURL kUrl("http://www.google.com");
TestCallback callback; TestCallback callback;
PageInfoUI::PermissionInfo permission; PageInfo::PermissionInfo permission;
permission.type = ContentSettingsType::SERIAL_GUARD; permission.type = ContentSettingsType::SERIAL_GUARD;
permission.setting = CONTENT_SETTING_ASK; permission.setting = CONTENT_SETTING_ASK;
permission.source = content_settings::SETTING_SOURCE_USER; permission.source = content_settings::SETTING_SOURCE_USER;
...@@ -132,7 +132,7 @@ TEST_F(PermissionMenuModelTest, TestSerialGuard) { ...@@ -132,7 +132,7 @@ TEST_F(PermissionMenuModelTest, TestSerialGuard) {
TEST_F(PermissionMenuModelTest, TestBluetoothScanning) { TEST_F(PermissionMenuModelTest, TestBluetoothScanning) {
const GURL kUrl("http://www.google.com"); const GURL kUrl("http://www.google.com");
TestCallback callback; TestCallback callback;
PageInfoUI::PermissionInfo permission; PageInfo::PermissionInfo permission;
permission.type = ContentSettingsType::BLUETOOTH_SCANNING; permission.type = ContentSettingsType::BLUETOOTH_SCANNING;
permission.setting = CONTENT_SETTING_ASK; permission.setting = CONTENT_SETTING_ASK;
permission.source = content_settings::SETTING_SOURCE_USER; permission.source = content_settings::SETTING_SOURCE_USER;
...@@ -160,7 +160,7 @@ TEST_F(PermissionMenuModelTest, TestBluetoothScanning) { ...@@ -160,7 +160,7 @@ TEST_F(PermissionMenuModelTest, TestBluetoothScanning) {
TEST_F(PermissionMenuModelTest, TestHidGuard) { TEST_F(PermissionMenuModelTest, TestHidGuard) {
const GURL kUrl("http://www.google.com"); const GURL kUrl("http://www.google.com");
TestCallback callback; TestCallback callback;
PageInfoUI::PermissionInfo permission; PageInfo::PermissionInfo permission;
permission.type = ContentSettingsType::HID_GUARD; permission.type = ContentSettingsType::HID_GUARD;
permission.setting = CONTENT_SETTING_ASK; permission.setting = CONTENT_SETTING_ASK;
permission.source = content_settings::SETTING_SOURCE_USER; permission.source = content_settings::SETTING_SOURCE_USER;
......
...@@ -455,11 +455,8 @@ views::BubbleDialogDelegateView* PageInfoBubbleView::CreatePageInfoBubble( ...@@ -455,11 +455,8 @@ views::BubbleDialogDelegateView* PageInfoBubbleView::CreatePageInfoBubble(
PageInfoClosingCallback closing_callback) { PageInfoClosingCallback closing_callback) {
gfx::NativeView parent_view = platform_util::GetViewForWindow(parent_window); gfx::NativeView parent_view = platform_util::GetViewForWindow(parent_window);
if (url.SchemeIs(content::kChromeUIScheme) || if (PageInfo::IsFileOrInternalPage(url) ||
url.SchemeIs(content::kChromeDevToolsScheme) ||
url.SchemeIs(extensions::kExtensionScheme) || url.SchemeIs(extensions::kExtensionScheme) ||
url.SchemeIs(content::kViewSourceScheme) ||
url.SchemeIs(url::kFileScheme) ||
url.SchemeIs(dom_distiller::kDomDistillerScheme)) { url.SchemeIs(dom_distiller::kDomDistillerScheme)) {
return new InternalPageInfoBubbleView(anchor_view, anchor_rect, parent_view, return new InternalPageInfoBubbleView(anchor_view, anchor_rect, parent_view,
web_contents, url); web_contents, url);
...@@ -571,7 +568,7 @@ void PageInfoBubbleView::WebContentsDestroyed() { ...@@ -571,7 +568,7 @@ void PageInfoBubbleView::WebContentsDestroyed() {
} }
void PageInfoBubbleView::OnPermissionChanged( void PageInfoBubbleView::OnPermissionChanged(
const PageInfoUI::PermissionInfo& permission) { const PageInfo::PermissionInfo& permission) {
presenter_->OnSitePermissionChanged(permission.type, permission.setting); presenter_->OnSitePermissionChanged(permission.type, permission.setting);
// The menu buttons for the permissions might have longer strings now, so we // The menu buttons for the permissions might have longer strings now, so we
// need to layout and size the whole bubble. // need to layout and size the whole bubble.
...@@ -662,7 +659,7 @@ void PageInfoBubbleView::SetCookieInfo(const CookieInfoList& cookie_info_list) { ...@@ -662,7 +659,7 @@ void PageInfoBubbleView::SetCookieInfo(const CookieInfoList& cookie_info_list) {
// part and just update the text. // part and just update the text.
if (cookie_button_ == nullptr) { if (cookie_button_ == nullptr) {
// Get the icon. // Get the icon.
PageInfoUI::PermissionInfo info; PageInfo::PermissionInfo info;
info.type = ContentSettingsType::COOKIES; info.type = ContentSettingsType::COOKIES;
info.setting = CONTENT_SETTING_ALLOW; info.setting = CONTENT_SETTING_ALLOW;
info.is_incognito = info.is_incognito =
......
...@@ -122,8 +122,7 @@ class PageInfoBubbleView : public PageInfoBubbleViewBase, ...@@ -122,8 +122,7 @@ class PageInfoBubbleView : public PageInfoBubbleViewBase,
void WebContentsDestroyed() override; void WebContentsDestroyed() override;
// PermissionSelectorRowObserver: // PermissionSelectorRowObserver:
void OnPermissionChanged( void OnPermissionChanged(const PageInfo::PermissionInfo& permission) override;
const PageInfoUI::PermissionInfo& permission) override;
// ChosenObjectViewObserver: // ChosenObjectViewObserver:
void OnChosenObjectDeleted(const PageInfoUI::ChosenObjectInfo& info) override; void OnChosenObjectDeleted(const PageInfoUI::ChosenObjectInfo& info) override;
......
...@@ -251,7 +251,7 @@ class PageInfoBubbleViewBrowserTest : public DialogBrowserTest { ...@@ -251,7 +251,7 @@ class PageInfoBubbleViewBrowserTest : public DialogBrowserTest {
PermissionInfoList permissions_list; PermissionInfoList permissions_list;
for (ContentSettingsType content_type : for (ContentSettingsType content_type :
PageInfo::GetAllPermissionsForTesting()) { PageInfo::GetAllPermissionsForTesting()) {
PageInfoUI::PermissionInfo info; PageInfo::PermissionInfo info;
info.type = content_type; info.type = content_type;
info.setting = (name == kAllowAllPermissions) ? CONTENT_SETTING_ALLOW info.setting = (name == kAllowAllPermissions) ? CONTENT_SETTING_ALLOW
: CONTENT_SETTING_BLOCK; : CONTENT_SETTING_BLOCK;
...@@ -339,7 +339,7 @@ class PageInfoBubbleViewBrowserTest : public DialogBrowserTest { ...@@ -339,7 +339,7 @@ class PageInfoBubbleViewBrowserTest : public DialogBrowserTest {
// Set some dummy non-default permissions. This will trigger a reload prompt // Set some dummy non-default permissions. This will trigger a reload prompt
// when the bubble is closed. // when the bubble is closed.
PageInfoUI::PermissionInfo permission; PageInfo::PermissionInfo permission;
permission.type = ContentSettingsType::NOTIFICATIONS; permission.type = ContentSettingsType::NOTIFICATIONS;
permission.setting = ContentSetting::CONTENT_SETTING_BLOCK; permission.setting = ContentSetting::CONTENT_SETTING_BLOCK;
permission.default_setting = ContentSetting::CONTENT_SETTING_ASK; permission.default_setting = ContentSetting::CONTENT_SETTING_ASK;
......
...@@ -129,7 +129,7 @@ class PageInfoBubbleViewTestApi { ...@@ -129,7 +129,7 @@ class PageInfoBubbleViewTestApi {
// Simulates recreating the dialog with a new PermissionInfoList. // Simulates recreating the dialog with a new PermissionInfoList.
void SetPermissionInfo(const PermissionInfoList& list) { void SetPermissionInfo(const PermissionInfoList& list) {
for (const PageInfoBubbleView::PermissionInfo& info : list) { for (const PageInfo::PermissionInfo& info : list) {
view_->presenter_->OnSitePermissionChanged(info.type, info.setting); view_->presenter_->OnSitePermissionChanged(info.type, info.setting);
} }
CreateView(); CreateView();
......
...@@ -6,12 +6,11 @@ ...@@ -6,12 +6,11 @@
#include "chrome/browser/ui/views/chrome_typography.h" #include "chrome/browser/ui/views/chrome_typography.h"
PermissionIcon::PermissionIcon( PermissionIcon::PermissionIcon(const PageInfo::PermissionInfo& permission_info)
const PageInfoUI::PermissionInfo& permission_info)
: permission_info_(permission_info) {} : permission_info_(permission_info) {}
void PermissionIcon::OnPermissionChanged( void PermissionIcon::OnPermissionChanged(
const PageInfoUI::PermissionInfo& permission_info) { const PageInfo::PermissionInfo& permission_info) {
permission_info_ = permission_info; permission_info_ = permission_info;
UpdateImage(); UpdateImage();
} }
......
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
class PermissionIcon : public NonAccessibleImageView { class PermissionIcon : public NonAccessibleImageView {
public: public:
explicit PermissionIcon(const PageInfoUI::PermissionInfo& permission_info); explicit PermissionIcon(const PageInfo::PermissionInfo& permission_info);
PermissionIcon(const PermissionIcon&) = delete; PermissionIcon(const PermissionIcon&) = delete;
PermissionIcon& operator=(const PermissionIcon&) = delete; PermissionIcon& operator=(const PermissionIcon&) = delete;
~PermissionIcon() override = default; ~PermissionIcon() override = default;
void OnPermissionChanged(const PageInfoUI::PermissionInfo& permission_info); void OnPermissionChanged(const PageInfo::PermissionInfo& permission_info);
// NonAccessibleImageView: // NonAccessibleImageView:
void OnThemeChanged() override; void OnThemeChanged() override;
...@@ -28,7 +28,7 @@ class PermissionIcon : public NonAccessibleImageView { ...@@ -28,7 +28,7 @@ class PermissionIcon : public NonAccessibleImageView {
void UpdateImage(); void UpdateImage();
PageInfoUI::PermissionInfo permission_info_; PageInfo::PermissionInfo permission_info_;
}; };
#endif // CHROME_BROWSER_UI_VIEWS_PAGE_INFO_PERMISSION_ICON_H_ #endif // CHROME_BROWSER_UI_VIEWS_PAGE_INFO_PERMISSION_ICON_H_
...@@ -157,7 +157,7 @@ void PermissionCombobox::OnPerformAction(Combobox* combobox) { ...@@ -157,7 +157,7 @@ void PermissionCombobox::OnPerformAction(Combobox* combobox) {
PermissionSelectorRow::PermissionSelectorRow( PermissionSelectorRow::PermissionSelectorRow(
Profile* profile, Profile* profile,
const GURL& url, const GURL& url,
const PageInfoUI::PermissionInfo& permission, const PageInfo::PermissionInfo& permission,
views::GridLayout* layout) views::GridLayout* layout)
: profile_(profile) { : profile_(profile) {
const int list_item_padding = ChromeLayoutProvider::Get()->GetDistanceMetric( const int list_item_padding = ChromeLayoutProvider::Get()->GetDistanceMetric(
...@@ -265,7 +265,7 @@ void PermissionSelectorRow::AddObserver( ...@@ -265,7 +265,7 @@ void PermissionSelectorRow::AddObserver(
void PermissionSelectorRow::InitializeComboboxView( void PermissionSelectorRow::InitializeComboboxView(
views::GridLayout* layout, views::GridLayout* layout,
const PageInfoUI::PermissionInfo& permission) { const PageInfo::PermissionInfo& permission) {
bool button_enabled = bool button_enabled =
permission.source == content_settings::SETTING_SOURCE_USER; permission.source == content_settings::SETTING_SOURCE_USER;
combobox_model_adapter_.reset( combobox_model_adapter_.reset(
...@@ -280,7 +280,7 @@ void PermissionSelectorRow::InitializeComboboxView( ...@@ -280,7 +280,7 @@ void PermissionSelectorRow::InitializeComboboxView(
} }
void PermissionSelectorRow::PermissionChanged( void PermissionSelectorRow::PermissionChanged(
const PageInfoUI::PermissionInfo& permission) { const PageInfo::PermissionInfo& permission) {
// Change the permission icon to reflect the selected setting. // Change the permission icon to reflect the selected setting.
icon_->OnPermissionChanged(permission); icon_->OnPermissionChanged(permission);
......
...@@ -44,7 +44,7 @@ class PermissionSelectorRow { ...@@ -44,7 +44,7 @@ class PermissionSelectorRow {
// The |PermissionSelectorRow|'s constituent views are added to |layout|. // The |PermissionSelectorRow|'s constituent views are added to |layout|.
PermissionSelectorRow(Profile* profile, PermissionSelectorRow(Profile* profile,
const GURL& url, const GURL& url,
const PageInfoUI::PermissionInfo& permission, const PageInfo::PermissionInfo& permission,
views::GridLayout* layout); views::GridLayout* layout);
virtual ~PermissionSelectorRow(); virtual ~PermissionSelectorRow();
...@@ -57,7 +57,7 @@ class PermissionSelectorRow { ...@@ -57,7 +57,7 @@ class PermissionSelectorRow {
void AddObserver(PermissionSelectorRowObserver* observer); void AddObserver(PermissionSelectorRowObserver* observer);
void PermissionChanged(const PageInfoUI::PermissionInfo& permission); void PermissionChanged(const PageInfo::PermissionInfo& permission);
// Returns the preferred width for the currently selected combobox option // Returns the preferred width for the currently selected combobox option
// (unchanged by any minimum width set using SetMinComboboxWidth()). // (unchanged by any minimum width set using SetMinComboboxWidth()).
...@@ -70,7 +70,7 @@ class PermissionSelectorRow { ...@@ -70,7 +70,7 @@ class PermissionSelectorRow {
friend class test::PageInfoBubbleViewTestApi; friend class test::PageInfoBubbleViewTestApi;
void InitializeComboboxView(views::GridLayout* layout, void InitializeComboboxView(views::GridLayout* layout,
const PageInfoUI::PermissionInfo& permission); const PageInfo::PermissionInfo& permission);
Profile* profile_; Profile* profile_;
......
...@@ -11,7 +11,7 @@ class PermissionSelectorRowObserver { ...@@ -11,7 +11,7 @@ class PermissionSelectorRowObserver {
public: public:
// This method is called whenever the permission setting is changed. // This method is called whenever the permission setting is changed.
virtual void OnPermissionChanged( virtual void OnPermissionChanged(
const PageInfoUI::PermissionInfo& permission) = 0; const PageInfo::PermissionInfo& permission) = 0;
protected: protected:
virtual ~PermissionSelectorRowObserver() {} virtual ~PermissionSelectorRowObserver() {}
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/content_settings/core/common/content_settings_types.h" #include "components/content_settings/core/common/content_settings_types.h"
#include "components/page_info/android/jni_headers/PageInfoController_jni.h" #include "components/page_info/android/jni_headers/PageInfoController_jni.h"
#include "components/page_info/android/page_info_client.h" #include "components/page_info/android/page_info_client.h"
#include "components/page_info/features.h"
#include "components/page_info/page_info.h" #include "components/page_info/page_info.h"
#include "components/page_info/page_info_ui.h" #include "components/page_info/page_info_ui.h"
#include "components/security_state/core/security_state.h" #include "components/security_state/core/security_state.h"
...@@ -106,9 +107,15 @@ void PageInfoControllerAndroid::SetPermissionInfo( ...@@ -106,9 +107,15 @@ void PageInfoControllerAndroid::SetPermissionInfo(
ChosenObjectInfoList chosen_object_info_list) { ChosenObjectInfoList chosen_object_info_list) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
// On Android, we only want to display a subset of the available options in a // Exit without permissions if it is an internal page.
// particular order, but only if their value is different from the default. if (PageInfo::IsFileOrInternalPage(url_)) {
// This order comes from https://crbug.com/610358. Java_PageInfoController_updatePermissionDisplay(env, controller_jobject_);
return;
}
// On Android, we only want to display a subset of the available options in
// a particular order, but only if their value is different from the
// default. This order comes from https://crbug.com/610358.
std::vector<ContentSettingsType> permissions_to_display; std::vector<ContentSettingsType> permissions_to_display;
permissions_to_display.push_back(ContentSettingsType::GEOLOCATION); permissions_to_display.push_back(ContentSettingsType::GEOLOCATION);
permissions_to_display.push_back(ContentSettingsType::MEDIASTREAM_CAMERA); permissions_to_display.push_back(ContentSettingsType::MEDIASTREAM_CAMERA);
...@@ -172,7 +179,7 @@ void PageInfoControllerAndroid::SetPermissionInfo( ...@@ -172,7 +179,7 @@ void PageInfoControllerAndroid::SetPermissionInfo(
} }
base::Optional<ContentSetting> PageInfoControllerAndroid::GetSettingToDisplay( base::Optional<ContentSetting> PageInfoControllerAndroid::GetSettingToDisplay(
const PermissionInfo& permission) { const PageInfo::PermissionInfo& permission) {
// All permissions should be displayed if they are non-default. // All permissions should be displayed if they are non-default.
if (permission.setting != CONTENT_SETTING_DEFAULT && if (permission.setting != CONTENT_SETTING_DEFAULT &&
permission.setting != permission.default_setting) { permission.setting != permission.default_setting) {
...@@ -193,5 +200,11 @@ base::Optional<ContentSetting> PageInfoControllerAndroid::GetSettingToDisplay( ...@@ -193,5 +200,11 @@ base::Optional<ContentSetting> PageInfoControllerAndroid::GetSettingToDisplay(
if (web_contents_->WasEverAudible()) if (web_contents_->WasEverAudible())
return permission.default_setting; return permission.default_setting;
} }
if (base::FeatureList::IsEnabled(page_info::kPageInfoV2) &&
!PageInfo::IsPermissionFactoryDefault(permission)) {
return permission.default_setting;
}
return base::Optional<ContentSetting>(); return base::Optional<ContentSetting>();
} }
...@@ -43,7 +43,7 @@ class PageInfoControllerAndroid : public PageInfoUI { ...@@ -43,7 +43,7 @@ class PageInfoControllerAndroid : public PageInfoUI {
// set to some non-default value, but there are some permissions which require // set to some non-default value, but there are some permissions which require
// customized behavior. // customized behavior.
base::Optional<ContentSetting> GetSettingToDisplay( base::Optional<ContentSetting> GetSettingToDisplay(
const PermissionInfo& permission); const PageInfo::PermissionInfo& permission);
// The presenter that controlls the Page Info UI. // The presenter that controlls the Page Info UI.
std::unique_ptr<PageInfo> presenter_; std::unique_ptr<PageInfo> presenter_;
......
...@@ -125,34 +125,9 @@ ContentSettingsType kPermissionType[] = { ...@@ -125,34 +125,9 @@ ContentSettingsType kPermissionType[] = {
ContentSettingsType::IDLE_DETECTION, ContentSettingsType::IDLE_DETECTION,
}; };
// Checks whether this permission is currently the factory default, as set by
// Chrome. Specifically, that the following three conditions are true:
// - The current active setting comes from the default or pref provider.
// - The setting is the factory default setting (as opposed to a global
// default setting set by the user).
// - The setting is a wildcard setting applying to all origins (which can only
// be set from the default provider).
bool IsPermissionFactoryDefault(HostContentSettingsMap* content_settings,
const PageInfoUI::PermissionInfo& info) {
const ContentSetting factory_default_setting =
content_settings::ContentSettingsRegistry::GetInstance()
->Get(info.type)
->GetInitialDefaultSetting();
// Settings that are granted in regular mode get reduced to ASK in incognito
// mode. These settings should not be displayed either.
const bool is_incognito_default =
info.is_incognito && info.setting == CONTENT_SETTING_ASK &&
factory_default_setting == CONTENT_SETTING_ASK;
return info.source == content_settings::SETTING_SOURCE_USER &&
factory_default_setting == info.default_setting &&
(info.setting == CONTENT_SETTING_DEFAULT || is_incognito_default);
}
// Determines whether to show permission |type| in the Page Info UI. Only // Determines whether to show permission |type| in the Page Info UI. Only
// applies to permissions listed in |kPermissionType|. // applies to permissions listed in |kPermissionType|.
bool ShouldShowPermission(const PageInfoUI::PermissionInfo& info, bool ShouldShowPermission(const PageInfo::PermissionInfo& info,
const GURL& site_url, const GURL& site_url,
HostContentSettingsMap* content_settings, HostContentSettingsMap* content_settings,
content::WebContents* web_contents, content::WebContents* web_contents,
...@@ -240,12 +215,12 @@ bool ShouldShowPermission(const PageInfoUI::PermissionInfo& info, ...@@ -240,12 +215,12 @@ bool ShouldShowPermission(const PageInfoUI::PermissionInfo& info,
if (info.type == ContentSettingsType::BLUETOOTH_GUARD && if (info.type == ContentSettingsType::BLUETOOTH_GUARD &&
base::FeatureList::IsEnabled( base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend) && features::kWebBluetoothNewPermissionsBackend) &&
!IsPermissionFactoryDefault(content_settings, info)) { !PageInfo::IsPermissionFactoryDefault(info)) {
return true; return true;
} }
// Show the content setting when it has a non-default value. // Show the content setting when it has a non-default value.
if (!IsPermissionFactoryDefault(content_settings, info)) if (!PageInfo::IsPermissionFactoryDefault(info))
return true; return true;
return false; return false;
...@@ -429,6 +404,32 @@ PageInfo::~PageInfo() { ...@@ -429,6 +404,32 @@ PageInfo::~PageInfo() {
} }
} }
// static
bool PageInfo::IsPermissionFactoryDefault(const PermissionInfo& info) {
const ContentSetting factory_default_setting =
content_settings::ContentSettingsRegistry::GetInstance()
->Get(info.type)
->GetInitialDefaultSetting();
// Settings that are granted in regular mode get reduced to ASK in incognito
// mode. These settings should not be displayed either.
const bool is_incognito_default =
info.is_incognito && info.setting == CONTENT_SETTING_ASK &&
factory_default_setting == CONTENT_SETTING_ASK;
return info.source == content_settings::SETTING_SOURCE_USER &&
factory_default_setting == info.default_setting &&
(info.setting == CONTENT_SETTING_DEFAULT || is_incognito_default);
}
// static
bool PageInfo::IsFileOrInternalPage(const GURL& url) {
return url.SchemeIs(content::kChromeUIScheme) ||
url.SchemeIs(content::kChromeDevToolsScheme) ||
url.SchemeIs(content::kViewSourceScheme) ||
url.SchemeIs(url::kFileScheme);
}
void PageInfo::InitializeUiState(PageInfoUI* ui) { void PageInfo::InitializeUiState(PageInfoUI* ui) {
ui_ = ui; ui_ = ui;
DCHECK(ui_); DCHECK(ui_);
...@@ -916,7 +917,7 @@ void PageInfo::PresentSitePermissions() { ...@@ -916,7 +917,7 @@ void PageInfo::PresentSitePermissions() {
PermissionInfoList permission_info_list; PermissionInfoList permission_info_list;
ChosenObjectInfoList chosen_object_info_list; ChosenObjectInfoList chosen_object_info_list;
PageInfoUI::PermissionInfo permission_info; PermissionInfo permission_info;
HostContentSettingsMap* content_settings = GetContentSettings(); HostContentSettingsMap* content_settings = GetContentSettings();
for (const ContentSettingsType type : kPermissionType) { for (const ContentSettingsType type : kPermissionType) {
permission_info.type = type; permission_info.type = type;
......
...@@ -146,6 +146,23 @@ class PageInfo : public content::WebContentsObserver { ...@@ -146,6 +146,23 @@ class PageInfo : public content::WebContentsObserver {
int delete_tooltip_string_id; int delete_tooltip_string_id;
}; };
// |PermissionInfo| contains information about a single permission |type| for
// the current website.
struct PermissionInfo {
PermissionInfo() = default;
// Site permission |type|.
ContentSettingsType type = ContentSettingsType::DEFAULT;
// The current value for the permission |type| (e.g. ALLOW or BLOCK).
ContentSetting setting = CONTENT_SETTING_DEFAULT;
// The global default settings for this permission |type|.
ContentSetting default_setting = CONTENT_SETTING_DEFAULT;
// The settings source e.g. user, extensions, policy, ... .
content_settings::SettingSource source =
content_settings::SETTING_SOURCE_NONE;
// Whether we're in incognito mode.
bool is_incognito = false;
};
// Creates a PageInfo for the passed |url| using the given |ssl| status // Creates a PageInfo for the passed |url| using the given |ssl| status
// object to determine the status of the site's connection. // object to determine the status of the site's connection.
PageInfo(std::unique_ptr<PageInfoDelegate> delegate, PageInfo(std::unique_ptr<PageInfoDelegate> delegate,
...@@ -153,6 +170,18 @@ class PageInfo : public content::WebContentsObserver { ...@@ -153,6 +170,18 @@ class PageInfo : public content::WebContentsObserver {
const GURL& url); const GURL& url);
~PageInfo() override; ~PageInfo() override;
// Checks whether this permission is currently the factory default, as set by
// Chrome. Specifically, that the following three conditions are true:
// - The current active setting comes from the default or pref provider.
// - The setting is the factory default setting (as opposed to a global
// default setting set by the user).
// - The setting is a wildcard setting applying to all origins (which can
// only be set from the default provider).
static bool IsPermissionFactoryDefault(const PermissionInfo& info);
// Returns whether this page info is for an internal page.
static bool IsFileOrInternalPage(const GURL& url);
// Initializes UI state that is dependent on having access to the PageInfoUI // Initializes UI state that is dependent on having access to the PageInfoUI
// object associated with this object. This explicit post-construction // object associated with this object. This explicit post-construction
// initialization step is necessary as PageInfoUI subclasses create this // initialization step is necessary as PageInfoUI subclasses create this
...@@ -220,6 +249,7 @@ class PageInfo : public content::WebContentsObserver { ...@@ -220,6 +249,7 @@ class PageInfo : public content::WebContentsObserver {
FRIEND_TEST_ALL_PREFIXES(PageInfoTest, IncognitoPermissionsEmptyByDefault); FRIEND_TEST_ALL_PREFIXES(PageInfoTest, IncognitoPermissionsEmptyByDefault);
FRIEND_TEST_ALL_PREFIXES(PageInfoTest, IncognitoPermissionsDontShowAsk); FRIEND_TEST_ALL_PREFIXES(PageInfoTest, IncognitoPermissionsDontShowAsk);
friend class PageInfoBubbleViewBrowserTest; friend class PageInfoBubbleViewBrowserTest;
// Populates this object's UI state with provided security context. This // Populates this object's UI state with provided security context. This
// function does not update visible UI-- that's part of Present*(). // function does not update visible UI-- that's part of Present*().
void ComputeUIInputs(const GURL& url); void ComputeUIInputs(const GURL& url);
......
...@@ -248,13 +248,6 @@ ContentSetting GetEffectiveSetting(ContentSettingsType type, ...@@ -248,13 +248,6 @@ ContentSetting GetEffectiveSetting(ContentSettingsType type,
PageInfoUI::CookieInfo::CookieInfo() : allowed(-1), blocked(-1) {} PageInfoUI::CookieInfo::CookieInfo() : allowed(-1), blocked(-1) {}
PageInfoUI::PermissionInfo::PermissionInfo()
: type(ContentSettingsType::DEFAULT),
setting(CONTENT_SETTING_DEFAULT),
default_setting(CONTENT_SETTING_DEFAULT),
source(content_settings::SETTING_SOURCE_NONE),
is_incognito(false) {}
PageInfoUI::ChosenObjectInfo::ChosenObjectInfo( PageInfoUI::ChosenObjectInfo::ChosenObjectInfo(
const PageInfo::ChooserUIInfo& ui_info, const PageInfo::ChooserUIInfo& ui_info,
std::unique_ptr<permissions::ChooserContextBase::Object> chooser_object) std::unique_ptr<permissions::ChooserContextBase::Object> chooser_object)
...@@ -451,7 +444,7 @@ base::string16 PageInfoUI::PermissionActionToUIString( ...@@ -451,7 +444,7 @@ base::string16 PageInfoUI::PermissionActionToUIString(
// static // static
base::string16 PageInfoUI::PermissionDecisionReasonToUIString( base::string16 PageInfoUI::PermissionDecisionReasonToUIString(
PageInfoUiDelegate* delegate, PageInfoUiDelegate* delegate,
const PageInfoUI::PermissionInfo& permission, const PageInfo::PermissionInfo& permission,
const GURL& url) { const GURL& url) {
ContentSetting effective_setting = GetEffectiveSetting( ContentSetting effective_setting = GetEffectiveSetting(
permission.type, permission.setting, permission.default_setting); permission.type, permission.setting, permission.default_setting);
...@@ -467,7 +460,7 @@ base::string16 PageInfoUI::PermissionDecisionReasonToUIString( ...@@ -467,7 +460,7 @@ base::string16 PageInfoUI::PermissionDecisionReasonToUIString(
break; break;
} }
// TODO(crbug.com/1063023): PermissionInfo should be modified // TODO(crbug.com/1063023): PageInfo::PermissionInfo should be modified
// to contain all needed information regarding Automatically Blocked flag. // to contain all needed information regarding Automatically Blocked flag.
if (permission.setting == CONTENT_SETTING_BLOCK && if (permission.setting == CONTENT_SETTING_BLOCK &&
permissions::PermissionUtil::IsPermission(permission.type)) { permissions::PermissionUtil::IsPermission(permission.type)) {
...@@ -556,8 +549,9 @@ int PageInfoUI::GetConnectionIconID(PageInfo::SiteConnectionStatus status) { ...@@ -556,8 +549,9 @@ int PageInfoUI::GetConnectionIconID(PageInfo::SiteConnectionStatus status) {
} }
#else // !defined(OS_ANDROID) #else // !defined(OS_ANDROID)
// static // static
const gfx::ImageSkia PageInfoUI::GetPermissionIcon(const PermissionInfo& info, const gfx::ImageSkia PageInfoUI::GetPermissionIcon(
SkColor related_text_color) { const PageInfo::PermissionInfo& info,
SkColor related_text_color) {
const gfx::VectorIcon* icon = &gfx::kNoneIcon; const gfx::VectorIcon* icon = &gfx::kNoneIcon;
switch (info.type) { switch (info.type) {
case ContentSettingsType::COOKIES: case ContentSettingsType::COOKIES:
......
...@@ -85,22 +85,6 @@ class PageInfoUI { ...@@ -85,22 +85,6 @@ class PageInfoUI {
bool is_first_party; bool is_first_party;
}; };
// |PermissionInfo| contains information about a single permission |type| for
// the current website.
struct PermissionInfo {
PermissionInfo();
// Site permission |type|.
ContentSettingsType type;
// The current value for the permission |type| (e.g. ALLOW or BLOCK).
ContentSetting setting;
// The global default settings for this permission |type|.
ContentSetting default_setting;
// The settings source e.g. user, extensions, policy, ... .
content_settings::SettingSource source;
// Whether we're in incognito mode.
bool is_incognito;
};
// |ChosenObjectInfo| contains information about a single |chooser_object| of // |ChosenObjectInfo| contains information about a single |chooser_object| of
// a chooser |type| that the current website has been granted access to. // a chooser |type| that the current website has been granted access to.
struct ChosenObjectInfo { struct ChosenObjectInfo {
...@@ -166,7 +150,7 @@ class PageInfoUI { ...@@ -166,7 +150,7 @@ class PageInfoUI {
}; };
using CookieInfoList = std::vector<CookieInfo>; using CookieInfoList = std::vector<CookieInfo>;
using PermissionInfoList = std::vector<PermissionInfo>; using PermissionInfoList = std::vector<PageInfo::PermissionInfo>;
using ChosenObjectInfoList = std::vector<std::unique_ptr<ChosenObjectInfo>>; using ChosenObjectInfoList = std::vector<std::unique_ptr<ChosenObjectInfo>>;
virtual ~PageInfoUI(); virtual ~PageInfoUI();
...@@ -189,7 +173,7 @@ class PageInfoUI { ...@@ -189,7 +173,7 @@ class PageInfoUI {
// extension, enterprise policy, or embargo. // extension, enterprise policy, or embargo.
static base::string16 PermissionDecisionReasonToUIString( static base::string16 PermissionDecisionReasonToUIString(
PageInfoUiDelegate* delegate, PageInfoUiDelegate* delegate,
const PermissionInfo& permission, const PageInfo::PermissionInfo& permission,
const GURL& url); const GURL& url);
// Returns the color to use for the permission decision reason strings. // Returns the color to use for the permission decision reason strings.
...@@ -202,11 +186,11 @@ class PageInfoUI { ...@@ -202,11 +186,11 @@ class PageInfoUI {
// Returns the connection icon ID for the given connection |status|. // Returns the connection icon ID for the given connection |status|.
static int GetConnectionIconID(PageInfo::SiteConnectionStatus status); static int GetConnectionIconID(PageInfo::SiteConnectionStatus status);
#else // !defined(OS_ANDROID) #else // !defined(OS_ANDROID)
// Returns icons for the given PermissionInfo |info|. If |info|'s current // Returns icons for the given PageInfo::PermissionInfo |info|. If |info|'s
// setting is CONTENT_SETTING_DEFAULT, it will return the icon for |info|'s // current setting is CONTENT_SETTING_DEFAULT, it will return the icon for
// default setting. // |info|'s default setting.
static const gfx::ImageSkia GetPermissionIcon( static const gfx::ImageSkia GetPermissionIcon(
const PermissionInfo& info, const PageInfo::PermissionInfo& info,
const SkColor related_text_color); const SkColor related_text_color);
// Returns the icon for the given object |info|. // Returns the icon for the given object |info|.
......
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