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") {
"//components/keyed_service/core",
"//components/password_manager/core/browser",
"//components/password_manager/core/common",
"//components/prefs",
"//components/prefs/ios",
"//components/resources",
"//components/search_engines",
......
......@@ -11,14 +11,19 @@
#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_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/content_settings/host_content_settings_map_factory.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_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/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_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"
#include "ios/chrome/browser/ui/ui_feature_flags.h"
#include "ios/chrome/grit/ios_strings.h"
......@@ -38,6 +43,7 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeMainSwitch = kItemTypeEnumZero,
ItemTypeManaged,
ItemTypeHeader,
ItemTypeException,
};
......@@ -55,6 +61,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
// The item related to the switch for the "Disable Popups" setting.
SettingsSwitchItem* _blockPopupsItem;
// The managed item for the "Disable Popups" setting.
TableViewInfoButtonItem* _blockPopupsManagedItem;
}
@end
......@@ -103,13 +112,21 @@ typedef NS_ENUM(NSInteger, ItemType) {
// Block popups switch.
[model addSectionWithIdentifier:SectionIdentifierMainSwitch];
_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 (base::FeatureList::IsEnabled(kEnableIOSManagedSettingsUI) &&
_browserState->GetPrefs()->IsManagedPreference(
prefs::kManagedDefaultPopupsSetting)) {
_blockPopupsManagedItem = [self blockPopupsManagedItem];
[model addItem:_blockPopupsManagedItem
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()) {
[self populateExceptionsItems];
......@@ -130,20 +147,48 @@ typedef NS_ENUM(NSInteger, ItemType) {
[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
- (UITableViewCell*)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)indexPath {
UITableViewCell* cell =
[super tableView:tableView cellForRowAtIndexPath:indexPath];
if ([self.tableViewModel itemTypeForIndexPath:indexPath] ==
ItemTypeMainSwitch) {
SettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<SettingsSwitchCell>(cell);
[switchCell.switchView addTarget:self
action:@selector(blockPopupsSwitchChanged:)
forControlEvents:UIControlEventValueChanged];
switch ([self.tableViewModel itemTypeForIndexPath:indexPath]) {
case ItemTypeHeader:
case ItemTypeException:
break;
case ItemTypeMainSwitch: {
SettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<SettingsSwitchCell>(cell);
[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;
}
......@@ -171,16 +216,21 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean {
DCHECK_EQ(observableBoolean, _disablePopupsSetting);
if (_blockPopupsItem.on == [_disablePopupsSetting value])
return;
// Update the item.
_blockPopupsItem.on = [_disablePopupsSetting value];
// Update the cell.
[self reconfigureCellsForItems:@[ _blockPopupsItem ]];
if (_blockPopupsItem) {
if (_blockPopupsItem.on == [_disablePopupsSetting value])
return;
// Update the item.
_blockPopupsItem.on = [_disablePopupsSetting value];
// Update the cell.
[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.
[self setEditing:NO animated:YES];
[self updateUIForEditState];
......@@ -202,6 +252,24 @@ typedef NS_ENUM(NSInteger, ItemType) {
[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
// 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