| 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/settings_collection_view_controller.h" | 5 #import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
| 10 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 51 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
| 52 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 52 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 53 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 53 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 54 #import "ios/chrome/browser/ui/settings/about_chrome_collection_view_controller.
h" | 54 #import "ios/chrome/browser/ui/settings/about_chrome_collection_view_controller.
h" |
| 55 #import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h" | 55 #import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h" |
| 56 #import "ios/chrome/browser/ui/settings/autofill_collection_view_controller.h" | 56 #import "ios/chrome/browser/ui/settings/autofill_collection_view_controller.h" |
| 57 #import "ios/chrome/browser/ui/settings/bandwidth_management_collection_view_con
troller.h" | 57 #import "ios/chrome/browser/ui/settings/bandwidth_management_collection_view_con
troller.h" |
| 58 #import "ios/chrome/browser/ui/settings/cells/account_signin_item.h" | 58 #import "ios/chrome/browser/ui/settings/cells/account_signin_item.h" |
| 59 #import "ios/chrome/browser/ui/settings/content_settings_collection_view_control
ler.h" | 59 #import "ios/chrome/browser/ui/settings/content_settings_collection_view_control
ler.h" |
| 60 #import "ios/chrome/browser/ui/settings/material_cell_catalog_view_controller.h" | 60 #import "ios/chrome/browser/ui/settings/material_cell_catalog_view_controller.h" |
| 61 #import "ios/chrome/browser/ui/settings/native_apps_collection_view_controller.h
" | |
| 62 #import "ios/chrome/browser/ui/settings/privacy_collection_view_controller.h" | 61 #import "ios/chrome/browser/ui/settings/privacy_collection_view_controller.h" |
| 63 #import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controlle
r.h" | 62 #import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controlle
r.h" |
| 64 #import "ios/chrome/browser/ui/settings/search_engine_settings_collection_view_c
ontroller.h" | 63 #import "ios/chrome/browser/ui/settings/search_engine_settings_collection_view_c
ontroller.h" |
| 65 #import "ios/chrome/browser/ui/settings/settings_utils.h" | 64 #import "ios/chrome/browser/ui/settings/settings_utils.h" |
| 66 #import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h" | 65 #import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h" |
| 67 #import "ios/chrome/browser/ui/settings/voicesearch_collection_view_controller.h
" | 66 #import "ios/chrome/browser/ui/settings/voicesearch_collection_view_controller.h
" |
| 68 #import "ios/chrome/browser/ui/sync/sync_util.h" | 67 #import "ios/chrome/browser/ui/sync/sync_util.h" |
| 69 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 68 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 70 #include "ios/chrome/browser/voice/speech_input_locale_config.h" | 69 #include "ios/chrome/browser/voice/speech_input_locale_config.h" |
| 71 #include "ios/chrome/grit/ios_chromium_strings.h" | 70 #include "ios/chrome/grit/ios_chromium_strings.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 }; | 104 }; |
| 106 | 105 |
| 107 typedef NS_ENUM(NSInteger, ItemType) { | 106 typedef NS_ENUM(NSInteger, ItemType) { |
| 108 ItemTypeSignInButton = kItemTypeEnumZero, | 107 ItemTypeSignInButton = kItemTypeEnumZero, |
| 109 ItemTypeSigninPromo, | 108 ItemTypeSigninPromo, |
| 110 ItemTypeAccount, | 109 ItemTypeAccount, |
| 111 ItemTypeHeader, | 110 ItemTypeHeader, |
| 112 ItemTypeSearchEngine, | 111 ItemTypeSearchEngine, |
| 113 ItemTypeSavedPasswords, | 112 ItemTypeSavedPasswords, |
| 114 ItemTypeAutofill, | 113 ItemTypeAutofill, |
| 115 ItemTypeNativeApps, | |
| 116 ItemTypeVoiceSearch, | 114 ItemTypeVoiceSearch, |
| 117 ItemTypePrivacy, | 115 ItemTypePrivacy, |
| 118 ItemTypeContentSettings, | 116 ItemTypeContentSettings, |
| 119 ItemTypeBandwidth, | 117 ItemTypeBandwidth, |
| 120 ItemTypeAboutChrome, | 118 ItemTypeAboutChrome, |
| 121 ItemTypeMemoryDebugging, | 119 ItemTypeMemoryDebugging, |
| 122 ItemTypeViewSource, | 120 ItemTypeViewSource, |
| 123 ItemTypeLogJavascript, | 121 ItemTypeLogJavascript, |
| 124 ItemTypeShowAutofillTypePredictions, | 122 ItemTypeShowAutofillTypePredictions, |
| 125 ItemTypeCellCatalog, | 123 ItemTypeCellCatalog, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 176 |
| 179 #pragma mark - SettingsCollectionViewController | 177 #pragma mark - SettingsCollectionViewController |
| 180 | 178 |
| 181 @interface SettingsCollectionViewController ()<SettingsControllerProtocol, | 179 @interface SettingsCollectionViewController ()<SettingsControllerProtocol, |
| 182 SyncObserverModelBridge, | 180 SyncObserverModelBridge, |
| 183 ChromeIdentityServiceObserver, | 181 ChromeIdentityServiceObserver, |
| 184 BooleanObserver, | 182 BooleanObserver, |
| 185 PrefObserverDelegate, | 183 PrefObserverDelegate, |
| 186 SigninPromoViewConsumer, | 184 SigninPromoViewConsumer, |
| 187 SigninPromoViewDelegate> { | 185 SigninPromoViewDelegate> { |
| 188 // The main browser state that hold the settings. Never off the record. | 186 // The current browser state that hold the settings. Never off the record. |
| 189 ios::ChromeBrowserState* _mainBrowserState; // weak | 187 ios::ChromeBrowserState* _browserState; // weak |
| 190 | 188 |
| 191 // The current browser state. It is either |_mainBrowserState| | |
| 192 // or |_mainBrowserState->GetOffTheRecordChromeBrowserState()|. | |
| 193 ios::ChromeBrowserState* _currentBrowserState; // weak | |
| 194 std::unique_ptr<SigninObserverBridge> _notificationBridge; | 189 std::unique_ptr<SigninObserverBridge> _notificationBridge; |
| 195 std::unique_ptr<SyncObserverBridge> _syncObserverBridge; | 190 std::unique_ptr<SyncObserverBridge> _syncObserverBridge; |
| 196 SigninInteractionController* _signinInteractionController; | 191 SigninInteractionController* _signinInteractionController; |
| 197 // Whether the impression of the Signin button has already been recorded. | 192 // Whether the impression of the Signin button has already been recorded. |
| 198 BOOL _hasRecordedSigninImpression; | 193 BOOL _hasRecordedSigninImpression; |
| 199 // PrefBackedBoolean for ShowMemoryDebugTools switch. | 194 // PrefBackedBoolean for ShowMemoryDebugTools switch. |
| 200 PrefBackedBoolean* _showMemoryDebugToolsEnabled; | 195 PrefBackedBoolean* _showMemoryDebugToolsEnabled; |
| 201 // The item related to the switch for the show suggestions setting. | 196 // The item related to the switch for the show suggestions setting. |
| 202 CollectionViewSwitchItem* _showMemoryDebugToolsItem; | 197 CollectionViewSwitchItem* _showMemoryDebugToolsItem; |
| 203 | 198 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 232 // Stops observing browser state services. This is required during the shutdown | 227 // Stops observing browser state services. This is required during the shutdown |
| 233 // phase to avoid observing services for a profile that is being killed. | 228 // phase to avoid observing services for a profile that is being killed. |
| 234 - (void)stopBrowserStateServiceObservers; | 229 - (void)stopBrowserStateServiceObservers; |
| 235 | 230 |
| 236 @end | 231 @end |
| 237 | 232 |
| 238 @implementation SettingsCollectionViewController | 233 @implementation SettingsCollectionViewController |
| 239 | 234 |
| 240 #pragma mark Initialization | 235 #pragma mark Initialization |
| 241 | 236 |
| 242 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)mainBrowserState | 237 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { |
| 243 currentBrowserState: | 238 // Checks that |browserState| is not an Incognito browser state. |
| 244 (ios::ChromeBrowserState*)currentBrowserState { | 239 DCHECK(browserState); |
| 245 DCHECK(mainBrowserState); | 240 DCHECK_EQ(browserState, browserState->GetOriginalChromeBrowserState()); |
| 246 DCHECK(currentBrowserState); | |
| 247 DCHECK_EQ(mainBrowserState, | |
| 248 currentBrowserState->GetOriginalChromeBrowserState()); | |
| 249 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; | 241 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |
| 250 if (self) { | 242 if (self) { |
| 251 _mainBrowserState = mainBrowserState; | 243 _browserState = browserState; |
| 252 _currentBrowserState = currentBrowserState; | |
| 253 self.title = l10n_util::GetNSStringWithFixup(IDS_IOS_SETTINGS_TITLE); | 244 self.title = l10n_util::GetNSStringWithFixup(IDS_IOS_SETTINGS_TITLE); |
| 254 self.collectionViewAccessibilityIdentifier = kSettingsCollectionViewId; | 245 self.collectionViewAccessibilityIdentifier = kSettingsCollectionViewId; |
| 255 _notificationBridge.reset( | 246 _notificationBridge.reset(new SigninObserverBridge(_browserState, self)); |
| 256 new SigninObserverBridge(_mainBrowserState, self)); | |
| 257 syncer::SyncService* syncService = | 247 syncer::SyncService* syncService = |
| 258 IOSChromeProfileSyncServiceFactory::GetForBrowserState( | 248 IOSChromeProfileSyncServiceFactory::GetForBrowserState(_browserState); |
| 259 _mainBrowserState); | |
| 260 _syncObserverBridge.reset(new SyncObserverBridge(self, syncService)); | 249 _syncObserverBridge.reset(new SyncObserverBridge(self, syncService)); |
| 261 | 250 |
| 262 _showMemoryDebugToolsEnabled = [[PrefBackedBoolean alloc] | 251 _showMemoryDebugToolsEnabled = [[PrefBackedBoolean alloc] |
| 263 initWithPrefService:GetApplicationContext()->GetLocalState() | 252 initWithPrefService:GetApplicationContext()->GetLocalState() |
| 264 prefName:prefs::kShowMemoryDebuggingTools]; | 253 prefName:prefs::kShowMemoryDebuggingTools]; |
| 265 [_showMemoryDebugToolsEnabled setObserver:self]; | 254 [_showMemoryDebugToolsEnabled setObserver:self]; |
| 266 | 255 |
| 267 AuthenticationService* authService = | 256 AuthenticationService* authService = |
| 268 AuthenticationServiceFactory::GetForBrowserState(_mainBrowserState); | 257 AuthenticationServiceFactory::GetForBrowserState(_browserState); |
| 269 _identity = authService->GetAuthenticatedIdentity(); | 258 _identity = authService->GetAuthenticatedIdentity(); |
| 270 _identityServiceObserver.reset( | 259 _identityServiceObserver.reset( |
| 271 new ChromeIdentityServiceObserverBridge(self)); | 260 new ChromeIdentityServiceObserverBridge(self)); |
| 272 | 261 |
| 273 PrefService* prefService = _mainBrowserState->GetPrefs(); | 262 PrefService* prefService = _browserState->GetPrefs(); |
| 274 | 263 |
| 275 _voiceLocaleCode.Init(prefs::kVoiceSearchLocale, prefService); | 264 _voiceLocaleCode.Init(prefs::kVoiceSearchLocale, prefService); |
| 276 | 265 |
| 277 _prefChangeRegistrar.Init(prefService); | 266 _prefChangeRegistrar.Init(prefService); |
| 278 _prefObserverBridge.reset(new PrefObserverBridge(self)); | 267 _prefObserverBridge.reset(new PrefObserverBridge(self)); |
| 279 // Register to observe any changes on Perf backed values displayed by the | 268 // Register to observe any changes on Perf backed values displayed by the |
| 280 // screen. | 269 // screen. |
| 281 _prefObserverBridge->ObserveChangesForPreference(prefs::kVoiceSearchLocale, | 270 _prefObserverBridge->ObserveChangesForPreference(prefs::kVoiceSearchLocale, |
| 282 &_prefChangeRegistrar); | 271 &_prefChangeRegistrar); |
| 283 _prefObserverBridge->ObserveChangesForPreference( | 272 _prefObserverBridge->ObserveChangesForPreference( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 #pragma mark SettingsRootCollectionViewController | 308 #pragma mark SettingsRootCollectionViewController |
| 320 | 309 |
| 321 - (void)loadModel { | 310 - (void)loadModel { |
| 322 [super loadModel]; | 311 [super loadModel]; |
| 323 | 312 |
| 324 CollectionViewModel* model = self.collectionViewModel; | 313 CollectionViewModel* model = self.collectionViewModel; |
| 325 | 314 |
| 326 // Sign in/Account section | 315 // Sign in/Account section |
| 327 [model addSectionWithIdentifier:SectionIdentifierSignIn]; | 316 [model addSectionWithIdentifier:SectionIdentifierSignIn]; |
| 328 AuthenticationService* authService = | 317 AuthenticationService* authService = |
| 329 AuthenticationServiceFactory::GetForBrowserState(_mainBrowserState); | 318 AuthenticationServiceFactory::GetForBrowserState(_browserState); |
| 330 if (!authService->IsAuthenticated()) { | 319 if (!authService->IsAuthenticated()) { |
| 331 if (!_hasRecordedSigninImpression) { | 320 if (!_hasRecordedSigninImpression) { |
| 332 // Once the Settings are open, this button impression will at most be | 321 // Once the Settings are open, this button impression will at most be |
| 333 // recorded once until they are closed. | 322 // recorded once until they are closed. |
| 334 base::RecordAction( | 323 base::RecordAction( |
| 335 base::UserMetricsAction("Signin_Impression_FromSettings")); | 324 base::UserMetricsAction("Signin_Impression_FromSettings")); |
| 336 _hasRecordedSigninImpression = YES; | 325 _hasRecordedSigninImpression = YES; |
| 337 } | 326 } |
| 338 if (experimental_flags::IsSigninPromoEnabled()) { | 327 if (experimental_flags::IsSigninPromoEnabled()) { |
| 339 _signinPromoViewMediator = [[SigninPromoViewMediator alloc] init]; | 328 _signinPromoViewMediator = [[SigninPromoViewMediator alloc] init]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 354 basicsHeader.text = l10n_util::GetNSString(IDS_IOS_OPTIONS_GENERAL_TAB_LABEL); | 343 basicsHeader.text = l10n_util::GetNSString(IDS_IOS_OPTIONS_GENERAL_TAB_LABEL); |
| 355 basicsHeader.textColor = [[MDCPalette greyPalette] tint500]; | 344 basicsHeader.textColor = [[MDCPalette greyPalette] tint500]; |
| 356 [model setHeader:basicsHeader | 345 [model setHeader:basicsHeader |
| 357 forSectionWithIdentifier:SectionIdentifierBasics]; | 346 forSectionWithIdentifier:SectionIdentifierBasics]; |
| 358 [model addItem:[self searchEngineDetailItem] | 347 [model addItem:[self searchEngineDetailItem] |
| 359 toSectionWithIdentifier:SectionIdentifierBasics]; | 348 toSectionWithIdentifier:SectionIdentifierBasics]; |
| 360 [model addItem:[self savePasswordsDetailItem] | 349 [model addItem:[self savePasswordsDetailItem] |
| 361 toSectionWithIdentifier:SectionIdentifierBasics]; | 350 toSectionWithIdentifier:SectionIdentifierBasics]; |
| 362 [model addItem:[self autoFillDetailItem] | 351 [model addItem:[self autoFillDetailItem] |
| 363 toSectionWithIdentifier:SectionIdentifierBasics]; | 352 toSectionWithIdentifier:SectionIdentifierBasics]; |
| 364 if (experimental_flags::IsNativeAppLauncherEnabled()) { | |
| 365 [model addItem:[self nativeAppsDetailItem] | |
| 366 toSectionWithIdentifier:SectionIdentifierBasics]; | |
| 367 } | |
| 368 | 353 |
| 369 // Advanced Section | 354 // Advanced Section |
| 370 [model addSectionWithIdentifier:SectionIdentifierAdvanced]; | 355 [model addSectionWithIdentifier:SectionIdentifierAdvanced]; |
| 371 CollectionViewTextItem* advancedHeader = | 356 CollectionViewTextItem* advancedHeader = |
| 372 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; | 357 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; |
| 373 advancedHeader.text = | 358 advancedHeader.text = |
| 374 l10n_util::GetNSString(IDS_IOS_OPTIONS_ADVANCED_TAB_LABEL); | 359 l10n_util::GetNSString(IDS_IOS_OPTIONS_ADVANCED_TAB_LABEL); |
| 375 advancedHeader.textColor = [[MDCPalette greyPalette] tint500]; | 360 advancedHeader.textColor = [[MDCPalette greyPalette] tint500]; |
| 376 [model setHeader:advancedHeader | 361 [model setHeader:advancedHeader |
| 377 forSectionWithIdentifier:SectionIdentifierAdvanced]; | 362 forSectionWithIdentifier:SectionIdentifierAdvanced]; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 identityAccountItem.accessoryType = | 431 identityAccountItem.accessoryType = |
| 447 MDCCollectionViewCellAccessoryDisclosureIndicator; | 432 MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 448 identityAccountItem.accessibilityIdentifier = kSettingsAccountCellId; | 433 identityAccountItem.accessibilityIdentifier = kSettingsAccountCellId; |
| 449 [self updateIdentityAccountItem:identityAccountItem]; | 434 [self updateIdentityAccountItem:identityAccountItem]; |
| 450 return identityAccountItem; | 435 return identityAccountItem; |
| 451 } | 436 } |
| 452 | 437 |
| 453 - (CollectionViewItem*)searchEngineDetailItem { | 438 - (CollectionViewItem*)searchEngineDetailItem { |
| 454 NSString* defaultSearchEngineName = | 439 NSString* defaultSearchEngineName = |
| 455 base::SysUTF16ToNSString(GetDefaultSearchEngineName( | 440 base::SysUTF16ToNSString(GetDefaultSearchEngineName( |
| 456 ios::TemplateURLServiceFactory::GetForBrowserState( | 441 ios::TemplateURLServiceFactory::GetForBrowserState(_browserState))); |
| 457 _mainBrowserState))); | |
| 458 | 442 |
| 459 _defaultSearchEngineItem = | 443 _defaultSearchEngineItem = |
| 460 [self detailItemWithType:ItemTypeSearchEngine | 444 [self detailItemWithType:ItemTypeSearchEngine |
| 461 text:l10n_util::GetNSString( | 445 text:l10n_util::GetNSString( |
| 462 IDS_IOS_SEARCH_ENGINE_SETTING_TITLE) | 446 IDS_IOS_SEARCH_ENGINE_SETTING_TITLE) |
| 463 detailText:defaultSearchEngineName]; | 447 detailText:defaultSearchEngineName]; |
| 464 _defaultSearchEngineItem.accessibilityIdentifier = | 448 _defaultSearchEngineItem.accessibilityIdentifier = |
| 465 kSettingsSearchEngineCellId; | 449 kSettingsSearchEngineCellId; |
| 466 return _defaultSearchEngineItem; | 450 return _defaultSearchEngineItem; |
| 467 } | 451 } |
| 468 | 452 |
| 469 - (CollectionViewItem*)savePasswordsDetailItem { | 453 - (CollectionViewItem*)savePasswordsDetailItem { |
| 470 BOOL savePasswordsEnabled = _mainBrowserState->GetPrefs()->GetBoolean( | 454 BOOL savePasswordsEnabled = _browserState->GetPrefs()->GetBoolean( |
| 471 password_manager::prefs::kPasswordManagerSavingEnabled); | 455 password_manager::prefs::kPasswordManagerSavingEnabled); |
| 472 NSString* passwordsDetail = savePasswordsEnabled | 456 NSString* passwordsDetail = savePasswordsEnabled |
| 473 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 457 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 474 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 458 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 475 | 459 |
| 476 _savePasswordsDetailItem = | 460 _savePasswordsDetailItem = |
| 477 [self detailItemWithType:ItemTypeSavedPasswords | 461 [self detailItemWithType:ItemTypeSavedPasswords |
| 478 text:l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS) | 462 text:l10n_util::GetNSString(IDS_IOS_SAVE_PASSWORDS) |
| 479 detailText:passwordsDetail]; | 463 detailText:passwordsDetail]; |
| 480 | 464 |
| 481 return _savePasswordsDetailItem; | 465 return _savePasswordsDetailItem; |
| 482 } | 466 } |
| 483 | 467 |
| 484 - (CollectionViewItem*)autoFillDetailItem { | 468 - (CollectionViewItem*)autoFillDetailItem { |
| 485 BOOL autofillEnabled = _mainBrowserState->GetPrefs()->GetBoolean( | 469 BOOL autofillEnabled = |
| 486 autofill::prefs::kAutofillEnabled); | 470 _browserState->GetPrefs()->GetBoolean(autofill::prefs::kAutofillEnabled); |
| 487 NSString* autofillDetail = autofillEnabled | 471 NSString* autofillDetail = autofillEnabled |
| 488 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 472 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 489 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 473 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 490 _autoFillDetailItem = | 474 _autoFillDetailItem = |
| 491 [self detailItemWithType:ItemTypeAutofill | 475 [self detailItemWithType:ItemTypeAutofill |
| 492 text:l10n_util::GetNSString(IDS_IOS_AUTOFILL) | 476 text:l10n_util::GetNSString(IDS_IOS_AUTOFILL) |
| 493 detailText:autofillDetail]; | 477 detailText:autofillDetail]; |
| 494 | 478 |
| 495 return _autoFillDetailItem; | 479 return _autoFillDetailItem; |
| 496 } | 480 } |
| 497 | 481 |
| 498 - (CollectionViewItem*)nativeAppsDetailItem { | |
| 499 return [self | |
| 500 detailItemWithType:ItemTypeNativeApps | |
| 501 text:l10n_util::GetNSString(IDS_IOS_GOOGLE_APPS_SM_SETTINGS) | |
| 502 detailText:nil]; | |
| 503 } | |
| 504 | |
| 505 - (CollectionViewItem*)voiceSearchDetailItem { | 482 - (CollectionViewItem*)voiceSearchDetailItem { |
| 506 voice::SpeechInputLocaleConfig* localeConfig = | 483 voice::SpeechInputLocaleConfig* localeConfig = |
| 507 voice::SpeechInputLocaleConfig::GetInstance(); | 484 voice::SpeechInputLocaleConfig::GetInstance(); |
| 508 voice::SpeechInputLocale locale = | 485 voice::SpeechInputLocale locale = |
| 509 _voiceLocaleCode.GetValue().length() | 486 _voiceLocaleCode.GetValue().length() |
| 510 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue()) | 487 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue()) |
| 511 : localeConfig->GetDefaultLocale(); | 488 : localeConfig->GetDefaultLocale(); |
| 512 NSString* languageName = base::SysUTF16ToNSString(locale.display_name); | 489 NSString* languageName = base::SysUTF16ToNSString(locale.display_name); |
| 513 _voiceSearchDetailItem = | 490 _voiceSearchDetailItem = |
| 514 [self detailItemWithType:ItemTypeVoiceSearch | 491 [self detailItemWithType:ItemTypeVoiceSearch |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 text:@"Cell Catalog" | 558 text:@"Cell Catalog" |
| 582 detailText:nil]; | 559 detailText:nil]; |
| 583 } | 560 } |
| 584 #endif // CHROMIUM_BUILD && !defined(NDEBUG) | 561 #endif // CHROMIUM_BUILD && !defined(NDEBUG) |
| 585 | 562 |
| 586 #pragma mark Item Updaters | 563 #pragma mark Item Updaters |
| 587 | 564 |
| 588 - (void)updateSearchCell { | 565 - (void)updateSearchCell { |
| 589 NSString* defaultSearchEngineName = | 566 NSString* defaultSearchEngineName = |
| 590 base::SysUTF16ToNSString(GetDefaultSearchEngineName( | 567 base::SysUTF16ToNSString(GetDefaultSearchEngineName( |
| 591 ios::TemplateURLServiceFactory::GetForBrowserState( | 568 ios::TemplateURLServiceFactory::GetForBrowserState(_browserState))); |
| 592 _mainBrowserState))); | |
| 593 | 569 |
| 594 _defaultSearchEngineItem.detailText = defaultSearchEngineName; | 570 _defaultSearchEngineItem.detailText = defaultSearchEngineName; |
| 595 [self reconfigureCellsForItems:@[ _defaultSearchEngineItem ]]; | 571 [self reconfigureCellsForItems:@[ _defaultSearchEngineItem ]]; |
| 596 } | 572 } |
| 597 | 573 |
| 598 #pragma mark Item Constructors | 574 #pragma mark Item Constructors |
| 599 | 575 |
| 600 - (CollectionViewDetailItem*)detailItemWithType:(NSInteger)type | 576 - (CollectionViewDetailItem*)detailItemWithType:(NSInteger)type |
| 601 text:(NSString*)text | 577 text:(NSString*)text |
| 602 detailText:(NSString*)detailText { | 578 detailText:(NSString*)detailText { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 632 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; | 608 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; |
| 633 NSInteger itemType = | 609 NSInteger itemType = |
| 634 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 610 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 635 | 611 |
| 636 if ([cell isKindOfClass:[CollectionViewDetailCell class]]) { | 612 if ([cell isKindOfClass:[CollectionViewDetailCell class]]) { |
| 637 CollectionViewDetailCell* detailCell = | 613 CollectionViewDetailCell* detailCell = |
| 638 base::mac::ObjCCastStrict<CollectionViewDetailCell>(cell); | 614 base::mac::ObjCCastStrict<CollectionViewDetailCell>(cell); |
| 639 if (itemType == ItemTypeSavedPasswords) { | 615 if (itemType == ItemTypeSavedPasswords) { |
| 640 scoped_refptr<password_manager::PasswordStore> passwordStore = | 616 scoped_refptr<password_manager::PasswordStore> passwordStore = |
| 641 IOSChromePasswordStoreFactory::GetForBrowserState( | 617 IOSChromePasswordStoreFactory::GetForBrowserState( |
| 642 _mainBrowserState, ServiceAccessType::EXPLICIT_ACCESS); | 618 _browserState, ServiceAccessType::EXPLICIT_ACCESS); |
| 643 if (!passwordStore) { | 619 if (!passwordStore) { |
| 644 // The password store factory returns a NULL password store if something | 620 // The password store factory returns a NULL password store if something |
| 645 // goes wrong during the password store initialization. Disable the save | 621 // goes wrong during the password store initialization. Disable the save |
| 646 // passwords cell in this case. | 622 // passwords cell in this case. |
| 647 LOG(ERROR) << "Save passwords cell was disabled as the password store" | 623 LOG(ERROR) << "Save passwords cell was disabled as the password store" |
| 648 " cannot be created."; | 624 " cannot be created."; |
| 649 [detailCell setUserInteractionEnabled:NO]; | 625 [detailCell setUserInteractionEnabled:NO]; |
| 650 detailCell.textLabel.textColor = [[MDCPalette greyPalette] tint500]; | 626 detailCell.textLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 651 detailCell.detailTextLabel.textColor = | 627 detailCell.detailTextLabel.textColor = |
| 652 [[MDCPalette greyPalette] tint400]; | 628 [[MDCPalette greyPalette] tint400]; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 UIViewController* controller; | 711 UIViewController* controller; |
| 736 | 712 |
| 737 switch (itemType) { | 713 switch (itemType) { |
| 738 case ItemTypeSignInButton: | 714 case ItemTypeSignInButton: |
| 739 [self showSignInWithIdentity:nil | 715 [self showSignInWithIdentity:nil |
| 740 promoAction:signin_metrics::PromoAction:: | 716 promoAction:signin_metrics::PromoAction:: |
| 741 PROMO_ACTION_NO_SIGNIN_PROMO]; | 717 PROMO_ACTION_NO_SIGNIN_PROMO]; |
| 742 break; | 718 break; |
| 743 case ItemTypeAccount: | 719 case ItemTypeAccount: |
| 744 controller = [[AccountsCollectionViewController alloc] | 720 controller = [[AccountsCollectionViewController alloc] |
| 745 initWithBrowserState:_mainBrowserState | 721 initWithBrowserState:_browserState |
| 746 closeSettingsOnAddAccount:NO]; | 722 closeSettingsOnAddAccount:NO]; |
| 747 break; | 723 break; |
| 748 case ItemTypeSearchEngine: | 724 case ItemTypeSearchEngine: |
| 749 controller = [[SearchEngineSettingsCollectionViewController alloc] | 725 controller = [[SearchEngineSettingsCollectionViewController alloc] |
| 750 initWithBrowserState:_mainBrowserState]; | 726 initWithBrowserState:_browserState]; |
| 751 break; | 727 break; |
| 752 case ItemTypeSavedPasswords: { | 728 case ItemTypeSavedPasswords: { |
| 753 controller = [[SavePasswordsCollectionViewController alloc] | 729 controller = [[SavePasswordsCollectionViewController alloc] |
| 754 initWithBrowserState:_mainBrowserState]; | 730 initWithBrowserState:_browserState]; |
| 755 break; | 731 break; |
| 756 } | 732 } |
| 757 case ItemTypeAutofill: | 733 case ItemTypeAutofill: |
| 758 controller = [[AutofillCollectionViewController alloc] | 734 controller = [[AutofillCollectionViewController alloc] |
| 759 initWithBrowserState:_mainBrowserState]; | 735 initWithBrowserState:_browserState]; |
| 760 break; | |
| 761 case ItemTypeNativeApps: | |
| 762 controller = [[NativeAppsCollectionViewController alloc] | |
| 763 initWithURLRequestContextGetter:_currentBrowserState | |
| 764 ->GetRequestContext()]; | |
| 765 break; | 736 break; |
| 766 case ItemTypeVoiceSearch: | 737 case ItemTypeVoiceSearch: |
| 767 controller = [[VoicesearchCollectionViewController alloc] | 738 controller = [[VoicesearchCollectionViewController alloc] |
| 768 initWithPrefs:_mainBrowserState->GetPrefs()]; | 739 initWithPrefs:_browserState->GetPrefs()]; |
| 769 break; | 740 break; |
| 770 case ItemTypePrivacy: | 741 case ItemTypePrivacy: |
| 771 controller = [[PrivacyCollectionViewController alloc] | 742 controller = [[PrivacyCollectionViewController alloc] |
| 772 initWithBrowserState:_mainBrowserState]; | 743 initWithBrowserState:_browserState]; |
| 773 break; | 744 break; |
| 774 case ItemTypeContentSettings: | 745 case ItemTypeContentSettings: |
| 775 controller = [[ContentSettingsCollectionViewController alloc] | 746 controller = [[ContentSettingsCollectionViewController alloc] |
| 776 initWithBrowserState:_mainBrowserState]; | 747 initWithBrowserState:_browserState]; |
| 777 break; | 748 break; |
| 778 case ItemTypeBandwidth: | 749 case ItemTypeBandwidth: |
| 779 controller = [[BandwidthManagementCollectionViewController alloc] | 750 controller = [[BandwidthManagementCollectionViewController alloc] |
| 780 initWithBrowserState:_mainBrowserState]; | 751 initWithBrowserState:_browserState]; |
| 781 break; | 752 break; |
| 782 case ItemTypeAboutChrome: | 753 case ItemTypeAboutChrome: |
| 783 controller = [[AboutChromeCollectionViewController alloc] init]; | 754 controller = [[AboutChromeCollectionViewController alloc] init]; |
| 784 break; | 755 break; |
| 785 case ItemTypeMemoryDebugging: | 756 case ItemTypeMemoryDebugging: |
| 786 case ItemTypeViewSource: | 757 case ItemTypeViewSource: |
| 787 case ItemTypeLogJavascript: | 758 case ItemTypeLogJavascript: |
| 788 case ItemTypeShowAutofillTypePredictions: | 759 case ItemTypeShowAutofillTypePredictions: |
| 789 // Taps on these don't do anything. They have a switch as accessory view | 760 // Taps on these don't do anything. They have a switch as accessory view |
| 790 // and only the switch is tappable. | 761 // and only the switch is tappable. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 return YES; | 892 return YES; |
| 922 } | 893 } |
| 923 return NO; | 894 return NO; |
| 924 #endif // CHROMIUM_BUILD && !defined(NDEBUG) | 895 #endif // CHROMIUM_BUILD && !defined(NDEBUG) |
| 925 } | 896 } |
| 926 | 897 |
| 927 // Updates the identity cell. | 898 // Updates the identity cell. |
| 928 - (void)updateIdentityAccountItem: | 899 - (void)updateIdentityAccountItem: |
| 929 (CollectionViewAccountItem*)identityAccountItem { | 900 (CollectionViewAccountItem*)identityAccountItem { |
| 930 AuthenticationService* authService = | 901 AuthenticationService* authService = |
| 931 AuthenticationServiceFactory::GetForBrowserState(_mainBrowserState); | 902 AuthenticationServiceFactory::GetForBrowserState(_browserState); |
| 932 _identity = authService->GetAuthenticatedIdentity(); | 903 _identity = authService->GetAuthenticatedIdentity(); |
| 933 if (!_identity) { | 904 if (!_identity) { |
| 934 // This could occur during the sign out process. Just ignore as the account | 905 // This could occur during the sign out process. Just ignore as the account |
| 935 // cell will be replaced by the "Sign in" button. | 906 // cell will be replaced by the "Sign in" button. |
| 936 return; | 907 return; |
| 937 } | 908 } |
| 938 identityAccountItem.image = [self userAccountImage]; | 909 identityAccountItem.image = [self userAccountImage]; |
| 939 identityAccountItem.text = [_identity userFullName]; | 910 identityAccountItem.text = [_identity userFullName]; |
| 940 | 911 |
| 941 SyncSetupService* syncSetupService = | 912 SyncSetupService* syncSetupService = |
| 942 SyncSetupServiceFactory::GetForBrowserState(_mainBrowserState); | 913 SyncSetupServiceFactory::GetForBrowserState(_browserState); |
| 943 if (!syncSetupService->HasFinishedInitialSetup()) { | 914 if (!syncSetupService->HasFinishedInitialSetup()) { |
| 944 identityAccountItem.detailText = | 915 identityAccountItem.detailText = |
| 945 l10n_util::GetNSString(IDS_IOS_SYNC_SETUP_IN_PROGRESS); | 916 l10n_util::GetNSString(IDS_IOS_SYNC_SETUP_IN_PROGRESS); |
| 946 identityAccountItem.shouldDisplayError = NO; | 917 identityAccountItem.shouldDisplayError = NO; |
| 947 return; | 918 return; |
| 948 } | 919 } |
| 949 identityAccountItem.shouldDisplayError = | 920 identityAccountItem.shouldDisplayError = |
| 950 !ios_internal::sync::IsTransientSyncError( | 921 !ios_internal::sync::IsTransientSyncError( |
| 951 syncSetupService->GetSyncServiceState()); | 922 syncSetupService->GetSyncServiceState()); |
| 952 if (identityAccountItem.shouldDisplayError) { | 923 if (identityAccountItem.shouldDisplayError) { |
| 953 identityAccountItem.detailText = | 924 identityAccountItem.detailText = |
| 954 ios_internal::sync::GetSyncErrorDescriptionForBrowserState( | 925 ios_internal::sync::GetSyncErrorDescriptionForBrowserState( |
| 955 _mainBrowserState); | 926 _browserState); |
| 956 } else { | 927 } else { |
| 957 identityAccountItem.detailText = | 928 identityAccountItem.detailText = |
| 958 syncSetupService->IsSyncEnabled() | 929 syncSetupService->IsSyncEnabled() |
| 959 ? l10n_util::GetNSStringF( | 930 ? l10n_util::GetNSStringF( |
| 960 IDS_IOS_SIGN_IN_TO_CHROME_SETTING_SYNCING, | 931 IDS_IOS_SIGN_IN_TO_CHROME_SETTING_SYNCING, |
| 961 base::SysNSStringToUTF16([_identity userEmail])) | 932 base::SysNSStringToUTF16([_identity userEmail])) |
| 962 : l10n_util::GetNSString( | 933 : l10n_util::GetNSString( |
| 963 IDS_IOS_SIGN_IN_TO_CHROME_SETTING_SYNC_OFF); | 934 IDS_IOS_SIGN_IN_TO_CHROME_SETTING_SYNC_OFF); |
| 964 } | 935 } |
| 965 } | 936 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 981 } | 952 } |
| 982 } | 953 } |
| 983 | 954 |
| 984 #pragma mark Sign in | 955 #pragma mark Sign in |
| 985 | 956 |
| 986 - (void)showSignInWithIdentity:(ChromeIdentity*)identity | 957 - (void)showSignInWithIdentity:(ChromeIdentity*)identity |
| 987 promoAction:(signin_metrics::PromoAction)promoAction { | 958 promoAction:(signin_metrics::PromoAction)promoAction { |
| 988 base::RecordAction(base::UserMetricsAction("Signin_Signin_FromSettings")); | 959 base::RecordAction(base::UserMetricsAction("Signin_Signin_FromSettings")); |
| 989 DCHECK(!_signinInteractionController); | 960 DCHECK(!_signinInteractionController); |
| 990 _signinInteractionController = [[SigninInteractionController alloc] | 961 _signinInteractionController = [[SigninInteractionController alloc] |
| 991 initWithBrowserState:_mainBrowserState | 962 initWithBrowserState:_browserState |
| 992 presentingViewController:self.navigationController | 963 presentingViewController:self.navigationController |
| 993 isPresentedOnSettings:YES | 964 isPresentedOnSettings:YES |
| 994 accessPoint:signin_metrics::AccessPoint:: | 965 accessPoint:signin_metrics::AccessPoint:: |
| 995 ACCESS_POINT_SETTINGS | 966 ACCESS_POINT_SETTINGS |
| 996 promoAction:promoAction]; | 967 promoAction:promoAction]; |
| 997 | 968 |
| 998 __weak SettingsCollectionViewController* weakSelf = self; | 969 __weak SettingsCollectionViewController* weakSelf = self; |
| 999 [_signinInteractionController | 970 [_signinInteractionController |
| 1000 signInWithViewController:self | 971 signInWithViewController:self |
| 1001 identity:identity | 972 identity:identity |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue()) | 1079 ? localeConfig->GetLocaleForCode(_voiceLocaleCode.GetValue()) |
| 1109 : localeConfig->GetDefaultLocale(); | 1080 : localeConfig->GetDefaultLocale(); |
| 1110 NSString* languageName = base::SysUTF16ToNSString(locale.display_name); | 1081 NSString* languageName = base::SysUTF16ToNSString(locale.display_name); |
| 1111 _voiceSearchDetailItem.detailText = languageName; | 1082 _voiceSearchDetailItem.detailText = languageName; |
| 1112 [self reconfigureCellsForItems:@[ _voiceSearchDetailItem ]]; | 1083 [self reconfigureCellsForItems:@[ _voiceSearchDetailItem ]]; |
| 1113 } | 1084 } |
| 1114 | 1085 |
| 1115 if (preferenceName == | 1086 if (preferenceName == |
| 1116 password_manager::prefs::kPasswordManagerSavingEnabled) { | 1087 password_manager::prefs::kPasswordManagerSavingEnabled) { |
| 1117 BOOL savePasswordsEnabled = | 1088 BOOL savePasswordsEnabled = |
| 1118 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName); | 1089 _browserState->GetPrefs()->GetBoolean(preferenceName); |
| 1119 NSString* passwordsDetail = | 1090 NSString* passwordsDetail = |
| 1120 savePasswordsEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 1091 savePasswordsEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 1121 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 1092 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 1122 | 1093 |
| 1123 _savePasswordsDetailItem.detailText = passwordsDetail; | 1094 _savePasswordsDetailItem.detailText = passwordsDetail; |
| 1124 [self reconfigureCellsForItems:@[ _savePasswordsDetailItem ]]; | 1095 [self reconfigureCellsForItems:@[ _savePasswordsDetailItem ]]; |
| 1125 } | 1096 } |
| 1126 | 1097 |
| 1127 if (preferenceName == autofill::prefs::kAutofillEnabled) { | 1098 if (preferenceName == autofill::prefs::kAutofillEnabled) { |
| 1128 BOOL autofillEnabled = | 1099 BOOL autofillEnabled = |
| 1129 _mainBrowserState->GetPrefs()->GetBoolean(preferenceName); | 1100 _browserState->GetPrefs()->GetBoolean(preferenceName); |
| 1130 NSString* autofillDetail = | 1101 NSString* autofillDetail = |
| 1131 autofillEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) | 1102 autofillEnabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) |
| 1132 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); | 1103 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); |
| 1133 _autoFillDetailItem.detailText = autofillDetail; | 1104 _autoFillDetailItem.detailText = autofillDetail; |
| 1134 [self reconfigureCellsForItems:@[ _autoFillDetailItem ]]; | 1105 [self reconfigureCellsForItems:@[ _autoFillDetailItem ]]; |
| 1135 } | 1106 } |
| 1136 } | 1107 } |
| 1137 | 1108 |
| 1138 #pragma mark - SigninPromoViewConsumer | 1109 #pragma mark - SigninPromoViewConsumer |
| 1139 | 1110 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 (SigninPromoView*)signinPromoView { | 1170 (SigninPromoView*)signinPromoView { |
| 1200 DCHECK(_signinPromoViewMediator.defaultIdentity); | 1171 DCHECK(_signinPromoViewMediator.defaultIdentity); |
| 1201 base::RecordAction( | 1172 base::RecordAction( |
| 1202 base::UserMetricsAction("Signin_SigninNotDefault_FromSettings")); | 1173 base::UserMetricsAction("Signin_SigninNotDefault_FromSettings")); |
| 1203 [self showSignInWithIdentity:nil | 1174 [self showSignInWithIdentity:nil |
| 1204 promoAction:signin_metrics::PromoAction:: | 1175 promoAction:signin_metrics::PromoAction:: |
| 1205 PROMO_ACTION_NOT_DEFAULT]; | 1176 PROMO_ACTION_NOT_DEFAULT]; |
| 1206 } | 1177 } |
| 1207 | 1178 |
| 1208 @end | 1179 @end |
| OLD | NEW |