Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/content_settings_collection_view_control ler.h" | 5 #import "ios/chrome/browser/ui/settings/content_settings_collection_view_control ler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "components/content_settings/core/browser/host_content_settings_map.h" | 8 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 9 #include "components/content_settings/core/common/content_settings.h" | 9 #include "components/content_settings/core/common/content_settings.h" |
| 10 #include "components/content_settings/core/common/content_settings_types.h" | 10 #include "components/content_settings/core/common/content_settings_types.h" |
| 11 #include "components/prefs/pref_change_registrar.h" | 11 #include "components/prefs/pref_change_registrar.h" |
| 12 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
| 13 #include "components/strings/grit/components_strings.h" | 13 #include "components/strings/grit/components_strings.h" |
| 14 #include "components/translate/core/browser/translate_pref_names.h" | 14 #include "components/translate/core/browser/translate_pref_names.h" |
| 15 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 15 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 16 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory. h" | 16 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory. h" |
| 17 #include "ios/chrome/browser/experimental_flags.h" | |
| 17 #import "ios/chrome/browser/prefs/pref_observer_bridge.h" | 18 #import "ios/chrome/browser/prefs/pref_observer_bridge.h" |
| 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" | 19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" |
| 19 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 20 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 20 #import "ios/chrome/browser/ui/settings/block_popups_collection_view_controller. h" | 21 #import "ios/chrome/browser/ui/settings/block_popups_collection_view_controller. h" |
| 22 #import "ios/chrome/browser/ui/settings/compose_email_handler_collection_view_co ntroller.h" | |
| 21 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" | 23 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" |
| 22 #import "ios/chrome/browser/ui/settings/translate_collection_view_controller.h" | 24 #import "ios/chrome/browser/ui/settings/translate_collection_view_controller.h" |
| 23 #import "ios/chrome/browser/ui/settings/utils/content_setting_backed_boolean.h" | 25 #import "ios/chrome/browser/ui/settings/utils/content_setting_backed_boolean.h" |
| 24 #include "ios/chrome/grit/ios_strings.h" | 26 #include "ios/chrome/grit/ios_strings.h" |
| 25 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h" | 27 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h" |
| 26 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" | 28 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/l10n/l10n_util_mac.h" | 30 #include "ui/base/l10n/l10n_util_mac.h" |
| 29 | 31 |
| 30 #if !defined(__has_feature) || !__has_feature(objc_arc) | 32 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 31 #error "This file requires ARC support." | 33 #error "This file requires ARC support." |
| 32 #endif | 34 #endif |
| 33 | 35 |
| 34 namespace { | 36 namespace { |
| 35 | 37 |
| 36 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 38 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 37 SectionIdentifierSettings = kSectionIdentifierEnumZero, | 39 SectionIdentifierSettings = kSectionIdentifierEnumZero, |
| 38 }; | 40 }; |
| 39 | 41 |
| 40 typedef NS_ENUM(NSInteger, ItemType) { | 42 typedef NS_ENUM(NSInteger, ItemType) { |
| 41 ItemTypeSettingsBlockPopups = kItemTypeEnumZero, | 43 ItemTypeSettingsBlockPopups = kItemTypeEnumZero, |
| 42 ItemTypeSettingsTranslate, | 44 ItemTypeSettingsTranslate, |
| 45 ItemTypeSettingsComposeEmail, | |
| 43 }; | 46 }; |
| 44 | 47 |
| 45 } // namespace | 48 } // namespace |
| 46 | 49 |
| 47 @interface ContentSettingsCollectionViewController ()<PrefObserverDelegate, | 50 @interface ContentSettingsCollectionViewController ()<PrefObserverDelegate, |
| 48 BooleanObserver> { | 51 BooleanObserver> { |
| 49 // Pref observer to track changes to prefs. | 52 // Pref observer to track changes to prefs. |
| 50 std::unique_ptr<PrefObserverBridge> _prefObserverBridge; | 53 std::unique_ptr<PrefObserverBridge> _prefObserverBridge; |
| 51 // Registrar for pref changes notifications. | 54 // Registrar for pref changes notifications. |
| 52 PrefChangeRegistrar _prefChangeRegistrar; | 55 PrefChangeRegistrar _prefChangeRegistrar; |
| 53 | 56 |
| 54 // The observable boolean that binds to the "Disable Popups" setting state. | 57 // The observable boolean that binds to the "Disable Popups" setting state. |
| 55 ContentSettingBackedBoolean* _disablePopupsSetting; | 58 ContentSettingBackedBoolean* _disablePopupsSetting; |
| 56 | 59 |
| 60 // This object contains the list of available Mail client apps that can | |
| 61 // handle mailto: URLs. The value can be nil if mailto: URL rewriting is | |
| 62 // not available because of experimental settings. | |
| 63 MailtoURLRewriter* _mailtoURLRewriter; | |
| 64 | |
| 57 // Updatable Items | 65 // Updatable Items |
| 58 CollectionViewDetailItem* _blockPopupsDetailItem; | 66 CollectionViewDetailItem* _blockPopupsDetailItem; |
| 59 CollectionViewDetailItem* _translateDetailItem; | 67 CollectionViewDetailItem* _translateDetailItem; |
| 68 CollectionViewDetailItem* _composeEmailDetailItem; | |
| 60 } | 69 } |
| 61 | 70 |
| 62 // Returns the value for the default setting with ID |settingID|. | 71 // Returns the value for the default setting with ID |settingID|. |
| 63 - (ContentSetting)getContentSetting:(ContentSettingsType)settingID; | 72 - (ContentSetting)getContentSetting:(ContentSettingsType)settingID; |
| 64 | 73 |
| 65 // Helpers to create collection view items. | 74 // Helpers to create collection view items. |
| 66 - (id)blockPopupsItem; | 75 - (id)blockPopupsItem; |
| 67 - (id)translateItem; | 76 - (id)translateItem; |
| 77 - (id)composeEmailItem; | |
| 68 | 78 |
| 69 @end | 79 @end |
| 70 | 80 |
| 71 @implementation ContentSettingsCollectionViewController { | 81 @implementation ContentSettingsCollectionViewController { |
| 72 ios::ChromeBrowserState* browserState_; // weak | 82 ios::ChromeBrowserState* browserState_; // weak |
| 73 } | 83 } |
| 74 | 84 |
| 75 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { | 85 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { |
| 76 DCHECK(browserState); | 86 DCHECK(browserState); |
| 77 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; | 87 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |
| 78 if (self) { | 88 if (self) { |
| 79 browserState_ = browserState; | 89 browserState_ = browserState; |
| 80 self.title = l10n_util::GetNSString(IDS_IOS_CONTENT_SETTINGS_TITLE); | 90 self.title = l10n_util::GetNSString(IDS_IOS_CONTENT_SETTINGS_TITLE); |
| 81 | 91 |
| 82 _prefChangeRegistrar.Init(browserState->GetPrefs()); | 92 _prefChangeRegistrar.Init(browserState->GetPrefs()); |
| 83 _prefObserverBridge.reset(new PrefObserverBridge(self)); | 93 _prefObserverBridge.reset(new PrefObserverBridge(self)); |
| 84 // Register to observe any changes on Perf backed values displayed by the | 94 // Register to observe any changes on Perf backed values displayed by the |
| 85 // screen. | 95 // screen. |
| 86 _prefObserverBridge->ObserveChangesForPreference(prefs::kEnableTranslate, | 96 _prefObserverBridge->ObserveChangesForPreference(prefs::kEnableTranslate, |
| 87 &_prefChangeRegistrar); | 97 &_prefChangeRegistrar); |
| 88 | 98 |
| 89 HostContentSettingsMap* settingsMap = | 99 HostContentSettingsMap* settingsMap = |
| 90 ios::HostContentSettingsMapFactory::GetForBrowserState(browserState); | 100 ios::HostContentSettingsMapFactory::GetForBrowserState(browserState); |
| 91 _disablePopupsSetting = [[ContentSettingBackedBoolean alloc] | 101 _disablePopupsSetting = [[ContentSettingBackedBoolean alloc] |
| 92 initWithHostContentSettingsMap:settingsMap | 102 initWithHostContentSettingsMap:settingsMap |
| 93 settingID:CONTENT_SETTINGS_TYPE_POPUPS | 103 settingID:CONTENT_SETTINGS_TYPE_POPUPS |
| 94 inverted:YES]; | 104 inverted:YES]; |
| 95 [_disablePopupsSetting setObserver:self]; | 105 [_disablePopupsSetting setObserver:self]; |
| 96 | 106 |
| 107 if (!experimental_flags::IsNativeAppLauncherEnabled()) { | |
| 108 _mailtoURLRewriter = [[MailtoURLRewriter alloc] initWithStandardHandlers]; | |
| 109 [_mailtoURLRewriter setObserver:self]; | |
| 110 } | |
| 111 | |
| 97 [self loadModel]; | 112 [self loadModel]; |
| 98 } | 113 } |
| 99 return self; | 114 return self; |
| 100 } | 115 } |
| 101 | 116 |
| 102 - (void)dealloc { | 117 - (void)dealloc { |
| 103 [_disablePopupsSetting setObserver:nil]; | 118 [_disablePopupsSetting setObserver:nil]; |
| 104 } | 119 } |
| 105 | 120 |
| 106 - (instancetype)init { | 121 - (instancetype)init { |
| 107 NOTREACHED(); | 122 NOTREACHED(); |
| 108 return nil; | 123 return nil; |
| 109 } | 124 } |
| 110 | 125 |
| 111 - (void)loadModel { | 126 - (void)loadModel { |
| 112 [super loadModel]; | 127 [super loadModel]; |
| 113 | 128 |
| 114 CollectionViewModel* model = self.collectionViewModel; | 129 CollectionViewModel* model = self.collectionViewModel; |
| 115 [model addSectionWithIdentifier:SectionIdentifierSettings]; | 130 [model addSectionWithIdentifier:SectionIdentifierSettings]; |
| 116 [model addItem:[self blockPopupsItem] | 131 [model addItem:[self blockPopupsItem] |
| 117 toSectionWithIdentifier:SectionIdentifierSettings]; | 132 toSectionWithIdentifier:SectionIdentifierSettings]; |
| 118 [model addItem:[self translateItem] | 133 [model addItem:[self translateItem] |
| 119 toSectionWithIdentifier:SectionIdentifierSettings]; | 134 toSectionWithIdentifier:SectionIdentifierSettings]; |
| 135 if (!experimental_flags::IsNativeAppLauncherEnabled() && | |
| 136 [[_mailtoURLRewriter defaultHandlers] count] > 1) { | |
|
rohitrao (ping after 24h)
2017/05/12 01:57:57
Consider always adding this page, rather than hidi
pkl (ping after 24h if needed)
2017/05/12 18:01:20
Acknowledged.
| |
| 137 [model addItem:[self composeEmailItem] | |
| 138 toSectionWithIdentifier:SectionIdentifierSettings]; | |
| 139 } | |
| 120 } | 140 } |
| 121 | 141 |
| 122 - (CollectionViewItem*)blockPopupsItem { | 142 - (CollectionViewItem*)blockPopupsItem { |
| 123 _blockPopupsDetailItem = [[CollectionViewDetailItem alloc] | 143 _blockPopupsDetailItem = [[CollectionViewDetailItem alloc] |
| 124 initWithType:ItemTypeSettingsBlockPopups]; | 144 initWithType:ItemTypeSettingsBlockPopups]; |
| 125 NSString* subtitle = [_disablePopupsSetting value] | 145 NSString* subtitle = [_disablePopupsSetting value] |
| 126 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 146 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 127 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 147 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 128 _blockPopupsDetailItem.text = l10n_util::GetNSString(IDS_IOS_BLOCK_POPUPS); | 148 _blockPopupsDetailItem.text = l10n_util::GetNSString(IDS_IOS_BLOCK_POPUPS); |
| 129 _blockPopupsDetailItem.detailText = subtitle; | 149 _blockPopupsDetailItem.detailText = subtitle; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 140 NSString* subtitle = enabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 160 NSString* subtitle = enabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 141 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 161 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 142 _translateDetailItem.text = l10n_util::GetNSString(IDS_IOS_TRANSLATE_SETTING); | 162 _translateDetailItem.text = l10n_util::GetNSString(IDS_IOS_TRANSLATE_SETTING); |
| 143 _translateDetailItem.detailText = subtitle; | 163 _translateDetailItem.detailText = subtitle; |
| 144 _translateDetailItem.accessoryType = | 164 _translateDetailItem.accessoryType = |
| 145 MDCCollectionViewCellAccessoryDisclosureIndicator; | 165 MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 146 _translateDetailItem.accessibilityTraits |= UIAccessibilityTraitButton; | 166 _translateDetailItem.accessibilityTraits |= UIAccessibilityTraitButton; |
| 147 return _translateDetailItem; | 167 return _translateDetailItem; |
| 148 } | 168 } |
| 149 | 169 |
| 170 - (CollectionViewItem*)composeEmailItem { | |
| 171 _composeEmailDetailItem = [[CollectionViewDetailItem alloc] | |
| 172 initWithType:ItemTypeSettingsComposeEmail]; | |
| 173 _composeEmailDetailItem.text = | |
| 174 l10n_util::GetNSString(IDS_IOS_COMPOSE_EMAIL_SETTING); | |
| 175 _composeEmailDetailItem.detailText = [_mailtoURLRewriter defaultHandlerName]; | |
| 176 _composeEmailDetailItem.accessoryType = | |
| 177 MDCCollectionViewCellAccessoryDisclosureIndicator; | |
| 178 _composeEmailDetailItem.accessibilityTraits |= UIAccessibilityTraitButton; | |
| 179 return _composeEmailDetailItem; | |
| 180 } | |
| 181 | |
| 150 - (ContentSetting)getContentSetting:(ContentSettingsType)settingID { | 182 - (ContentSetting)getContentSetting:(ContentSettingsType)settingID { |
| 151 return ios::HostContentSettingsMapFactory::GetForBrowserState(browserState_) | 183 return ios::HostContentSettingsMapFactory::GetForBrowserState(browserState_) |
| 152 ->GetDefaultContentSetting(settingID, NULL); | 184 ->GetDefaultContentSetting(settingID, NULL); |
| 153 } | 185 } |
| 154 | 186 |
| 155 #pragma mark - UICollectionViewDelegate | 187 #pragma mark - UICollectionViewDelegate |
| 156 | 188 |
| 157 - (void)collectionView:(UICollectionView*)collectionView | 189 - (void)collectionView:(UICollectionView*)collectionView |
| 158 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 190 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| 159 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 191 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
| 160 | 192 |
| 161 NSInteger itemType = | 193 NSInteger itemType = |
| 162 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 194 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 163 switch (itemType) { | 195 switch (itemType) { |
| 164 case ItemTypeSettingsBlockPopups: { | 196 case ItemTypeSettingsBlockPopups: { |
| 165 UIViewController* controller = | 197 UIViewController* controller = |
| 166 [[BlockPopupsCollectionViewController alloc] | 198 [[BlockPopupsCollectionViewController alloc] |
| 167 initWithBrowserState:browserState_]; | 199 initWithBrowserState:browserState_]; |
| 168 [self.navigationController pushViewController:controller animated:YES]; | 200 [self.navigationController pushViewController:controller animated:YES]; |
| 169 break; | 201 break; |
| 170 } | 202 } |
| 171 case ItemTypeSettingsTranslate: { | 203 case ItemTypeSettingsTranslate: { |
| 172 UIViewController* controller = [[TranslateCollectionViewController alloc] | 204 UIViewController* controller = [[TranslateCollectionViewController alloc] |
| 173 initWithPrefs:browserState_->GetPrefs()]; | 205 initWithPrefs:browserState_->GetPrefs()]; |
| 174 [self.navigationController pushViewController:controller animated:YES]; | 206 [self.navigationController pushViewController:controller animated:YES]; |
| 175 break; | 207 break; |
| 176 } | 208 } |
| 209 case ItemTypeSettingsComposeEmail: { | |
| 210 UIViewController* controller = | |
| 211 [[ComposeEmailHandlerCollectionViewController alloc] | |
| 212 initWithRewriter:_mailtoURLRewriter]; | |
| 213 [self.navigationController pushViewController:controller animated:YES]; | |
| 214 break; | |
| 215 } | |
| 177 } | 216 } |
| 178 } | 217 } |
| 179 | 218 |
| 180 #pragma mark - PrefObserverDelegate | 219 #pragma mark - PrefObserverDelegate |
| 181 | 220 |
| 182 - (void)onPreferenceChanged:(const std::string&)preferenceName { | 221 - (void)onPreferenceChanged:(const std::string&)preferenceName { |
| 183 if (preferenceName == prefs::kEnableTranslate) { | 222 if (preferenceName == prefs::kEnableTranslate) { |
| 184 BOOL enabled = browserState_->GetPrefs()->GetBoolean(preferenceName); | 223 BOOL enabled = browserState_->GetPrefs()->GetBoolean(preferenceName); |
| 185 NSString* subtitle = enabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 224 NSString* subtitle = enabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 186 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 225 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 197 NSString* subtitle = [_disablePopupsSetting value] | 236 NSString* subtitle = [_disablePopupsSetting value] |
| 198 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 237 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 199 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 238 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 200 // Update the item. | 239 // Update the item. |
| 201 _blockPopupsDetailItem.detailText = subtitle; | 240 _blockPopupsDetailItem.detailText = subtitle; |
| 202 | 241 |
| 203 // Update the cell. | 242 // Update the cell. |
| 204 [self reconfigureCellsForItems:@[ _blockPopupsDetailItem ]]; | 243 [self reconfigureCellsForItems:@[ _blockPopupsDetailItem ]]; |
| 205 } | 244 } |
| 206 | 245 |
| 246 #pragma mark - MailtoURLRewriterObserver | |
| 247 | |
| 248 - (void)rewriterDidChange:(MailtoURLRewriter*)rewriter { | |
| 249 if (rewriter != _mailtoURLRewriter) | |
| 250 return; | |
| 251 _composeEmailDetailItem.detailText = [rewriter defaultHandlerName]; | |
| 252 [self reconfigureCellsForItems:@[ _composeEmailDetailItem ]]; | |
| 253 } | |
| 254 | |
| 207 @end | 255 @end |
| OLD | NEW |