Skip to content

Commit

Permalink
[ios] Support managed settings UI for SearchSuggestEnabled
Browse files Browse the repository at this point in the history
Change the setting UI to uneditable when SearchSuggestEnabled is managed
by enterprise policy.

Bug: 1117253
Change-Id: I2c9619fd3e0d72de572d2dab4124695d8926503e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2360574
Reviewed-by: Sergio Collazos <sczs@chromium.org>
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799704}
  • Loading branch information
Tina Wang authored and Commit Bot committed Aug 19, 2020
1 parent 70879ba commit 17154cb
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 13 deletions.
1 change: 1 addition & 0 deletions ios/chrome/browser/ui/settings/google_services/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ source_set("google_services") {
"//ios/chrome/browser/ui/list_model",
"//ios/chrome/browser/ui/settings:settings_root",
"//ios/chrome/browser/ui/settings/cells",
"//ios/chrome/browser/ui/settings/elements:enterprise_info_popover_view_controller",
"//ios/chrome/browser/ui/settings/sync",
"//ios/chrome/browser/ui/settings/sync/utils",
"//ios/chrome/browser/ui/settings/utils",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ - (void)start {
self.browser->GetBrowserState());
viewController.modelDelegate = self.mediator;
viewController.serviceDelegate = self.mediator;
viewController.dispatcher = static_cast<
id<ApplicationCommands, BrowserCommands, BrowsingDataCommands>>(
self.browser->GetCommandDispatcher());
DCHECK(self.baseNavigationController);
[self.baseNavigationController pushViewController:self.viewController
animated:YES];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_image_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_info_button_item.h"
#import "ios/chrome/browser/ui/ui_feature_flags.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/ui/colors/UIColor+cr_semantic_colors.h"
Expand Down Expand Up @@ -84,6 +85,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
ManageSyncItemType,
// NonPersonalizedSectionIdentifier section.
AutocompleteSearchesAndURLsItemType,
AutocompleteSearchesAndURLsManagedItemType,
SafeBrowsingItemType,
ImproveChromeItemType,
BetterSearchAndBrowsingItemType,
Expand Down Expand Up @@ -166,6 +168,10 @@ @interface GoogleServicesSettingsMediator () <
// All the items for the non-personalized section.
@property(nonatomic, strong, readonly) ItemArray nonPersonalizedItems;

// Pref service used to check if a specific pref is managed by enterprise
// policies.
@property(nonatomic, assign, readonly) PrefService* userPrefService;

@end

@implementation GoogleServicesSettingsMediator
Expand All @@ -183,6 +189,7 @@ - (instancetype)initWithUserPrefService:(PrefService*)userPrefService
DCHECK(syncSetupService);
_mode = mode;
_syncSetupService = syncSetupService;
_userPrefService = userPrefService;
_autocompleteSearchPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService
prefName:prefs::kSearchSuggestEnabled];
Expand Down Expand Up @@ -513,19 +520,28 @@ - (void)loadNonPersonalizedSection {
- (void)updateNonPersonalizedSection {
for (TableViewItem* item in self.nonPersonalizedItems) {
ItemType type = static_cast<ItemType>(item.type);
SyncSwitchItem* switchItem = base::mac::ObjCCast<SyncSwitchItem>(item);
switch (type) {
case AutocompleteSearchesAndURLsItemType:
switchItem.on = self.autocompleteSearchPreference.value;
base::mac::ObjCCast<SyncSwitchItem>(item).on =
self.autocompleteSearchPreference.value;
break;
case AutocompleteSearchesAndURLsManagedItemType:
base::mac::ObjCCast<TableViewInfoButtonItem>(item).statusText =
self.autocompleteSearchPreference.value
? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
: l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
break;
case SafeBrowsingItemType:
switchItem.on = self.safeBrowsingPreference.value;
base::mac::ObjCCast<SyncSwitchItem>(item).on =
self.safeBrowsingPreference.value;
break;
case ImproveChromeItemType:
switchItem.on = self.sendDataUsagePreference.value;
base::mac::ObjCCast<SyncSwitchItem>(item).on =
self.sendDataUsagePreference.value;
break;
case BetterSearchAndBrowsingItemType:
switchItem.on = self.anonymizedDataCollectionPreference.value;
base::mac::ObjCCast<SyncSwitchItem>(item).on =
self.anonymizedDataCollectionPreference.value;
break;
case ItemTypePasswordLeakCheckSwitch:
[self updateLeakCheckItem];
Expand Down Expand Up @@ -579,14 +595,27 @@ - (BOOL)isSyncCanBeAvailable {
- (ItemArray)nonPersonalizedItems {
if (!_nonPersonalizedItems) {
NSMutableArray* items = [NSMutableArray array];
SyncSwitchItem* autocompleteItem = [self
switchItemWithItemType:AutocompleteSearchesAndURLsItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_SEARCHES_AND_URLS_TEXT
detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_SEARCHES_AND_URLS_DETAIL
dataType:0];
[items addObject:autocompleteItem];
if (base::FeatureList::IsEnabled(kEnableIOSManagedSettingsUI) &&
self.userPrefService->IsManagedPreference(
prefs::kSearchSuggestEnabled)) {
TableViewInfoButtonItem* autocompleteItem = [self
TableViewInfoButtonItemType:AutocompleteSearchesAndURLsManagedItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_SEARCHES_AND_URLS_TEXT
detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_SEARCHES_AND_URLS_DETAIL
status:self.autocompleteSearchPreference];
[items addObject:autocompleteItem];
} else {
SyncSwitchItem* autocompleteItem = [self
switchItemWithItemType:AutocompleteSearchesAndURLsItemType
textStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_SEARCHES_AND_URLS_TEXT
detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_AUTOCOMPLETE_SEARCHES_AND_URLS_DETAIL
dataType:0];
[items addObject:autocompleteItem];
}
if (base::FeatureList::IsEnabled(kSafeBrowsingAvailableOnIOS)) {
SyncSwitchItem* safeBrowsingItem = [self
switchItemWithItemType:SafeBrowsingItemType
Expand Down Expand Up @@ -653,6 +682,20 @@ - (SyncSwitchItem*)switchItemWithItemType:(NSInteger)itemType
return switchItem;
}

// Create a TableViewInfoButtonItem instance.
- (TableViewInfoButtonItem*)TableViewInfoButtonItemType:(NSInteger)itemType
textStringID:(int)textStringID
detailStringID:(int)detailStringID
status:(BOOL)status {
TableViewInfoButtonItem* managedItem =
[[TableViewInfoButtonItem alloc] initWithType:itemType];
managedItem.text = GetNSString(textStringID);
managedItem.detailText = GetNSString(detailStringID);
managedItem.statusText = status ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
: l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
return managedItem;
}

// Creates an item to display the sync error. |itemType| should only be one of
// those types:
// + RestartAuthenticationFlowErrorItemType
Expand Down Expand Up @@ -800,6 +843,7 @@ - (void)toggleSwitchItem:(TableViewItem*)item withValue:(BOOL)value {
// Update the item.
[self updateLeakCheckItem];
break;
case AutocompleteSearchesAndURLsManagedItemType:
case IdentityItemType:
case ManageGoogleAccountItemType:
case SignInItemType:
Expand Down Expand Up @@ -849,6 +893,7 @@ - (void)didSelectItem:(TableViewItem*)item {
case SyncDisabledByAdministratorErrorItemType:
case SyncSettingsNotCofirmedErrorItemType:
case AutocompleteSearchesAndURLsItemType:
case AutocompleteSearchesAndURLsManagedItemType:
case SafeBrowsingItemType:
case ItemTypePasswordLeakCheckSwitch:
case ImproveChromeItemType:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@
#include "base/metrics/user_metrics_action.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_cell.h"
#import "ios/chrome/browser/ui/settings/cells/sync_switch_item.h"
#import "ios/chrome/browser/ui/settings/elements/enterprise_info_popover_view_controller.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_constants.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_service_delegate.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_view_controller_model_delegate.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_info_button_cell.h"
#include "ios/chrome/grit/ios_strings.h"
#import "net/base/mac/url_conversions.h"
#include "ui/base/l10n/l10n_util_mac.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif

@interface GoogleServicesSettingsViewController () <
PopoverLabelViewControllerDelegate> {
}

@end

@implementation GoogleServicesSettingsViewController

- (void)viewDidLoad {
Expand Down Expand Up @@ -52,6 +61,12 @@ - (UITableViewCell*)tableView:(UITableView*)tableView
forControlEvents:UIControlEventValueChanged];
TableViewItem* item = [self.tableViewModel itemAtIndexPath:indexPath];
switchCell.switchView.tag = item.type;
} else if ([cell isKindOfClass:[TableViewInfoButtonCell class]]) {
TableViewInfoButtonCell* managedCell =
base::mac::ObjCCastStrict<TableViewInfoButtonCell>(cell);
[managedCell.trailingButton addTarget:self
action:@selector(didTapManagedUIInfoButton:)
forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
Expand Down Expand Up @@ -147,4 +162,33 @@ - (void)presentationControllerDidDismiss:
base::UserMetricsAction("IOSGoogleServicesSettingsCloseWithSwipe"));
}

#pragma mark - Actions

// 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];

bubbleViewController.delegate = self;
// 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;

[self presentViewController:bubbleViewController animated:YES completion:nil];
}

#pragma mark - PopoverLabelViewControllerDelegate

- (void)didTapLinkURL:(NSURL*)URL {
GURL convertedURL = net::GURLWithNSURL(URL);
[self view:nil didTapLinkURL:convertedURL];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style
[UIFont preferredFontForTextStyle:kTableViewSublabelFontStyle];
_detailTextLabel.adjustsFontForContentSizeCategory = YES;
_detailTextLabel.textColor = UIColor.cr_secondaryLabelColor;
_detailTextLabel.numberOfLines = 0;
[self.contentView addSubview:_detailTextLabel];

_statusTextLabel = [[UILabel alloc] init];
Expand Down

0 comments on commit 17154cb

Please sign in to comment.