| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/settings/block_popups_collection_view_controller.
h" | 5 #import "ios/chrome/browser/ui/settings/block_popups_collection_view_controller.
h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac/foundation_util.h" | 8 #import "base/mac/foundation_util.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "components/content_settings/core/browser/host_content_settings_map.h" | 11 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 12 #include "components/content_settings/core/common/content_settings_pattern.h" | 12 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 14 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory.
h" | 14 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory.
h" |
| 15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" | 15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" |
| 16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h
" |
| 16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
| 17 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 18 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 18 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" | 19 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" |
| 19 #import "ios/chrome/browser/ui/settings/utils/content_setting_backed_boolean.h" | 20 #import "ios/chrome/browser/ui/settings/utils/content_setting_backed_boolean.h" |
| 20 #include "ios/chrome/grit/ios_strings.h" | 21 #include "ios/chrome/grit/ios_strings.h" |
| 21 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 22 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 23 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/l10n/l10n_util_mac.h" | 25 #include "ui/base/l10n/l10n_util_mac.h" |
| 24 | 26 |
| 25 #if !defined(__has_feature) || !__has_feature(objc_arc) | 27 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 26 #error "This file requires ARC support." | 28 #error "This file requires ARC support." |
| 27 #endif | 29 #endif |
| 28 | 30 |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 33 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return YES; | 130 return YES; |
| 129 } | 131 } |
| 130 | 132 |
| 131 #pragma mark - UICollectionViewDataSource | 133 #pragma mark - UICollectionViewDataSource |
| 132 | 134 |
| 133 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | 135 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
| 134 cellForItemAtIndexPath:(NSIndexPath*)indexPath { | 136 cellForItemAtIndexPath:(NSIndexPath*)indexPath { |
| 135 UICollectionViewCell* cell = | 137 UICollectionViewCell* cell = |
| 136 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; | 138 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; |
| 137 | 139 |
| 138 if ([self.collectionViewModel itemTypeForIndexPath:indexPath] == | 140 NSInteger itemType = |
| 139 ItemTypeMainSwitch) { | 141 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 142 if (itemType == ItemTypeMainSwitch) { |
| 140 CollectionViewSwitchCell* switchCell = | 143 CollectionViewSwitchCell* switchCell = |
| 141 base::mac::ObjCCastStrict<CollectionViewSwitchCell>(cell); | 144 base::mac::ObjCCastStrict<CollectionViewSwitchCell>(cell); |
| 142 [switchCell.switchView addTarget:self | 145 [switchCell.switchView addTarget:self |
| 143 action:@selector(blockPopupsSwitchChanged:) | 146 action:@selector(blockPopupsSwitchChanged:) |
| 144 forControlEvents:UIControlEventValueChanged]; | 147 forControlEvents:UIControlEventValueChanged]; |
| 148 } else if (itemType == ItemTypeHeader || itemType == ItemTypeException) { |
| 149 CollectionViewTextCell* textCell = |
| 150 base::mac::ObjCCastStrict<CollectionViewTextCell>(cell); |
| 151 textCell.textLabel.font = [MDCTypography body2Font]; |
| 152 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 153 textCell.detailTextLabel.font = [MDCTypography body1Font]; |
| 154 textCell.detailTextLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 145 } | 155 } |
| 146 return cell; | 156 return cell; |
| 147 } | 157 } |
| 148 | 158 |
| 149 #pragma mark - MDCCollectionViewEditingDelegate | 159 #pragma mark - MDCCollectionViewEditingDelegate |
| 150 | 160 |
| 151 - (BOOL)collectionView:(UICollectionView*)collectionView | 161 - (BOOL)collectionView:(UICollectionView*)collectionView |
| 152 canEditItemAtIndexPath:(NSIndexPath*)indexPath { | 162 canEditItemAtIndexPath:(NSIndexPath*)indexPath { |
| 153 // Any item in SectionIdentifierExceptions is editable. | 163 // Any item in SectionIdentifierExceptions is editable. |
| 154 return [self.collectionViewModel | 164 return [self.collectionViewModel |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 299 } |
| 290 } | 300 } |
| 291 | 301 |
| 292 - (void)populateExceptionsItems { | 302 - (void)populateExceptionsItems { |
| 293 CollectionViewModel* model = self.collectionViewModel; | 303 CollectionViewModel* model = self.collectionViewModel; |
| 294 [model addSectionWithIdentifier:SectionIdentifierExceptions]; | 304 [model addSectionWithIdentifier:SectionIdentifierExceptions]; |
| 295 | 305 |
| 296 CollectionViewTextItem* header = | 306 CollectionViewTextItem* header = |
| 297 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; | 307 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; |
| 298 header.text = l10n_util::GetNSString(IDS_IOS_POPUPS_ALLOWED); | 308 header.text = l10n_util::GetNSString(IDS_IOS_POPUPS_ALLOWED); |
| 299 header.textColor = [[MDCPalette greyPalette] tint500]; | |
| 300 [model setHeader:header forSectionWithIdentifier:SectionIdentifierExceptions]; | 309 [model setHeader:header forSectionWithIdentifier:SectionIdentifierExceptions]; |
| 301 | 310 |
| 302 for (size_t i = 0; i < _exceptions.GetSize(); ++i) { | 311 for (size_t i = 0; i < _exceptions.GetSize(); ++i) { |
| 303 std::string allowed_url; | 312 std::string allowed_url; |
| 304 _exceptions.GetString(i, &allowed_url); | 313 _exceptions.GetString(i, &allowed_url); |
| 305 CollectionViewTextItem* item = | 314 CollectionViewTextItem* item = |
| 306 [[CollectionViewTextItem alloc] initWithType:ItemTypeException]; | 315 [[CollectionViewTextItem alloc] initWithType:ItemTypeException]; |
| 307 item.text = base::SysUTF8ToNSString(allowed_url); | 316 item.text = base::SysUTF8ToNSString(allowed_url); |
| 308 [model addItem:item toSectionWithIdentifier:SectionIdentifierExceptions]; | 317 [model addItem:item toSectionWithIdentifier:SectionIdentifierExceptions]; |
| 309 } | 318 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 [[strongSelf collectionViewModel] | 350 [[strongSelf collectionViewModel] |
| 342 removeSectionWithIdentifier:SectionIdentifierExceptions]; | 351 removeSectionWithIdentifier:SectionIdentifierExceptions]; |
| 343 [[strongSelf collectionView] | 352 [[strongSelf collectionView] |
| 344 deleteSections:[NSIndexSet indexSetWithIndex:index]]; | 353 deleteSections:[NSIndexSet indexSetWithIndex:index]]; |
| 345 } | 354 } |
| 346 completion:nil]; | 355 completion:nil]; |
| 347 } | 356 } |
| 348 } | 357 } |
| 349 | 358 |
| 350 @end | 359 @end |
| OLD | NEW |