Commit b2b07a66 authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[SettingsUI] Modify managed UI for block pop-ups setting

Change the UI to managed when the pref is managed by policy.

Bug: 1093169
Change-Id: I2aaf5c5b1d948501a48ab600d40a1af5ab8ce733
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2255627
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781585}
parent d27d930c
...@@ -110,6 +110,7 @@ source_set("settings") { ...@@ -110,6 +110,7 @@ source_set("settings") {
"//components/keyed_service/core", "//components/keyed_service/core",
"//components/password_manager/core/browser", "//components/password_manager/core/browser",
"//components/password_manager/core/common", "//components/password_manager/core/common",
"//components/prefs",
"//components/prefs/ios", "//components/prefs/ios",
"//components/resources", "//components/resources",
"//components/search_engines", "//components/search_engines",
......
...@@ -11,14 +11,19 @@ ...@@ -11,14 +11,19 @@
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_pattern.h" #include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h" #include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h" #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_cell.h" #import "ios/chrome/browser/ui/settings/cells/settings_switch_cell.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_item.h" #import "ios/chrome/browser/ui/settings/cells/settings_switch_item.h"
#import "ios/chrome/browser/ui/settings/elements/enterprise_info_popover_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#import "ios/chrome/browser/ui/settings/utils/content_setting_backed_boolean.h" #import "ios/chrome/browser/ui/settings/utils/content_setting_backed_boolean.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_detail_text_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_detail_text_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_info_button_cell.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_info_button_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h"
#include "ios/chrome/browser/ui/ui_feature_flags.h" #include "ios/chrome/browser/ui/ui_feature_flags.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
...@@ -38,6 +43,7 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) { ...@@ -38,6 +43,7 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
typedef NS_ENUM(NSInteger, ItemType) { typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeMainSwitch = kItemTypeEnumZero, ItemTypeMainSwitch = kItemTypeEnumZero,
ItemTypeManaged,
ItemTypeHeader, ItemTypeHeader,
ItemTypeException, ItemTypeException,
}; };
...@@ -55,6 +61,9 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -55,6 +61,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
// The item related to the switch for the "Disable Popups" setting. // The item related to the switch for the "Disable Popups" setting.
SettingsSwitchItem* _blockPopupsItem; SettingsSwitchItem* _blockPopupsItem;
// The managed item for the "Disable Popups" setting.
TableViewInfoButtonItem* _blockPopupsManagedItem;
} }
@end @end
...@@ -103,13 +112,21 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -103,13 +112,21 @@ typedef NS_ENUM(NSInteger, ItemType) {
// Block popups switch. // Block popups switch.
[model addSectionWithIdentifier:SectionIdentifierMainSwitch]; [model addSectionWithIdentifier:SectionIdentifierMainSwitch];
_blockPopupsItem = if (base::FeatureList::IsEnabled(kEnableIOSManagedSettingsUI) &&
[[SettingsSwitchItem alloc] initWithType:ItemTypeMainSwitch]; _browserState->GetPrefs()->IsManagedPreference(
_blockPopupsItem.text = l10n_util::GetNSString(IDS_IOS_BLOCK_POPUPS); prefs::kManagedDefaultPopupsSetting)) {
_blockPopupsItem.on = [_disablePopupsSetting value]; _blockPopupsManagedItem = [self blockPopupsManagedItem];
_blockPopupsItem.accessibilityIdentifier = @"blockPopupsContentView_switch"; [model addItem:_blockPopupsManagedItem
[model addItem:_blockPopupsItem toSectionWithIdentifier:SectionIdentifierMainSwitch];
toSectionWithIdentifier:SectionIdentifierMainSwitch]; } else {
_blockPopupsItem =
[[SettingsSwitchItem alloc] initWithType:ItemTypeMainSwitch];
_blockPopupsItem.text = l10n_util::GetNSString(IDS_IOS_BLOCK_POPUPS);
_blockPopupsItem.on = [_disablePopupsSetting value];
_blockPopupsItem.accessibilityIdentifier = @"blockPopupsContentView_switch";
[model addItem:_blockPopupsItem
toSectionWithIdentifier:SectionIdentifierMainSwitch];
}
if ([self popupsCurrentlyBlocked] && _exceptions.GetSize()) { if ([self popupsCurrentlyBlocked] && _exceptions.GetSize()) {
[self populateExceptionsItems]; [self populateExceptionsItems];
...@@ -130,20 +147,48 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -130,20 +147,48 @@ typedef NS_ENUM(NSInteger, ItemType) {
[self deleteItemAtIndexPaths:indexPaths]; [self deleteItemAtIndexPaths:indexPaths];
} }
#pragma mark - LoadModel Helpers
- (TableViewInfoButtonItem*)blockPopupsManagedItem {
TableViewInfoButtonItem* blockPopupsManagedItem =
[[TableViewInfoButtonItem alloc] initWithType:ItemTypeManaged];
blockPopupsManagedItem.text = l10n_util::GetNSString(IDS_IOS_BLOCK_POPUPS);
blockPopupsManagedItem.statusText =
[_disablePopupsSetting value]
? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
: l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
blockPopupsManagedItem.accessibilityIdentifier =
@"blockPopupsContentView_managed";
return blockPopupsManagedItem;
}
#pragma mark - UITableViewDataSource #pragma mark - UITableViewDataSource
- (UITableViewCell*)tableView:(UITableView*)tableView - (UITableViewCell*)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)indexPath { cellForRowAtIndexPath:(NSIndexPath*)indexPath {
UITableViewCell* cell = UITableViewCell* cell =
[super tableView:tableView cellForRowAtIndexPath:indexPath]; [super tableView:tableView cellForRowAtIndexPath:indexPath];
switch ([self.tableViewModel itemTypeForIndexPath:indexPath]) {
if ([self.tableViewModel itemTypeForIndexPath:indexPath] == case ItemTypeHeader:
ItemTypeMainSwitch) { case ItemTypeException:
SettingsSwitchCell* switchCell = break;
base::mac::ObjCCastStrict<SettingsSwitchCell>(cell); case ItemTypeMainSwitch: {
[switchCell.switchView addTarget:self SettingsSwitchCell* switchCell =
action:@selector(blockPopupsSwitchChanged:) base::mac::ObjCCastStrict<SettingsSwitchCell>(cell);
forControlEvents:UIControlEventValueChanged]; [switchCell.switchView addTarget:self
action:@selector(blockPopupsSwitchChanged:)
forControlEvents:UIControlEventValueChanged];
break;
}
case ItemTypeManaged: {
TableViewInfoButtonCell* managedCell =
base::mac::ObjCCastStrict<TableViewInfoButtonCell>(cell);
[managedCell.trailingButton
addTarget:self
action:@selector(didTapManagedUIInfoButton:)
forControlEvents:UIControlEventTouchUpInside];
break;
}
} }
return cell; return cell;
} }
...@@ -171,16 +216,21 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -171,16 +216,21 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean {
DCHECK_EQ(observableBoolean, _disablePopupsSetting); DCHECK_EQ(observableBoolean, _disablePopupsSetting);
if (_blockPopupsItem) {
if (_blockPopupsItem.on == [_disablePopupsSetting value]) if (_blockPopupsItem.on == [_disablePopupsSetting value])
return; return;
// Update the item. // Update the item.
_blockPopupsItem.on = [_disablePopupsSetting value]; _blockPopupsItem.on = [_disablePopupsSetting value];
// Update the cell. // Update the cell.
[self reconfigureCellsForItems:@[ _blockPopupsItem ]]; [self reconfigureCellsForItems:@[ _blockPopupsItem ]];
} else {
_blockPopupsManagedItem.statusText =
[_disablePopupsSetting value]
? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
: l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
}
// Update the rest of the UI. // Update the rest of the UI.
[self setEditing:NO animated:YES]; [self setEditing:NO animated:YES];
[self updateUIForEditState]; [self updateUIForEditState];
...@@ -202,6 +252,24 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -202,6 +252,24 @@ typedef NS_ENUM(NSInteger, ItemType) {
[self layoutSections:switchView.on]; [self layoutSections:switchView.on];
} }
// Called when the user clicks on the information button of the managed
// setting's UI. Shows a textual bubble with the information of the enterprise.
- (void)didTapManagedUIInfoButton:(UIButton*)buttonView {
EnterpriseInfoPopoverViewController* bubbleViewController =
[[EnterpriseInfoPopoverViewController alloc] initWithEnterpriseName:nil];
[self presentViewController:bubbleViewController animated:YES completion:nil];
// Disable the button when showing the bubble.
buttonView.enabled = NO;
// Set the anchor and arrow direction of the bubble.
bubbleViewController.popoverPresentationController.sourceView = buttonView;
bubbleViewController.popoverPresentationController.sourceRect =
buttonView.bounds;
bubbleViewController.popoverPresentationController.permittedArrowDirections =
UIPopoverArrowDirectionAny;
}
#pragma mark - Private #pragma mark - Private
// Deletes the item at the |indexPaths|. Removes the SectionIdentifierExceptions // Deletes the item at the |indexPaths|. Removes the SectionIdentifierExceptions
......
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