OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/settings/privacy_collection_view_controller.h" |
| 6 |
| 7 #include "base/ios/ios_util.h" |
| 8 #include "base/ios/weak_nsobject.h" |
| 9 #include "base/logging.h" |
| 10 #import "base/mac/foundation_util.h" |
| 11 #include "base/mac/scoped_nsobject.h" |
| 12 #include "components/google/core/browser/google_util.h" |
| 13 #include "components/handoff/pref_names_ios.h" |
| 14 #include "components/metrics/metrics_pref_names.h" |
| 15 #include "components/prefs/pref_change_registrar.h" |
| 16 #include "components/prefs/pref_service.h" |
| 17 #include "components/signin/core/browser/signin_manager.h" |
| 18 #include "components/strings/grit/components_strings.h" |
| 19 #include "ios/chrome/browser/application_context.h" |
| 20 #import "ios/chrome/browser/autofill/autofill_controller.h" |
| 21 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 22 #include "ios/chrome/browser/chrome_url_constants.h" |
| 23 #include "ios/chrome/browser/experimental_flags.h" |
| 24 #include "ios/chrome/browser/physical_web/physical_web_constants.h" |
| 25 #include "ios/chrome/browser/pref_names.h" |
| 26 #import "ios/chrome/browser/prefs/pref_observer_bridge.h" |
| 27 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
| 28 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" |
| 29 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" |
| 30 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" |
| 31 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
| 32 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 33 #import "ios/chrome/browser/ui/contextual_search/touch_to_search_permissions_med
iator.h" |
| 34 #import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h" |
| 35 #import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_cont
roller.h" |
| 36 #import "ios/chrome/browser/ui/settings/contextual_search_collection_view_contro
ller.h" |
| 37 #import "ios/chrome/browser/ui/settings/dataplan_usage_collection_view_controlle
r.h" |
| 38 #import "ios/chrome/browser/ui/settings/do_not_track_collection_view_controller.
h" |
| 39 #import "ios/chrome/browser/ui/settings/handoff_collection_view_controller.h" |
| 40 #import "ios/chrome/browser/ui/settings/physical_web_collection_view_controller.
h" |
| 41 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" |
| 42 #import "ios/chrome/browser/ui/settings/settings_utils.h" |
| 43 #import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h" |
| 44 #include "ios/chrome/browser/ui/ui_util.h" |
| 45 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 46 #include "ios/chrome/grit/ios_strings.h" |
| 47 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 48 #include "ios/web/public/web_capabilities.h" |
| 49 #include "ui/base/l10n/l10n_util.h" |
| 50 #include "ui/base/l10n/l10n_util_mac.h" |
| 51 #include "url/gurl.h" |
| 52 |
| 53 NSString* const kPrivacyCollectionViewId = @"kPrivacyCollectionViewId"; |
| 54 |
| 55 namespace { |
| 56 |
| 57 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 58 SectionIdentifierOtherDevices = kSectionIdentifierEnumZero, |
| 59 SectionIdentifierWebServices, |
| 60 SectionIdentifierWebServicesFooter, |
| 61 SectionIdentifierClearBrowsingData, |
| 62 }; |
| 63 |
| 64 typedef NS_ENUM(NSInteger, ItemType) { |
| 65 ItemTypeOtherDevicesHeader = kItemTypeEnumZero, |
| 66 ItemTypeOtherDevicesHandoff, |
| 67 ItemTypeWebServicesHeader, |
| 68 ItemTypeWebServicesFooter, |
| 69 ItemTypeWebServicesShowSuggestions, |
| 70 ItemTypeWebServicesTouchToSearch, |
| 71 ItemTypeWebServicesSendUsageData, |
| 72 ItemTypeWebServicesDoNotTrack, |
| 73 ItemTypeWebServicesPhysicalWeb, |
| 74 ItemTypeClearBrowsingDataClear, |
| 75 }; |
| 76 |
| 77 } // namespace |
| 78 |
| 79 @interface PrivacyCollectionViewController ()<BooleanObserver, |
| 80 PrefObserverDelegate> { |
| 81 ios::ChromeBrowserState* _browserState; // weak |
| 82 base::scoped_nsobject<PrefBackedBoolean> _suggestionsEnabled; |
| 83 // The item related to the switch for the show suggestions setting. |
| 84 base::scoped_nsobject<CollectionViewSwitchItem> _showSuggestionsItem; |
| 85 base::scoped_nsobject<TouchToSearchPermissionsMediator> |
| 86 _touchToSearchPermissions; |
| 87 |
| 88 // Pref observer to track changes to prefs. |
| 89 std::unique_ptr<PrefObserverBridge> _prefObserverBridge; |
| 90 // Registrar for pref changes notifications. |
| 91 PrefChangeRegistrar _prefChangeRegistrar; |
| 92 PrefChangeRegistrar _prefChangeRegistrarApplicationContext; |
| 93 |
| 94 // Updatable Items |
| 95 base::scoped_nsobject<CollectionViewDetailItem> _handoffDetailItem; |
| 96 base::scoped_nsobject<CollectionViewDetailItem> _sendUsageDetailItem; |
| 97 } |
| 98 |
| 99 // Initialization methods for various model items. |
| 100 - (CollectionViewItem*)handoffDetailItem; |
| 101 - (CollectionViewSwitchItem*)showSuggestionsSwitchItem; |
| 102 - (CollectionViewItem*)showSuggestionsFooterItem; |
| 103 - (CollectionViewItem*)clearBrowsingDetailItem; |
| 104 - (CollectionViewItem*)sendUsageDetailItem; |
| 105 - (CollectionViewItem*)physicalWebDetailItem; |
| 106 - (CollectionViewItem*)contextualSearchDetailItem; |
| 107 - (CollectionViewItem*)doNotTrackDetailItem; |
| 108 |
| 109 @end |
| 110 |
| 111 @implementation PrivacyCollectionViewController |
| 112 |
| 113 #pragma mark - Initialization |
| 114 |
| 115 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { |
| 116 DCHECK(browserState); |
| 117 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |
| 118 if (self) { |
| 119 _browserState = browserState; |
| 120 self.title = |
| 121 l10n_util::GetNSString(IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY); |
| 122 self.collectionViewAccessibilityIdentifier = kPrivacyCollectionViewId; |
| 123 _suggestionsEnabled.reset([[PrefBackedBoolean alloc] |
| 124 initWithPrefService:_browserState->GetPrefs() |
| 125 prefName:prefs::kSearchSuggestEnabled]); |
| 126 [_suggestionsEnabled setObserver:self]; |
| 127 |
| 128 PrefService* prefService = _browserState->GetPrefs(); |
| 129 |
| 130 _prefChangeRegistrar.Init(prefService); |
| 131 _prefChangeRegistrarApplicationContext.Init( |
| 132 GetApplicationContext()->GetLocalState()); |
| 133 _prefObserverBridge.reset(new PrefObserverBridge(self)); |
| 134 // Register to observe any changes on Perf backed values displayed by the |
| 135 // screen. |
| 136 _prefObserverBridge->ObserveChangesForPreference( |
| 137 prefs::kIosHandoffToOtherDevices, &_prefChangeRegistrar); |
| 138 _prefObserverBridge->ObserveChangesForPreference( |
| 139 metrics::prefs::kMetricsReportingEnabled, |
| 140 &_prefChangeRegistrarApplicationContext); |
| 141 _prefObserverBridge->ObserveChangesForPreference( |
| 142 prefs::kMetricsReportingWifiOnly, |
| 143 &_prefChangeRegistrarApplicationContext); |
| 144 |
| 145 [self loadModel]; |
| 146 } |
| 147 return self; |
| 148 } |
| 149 |
| 150 - (void)dealloc { |
| 151 [_suggestionsEnabled setObserver:nil]; |
| 152 [super dealloc]; |
| 153 } |
| 154 |
| 155 #pragma mark - SettingsRootCollectionViewController |
| 156 |
| 157 - (void)loadModel { |
| 158 [super loadModel]; |
| 159 |
| 160 CollectionViewModel* model = self.collectionViewModel; |
| 161 |
| 162 // Other Devices Section |
| 163 [model addSectionWithIdentifier:SectionIdentifierOtherDevices]; |
| 164 CollectionViewTextItem* otherDevicesHeader = [[[CollectionViewTextItem alloc] |
| 165 initWithType:ItemTypeOtherDevicesHeader] autorelease]; |
| 166 otherDevicesHeader.text = |
| 167 l10n_util::GetNSString(IDS_IOS_OPTIONS_CONTINUITY_LABEL); |
| 168 [model setHeader:otherDevicesHeader |
| 169 forSectionWithIdentifier:SectionIdentifierOtherDevices]; |
| 170 [model addItem:[self handoffDetailItem] |
| 171 toSectionWithIdentifier:SectionIdentifierOtherDevices]; |
| 172 |
| 173 // Web Services Section |
| 174 [model addSectionWithIdentifier:SectionIdentifierWebServices]; |
| 175 CollectionViewTextItem* webServicesHeader = [[[CollectionViewTextItem alloc] |
| 176 initWithType:ItemTypeWebServicesHeader] autorelease]; |
| 177 webServicesHeader.text = |
| 178 l10n_util::GetNSString(IDS_IOS_OPTIONS_WEB_SERVICES_LABEL); |
| 179 [model setHeader:webServicesHeader |
| 180 forSectionWithIdentifier:SectionIdentifierWebServices]; |
| 181 _showSuggestionsItem.reset([[self showSuggestionsSwitchItem] retain]); |
| 182 [model addItem:_showSuggestionsItem |
| 183 toSectionWithIdentifier:SectionIdentifierWebServices]; |
| 184 |
| 185 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice]) { |
| 186 [model addItem:[self contextualSearchDetailItem] |
| 187 toSectionWithIdentifier:SectionIdentifierWebServices]; |
| 188 } |
| 189 |
| 190 #if defined(GOOGLE_CHROME_BUILD) |
| 191 [model addItem:[self sendUsageDetailItem] |
| 192 toSectionWithIdentifier:SectionIdentifierWebServices]; |
| 193 #endif |
| 194 |
| 195 if (web::IsDoNotTrackSupported()) { |
| 196 [model addItem:[self doNotTrackDetailItem] |
| 197 toSectionWithIdentifier:SectionIdentifierWebServices]; |
| 198 } |
| 199 |
| 200 if (experimental_flags::IsPhysicalWebEnabled()) { |
| 201 [model addItem:[self physicalWebDetailItem] |
| 202 toSectionWithIdentifier:SectionIdentifierWebServices]; |
| 203 } |
| 204 |
| 205 // Footer Section |
| 206 [model addSectionWithIdentifier:SectionIdentifierWebServicesFooter]; |
| 207 [model addItem:[self showSuggestionsFooterItem] |
| 208 toSectionWithIdentifier:SectionIdentifierWebServicesFooter]; |
| 209 |
| 210 // Clear Browsing Section |
| 211 [model addSectionWithIdentifier:SectionIdentifierClearBrowsingData]; |
| 212 [model addItem:[self clearBrowsingDetailItem] |
| 213 toSectionWithIdentifier:SectionIdentifierClearBrowsingData]; |
| 214 } |
| 215 |
| 216 #pragma mark - Model Objects |
| 217 |
| 218 - (CollectionViewItem*)handoffDetailItem { |
| 219 NSString* detailText = |
| 220 _browserState->GetPrefs()->GetBoolean(prefs::kIosHandoffToOtherDevices) |
| 221 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 222 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 223 _handoffDetailItem.reset( |
| 224 [[self detailItemWithType:ItemTypeOtherDevicesHandoff |
| 225 titleId:IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES |
| 226 detailText:detailText] retain]); |
| 227 |
| 228 return _handoffDetailItem; |
| 229 } |
| 230 |
| 231 - (CollectionViewSwitchItem*)showSuggestionsSwitchItem { |
| 232 CollectionViewSwitchItem* showSuggestionsSwitchItem = |
| 233 [[[CollectionViewSwitchItem alloc] |
| 234 initWithType:ItemTypeWebServicesShowSuggestions] autorelease]; |
| 235 showSuggestionsSwitchItem.text = |
| 236 l10n_util::GetNSString(IDS_IOS_OPTIONS_SEARCH_URL_SUGGESTIONS); |
| 237 showSuggestionsSwitchItem.on = [_suggestionsEnabled value]; |
| 238 |
| 239 return showSuggestionsSwitchItem; |
| 240 } |
| 241 |
| 242 - (CollectionViewItem*)showSuggestionsFooterItem { |
| 243 CollectionViewFooterItem* showSuggestionsFooterItem = |
| 244 [[[CollectionViewFooterItem alloc] initWithType:ItemTypeWebServicesFooter] |
| 245 autorelease]; |
| 246 showSuggestionsFooterItem.text = |
| 247 l10n_util::GetNSString(IDS_IOS_OPTIONS_PRIVACY_FOOTER); |
| 248 showSuggestionsFooterItem.linkURL = google_util::AppendGoogleLocaleParam( |
| 249 GURL(kPrivacyLearnMoreURL), |
| 250 GetApplicationContext()->GetApplicationLocale()); |
| 251 showSuggestionsFooterItem.linkDelegate = self; |
| 252 |
| 253 return showSuggestionsFooterItem; |
| 254 } |
| 255 |
| 256 - (CollectionViewItem*)clearBrowsingDetailItem { |
| 257 return [self detailItemWithType:ItemTypeClearBrowsingDataClear |
| 258 titleId:IDS_IOS_CLEAR_BROWSING_DATA_TITLE |
| 259 detailText:nil]; |
| 260 } |
| 261 |
| 262 - (CollectionViewItem*)sendUsageDetailItem { |
| 263 NSString* detailText = [DataplanUsageCollectionViewController |
| 264 currentLabelForPreference:GetApplicationContext()->GetLocalState() |
| 265 basePref:metrics::prefs::kMetricsReportingEnabled |
| 266 wifiPref:prefs::kMetricsReportingWifiOnly]; |
| 267 _sendUsageDetailItem.reset( |
| 268 [[self detailItemWithType:ItemTypeWebServicesSendUsageData |
| 269 titleId:IDS_IOS_OPTIONS_SEND_USAGE_DATA |
| 270 detailText:detailText] retain]); |
| 271 |
| 272 return _sendUsageDetailItem; |
| 273 } |
| 274 |
| 275 - (CollectionViewItem*)physicalWebDetailItem { |
| 276 PrefService* prefService = GetApplicationContext()->GetLocalState(); |
| 277 int preferenceState = prefService->GetInteger(prefs::kIosPhysicalWebEnabled); |
| 278 BOOL enabled = [PhysicalWebCollectionViewController |
| 279 shouldEnableForPreferenceState:preferenceState]; |
| 280 NSString* detailText = enabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 281 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 282 return [self detailItemWithType:ItemTypeWebServicesPhysicalWeb |
| 283 titleId:IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB |
| 284 detailText:detailText]; |
| 285 } |
| 286 |
| 287 - (CollectionViewItem*)contextualSearchDetailItem { |
| 288 _touchToSearchPermissions.reset([[TouchToSearchPermissionsMediator alloc] |
| 289 initWithBrowserState:_browserState]); |
| 290 NSString* detailText = |
| 291 [_touchToSearchPermissions preferenceState] == TouchToSearch::DISABLED |
| 292 ? l10n_util::GetNSString(IDS_IOS_SETTING_OFF) |
| 293 : l10n_util::GetNSString(IDS_IOS_SETTING_ON); |
| 294 return [self detailItemWithType:ItemTypeWebServicesTouchToSearch |
| 295 titleId:IDS_IOS_CONTEXTUAL_SEARCH_TITLE |
| 296 detailText:detailText]; |
| 297 } |
| 298 |
| 299 - (CollectionViewItem*)doNotTrackDetailItem { |
| 300 NSString* detailText = |
| 301 _browserState->GetPrefs()->GetBoolean(prefs::kEnableDoNotTrack) |
| 302 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 303 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 304 return [self detailItemWithType:ItemTypeWebServicesDoNotTrack |
| 305 titleId:IDS_IOS_OPTIONS_DO_NOT_TRACK_MOBILE |
| 306 detailText:detailText]; |
| 307 } |
| 308 |
| 309 - (CollectionViewDetailItem*)detailItemWithType:(NSInteger)type |
| 310 titleId:(NSInteger)titleId |
| 311 detailText:(NSString*)detailText { |
| 312 CollectionViewDetailItem* detailItem = |
| 313 [[[CollectionViewDetailItem alloc] initWithType:type] autorelease]; |
| 314 detailItem.text = l10n_util::GetNSString(titleId); |
| 315 detailItem.detailText = detailText; |
| 316 detailItem.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 317 detailItem.accessibilityTraits |= UIAccessibilityTraitButton; |
| 318 |
| 319 return detailItem; |
| 320 } |
| 321 |
| 322 #pragma mark UICollectionViewDataSource |
| 323 |
| 324 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
| 325 cellForItemAtIndexPath:(NSIndexPath*)indexPath { |
| 326 UICollectionViewCell* cell = |
| 327 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; |
| 328 |
| 329 NSInteger itemType = |
| 330 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 331 |
| 332 if (itemType == ItemTypeWebServicesShowSuggestions) { |
| 333 CollectionViewSwitchCell* switchCell = |
| 334 base::mac::ObjCCastStrict<CollectionViewSwitchCell>(cell); |
| 335 [switchCell.switchView addTarget:self |
| 336 action:@selector(showSuggestionsToggled:) |
| 337 forControlEvents:UIControlEventValueChanged]; |
| 338 } |
| 339 |
| 340 return cell; |
| 341 } |
| 342 |
| 343 - (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView |
| 344 viewForSupplementaryElementOfKind:(NSString*)kind |
| 345 atIndexPath:(NSIndexPath*)indexPath { |
| 346 UICollectionReusableView* view = [super collectionView:collectionView |
| 347 viewForSupplementaryElementOfKind:kind |
| 348 atIndexPath:indexPath]; |
| 349 |
| 350 MDCCollectionViewTextCell* textCell = |
| 351 base::mac::ObjCCast<MDCCollectionViewTextCell>(view); |
| 352 if (textCell) { |
| 353 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 354 } |
| 355 return view; |
| 356 } |
| 357 |
| 358 #pragma mark UICollectionViewDelegate |
| 359 - (void)collectionView:(UICollectionView*)collectionView |
| 360 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| 361 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
| 362 NSInteger itemType = |
| 363 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 364 |
| 365 // Items that push a new view controller. |
| 366 base::scoped_nsobject<UIViewController> controller; |
| 367 |
| 368 switch (itemType) { |
| 369 case ItemTypeOtherDevicesHandoff: |
| 370 controller.reset([[HandoffCollectionViewController alloc] |
| 371 initWithBrowserState:_browserState]); |
| 372 break; |
| 373 case ItemTypeWebServicesTouchToSearch: |
| 374 controller.reset([[ContextualSearchCollectionViewController alloc] |
| 375 initWithPermissions:_touchToSearchPermissions]); |
| 376 break; |
| 377 case ItemTypeWebServicesSendUsageData: |
| 378 controller.reset([[DataplanUsageCollectionViewController alloc] |
| 379 initWithPrefs:GetApplicationContext()->GetLocalState() |
| 380 basePref:metrics::prefs::kMetricsReportingEnabled |
| 381 wifiPref:prefs::kMetricsReportingWifiOnly |
| 382 title:l10n_util::GetNSString( |
| 383 IDS_IOS_OPTIONS_SEND_USAGE_DATA)]); |
| 384 break; |
| 385 case ItemTypeWebServicesDoNotTrack: |
| 386 controller.reset([[DoNotTrackCollectionViewController alloc] |
| 387 initWithPrefs:_browserState->GetPrefs()]); |
| 388 break; |
| 389 case ItemTypeWebServicesPhysicalWeb: |
| 390 controller.reset([[PhysicalWebCollectionViewController alloc] |
| 391 initWithPrefs:GetApplicationContext()->GetLocalState()]); |
| 392 break; |
| 393 case ItemTypeClearBrowsingDataClear: |
| 394 controller.reset([[ClearBrowsingDataCollectionViewController alloc] |
| 395 initWithBrowserState:_browserState]); |
| 396 break; |
| 397 case ItemTypeWebServicesShowSuggestions: |
| 398 default: |
| 399 break; |
| 400 } |
| 401 |
| 402 if (controller.get()) { |
| 403 [self.navigationController pushViewController:controller animated:YES]; |
| 404 } |
| 405 } |
| 406 |
| 407 #pragma mark MDCCollectionViewStylingDelegate |
| 408 |
| 409 - (BOOL)collectionView:(UICollectionView*)collectionView |
| 410 shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath { |
| 411 NSInteger sectionIdentifier = |
| 412 [self.collectionViewModel sectionIdentifierForSection:indexPath.section]; |
| 413 |
| 414 if (sectionIdentifier == SectionIdentifierWebServicesFooter) { |
| 415 return YES; |
| 416 } |
| 417 return NO; |
| 418 } |
| 419 |
| 420 - (BOOL)collectionView:(UICollectionView*)collectionView |
| 421 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
| 422 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 423 switch (type) { |
| 424 case ItemTypeWebServicesFooter: |
| 425 case ItemTypeWebServicesShowSuggestions: |
| 426 return YES; |
| 427 default: |
| 428 return NO; |
| 429 } |
| 430 } |
| 431 |
| 432 - (CGFloat)collectionView:(UICollectionView*)collectionView |
| 433 cellHeightAtIndexPath:(NSIndexPath*)indexPath { |
| 434 CollectionViewItem* item = |
| 435 [self.collectionViewModel itemAtIndexPath:indexPath]; |
| 436 |
| 437 if (item.type == ItemTypeWebServicesFooter) |
| 438 return [MDCCollectionViewCell |
| 439 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
| 440 forItem:item]; |
| 441 return MDCCellDefaultOneLineHeight; |
| 442 } |
| 443 |
| 444 - (MDCCollectionViewCellStyle)collectionView:(UICollectionView*)collectionView |
| 445 cellStyleForSection:(NSInteger)section { |
| 446 NSInteger sectionIdentifier = |
| 447 [self.collectionViewModel sectionIdentifierForSection:section]; |
| 448 |
| 449 if (sectionIdentifier == SectionIdentifierWebServicesFooter) { |
| 450 return MDCCollectionViewCellStyleDefault; |
| 451 } |
| 452 |
| 453 return self.styler.cellStyle; |
| 454 } |
| 455 |
| 456 #pragma mark - BooleanObserver |
| 457 |
| 458 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { |
| 459 DCHECK_EQ(observableBoolean, _suggestionsEnabled.get()); |
| 460 |
| 461 // Update the item. |
| 462 _showSuggestionsItem.get().on = [_suggestionsEnabled value]; |
| 463 |
| 464 // Update the cell. |
| 465 [self reconfigureCellsForItems:@[ _showSuggestionsItem ] |
| 466 inSectionWithIdentifier:SectionIdentifierWebServices]; |
| 467 } |
| 468 |
| 469 #pragma mark - Actions |
| 470 |
| 471 - (void)showSuggestionsToggled:(UISwitch*)sender { |
| 472 NSIndexPath* switchPath = [self.collectionViewModel |
| 473 indexPathForItemType:ItemTypeWebServicesShowSuggestions |
| 474 sectionIdentifier:SectionIdentifierWebServices]; |
| 475 |
| 476 CollectionViewSwitchItem* switchItem = |
| 477 base::mac::ObjCCastStrict<CollectionViewSwitchItem>( |
| 478 [self.collectionViewModel itemAtIndexPath:switchPath]); |
| 479 CollectionViewSwitchCell* switchCell = |
| 480 base::mac::ObjCCastStrict<CollectionViewSwitchCell>( |
| 481 [self.collectionView cellForItemAtIndexPath:switchPath]); |
| 482 |
| 483 DCHECK_EQ(switchCell.switchView, sender); |
| 484 BOOL isOn = switchCell.switchView.isOn; |
| 485 switchItem.on = isOn; |
| 486 [_suggestionsEnabled setValue:isOn]; |
| 487 } |
| 488 |
| 489 #pragma mark - PrefObserverDelegate |
| 490 |
| 491 - (void)onPreferenceChanged:(const std::string&)preferenceName { |
| 492 if (preferenceName == prefs::kIosHandoffToOtherDevices) { |
| 493 NSString* detailText = |
| 494 _browserState->GetPrefs()->GetBoolean(prefs::kIosHandoffToOtherDevices) |
| 495 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 496 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 497 _handoffDetailItem.get().detailText = detailText; |
| 498 [self reconfigureCellsForItems:@[ _handoffDetailItem ] |
| 499 inSectionWithIdentifier:SectionIdentifierOtherDevices]; |
| 500 return; |
| 501 } |
| 502 |
| 503 if (preferenceName == metrics::prefs::kMetricsReportingEnabled || |
| 504 preferenceName == prefs::kMetricsReportingWifiOnly) { |
| 505 NSString* detailText = [DataplanUsageCollectionViewController |
| 506 currentLabelForPreference:GetApplicationContext()->GetLocalState() |
| 507 basePref:metrics::prefs::kMetricsReportingEnabled |
| 508 wifiPref:prefs::kMetricsReportingWifiOnly]; |
| 509 |
| 510 _sendUsageDetailItem.get().detailText = detailText; |
| 511 |
| 512 [self reconfigureCellsForItems:@[ _sendUsageDetailItem ] |
| 513 inSectionWithIdentifier:SectionIdentifierWebServices]; |
| 514 return; |
| 515 } |
| 516 } |
| 517 |
| 518 @end |
OLD | NEW |