Commit 092e4d77 authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[ios] Adjust the UI if exceptional allowed popups

For the exception section shown in settings -> content settings ->
pop-ups, if there are exceptions set by the policy(AllowedPopupsForUrls)
when pop-ups is blocked, they shouldn't be editable. At the same time,
if there are some exceptional allowed popups set by the user, they
remain editable. If all allowed popups urls are set by the policy, then
the "edit" button on the top right of the page should be disabled.

The UI and behaviour of the exception section is the same with above if
DefaultPopupsSetting is set to "2" (block).

Bug: 1142620
Change-Id: I0948acccc3bdf78be277b818a8f01a119a51856a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2500252Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821772}
parent 34bce448
...@@ -47,6 +47,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -47,6 +47,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeManaged, ItemTypeManaged,
ItemTypeHeader, ItemTypeHeader,
ItemTypeException, ItemTypeException,
ItemTypeExceptionByPolicy,
}; };
} // namespace } // namespace
...@@ -59,6 +60,9 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -59,6 +60,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
// List of url patterns that are allowed to display popups. // List of url patterns that are allowed to display popups.
base::ListValue _exceptions; base::ListValue _exceptions;
// List of url patterns set by policy that are allowed to display popups.
base::ListValue _allowPopupsByPolicy;
// The observable boolean that binds to the "Disable Popups" setting state. // The observable boolean that binds to the "Disable Popups" setting state.
ContentSettingBackedBoolean* _disablePopupsSetting; ContentSettingBackedBoolean* _disablePopupsSetting;
...@@ -131,7 +135,8 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -131,7 +135,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
toSectionWithIdentifier:SectionIdentifierMainSwitch]; toSectionWithIdentifier:SectionIdentifierMainSwitch];
} }
if ([self popupsCurrentlyBlocked] && _exceptions.GetSize()) { if ([self popupsCurrentlyBlocked] &&
(_exceptions.GetSize() || _allowPopupsByPolicy.GetSize())) {
[self populateExceptionsItems]; [self populateExceptionsItems];
} }
} }
...@@ -200,9 +205,12 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -200,9 +205,12 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (BOOL)tableView:(UITableView*)tableView - (BOOL)tableView:(UITableView*)tableView
canEditRowAtIndexPath:(NSIndexPath*)indexPath { canEditRowAtIndexPath:(NSIndexPath*)indexPath {
// Any item in SectionIdentifierExceptions is editable. // Only when items are in SectionIdentifierExceptions and are not set by the
return [self.tableViewModel sectionIdentifierForSection:indexPath.section] == // policy are editable.
SectionIdentifierExceptions; return
[self.tableViewModel sectionIdentifierForSection:indexPath.section] ==
SectionIdentifierExceptions &&
[self.tableViewModel itemAtIndexPath:indexPath].type == ItemTypeException;
} }
- (void)tableView:(UITableView*)tableView - (void)tableView:(UITableView*)tableView
...@@ -212,7 +220,8 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -212,7 +220,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
return; return;
[self deleteItemAtIndexPaths:@[ indexPath ]]; [self deleteItemAtIndexPaths:@[ indexPath ]];
if (![self.tableViewModel if (![self.tableViewModel
hasSectionForSectionIdentifier:SectionIdentifierExceptions]) { hasSectionForSectionIdentifier:SectionIdentifierExceptions] ||
!_exceptions.GetSize()) {
self.navigationItem.rightBarButtonItem.enabled = NO; self.navigationItem.rightBarButtonItem.enabled = NO;
} }
} }
...@@ -322,7 +331,9 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -322,7 +331,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
return [_disablePopupsSetting value]; return [_disablePopupsSetting value];
} }
// Fetch the urls that can display popups and add them to |_exceptions|. // Fetch the urls that can display popups and
// add items set by the user to |_exceptions|,
// add items set by the policy to |_allowPopupsByPolicy|.
- (void)populateExceptionsList { - (void)populateExceptionsList {
// The body of this method was mostly copied from // The body of this method was mostly copied from
// chrome/browser/ui/webui/options/content_settings_handler.cc and simplified // chrome/browser/ui/webui/options/content_settings_handler.cc and simplified
...@@ -346,7 +357,14 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -346,7 +357,14 @@ typedef NS_ENUM(NSInteger, ItemType) {
// wildcard pattern. So only show settings that the user is able to modify. // wildcard pattern. So only show settings that the user is able to modify.
if (entries[i].secondary_pattern == ContentSettingsPattern::Wildcard() && if (entries[i].secondary_pattern == ContentSettingsPattern::Wildcard() &&
entries[i].GetContentSetting() == CONTENT_SETTING_ALLOW) { entries[i].GetContentSetting() == CONTENT_SETTING_ALLOW) {
if (entries[i].source == "policy") {
// Add the urls to |_allowPopupsByPolicy| if the allowed urls are set by
// the policy.
_allowPopupsByPolicy.AppendString(
entries[i].primary_pattern.ToString());
} else {
_exceptions.AppendString(entries[i].primary_pattern.ToString()); _exceptions.AppendString(entries[i].primary_pattern.ToString());
}
} else { } else {
LOG(ERROR) << "Secondary content settings patterns are not " LOG(ERROR) << "Secondary content settings patterns are not "
<< "supported by the content settings UI"; << "supported by the content settings UI";
...@@ -363,6 +381,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -363,6 +381,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
header.text = l10n_util::GetNSString(IDS_IOS_POPUPS_ALLOWED); header.text = l10n_util::GetNSString(IDS_IOS_POPUPS_ALLOWED);
[model setHeader:header forSectionWithIdentifier:SectionIdentifierExceptions]; [model setHeader:header forSectionWithIdentifier:SectionIdentifierExceptions];
// Populate the exception items set by the user.
for (size_t i = 0; i < _exceptions.GetSize(); ++i) { for (size_t i = 0; i < _exceptions.GetSize(); ++i) {
std::string allowed_url; std::string allowed_url;
_exceptions.GetString(i, &allowed_url); _exceptions.GetString(i, &allowed_url);
...@@ -371,10 +390,20 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -371,10 +390,20 @@ typedef NS_ENUM(NSInteger, ItemType) {
item.text = base::SysUTF8ToNSString(allowed_url); item.text = base::SysUTF8ToNSString(allowed_url);
[model addItem:item toSectionWithIdentifier:SectionIdentifierExceptions]; [model addItem:item toSectionWithIdentifier:SectionIdentifierExceptions];
} }
// Populate the exception items set by the policy.
for (size_t l = 0; l < _allowPopupsByPolicy.GetSize(); ++l) {
std::string allowed_url_by_policy;
_allowPopupsByPolicy.GetString(l, &allowed_url_by_policy);
TableViewDetailTextItem* item = [[TableViewDetailTextItem alloc]
initWithType:ItemTypeExceptionByPolicy];
item.text = base::SysUTF8ToNSString(allowed_url_by_policy);
[model addItem:item toSectionWithIdentifier:SectionIdentifierExceptions];
}
} }
- (void)layoutSections:(BOOL)blockPopupsIsOn { - (void)layoutSections:(BOOL)blockPopupsIsOn {
BOOL hasExceptions = _exceptions.GetSize(); BOOL hasExceptions = _exceptions.GetSize() || _allowPopupsByPolicy.GetSize();
BOOL exceptionsListShown = [self.tableViewModel BOOL exceptionsListShown = [self.tableViewModel
hasSectionForSectionIdentifier:SectionIdentifierExceptions]; hasSectionForSectionIdentifier: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