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/privacy_collection_view_controller.h" | 5 #import "ios/chrome/browser/ui/settings/privacy_collection_view_controller.h" |
6 | 6 |
7 #include "base/ios/ios_util.h" | 7 #include "base/ios/ios_util.h" |
8 #import "base/ios/weak_nsobject.h" | |
9 #include "base/logging.h" | 8 #include "base/logging.h" |
10 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
11 #import "base/mac/scoped_nsobject.h" | |
12 #include "components/google/core/browser/google_util.h" | 10 #include "components/google/core/browser/google_util.h" |
13 #include "components/handoff/pref_names_ios.h" | 11 #include "components/handoff/pref_names_ios.h" |
14 #include "components/metrics/metrics_pref_names.h" | 12 #include "components/metrics/metrics_pref_names.h" |
15 #include "components/prefs/pref_change_registrar.h" | 13 #include "components/prefs/pref_change_registrar.h" |
16 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
17 #include "components/signin/core/browser/signin_manager.h" | 15 #include "components/signin/core/browser/signin_manager.h" |
18 #include "components/strings/grit/components_strings.h" | 16 #include "components/strings/grit/components_strings.h" |
19 #include "ios/chrome/browser/application_context.h" | 17 #include "ios/chrome/browser/application_context.h" |
20 #import "ios/chrome/browser/autofill/autofill_controller.h" | 18 #import "ios/chrome/browser/autofill/autofill_controller.h" |
21 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
(...skipping 21 matching lines...) Expand all Loading... |
43 #import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h" | 41 #import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h" |
44 #include "ios/chrome/browser/ui/ui_util.h" | 42 #include "ios/chrome/browser/ui/ui_util.h" |
45 #include "ios/chrome/grit/ios_chromium_strings.h" | 43 #include "ios/chrome/grit/ios_chromium_strings.h" |
46 #include "ios/chrome/grit/ios_strings.h" | 44 #include "ios/chrome/grit/ios_strings.h" |
47 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 45 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
48 #include "ios/web/public/web_capabilities.h" | 46 #include "ios/web/public/web_capabilities.h" |
49 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
50 #include "ui/base/l10n/l10n_util_mac.h" | 48 #include "ui/base/l10n/l10n_util_mac.h" |
51 #include "url/gurl.h" | 49 #include "url/gurl.h" |
52 | 50 |
| 51 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 52 #error "This file requires ARC support." |
| 53 #endif |
| 54 |
53 NSString* const kPrivacyCollectionViewId = @"kPrivacyCollectionViewId"; | 55 NSString* const kPrivacyCollectionViewId = @"kPrivacyCollectionViewId"; |
54 | 56 |
55 namespace { | 57 namespace { |
56 | 58 |
57 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 59 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
58 SectionIdentifierOtherDevices = kSectionIdentifierEnumZero, | 60 SectionIdentifierOtherDevices = kSectionIdentifierEnumZero, |
59 SectionIdentifierWebServices, | 61 SectionIdentifierWebServices, |
60 SectionIdentifierWebServicesFooter, | 62 SectionIdentifierWebServicesFooter, |
61 SectionIdentifierClearBrowsingData, | 63 SectionIdentifierClearBrowsingData, |
62 }; | 64 }; |
63 | 65 |
64 typedef NS_ENUM(NSInteger, ItemType) { | 66 typedef NS_ENUM(NSInteger, ItemType) { |
65 ItemTypeOtherDevicesHeader = kItemTypeEnumZero, | 67 ItemTypeOtherDevicesHeader = kItemTypeEnumZero, |
66 ItemTypeOtherDevicesHandoff, | 68 ItemTypeOtherDevicesHandoff, |
67 ItemTypeWebServicesHeader, | 69 ItemTypeWebServicesHeader, |
68 ItemTypeWebServicesFooter, | 70 ItemTypeWebServicesFooter, |
69 ItemTypeWebServicesShowSuggestions, | 71 ItemTypeWebServicesShowSuggestions, |
70 ItemTypeWebServicesTouchToSearch, | 72 ItemTypeWebServicesTouchToSearch, |
71 ItemTypeWebServicesSendUsageData, | 73 ItemTypeWebServicesSendUsageData, |
72 ItemTypeWebServicesDoNotTrack, | 74 ItemTypeWebServicesDoNotTrack, |
73 ItemTypeWebServicesPhysicalWeb, | 75 ItemTypeWebServicesPhysicalWeb, |
74 ItemTypeClearBrowsingDataClear, | 76 ItemTypeClearBrowsingDataClear, |
75 }; | 77 }; |
76 | 78 |
77 } // namespace | 79 } // namespace |
78 | 80 |
79 @interface PrivacyCollectionViewController ()<BooleanObserver, | 81 @interface PrivacyCollectionViewController ()<BooleanObserver, |
80 PrefObserverDelegate> { | 82 PrefObserverDelegate> { |
81 ios::ChromeBrowserState* _browserState; // weak | 83 ios::ChromeBrowserState* _browserState; // weak |
82 base::scoped_nsobject<PrefBackedBoolean> _suggestionsEnabled; | 84 PrefBackedBoolean* _suggestionsEnabled; |
83 // The item related to the switch for the show suggestions setting. | 85 // The item related to the switch for the show suggestions setting. |
84 base::scoped_nsobject<CollectionViewSwitchItem> _showSuggestionsItem; | 86 CollectionViewSwitchItem* _showSuggestionsItem; |
85 base::scoped_nsobject<TouchToSearchPermissionsMediator> | 87 TouchToSearchPermissionsMediator* _touchToSearchPermissions; |
86 _touchToSearchPermissions; | |
87 | 88 |
88 // Pref observer to track changes to prefs. | 89 // Pref observer to track changes to prefs. |
89 std::unique_ptr<PrefObserverBridge> _prefObserverBridge; | 90 std::unique_ptr<PrefObserverBridge> _prefObserverBridge; |
90 // Registrar for pref changes notifications. | 91 // Registrar for pref changes notifications. |
91 PrefChangeRegistrar _prefChangeRegistrar; | 92 PrefChangeRegistrar _prefChangeRegistrar; |
92 PrefChangeRegistrar _prefChangeRegistrarApplicationContext; | 93 PrefChangeRegistrar _prefChangeRegistrarApplicationContext; |
93 | 94 |
94 // Updatable Items | 95 // Updatable Items |
95 base::scoped_nsobject<CollectionViewDetailItem> _handoffDetailItem; | 96 CollectionViewDetailItem* _handoffDetailItem; |
96 base::scoped_nsobject<CollectionViewDetailItem> _sendUsageDetailItem; | 97 CollectionViewDetailItem* _sendUsageDetailItem; |
97 } | 98 } |
98 | 99 |
99 // Initialization methods for various model items. | 100 // Initialization methods for various model items. |
100 - (CollectionViewItem*)handoffDetailItem; | 101 - (CollectionViewItem*)handoffDetailItem; |
101 - (CollectionViewSwitchItem*)showSuggestionsSwitchItem; | 102 - (CollectionViewSwitchItem*)showSuggestionsSwitchItem; |
102 - (CollectionViewItem*)showSuggestionsFooterItem; | 103 - (CollectionViewItem*)showSuggestionsFooterItem; |
103 - (CollectionViewItem*)clearBrowsingDetailItem; | 104 - (CollectionViewItem*)clearBrowsingDetailItem; |
104 - (CollectionViewItem*)sendUsageDetailItem; | 105 - (CollectionViewItem*)sendUsageDetailItem; |
105 - (CollectionViewItem*)physicalWebDetailItem; | 106 - (CollectionViewItem*)physicalWebDetailItem; |
106 - (CollectionViewItem*)contextualSearchDetailItem; | 107 - (CollectionViewItem*)contextualSearchDetailItem; |
107 - (CollectionViewItem*)doNotTrackDetailItem; | 108 - (CollectionViewItem*)doNotTrackDetailItem; |
108 | 109 |
109 @end | 110 @end |
110 | 111 |
111 @implementation PrivacyCollectionViewController | 112 @implementation PrivacyCollectionViewController |
112 | 113 |
113 #pragma mark - Initialization | 114 #pragma mark - Initialization |
114 | 115 |
115 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { | 116 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { |
116 DCHECK(browserState); | 117 DCHECK(browserState); |
117 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; | 118 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |
118 if (self) { | 119 if (self) { |
119 _browserState = browserState; | 120 _browserState = browserState; |
120 self.title = | 121 self.title = |
121 l10n_util::GetNSString(IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY); | 122 l10n_util::GetNSString(IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY); |
122 self.collectionViewAccessibilityIdentifier = kPrivacyCollectionViewId; | 123 self.collectionViewAccessibilityIdentifier = kPrivacyCollectionViewId; |
123 _suggestionsEnabled.reset([[PrefBackedBoolean alloc] | 124 _suggestionsEnabled = [[PrefBackedBoolean alloc] |
124 initWithPrefService:_browserState->GetPrefs() | 125 initWithPrefService:_browserState->GetPrefs() |
125 prefName:prefs::kSearchSuggestEnabled]); | 126 prefName:prefs::kSearchSuggestEnabled]; |
126 [_suggestionsEnabled setObserver:self]; | 127 [_suggestionsEnabled setObserver:self]; |
127 | 128 |
128 PrefService* prefService = _browserState->GetPrefs(); | 129 PrefService* prefService = _browserState->GetPrefs(); |
129 | 130 |
130 _prefChangeRegistrar.Init(prefService); | 131 _prefChangeRegistrar.Init(prefService); |
131 _prefChangeRegistrarApplicationContext.Init( | 132 _prefChangeRegistrarApplicationContext.Init( |
132 GetApplicationContext()->GetLocalState()); | 133 GetApplicationContext()->GetLocalState()); |
133 _prefObserverBridge.reset(new PrefObserverBridge(self)); | 134 _prefObserverBridge.reset(new PrefObserverBridge(self)); |
134 // Register to observe any changes on Perf backed values displayed by the | 135 // Register to observe any changes on Perf backed values displayed by the |
135 // screen. | 136 // screen. |
136 _prefObserverBridge->ObserveChangesForPreference( | 137 _prefObserverBridge->ObserveChangesForPreference( |
137 prefs::kIosHandoffToOtherDevices, &_prefChangeRegistrar); | 138 prefs::kIosHandoffToOtherDevices, &_prefChangeRegistrar); |
138 _prefObserverBridge->ObserveChangesForPreference( | 139 _prefObserverBridge->ObserveChangesForPreference( |
139 metrics::prefs::kMetricsReportingEnabled, | 140 metrics::prefs::kMetricsReportingEnabled, |
140 &_prefChangeRegistrarApplicationContext); | 141 &_prefChangeRegistrarApplicationContext); |
141 _prefObserverBridge->ObserveChangesForPreference( | 142 _prefObserverBridge->ObserveChangesForPreference( |
142 prefs::kMetricsReportingWifiOnly, | 143 prefs::kMetricsReportingWifiOnly, |
143 &_prefChangeRegistrarApplicationContext); | 144 &_prefChangeRegistrarApplicationContext); |
144 | 145 |
145 [self loadModel]; | 146 [self loadModel]; |
146 } | 147 } |
147 return self; | 148 return self; |
148 } | 149 } |
149 | 150 |
150 - (void)dealloc { | 151 - (void)dealloc { |
151 [_suggestionsEnabled setObserver:nil]; | 152 [_suggestionsEnabled setObserver:nil]; |
152 [super dealloc]; | |
153 } | 153 } |
154 | 154 |
155 #pragma mark - SettingsRootCollectionViewController | 155 #pragma mark - SettingsRootCollectionViewController |
156 | 156 |
157 - (void)loadModel { | 157 - (void)loadModel { |
158 [super loadModel]; | 158 [super loadModel]; |
159 | 159 |
160 CollectionViewModel* model = self.collectionViewModel; | 160 CollectionViewModel* model = self.collectionViewModel; |
161 | 161 |
162 // Other Devices Section | 162 // Other Devices Section |
163 [model addSectionWithIdentifier:SectionIdentifierOtherDevices]; | 163 [model addSectionWithIdentifier:SectionIdentifierOtherDevices]; |
164 CollectionViewTextItem* otherDevicesHeader = [[[CollectionViewTextItem alloc] | 164 CollectionViewTextItem* otherDevicesHeader = |
165 initWithType:ItemTypeOtherDevicesHeader] autorelease]; | 165 [[CollectionViewTextItem alloc] initWithType:ItemTypeOtherDevicesHeader]; |
166 otherDevicesHeader.text = | 166 otherDevicesHeader.text = |
167 l10n_util::GetNSString(IDS_IOS_OPTIONS_CONTINUITY_LABEL); | 167 l10n_util::GetNSString(IDS_IOS_OPTIONS_CONTINUITY_LABEL); |
168 otherDevicesHeader.textColor = [[MDCPalette greyPalette] tint500]; | 168 otherDevicesHeader.textColor = [[MDCPalette greyPalette] tint500]; |
169 [model setHeader:otherDevicesHeader | 169 [model setHeader:otherDevicesHeader |
170 forSectionWithIdentifier:SectionIdentifierOtherDevices]; | 170 forSectionWithIdentifier:SectionIdentifierOtherDevices]; |
171 [model addItem:[self handoffDetailItem] | 171 [model addItem:[self handoffDetailItem] |
172 toSectionWithIdentifier:SectionIdentifierOtherDevices]; | 172 toSectionWithIdentifier:SectionIdentifierOtherDevices]; |
173 | 173 |
174 // Web Services Section | 174 // Web Services Section |
175 [model addSectionWithIdentifier:SectionIdentifierWebServices]; | 175 [model addSectionWithIdentifier:SectionIdentifierWebServices]; |
176 CollectionViewTextItem* webServicesHeader = [[[CollectionViewTextItem alloc] | 176 CollectionViewTextItem* webServicesHeader = |
177 initWithType:ItemTypeWebServicesHeader] autorelease]; | 177 [[CollectionViewTextItem alloc] initWithType:ItemTypeWebServicesHeader]; |
178 webServicesHeader.text = | 178 webServicesHeader.text = |
179 l10n_util::GetNSString(IDS_IOS_OPTIONS_WEB_SERVICES_LABEL); | 179 l10n_util::GetNSString(IDS_IOS_OPTIONS_WEB_SERVICES_LABEL); |
180 webServicesHeader.textColor = [[MDCPalette greyPalette] tint500]; | 180 webServicesHeader.textColor = [[MDCPalette greyPalette] tint500]; |
181 [model setHeader:webServicesHeader | 181 [model setHeader:webServicesHeader |
182 forSectionWithIdentifier:SectionIdentifierWebServices]; | 182 forSectionWithIdentifier:SectionIdentifierWebServices]; |
183 _showSuggestionsItem.reset([[self showSuggestionsSwitchItem] retain]); | 183 _showSuggestionsItem = [self showSuggestionsSwitchItem]; |
184 [model addItem:_showSuggestionsItem | 184 [model addItem:_showSuggestionsItem |
185 toSectionWithIdentifier:SectionIdentifierWebServices]; | 185 toSectionWithIdentifier:SectionIdentifierWebServices]; |
186 | 186 |
187 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice]) { | 187 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice]) { |
188 [model addItem:[self contextualSearchDetailItem] | 188 [model addItem:[self contextualSearchDetailItem] |
189 toSectionWithIdentifier:SectionIdentifierWebServices]; | 189 toSectionWithIdentifier:SectionIdentifierWebServices]; |
190 } | 190 } |
191 | 191 |
192 [model addItem:[self sendUsageDetailItem] | 192 [model addItem:[self sendUsageDetailItem] |
193 toSectionWithIdentifier:SectionIdentifierWebServices]; | 193 toSectionWithIdentifier:SectionIdentifierWebServices]; |
(...skipping 19 matching lines...) Expand all Loading... |
213 toSectionWithIdentifier:SectionIdentifierClearBrowsingData]; | 213 toSectionWithIdentifier:SectionIdentifierClearBrowsingData]; |
214 } | 214 } |
215 | 215 |
216 #pragma mark - Model Objects | 216 #pragma mark - Model Objects |
217 | 217 |
218 - (CollectionViewItem*)handoffDetailItem { | 218 - (CollectionViewItem*)handoffDetailItem { |
219 NSString* detailText = | 219 NSString* detailText = |
220 _browserState->GetPrefs()->GetBoolean(prefs::kIosHandoffToOtherDevices) | 220 _browserState->GetPrefs()->GetBoolean(prefs::kIosHandoffToOtherDevices) |
221 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 221 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
222 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 222 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
223 _handoffDetailItem.reset( | 223 _handoffDetailItem = |
224 [[self detailItemWithType:ItemTypeOtherDevicesHandoff | 224 [self detailItemWithType:ItemTypeOtherDevicesHandoff |
225 titleId:IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES | 225 titleId:IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES |
226 detailText:detailText] retain]); | 226 detailText:detailText]; |
227 | 227 |
228 return _handoffDetailItem; | 228 return _handoffDetailItem; |
229 } | 229 } |
230 | 230 |
231 - (CollectionViewSwitchItem*)showSuggestionsSwitchItem { | 231 - (CollectionViewSwitchItem*)showSuggestionsSwitchItem { |
232 CollectionViewSwitchItem* showSuggestionsSwitchItem = | 232 CollectionViewSwitchItem* showSuggestionsSwitchItem = |
233 [[[CollectionViewSwitchItem alloc] | 233 [[CollectionViewSwitchItem alloc] |
234 initWithType:ItemTypeWebServicesShowSuggestions] autorelease]; | 234 initWithType:ItemTypeWebServicesShowSuggestions]; |
235 showSuggestionsSwitchItem.text = | 235 showSuggestionsSwitchItem.text = |
236 l10n_util::GetNSString(IDS_IOS_OPTIONS_SEARCH_URL_SUGGESTIONS); | 236 l10n_util::GetNSString(IDS_IOS_OPTIONS_SEARCH_URL_SUGGESTIONS); |
237 showSuggestionsSwitchItem.on = [_suggestionsEnabled value]; | 237 showSuggestionsSwitchItem.on = [_suggestionsEnabled value]; |
238 | 238 |
239 return showSuggestionsSwitchItem; | 239 return showSuggestionsSwitchItem; |
240 } | 240 } |
241 | 241 |
242 - (CollectionViewItem*)showSuggestionsFooterItem { | 242 - (CollectionViewItem*)showSuggestionsFooterItem { |
243 CollectionViewFooterItem* showSuggestionsFooterItem = | 243 CollectionViewFooterItem* showSuggestionsFooterItem = |
244 [[[CollectionViewFooterItem alloc] initWithType:ItemTypeWebServicesFooter] | 244 [[CollectionViewFooterItem alloc] initWithType:ItemTypeWebServicesFooter]; |
245 autorelease]; | |
246 showSuggestionsFooterItem.text = | 245 showSuggestionsFooterItem.text = |
247 l10n_util::GetNSString(IDS_IOS_OPTIONS_PRIVACY_FOOTER); | 246 l10n_util::GetNSString(IDS_IOS_OPTIONS_PRIVACY_FOOTER); |
248 showSuggestionsFooterItem.linkURL = google_util::AppendGoogleLocaleParam( | 247 showSuggestionsFooterItem.linkURL = google_util::AppendGoogleLocaleParam( |
249 GURL(kPrivacyLearnMoreURL), | 248 GURL(kPrivacyLearnMoreURL), |
250 GetApplicationContext()->GetApplicationLocale()); | 249 GetApplicationContext()->GetApplicationLocale()); |
251 showSuggestionsFooterItem.linkDelegate = self; | 250 showSuggestionsFooterItem.linkDelegate = self; |
252 | 251 |
253 return showSuggestionsFooterItem; | 252 return showSuggestionsFooterItem; |
254 } | 253 } |
255 | 254 |
256 - (CollectionViewItem*)clearBrowsingDetailItem { | 255 - (CollectionViewItem*)clearBrowsingDetailItem { |
257 return [self detailItemWithType:ItemTypeClearBrowsingDataClear | 256 return [self detailItemWithType:ItemTypeClearBrowsingDataClear |
258 titleId:IDS_IOS_CLEAR_BROWSING_DATA_TITLE | 257 titleId:IDS_IOS_CLEAR_BROWSING_DATA_TITLE |
259 detailText:nil]; | 258 detailText:nil]; |
260 } | 259 } |
261 | 260 |
262 - (CollectionViewItem*)sendUsageDetailItem { | 261 - (CollectionViewItem*)sendUsageDetailItem { |
263 NSString* detailText = [DataplanUsageCollectionViewController | 262 NSString* detailText = [DataplanUsageCollectionViewController |
264 currentLabelForPreference:GetApplicationContext()->GetLocalState() | 263 currentLabelForPreference:GetApplicationContext()->GetLocalState() |
265 basePref:metrics::prefs::kMetricsReportingEnabled | 264 basePref:metrics::prefs::kMetricsReportingEnabled |
266 wifiPref:prefs::kMetricsReportingWifiOnly]; | 265 wifiPref:prefs::kMetricsReportingWifiOnly]; |
267 _sendUsageDetailItem.reset( | 266 _sendUsageDetailItem = |
268 [[self detailItemWithType:ItemTypeWebServicesSendUsageData | 267 [self detailItemWithType:ItemTypeWebServicesSendUsageData |
269 titleId:IDS_IOS_OPTIONS_SEND_USAGE_DATA | 268 titleId:IDS_IOS_OPTIONS_SEND_USAGE_DATA |
270 detailText:detailText] retain]); | 269 detailText:detailText]; |
271 | 270 |
272 return _sendUsageDetailItem; | 271 return _sendUsageDetailItem; |
273 } | 272 } |
274 | 273 |
275 - (CollectionViewItem*)physicalWebDetailItem { | 274 - (CollectionViewItem*)physicalWebDetailItem { |
276 PrefService* prefService = GetApplicationContext()->GetLocalState(); | 275 PrefService* prefService = GetApplicationContext()->GetLocalState(); |
277 int preferenceState = prefService->GetInteger(prefs::kIosPhysicalWebEnabled); | 276 int preferenceState = prefService->GetInteger(prefs::kIosPhysicalWebEnabled); |
278 BOOL enabled = [PhysicalWebCollectionViewController | 277 BOOL enabled = [PhysicalWebCollectionViewController |
279 shouldEnableForPreferenceState:preferenceState]; | 278 shouldEnableForPreferenceState:preferenceState]; |
280 NSString* detailText = enabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 279 NSString* detailText = enabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
281 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 280 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
282 return [self detailItemWithType:ItemTypeWebServicesPhysicalWeb | 281 return [self detailItemWithType:ItemTypeWebServicesPhysicalWeb |
283 titleId:IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB | 282 titleId:IDS_IOS_OPTIONS_ENABLE_PHYSICAL_WEB |
284 detailText:detailText]; | 283 detailText:detailText]; |
285 } | 284 } |
286 | 285 |
287 - (CollectionViewItem*)contextualSearchDetailItem { | 286 - (CollectionViewItem*)contextualSearchDetailItem { |
288 _touchToSearchPermissions.reset([[TouchToSearchPermissionsMediator alloc] | 287 _touchToSearchPermissions = [[TouchToSearchPermissionsMediator alloc] |
289 initWithBrowserState:_browserState]); | 288 initWithBrowserState:_browserState]; |
290 NSString* detailText = | 289 NSString* detailText = |
291 [_touchToSearchPermissions preferenceState] == TouchToSearch::DISABLED | 290 [_touchToSearchPermissions preferenceState] == TouchToSearch::DISABLED |
292 ? l10n_util::GetNSString(IDS_IOS_SETTING_OFF) | 291 ? l10n_util::GetNSString(IDS_IOS_SETTING_OFF) |
293 : l10n_util::GetNSString(IDS_IOS_SETTING_ON); | 292 : l10n_util::GetNSString(IDS_IOS_SETTING_ON); |
294 return [self detailItemWithType:ItemTypeWebServicesTouchToSearch | 293 return [self detailItemWithType:ItemTypeWebServicesTouchToSearch |
295 titleId:IDS_IOS_CONTEXTUAL_SEARCH_TITLE | 294 titleId:IDS_IOS_CONTEXTUAL_SEARCH_TITLE |
296 detailText:detailText]; | 295 detailText:detailText]; |
297 } | 296 } |
298 | 297 |
299 - (CollectionViewItem*)doNotTrackDetailItem { | 298 - (CollectionViewItem*)doNotTrackDetailItem { |
300 NSString* detailText = | 299 NSString* detailText = |
301 _browserState->GetPrefs()->GetBoolean(prefs::kEnableDoNotTrack) | 300 _browserState->GetPrefs()->GetBoolean(prefs::kEnableDoNotTrack) |
302 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 301 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
303 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 302 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
304 return [self detailItemWithType:ItemTypeWebServicesDoNotTrack | 303 return [self detailItemWithType:ItemTypeWebServicesDoNotTrack |
305 titleId:IDS_IOS_OPTIONS_DO_NOT_TRACK_MOBILE | 304 titleId:IDS_IOS_OPTIONS_DO_NOT_TRACK_MOBILE |
306 detailText:detailText]; | 305 detailText:detailText]; |
307 } | 306 } |
308 | 307 |
309 - (CollectionViewDetailItem*)detailItemWithType:(NSInteger)type | 308 - (CollectionViewDetailItem*)detailItemWithType:(NSInteger)type |
310 titleId:(NSInteger)titleId | 309 titleId:(NSInteger)titleId |
311 detailText:(NSString*)detailText { | 310 detailText:(NSString*)detailText { |
312 CollectionViewDetailItem* detailItem = | 311 CollectionViewDetailItem* detailItem = |
313 [[[CollectionViewDetailItem alloc] initWithType:type] autorelease]; | 312 [[CollectionViewDetailItem alloc] initWithType:type]; |
314 detailItem.text = l10n_util::GetNSString(titleId); | 313 detailItem.text = l10n_util::GetNSString(titleId); |
315 detailItem.detailText = detailText; | 314 detailItem.detailText = detailText; |
316 detailItem.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; | 315 detailItem.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; |
317 detailItem.accessibilityTraits |= UIAccessibilityTraitButton; | 316 detailItem.accessibilityTraits |= UIAccessibilityTraitButton; |
318 | 317 |
319 return detailItem; | 318 return detailItem; |
320 } | 319 } |
321 | 320 |
322 #pragma mark UICollectionViewDataSource | 321 #pragma mark UICollectionViewDataSource |
323 | 322 |
(...skipping 17 matching lines...) Expand all Loading... |
341 } | 340 } |
342 | 341 |
343 #pragma mark UICollectionViewDelegate | 342 #pragma mark UICollectionViewDelegate |
344 - (void)collectionView:(UICollectionView*)collectionView | 343 - (void)collectionView:(UICollectionView*)collectionView |
345 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 344 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
346 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 345 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
347 NSInteger itemType = | 346 NSInteger itemType = |
348 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 347 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
349 | 348 |
350 // Items that push a new view controller. | 349 // Items that push a new view controller. |
351 base::scoped_nsobject<UIViewController> controller; | 350 UIViewController* controller; |
352 | 351 |
353 switch (itemType) { | 352 switch (itemType) { |
354 case ItemTypeOtherDevicesHandoff: | 353 case ItemTypeOtherDevicesHandoff: |
355 controller.reset([[HandoffCollectionViewController alloc] | 354 controller = [[HandoffCollectionViewController alloc] |
356 initWithBrowserState:_browserState]); | 355 initWithBrowserState:_browserState]; |
357 break; | 356 break; |
358 case ItemTypeWebServicesTouchToSearch: | 357 case ItemTypeWebServicesTouchToSearch: |
359 controller.reset([[ContextualSearchCollectionViewController alloc] | 358 controller = [[ContextualSearchCollectionViewController alloc] |
360 initWithPermissions:_touchToSearchPermissions]); | 359 initWithPermissions:_touchToSearchPermissions]; |
361 break; | 360 break; |
362 case ItemTypeWebServicesSendUsageData: | 361 case ItemTypeWebServicesSendUsageData: |
363 controller.reset([[DataplanUsageCollectionViewController alloc] | 362 controller = [[DataplanUsageCollectionViewController alloc] |
364 initWithPrefs:GetApplicationContext()->GetLocalState() | 363 initWithPrefs:GetApplicationContext()->GetLocalState() |
365 basePref:metrics::prefs::kMetricsReportingEnabled | 364 basePref:metrics::prefs::kMetricsReportingEnabled |
366 wifiPref:prefs::kMetricsReportingWifiOnly | 365 wifiPref:prefs::kMetricsReportingWifiOnly |
367 title:l10n_util::GetNSString( | 366 title:l10n_util::GetNSString( |
368 IDS_IOS_OPTIONS_SEND_USAGE_DATA)]); | 367 IDS_IOS_OPTIONS_SEND_USAGE_DATA)]; |
369 break; | 368 break; |
370 case ItemTypeWebServicesDoNotTrack: | 369 case ItemTypeWebServicesDoNotTrack: |
371 controller.reset([[DoNotTrackCollectionViewController alloc] | 370 controller = [[DoNotTrackCollectionViewController alloc] |
372 initWithPrefs:_browserState->GetPrefs()]); | 371 initWithPrefs:_browserState->GetPrefs()]; |
373 break; | 372 break; |
374 case ItemTypeWebServicesPhysicalWeb: | 373 case ItemTypeWebServicesPhysicalWeb: |
375 controller.reset([[PhysicalWebCollectionViewController alloc] | 374 controller = [[PhysicalWebCollectionViewController alloc] |
376 initWithPrefs:GetApplicationContext()->GetLocalState()]); | 375 initWithPrefs:GetApplicationContext()->GetLocalState()]; |
377 break; | 376 break; |
378 case ItemTypeClearBrowsingDataClear: | 377 case ItemTypeClearBrowsingDataClear: |
379 controller.reset([[ClearBrowsingDataCollectionViewController alloc] | 378 controller = [[ClearBrowsingDataCollectionViewController alloc] |
380 initWithBrowserState:_browserState]); | 379 initWithBrowserState:_browserState]; |
381 break; | 380 break; |
382 case ItemTypeWebServicesShowSuggestions: | 381 case ItemTypeWebServicesShowSuggestions: |
383 default: | 382 default: |
384 break; | 383 break; |
385 } | 384 } |
386 | 385 |
387 if (controller.get()) { | 386 if (controller) { |
388 [self.navigationController pushViewController:controller animated:YES]; | 387 [self.navigationController pushViewController:controller animated:YES]; |
389 } | 388 } |
390 } | 389 } |
391 | 390 |
392 #pragma mark MDCCollectionViewStylingDelegate | 391 #pragma mark MDCCollectionViewStylingDelegate |
393 | 392 |
394 - (BOOL)collectionView:(UICollectionView*)collectionView | 393 - (BOOL)collectionView:(UICollectionView*)collectionView |
395 shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath { | 394 shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath { |
396 NSInteger sectionIdentifier = | 395 NSInteger sectionIdentifier = |
397 [self.collectionViewModel sectionIdentifierForSection:indexPath.section]; | 396 [self.collectionViewModel sectionIdentifierForSection:indexPath.section]; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 if (sectionIdentifier == SectionIdentifierWebServicesFooter) { | 433 if (sectionIdentifier == SectionIdentifierWebServicesFooter) { |
435 return MDCCollectionViewCellStyleDefault; | 434 return MDCCollectionViewCellStyleDefault; |
436 } | 435 } |
437 | 436 |
438 return self.styler.cellStyle; | 437 return self.styler.cellStyle; |
439 } | 438 } |
440 | 439 |
441 #pragma mark - BooleanObserver | 440 #pragma mark - BooleanObserver |
442 | 441 |
443 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { | 442 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { |
444 DCHECK_EQ(observableBoolean, _suggestionsEnabled.get()); | 443 DCHECK_EQ(observableBoolean, _suggestionsEnabled); |
445 | 444 |
446 // Update the item. | 445 // Update the item. |
447 _showSuggestionsItem.get().on = [_suggestionsEnabled value]; | 446 _showSuggestionsItem.on = [_suggestionsEnabled value]; |
448 | 447 |
449 // Update the cell. | 448 // Update the cell. |
450 [self reconfigureCellsForItems:@[ _showSuggestionsItem ]]; | 449 [self reconfigureCellsForItems:@[ _showSuggestionsItem ]]; |
451 } | 450 } |
452 | 451 |
453 #pragma mark - Actions | 452 #pragma mark - Actions |
454 | 453 |
455 - (void)showSuggestionsToggled:(UISwitch*)sender { | 454 - (void)showSuggestionsToggled:(UISwitch*)sender { |
456 NSIndexPath* switchPath = [self.collectionViewModel | 455 NSIndexPath* switchPath = [self.collectionViewModel |
457 indexPathForItemType:ItemTypeWebServicesShowSuggestions | 456 indexPathForItemType:ItemTypeWebServicesShowSuggestions |
(...skipping 13 matching lines...) Expand all Loading... |
471 } | 470 } |
472 | 471 |
473 #pragma mark - PrefObserverDelegate | 472 #pragma mark - PrefObserverDelegate |
474 | 473 |
475 - (void)onPreferenceChanged:(const std::string&)preferenceName { | 474 - (void)onPreferenceChanged:(const std::string&)preferenceName { |
476 if (preferenceName == prefs::kIosHandoffToOtherDevices) { | 475 if (preferenceName == prefs::kIosHandoffToOtherDevices) { |
477 NSString* detailText = | 476 NSString* detailText = |
478 _browserState->GetPrefs()->GetBoolean(prefs::kIosHandoffToOtherDevices) | 477 _browserState->GetPrefs()->GetBoolean(prefs::kIosHandoffToOtherDevices) |
479 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 478 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
480 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 479 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
481 _handoffDetailItem.get().detailText = detailText; | 480 _handoffDetailItem.detailText = detailText; |
482 [self reconfigureCellsForItems:@[ _handoffDetailItem ]]; | 481 [self reconfigureCellsForItems:@[ _handoffDetailItem ]]; |
483 return; | 482 return; |
484 } | 483 } |
485 | 484 |
486 if (preferenceName == metrics::prefs::kMetricsReportingEnabled || | 485 if (preferenceName == metrics::prefs::kMetricsReportingEnabled || |
487 preferenceName == prefs::kMetricsReportingWifiOnly) { | 486 preferenceName == prefs::kMetricsReportingWifiOnly) { |
488 NSString* detailText = [DataplanUsageCollectionViewController | 487 NSString* detailText = [DataplanUsageCollectionViewController |
489 currentLabelForPreference:GetApplicationContext()->GetLocalState() | 488 currentLabelForPreference:GetApplicationContext()->GetLocalState() |
490 basePref:metrics::prefs::kMetricsReportingEnabled | 489 basePref:metrics::prefs::kMetricsReportingEnabled |
491 wifiPref:prefs::kMetricsReportingWifiOnly]; | 490 wifiPref:prefs::kMetricsReportingWifiOnly]; |
492 | 491 |
493 _sendUsageDetailItem.get().detailText = detailText; | 492 _sendUsageDetailItem.detailText = detailText; |
494 | 493 |
495 [self reconfigureCellsForItems:@[ _sendUsageDetailItem ]]; | 494 [self reconfigureCellsForItems:@[ _sendUsageDetailItem ]]; |
496 return; | 495 return; |
497 } | 496 } |
498 } | 497 } |
499 | 498 |
500 @end | 499 @end |
OLD | NEW |