Commit 17154cb6 authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[ios] Support managed settings UI for SearchSuggestEnabled

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/+/2360574Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799704}
parent 70879ba6
......@@ -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",
......
......@@ -115,6 +115,9 @@ using signin_metrics::PromoAction;
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];
......
......@@ -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"
......@@ -84,6 +85,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
ManageSyncItemType,
// NonPersonalizedSectionIdentifier section.
AutocompleteSearchesAndURLsItemType,
AutocompleteSearchesAndURLsManagedItemType,
SafeBrowsingItemType,
ImproveChromeItemType,
BetterSearchAndBrowsingItemType,
......@@ -166,6 +168,10 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
// 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
......@@ -183,6 +189,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
DCHECK(syncSetupService);
_mode = mode;
_syncSetupService = syncSetupService;
_userPrefService = userPrefService;
_autocompleteSearchPreference = [[PrefBackedBoolean alloc]
initWithPrefService:userPrefService
prefName:prefs::kSearchSuggestEnabled];
......@@ -513,19 +520,28 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
- (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];
......@@ -579,14 +595,27 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
- (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
......@@ -653,6 +682,20 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
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
......@@ -800,6 +843,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
// Update the item.
[self updateLeakCheckItem];
break;
case AutocompleteSearchesAndURLsManagedItemType:
case IdentityItemType:
case ManageGoogleAccountItemType:
case SignInItemType:
......@@ -849,6 +893,7 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
case SyncDisabledByAdministratorErrorItemType:
case SyncSettingsNotCofirmedErrorItemType:
case AutocompleteSearchesAndURLsItemType:
case AutocompleteSearchesAndURLsManagedItemType:
case SafeBrowsingItemType:
case ItemTypePasswordLeakCheckSwitch:
case ImproveChromeItemType:
......
......@@ -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 {
......@@ -52,6 +61,12 @@
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;
}
......@@ -147,4 +162,33 @@
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
......@@ -86,6 +86,7 @@ const CGFloat kCellLabelsWidthProportion = 0.2f;
[UIFont preferredFontForTextStyle:kTableViewSublabelFontStyle];
_detailTextLabel.adjustsFontForContentSizeCategory = YES;
_detailTextLabel.textColor = UIColor.cr_secondaryLabelColor;
_detailTextLabel.numberOfLines = 0;
[self.contentView addSubview:_detailTextLabel];
_statusTextLabel = [[UILabel alloc] init];
......
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