| 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/settings_navigation_controller.h" | 5 #import "ios/chrome/browser/ui/settings/settings_navigation_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/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 10 #import "base/mac/scoped_nsobject.h" | |
| 11 #include "components/strings/grit/components_strings.h" | 9 #include "components/strings/grit/components_strings.h" |
| 12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 10 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 13 #include "ios/chrome/browser/sync/sync_setup_service.h" | 11 #include "ios/chrome/browser/sync/sync_setup_service.h" |
| 14 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" | 12 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" |
| 15 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 13 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 16 #import "ios/chrome/browser/ui/commands/clear_browsing_data_command.h" | 14 #import "ios/chrome/browser/ui/commands/clear_browsing_data_command.h" |
| 17 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 15 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 18 #import "ios/chrome/browser/ui/commands/show_signin_command.h" | 16 #import "ios/chrome/browser/ui/commands/show_signin_command.h" |
| 19 #import "ios/chrome/browser/ui/icons/chrome_icon.h" | 17 #import "ios/chrome/browser/ui/icons/chrome_icon.h" |
| 20 #import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h" | 18 #import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 33 #import "ios/chrome/browser/ui/settings/sync_settings_collection_view_controller
.h" | 31 #import "ios/chrome/browser/ui/settings/sync_settings_collection_view_controller
.h" |
| 34 #include "ios/chrome/browser/ui/ui_util.h" | 32 #include "ios/chrome/browser/ui/ui_util.h" |
| 35 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 33 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 36 #include "ios/chrome/grit/ios_strings.h" | 34 #include "ios/chrome/grit/ios_strings.h" |
| 37 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 35 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 38 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider
.h" | 36 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider
.h" |
| 39 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater
ialAppBar.h" | 37 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater
ialAppBar.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 41 #include "ui/base/l10n/l10n_util_mac.h" | 39 #include "ui/base/l10n/l10n_util_mac.h" |
| 42 | 40 |
| 41 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 42 #error "This file requires ARC support." |
| 43 #endif |
| 44 |
| 43 // TODO(crbug.com/620361): Remove the entire class when iOS 9 is dropped. | 45 // TODO(crbug.com/620361): Remove the entire class when iOS 9 is dropped. |
| 44 @interface SettingsAppBarContainerViewController | 46 @interface SettingsAppBarContainerViewController |
| 45 : MDCAppBarContainerViewController | 47 : MDCAppBarContainerViewController |
| 46 @end | 48 @end |
| 47 | 49 |
| 48 @implementation SettingsAppBarContainerViewController | 50 @implementation SettingsAppBarContainerViewController |
| 49 | 51 |
| 50 #pragma mark - Status bar | 52 #pragma mark - Status bar |
| 51 | 53 |
| 52 - (UIViewController*)childViewControllerForStatusBarHidden { | 54 - (UIViewController*)childViewControllerForStatusBarHidden { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // Intercepts the chrome command |sender|. If |sender| is an | 95 // Intercepts the chrome command |sender|. If |sender| is an |
| 94 // |IDC_CLOSE_SETTINGS_AND_OPEN_URL| and |delegate_| is not nil, then it | 96 // |IDC_CLOSE_SETTINGS_AND_OPEN_URL| and |delegate_| is not nil, then it |
| 95 // calls [delegate closeSettingsAndOpenUrl:sender], otherwise it forwards the | 97 // calls [delegate closeSettingsAndOpenUrl:sender], otherwise it forwards the |
| 96 // command up the responder chain. | 98 // command up the responder chain. |
| 97 - (void)chromeExecuteCommand:(id)sender; | 99 - (void)chromeExecuteCommand:(id)sender; |
| 98 | 100 |
| 99 @end | 101 @end |
| 100 | 102 |
| 101 @implementation SettingsNavigationController { | 103 @implementation SettingsNavigationController { |
| 102 ios::ChromeBrowserState* mainBrowserState_; // weak | 104 ios::ChromeBrowserState* mainBrowserState_; // weak |
| 103 base::WeakNSProtocol<id<SettingsNavigationControllerDelegate>> delegate_; | 105 __weak id<SettingsNavigationControllerDelegate> delegate_; |
| 104 // Keeps a mapping between the view controllers that are wrapped to display an | 106 // Keeps a mapping between the view controllers that are wrapped to display an |
| 105 // app bar and the containers that wrap them. | 107 // app bar and the containers that wrap them. |
| 106 base::scoped_nsobject<NSMutableDictionary> appBarContainedViewControllers_; | 108 NSMutableDictionary* appBarContainedViewControllers_; |
| 107 } | 109 } |
| 108 | 110 |
| 109 @synthesize shouldCommitSyncChangesOnDismissal = | 111 @synthesize shouldCommitSyncChangesOnDismissal = |
| 110 shouldCommitSyncChangesOnDismissal_; | 112 shouldCommitSyncChangesOnDismissal_; |
| 111 | 113 |
| 112 #pragma mark - SettingsNavigationController methods. | 114 #pragma mark - SettingsNavigationController methods. |
| 113 | 115 |
| 114 // clang-format off | 116 // clang-format off |
| 115 + (SettingsNavigationController*)newSettingsMainControllerWithMainBrowserState: | 117 + (SettingsNavigationController*)newSettingsMainControllerWithMainBrowserState: |
| 116 (ios::ChromeBrowserState*)browserState | 118 (ios::ChromeBrowserState*)browserState |
| 117 currentBrowserState: | 119 currentBrowserState: |
| 118 (ios::ChromeBrowserState*)currentBrowserState | 120 (ios::ChromeBrowserState*)currentBrowserState |
| 119 delegate: | 121 delegate: |
| 120 (id<SettingsNavigationControllerDelegate>)delegate { | 122 (id<SettingsNavigationControllerDelegate>)delegate { |
| 121 // clang-format on | 123 // clang-format on |
| 122 base::scoped_nsobject<UIViewController> controller( | 124 UIViewController* controller = [[SettingsCollectionViewController alloc] |
| 123 [[SettingsCollectionViewController alloc] | 125 initWithBrowserState:browserState |
| 124 initWithBrowserState:browserState | 126 currentBrowserState:currentBrowserState]; |
| 125 currentBrowserState:currentBrowserState]); | |
| 126 SettingsNavigationController* nc = [[SettingsNavigationController alloc] | 127 SettingsNavigationController* nc = [[SettingsNavigationController alloc] |
| 127 initWithRootViewController:controller | 128 initWithRootViewController:controller |
| 128 browserState:browserState | 129 browserState:browserState |
| 129 delegate:delegate]; | 130 delegate:delegate]; |
| 130 [controller navigationItem].rightBarButtonItem = [nc doneButton]; | 131 [controller navigationItem].rightBarButtonItem = [nc doneButton]; |
| 131 return nc; | 132 return nc; |
| 132 } | 133 } |
| 133 | 134 |
| 134 + (SettingsNavigationController*) | 135 + (SettingsNavigationController*) |
| 135 newAccountsController:(ios::ChromeBrowserState*)browserState | 136 newAccountsController:(ios::ChromeBrowserState*)browserState |
| 136 delegate:(id<SettingsNavigationControllerDelegate>)delegate { | 137 delegate:(id<SettingsNavigationControllerDelegate>)delegate { |
| 137 base::scoped_nsobject<UIViewController> controller([ | 138 UIViewController* controller = [[AccountsCollectionViewController alloc] |
| 138 [AccountsCollectionViewController alloc] initWithBrowserState:browserState | 139 initWithBrowserState:browserState |
| 139 closeSettingsOnAddAccount:YES]); | 140 closeSettingsOnAddAccount:YES]; |
| 140 SettingsNavigationController* nc = [[SettingsNavigationController alloc] | 141 SettingsNavigationController* nc = [[SettingsNavigationController alloc] |
| 141 initWithRootViewController:controller | 142 initWithRootViewController:controller |
| 142 browserState:browserState | 143 browserState:browserState |
| 143 delegate:delegate]; | 144 delegate:delegate]; |
| 144 [controller navigationItem].leftBarButtonItem = [nc closeButton]; | 145 [controller navigationItem].leftBarButtonItem = [nc closeButton]; |
| 145 return nc; | 146 return nc; |
| 146 } | 147 } |
| 147 | 148 |
| 148 + (SettingsNavigationController*) | 149 + (SettingsNavigationController*) |
| 149 newSyncController:(ios::ChromeBrowserState*)browserState | 150 newSyncController:(ios::ChromeBrowserState*)browserState |
| 150 allowSwitchSyncAccount:(BOOL)allowSwitchSyncAccount | 151 allowSwitchSyncAccount:(BOOL)allowSwitchSyncAccount |
| 151 delegate:(id<SettingsNavigationControllerDelegate>)delegate { | 152 delegate:(id<SettingsNavigationControllerDelegate>)delegate { |
| 152 base::scoped_nsobject<UIViewController> controller( | 153 UIViewController* controller = [[SyncSettingsCollectionViewController alloc] |
| 153 [[SyncSettingsCollectionViewController alloc] | 154 initWithBrowserState:browserState |
| 154 initWithBrowserState:browserState | 155 allowSwitchSyncAccount:allowSwitchSyncAccount]; |
| 155 allowSwitchSyncAccount:allowSwitchSyncAccount]); | |
| 156 SettingsNavigationController* nc = [[SettingsNavigationController alloc] | 156 SettingsNavigationController* nc = [[SettingsNavigationController alloc] |
| 157 initWithRootViewController:controller | 157 initWithRootViewController:controller |
| 158 browserState:browserState | 158 browserState:browserState |
| 159 delegate:delegate]; | 159 delegate:delegate]; |
| 160 [controller navigationItem].rightBarButtonItem = [nc doneButton]; | 160 [controller navigationItem].rightBarButtonItem = [nc doneButton]; |
| 161 return nc; | 161 return nc; |
| 162 } | 162 } |
| 163 | 163 |
| 164 + (SettingsNavigationController*) | 164 + (SettingsNavigationController*) |
| 165 newUserFeedbackController:(ios::ChromeBrowserState*)browserState | 165 newUserFeedbackController:(ios::ChromeBrowserState*)browserState |
| 166 delegate:(id<SettingsNavigationControllerDelegate>)delegate | 166 delegate:(id<SettingsNavigationControllerDelegate>)delegate |
| 167 feedbackDataSource:(id<UserFeedbackDataSource>)dataSource { | 167 feedbackDataSource:(id<UserFeedbackDataSource>)dataSource { |
| 168 DCHECK(ios::GetChromeBrowserProvider() | 168 DCHECK(ios::GetChromeBrowserProvider() |
| 169 ->GetUserFeedbackProvider() | 169 ->GetUserFeedbackProvider() |
| 170 ->IsUserFeedbackEnabled()); | 170 ->IsUserFeedbackEnabled()); |
| 171 base::scoped_nsobject<UIViewController> controller( | 171 UIViewController* controller = ios::GetChromeBrowserProvider() |
| 172 ios::GetChromeBrowserProvider() | 172 ->GetUserFeedbackProvider() |
| 173 ->GetUserFeedbackProvider() | 173 ->CreateViewController(dataSource); |
| 174 ->CreateViewController(dataSource)); | |
| 175 DCHECK(controller); | 174 DCHECK(controller); |
| 176 SettingsNavigationController* nc = [[SettingsNavigationController alloc] | 175 SettingsNavigationController* nc = [[SettingsNavigationController alloc] |
| 177 initWithRootViewController:controller | 176 initWithRootViewController:controller |
| 178 browserState:browserState | 177 browserState:browserState |
| 179 delegate:delegate]; | 178 delegate:delegate]; |
| 180 [controller navigationItem].rightBarButtonItem = [nc cancelButton]; | 179 [controller navigationItem].rightBarButtonItem = [nc cancelButton]; |
| 181 return nc; | 180 return nc; |
| 182 } | 181 } |
| 183 | 182 |
| 184 + (SettingsNavigationController*) | 183 + (SettingsNavigationController*) |
| 185 newClearBrowsingDataController:(ios::ChromeBrowserState*)browserState | 184 newClearBrowsingDataController:(ios::ChromeBrowserState*)browserState |
| 186 delegate: | 185 delegate: |
| 187 (id<SettingsNavigationControllerDelegate>)delegate { | 186 (id<SettingsNavigationControllerDelegate>)delegate { |
| 188 base::scoped_nsobject<UIViewController> controller( | 187 UIViewController* controller = |
| 189 [[ClearBrowsingDataCollectionViewController alloc] | 188 [[ClearBrowsingDataCollectionViewController alloc] |
| 190 initWithBrowserState:browserState]); | 189 initWithBrowserState:browserState]; |
| 191 SettingsNavigationController* nc = [[SettingsNavigationController alloc] | 190 SettingsNavigationController* nc = [[SettingsNavigationController alloc] |
| 192 initWithRootViewController:controller | 191 initWithRootViewController:controller |
| 193 browserState:browserState | 192 browserState:browserState |
| 194 delegate:delegate]; | 193 delegate:delegate]; |
| 195 [controller navigationItem].rightBarButtonItem = [nc doneButton]; | 194 [controller navigationItem].rightBarButtonItem = [nc doneButton]; |
| 196 return nc; | 195 return nc; |
| 197 } | 196 } |
| 198 | 197 |
| 199 + (SettingsNavigationController*) | 198 + (SettingsNavigationController*) |
| 200 newContextualSearchController:(ios::ChromeBrowserState*)browserState | 199 newContextualSearchController:(ios::ChromeBrowserState*)browserState |
| 201 delegate: | 200 delegate: |
| 202 (id<SettingsNavigationControllerDelegate>)delegate { | 201 (id<SettingsNavigationControllerDelegate>)delegate { |
| 203 base::scoped_nsobject<UIViewController> controller( | 202 UIViewController* controller = |
| 204 [[ContextualSearchCollectionViewController alloc] | 203 [[ContextualSearchCollectionViewController alloc] |
| 205 initWithBrowserState:browserState]); | 204 initWithBrowserState:browserState]; |
| 206 SettingsNavigationController* nc = [[SettingsNavigationController alloc] | 205 SettingsNavigationController* nc = [[SettingsNavigationController alloc] |
| 207 initWithRootViewController:controller | 206 initWithRootViewController:controller |
| 208 browserState:browserState | 207 browserState:browserState |
| 209 delegate:delegate]; | 208 delegate:delegate]; |
| 210 [controller navigationItem].rightBarButtonItem = [nc doneButton]; | 209 [controller navigationItem].rightBarButtonItem = [nc doneButton]; |
| 211 return nc; | 210 return nc; |
| 212 } | 211 } |
| 213 | 212 |
| 214 + (SettingsNavigationController*) | 213 + (SettingsNavigationController*) |
| 215 newSyncEncryptionPassphraseController:(ios::ChromeBrowserState*)browserState | 214 newSyncEncryptionPassphraseController:(ios::ChromeBrowserState*)browserState |
| 216 delegate:(id<SettingsNavigationControllerDelegate>) | 215 delegate:(id<SettingsNavigationControllerDelegate>) |
| 217 delegate { | 216 delegate { |
| 218 base::scoped_nsobject<UIViewController> controller( | 217 UIViewController* controller = |
| 219 [[SyncEncryptionPassphraseCollectionViewController alloc] | 218 [[SyncEncryptionPassphraseCollectionViewController alloc] |
| 220 initWithBrowserState:browserState]); | 219 initWithBrowserState:browserState]; |
| 221 SettingsNavigationController* nc = [[SettingsNavigationController alloc] | 220 SettingsNavigationController* nc = [[SettingsNavigationController alloc] |
| 222 initWithRootViewController:controller | 221 initWithRootViewController:controller |
| 223 browserState:browserState | 222 browserState:browserState |
| 224 delegate:delegate]; | 223 delegate:delegate]; |
| 225 [controller navigationItem].leftBarButtonItem = [nc closeButton]; | 224 [controller navigationItem].leftBarButtonItem = [nc closeButton]; |
| 226 return nc; | 225 return nc; |
| 227 } | 226 } |
| 228 | 227 |
| 229 + (SettingsNavigationController*) | 228 + (SettingsNavigationController*) |
| 230 newNativeAppsController:(ios::ChromeBrowserState*)browserState | 229 newNativeAppsController:(ios::ChromeBrowserState*)browserState |
| 231 delegate:(id<SettingsNavigationControllerDelegate>)delegate { | 230 delegate:(id<SettingsNavigationControllerDelegate>)delegate { |
| 232 base::scoped_nsobject<UIViewController> controller( | 231 UIViewController* controller = [[NativeAppsCollectionViewController alloc] |
| 233 [[NativeAppsCollectionViewController alloc] | 232 initWithURLRequestContextGetter:browserState->GetRequestContext()]; |
| 234 initWithURLRequestContextGetter:browserState->GetRequestContext()]); | |
| 235 SettingsNavigationController* nc = [[SettingsNavigationController alloc] | 233 SettingsNavigationController* nc = [[SettingsNavigationController alloc] |
| 236 initWithRootViewController:controller | 234 initWithRootViewController:controller |
| 237 browserState:browserState | 235 browserState:browserState |
| 238 delegate:delegate]; | 236 delegate:delegate]; |
| 239 return nc; | 237 return nc; |
| 240 } | 238 } |
| 241 | 239 |
| 242 + (SettingsNavigationController*) | 240 + (SettingsNavigationController*) |
| 243 newSavePasswordsController:(ios::ChromeBrowserState*)browserState | 241 newSavePasswordsController:(ios::ChromeBrowserState*)browserState |
| 244 delegate:(id<SettingsNavigationControllerDelegate>)delegate { | 242 delegate:(id<SettingsNavigationControllerDelegate>)delegate { |
| 245 base::scoped_nsobject<UIViewController> controller( | 243 UIViewController* controller = [[SavePasswordsCollectionViewController alloc] |
| 246 [[SavePasswordsCollectionViewController alloc] | 244 initWithBrowserState:browserState]; |
| 247 initWithBrowserState:browserState]); | |
| 248 | 245 |
| 249 SettingsNavigationController* nc = [[SettingsNavigationController alloc] | 246 SettingsNavigationController* nc = [[SettingsNavigationController alloc] |
| 250 initWithRootViewController:controller | 247 initWithRootViewController:controller |
| 251 browserState:browserState | 248 browserState:browserState |
| 252 delegate:delegate]; | 249 delegate:delegate]; |
| 253 [controller navigationItem].rightBarButtonItem = [nc doneButton]; | 250 [controller navigationItem].rightBarButtonItem = [nc doneButton]; |
| 254 | 251 |
| 255 // Make sure the close button is always present, as the Save Passwords screen | 252 // Make sure the close button is always present, as the Save Passwords screen |
| 256 // isn't just shown from Settings. | 253 // isn't just shown from Settings. |
| 257 [controller navigationItem].leftBarButtonItem = [nc closeButton]; | 254 [controller navigationItem].leftBarButtonItem = [nc closeButton]; |
| 258 return nc; | 255 return nc; |
| 259 } | 256 } |
| 260 | 257 |
| 261 + (SettingsNavigationController*) | 258 + (SettingsNavigationController*) |
| 262 newImportDataController:(ios::ChromeBrowserState*)browserState | 259 newImportDataController:(ios::ChromeBrowserState*)browserState |
| 263 delegate:(id<SettingsNavigationControllerDelegate>)delegate | 260 delegate:(id<SettingsNavigationControllerDelegate>)delegate |
| 264 importDataDelegate:(id<ImportDataControllerDelegate>)importDataDelegate | 261 importDataDelegate:(id<ImportDataControllerDelegate>)importDataDelegate |
| 265 fromEmail:(NSString*)fromEmail | 262 fromEmail:(NSString*)fromEmail |
| 266 toEmail:(NSString*)toEmail | 263 toEmail:(NSString*)toEmail |
| 267 isSignedIn:(BOOL)isSignedIn { | 264 isSignedIn:(BOOL)isSignedIn { |
| 268 base::scoped_nsobject<UIViewController> controller( | 265 UIViewController* controller = [[ImportDataCollectionViewController alloc] |
| 269 [[ImportDataCollectionViewController alloc] | 266 initWithDelegate:importDataDelegate |
| 270 initWithDelegate:importDataDelegate | 267 fromEmail:fromEmail |
| 271 fromEmail:fromEmail | 268 toEmail:toEmail |
| 272 toEmail:toEmail | 269 isSignedIn:isSignedIn]; |
| 273 isSignedIn:isSignedIn]); | |
| 274 | 270 |
| 275 SettingsNavigationController* nc = [[SettingsNavigationController alloc] | 271 SettingsNavigationController* nc = [[SettingsNavigationController alloc] |
| 276 initWithRootViewController:controller | 272 initWithRootViewController:controller |
| 277 browserState:browserState | 273 browserState:browserState |
| 278 delegate:delegate]; | 274 delegate:delegate]; |
| 279 | 275 |
| 280 // Make sure the close button is always present, as the Save Passwords screen | 276 // Make sure the close button is always present, as the Save Passwords screen |
| 281 // isn't just shown from Settings. | 277 // isn't just shown from Settings. |
| 282 [controller navigationItem].leftBarButtonItem = [nc closeButton]; | 278 [controller navigationItem].leftBarButtonItem = [nc closeButton]; |
| 283 return nc; | 279 return nc; |
| 284 } | 280 } |
| 285 | 281 |
| 286 + (SettingsNavigationController*) | 282 + (SettingsNavigationController*) |
| 287 newAutofillController:(ios::ChromeBrowserState*)browserState | 283 newAutofillController:(ios::ChromeBrowserState*)browserState |
| 288 delegate:(id<SettingsNavigationControllerDelegate>)delegate { | 284 delegate:(id<SettingsNavigationControllerDelegate>)delegate { |
| 289 base::scoped_nsobject<UIViewController> controller( | 285 UIViewController* controller = [[AutofillCollectionViewController alloc] |
| 290 [[AutofillCollectionViewController alloc] | 286 initWithBrowserState:browserState]; |
| 291 initWithBrowserState:browserState]); | |
| 292 | 287 |
| 293 SettingsNavigationController* nc = [[SettingsNavigationController alloc] | 288 SettingsNavigationController* nc = [[SettingsNavigationController alloc] |
| 294 initWithRootViewController:controller | 289 initWithRootViewController:controller |
| 295 browserState:browserState | 290 browserState:browserState |
| 296 delegate:delegate]; | 291 delegate:delegate]; |
| 297 [controller navigationItem].rightBarButtonItem = [nc doneButton]; | 292 [controller navigationItem].rightBarButtonItem = [nc doneButton]; |
| 298 | 293 |
| 299 // Make sure the close button is always present, as the Autofill screen | 294 // Make sure the close button is always present, as the Autofill screen |
| 300 // isn't just shown from Settings. | 295 // isn't just shown from Settings. |
| 301 [controller navigationItem].leftBarButtonItem = [nc closeButton]; | 296 [controller navigationItem].leftBarButtonItem = [nc closeButton]; |
| 302 return nc; | 297 return nc; |
| 303 } | 298 } |
| 304 | 299 |
| 305 #pragma mark - Lifecycle | 300 #pragma mark - Lifecycle |
| 306 | 301 |
| 307 - (instancetype) | 302 - (instancetype) |
| 308 initWithRootViewController:(UIViewController*)rootViewController | 303 initWithRootViewController:(UIViewController*)rootViewController |
| 309 browserState:(ios::ChromeBrowserState*)browserState | 304 browserState:(ios::ChromeBrowserState*)browserState |
| 310 delegate:(id<SettingsNavigationControllerDelegate>)delegate { | 305 delegate:(id<SettingsNavigationControllerDelegate>)delegate { |
| 311 DCHECK(browserState); | 306 DCHECK(browserState); |
| 312 DCHECK(!browserState->IsOffTheRecord()); | 307 DCHECK(!browserState->IsOffTheRecord()); |
| 313 self = [super initWithRootViewController:rootViewController]; | 308 self = [super initWithRootViewController:rootViewController]; |
| 314 if (self) { | 309 if (self) { |
| 315 mainBrowserState_ = browserState; | 310 mainBrowserState_ = browserState; |
| 316 delegate_.reset(delegate); | 311 delegate_ = delegate; |
| 317 shouldCommitSyncChangesOnDismissal_ = YES; | 312 shouldCommitSyncChangesOnDismissal_ = YES; |
| 318 [self configureUI]; | 313 [self configureUI]; |
| 319 } | 314 } |
| 320 return self; | 315 return self; |
| 321 } | 316 } |
| 322 | 317 |
| 323 - (void)settingsWillBeDismissed { | 318 - (void)settingsWillBeDismissed { |
| 324 // Notify all controllers that settings are about to be dismissed. | 319 // Notify all controllers that settings are about to be dismissed. |
| 325 for (UIViewController* controller in [self viewControllers]) { | 320 for (UIViewController* controller in [self viewControllers]) { |
| 326 if ([controller respondsToSelector:@selector(settingsWillBeDismissed)]) { | 321 if ([controller respondsToSelector:@selector(settingsWillBeDismissed)]) { |
| 327 [controller performSelector:@selector(settingsWillBeDismissed)]; | 322 [controller performSelector:@selector(settingsWillBeDismissed)]; |
| 328 } | 323 } |
| 329 } | 324 } |
| 330 | 325 |
| 331 // Sync changes cannot be cancelled and they must always be commited when | 326 // Sync changes cannot be cancelled and they must always be commited when |
| 332 // existing settings. | 327 // existing settings. |
| 333 if (shouldCommitSyncChangesOnDismissal_) { | 328 if (shouldCommitSyncChangesOnDismissal_) { |
| 334 SyncSetupServiceFactory::GetForBrowserState([self mainBrowserState]) | 329 SyncSetupServiceFactory::GetForBrowserState([self mainBrowserState]) |
| 335 ->CommitChanges(); | 330 ->CommitChanges(); |
| 336 } | 331 } |
| 337 | 332 |
| 338 // Reset the delegate to prevent any queued transitions from attempting to | 333 // Reset the delegate to prevent any queued transitions from attempting to |
| 339 // close the settings. | 334 // close the settings. |
| 340 delegate_.reset(); | 335 delegate_ = nil; |
| 341 } | 336 } |
| 342 | 337 |
| 343 - (void)closeSettings { | 338 - (void)closeSettings { |
| 344 [delegate_ closeSettings]; | 339 [delegate_ closeSettings]; |
| 345 } | 340 } |
| 346 | 341 |
| 347 - (void)back { | 342 - (void)back { |
| 348 [self popViewControllerAnimated:YES]; | 343 [self popViewControllerAnimated:YES]; |
| 349 } | 344 } |
| 350 | 345 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 368 // https://github.com/material-components/material-components-ios/issues/720 | 363 // https://github.com/material-components/material-components-ios/issues/720 |
| 369 [self setNavigationBarHidden:YES]; | 364 [self setNavigationBarHidden:YES]; |
| 370 [self.interactivePopGestureRecognizer setDelegate:self]; | 365 [self.interactivePopGestureRecognizer setDelegate:self]; |
| 371 } | 366 } |
| 372 | 367 |
| 373 - (BOOL)hasRightDoneButton { | 368 - (BOOL)hasRightDoneButton { |
| 374 UIBarButtonItem* rightButton = | 369 UIBarButtonItem* rightButton = |
| 375 self.topViewController.navigationItem.rightBarButtonItem; | 370 self.topViewController.navigationItem.rightBarButtonItem; |
| 376 if (!rightButton) | 371 if (!rightButton) |
| 377 return NO; | 372 return NO; |
| 378 base::scoped_nsobject<UIBarButtonItem> doneButton([self doneButton]); | 373 UIBarButtonItem* doneButton = [self doneButton]; |
| 379 return [rightButton style] == [doneButton style] && | 374 return [rightButton style] == [doneButton style] && |
| 380 [[rightButton title] compare:[doneButton title]] == NSOrderedSame; | 375 [[rightButton title] compare:[doneButton title]] == NSOrderedSame; |
| 381 } | 376 } |
| 382 | 377 |
| 383 - (UIBarButtonItem*)backButton { | 378 - (UIBarButtonItem*)backButton { |
| 384 // Create a custom Back bar button item, as Material Navigation Bar deprecated | 379 // Create a custom Back bar button item, as Material Navigation Bar deprecated |
| 385 // the back arrow with a shaft. | 380 // the back arrow with a shaft. |
| 386 return [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] | 381 return [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] |
| 387 target:self | 382 target:self |
| 388 action:@selector(back)]; | 383 action:@selector(back)]; |
| 389 } | 384 } |
| 390 | 385 |
| 391 - (UIBarButtonItem*)doneButton { | 386 - (UIBarButtonItem*)doneButton { |
| 392 // Create a custom Done bar button item, as Material Navigation Bar does not | 387 // Create a custom Done bar button item, as Material Navigation Bar does not |
| 393 // handle a system UIBarButtonSystemItemDone item. | 388 // handle a system UIBarButtonSystemItemDone item. |
| 394 return [[[UIBarButtonItem alloc] | 389 return [[UIBarButtonItem alloc] |
| 395 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON) | 390 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON) |
| 396 style:UIBarButtonItemStyleDone | 391 style:UIBarButtonItemStyleDone |
| 397 target:self | 392 target:self |
| 398 action:@selector(closeSettings)] autorelease]; | 393 action:@selector(closeSettings)]; |
| 399 } | 394 } |
| 400 | 395 |
| 401 - (UIBarButtonItem*)closeButton { | 396 - (UIBarButtonItem*)closeButton { |
| 402 UIBarButtonItem* closeButton = | 397 UIBarButtonItem* closeButton = |
| 403 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon closeIcon] | 398 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon closeIcon] |
| 404 target:self | 399 target:self |
| 405 action:@selector(closeSettings)]; | 400 action:@selector(closeSettings)]; |
| 406 closeButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_CLOSE); | 401 closeButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_CLOSE); |
| 407 return closeButton; | 402 return closeButton; |
| 408 } | 403 } |
| 409 | 404 |
| 410 - (UIBarButtonItem*)cancelButton { | 405 - (UIBarButtonItem*)cancelButton { |
| 411 // Create a custom Cancel bar button item, as Material Navigation Bar does not | 406 // Create a custom Cancel bar button item, as Material Navigation Bar does not |
| 412 // handle a system UIBarButtonSystemItemCancel item. | 407 // handle a system UIBarButtonSystemItemCancel item. |
| 413 return [[[UIBarButtonItem alloc] | 408 return [[UIBarButtonItem alloc] |
| 414 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_CANCEL_BUTTON) | 409 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_CANCEL_BUTTON) |
| 415 style:UIBarButtonItemStyleDone | 410 style:UIBarButtonItemStyleDone |
| 416 target:self | 411 target:self |
| 417 action:@selector(closeSettings)] autorelease]; | 412 action:@selector(closeSettings)]; |
| 418 } | 413 } |
| 419 | 414 |
| 420 - (UIInterfaceOrientationMask)supportedInterfaceOrientations { | 415 - (UIInterfaceOrientationMask)supportedInterfaceOrientations { |
| 421 return [self.topViewController supportedInterfaceOrientations]; | 416 return [self.topViewController supportedInterfaceOrientations]; |
| 422 } | 417 } |
| 423 | 418 |
| 424 - (BOOL)shouldAutorotate { | 419 - (BOOL)shouldAutorotate { |
| 425 return [self.topViewController shouldAutorotate]; | 420 return [self.topViewController shouldAutorotate]; |
| 426 } | 421 } |
| 427 | 422 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // Executing it on the wrong profile is a privacy issue. Kill the | 517 // Executing it on the wrong profile is a privacy issue. Kill the |
| 523 // app if this ever happens. | 518 // app if this ever happens. |
| 524 CHECK_EQ(commandBrowserState, [self mainBrowserState]); | 519 CHECK_EQ(commandBrowserState, [self mainBrowserState]); |
| 525 break; | 520 break; |
| 526 } | 521 } |
| 527 case IDC_RESET_ALL_WEBVIEWS: | 522 case IDC_RESET_ALL_WEBVIEWS: |
| 528 // The command to reset all webview is not related to the browser state so | 523 // The command to reset all webview is not related to the browser state so |
| 529 // it can just be forwarded it up the responder chain. | 524 // it can just be forwarded it up the responder chain. |
| 530 break; | 525 break; |
| 531 case IDC_SHOW_ACCOUNTS_SETTINGS: { | 526 case IDC_SHOW_ACCOUNTS_SETTINGS: { |
| 532 base::scoped_nsobject<UIViewController> controller( | 527 UIViewController* controller = [[AccountsCollectionViewController alloc] |
| 533 [[AccountsCollectionViewController alloc] | 528 initWithBrowserState:mainBrowserState_ |
| 534 initWithBrowserState:mainBrowserState_ | 529 closeSettingsOnAddAccount:NO]; |
| 535 closeSettingsOnAddAccount:NO]); | |
| 536 [self pushViewController:controller animated:YES]; | 530 [self pushViewController:controller animated:YES]; |
| 537 return; | 531 return; |
| 538 } | 532 } |
| 539 case IDC_SHOW_SYNC_SETTINGS: { | 533 case IDC_SHOW_SYNC_SETTINGS: { |
| 540 base::scoped_nsobject<UIViewController> controller( | 534 UIViewController* controller = |
| 541 [[SyncSettingsCollectionViewController alloc] | 535 [[SyncSettingsCollectionViewController alloc] |
| 542 initWithBrowserState:mainBrowserState_ | 536 initWithBrowserState:mainBrowserState_ |
| 543 allowSwitchSyncAccount:YES]); | 537 allowSwitchSyncAccount:YES]; |
| 544 [self pushViewController:controller animated:YES]; | 538 [self pushViewController:controller animated:YES]; |
| 545 return; | 539 return; |
| 546 } | 540 } |
| 547 case IDC_SHOW_SYNC_PASSPHRASE_SETTINGS: { | 541 case IDC_SHOW_SYNC_PASSPHRASE_SETTINGS: { |
| 548 base::scoped_nsobject<UIViewController> controller( | 542 UIViewController* controller = |
| 549 [[SyncEncryptionPassphraseCollectionViewController alloc] | 543 [[SyncEncryptionPassphraseCollectionViewController alloc] |
| 550 initWithBrowserState:mainBrowserState_]); | 544 initWithBrowserState:mainBrowserState_]; |
| 551 [self pushViewController:controller animated:YES]; | 545 [self pushViewController:controller animated:YES]; |
| 552 return; | 546 return; |
| 553 } | 547 } |
| 554 default: | 548 default: |
| 555 NOTREACHED() | 549 NOTREACHED() |
| 556 << "Unexpected command " << [sender tag] | 550 << "Unexpected command " << [sender tag] |
| 557 << " Settings commands must execute on the main browser state."; | 551 << " Settings commands must execute on the main browser state."; |
| 558 } | 552 } |
| 559 [[self nextResponder] chromeExecuteCommand:sender]; | 553 [[self nextResponder] chromeExecuteCommand:sender]; |
| 560 } | 554 } |
| 561 | 555 |
| 562 #pragma mark - UIResponder | 556 #pragma mark - UIResponder |
| 563 | 557 |
| 564 - (NSArray*)keyCommands { | 558 - (NSArray*)keyCommands { |
| 565 if ([self presentedViewController]) { | 559 if ([self presentedViewController]) { |
| 566 return nil; | 560 return nil; |
| 567 } | 561 } |
| 568 base::WeakNSObject<SettingsNavigationController> weakSelf(self); | 562 __weak SettingsNavigationController* weakSelf = self; |
| 569 return @[ | 563 return @[ |
| 570 [UIKeyCommand cr_keyCommandWithInput:UIKeyInputEscape | 564 [UIKeyCommand cr_keyCommandWithInput:UIKeyInputEscape |
| 571 modifierFlags:Cr_UIKeyModifierNone | 565 modifierFlags:Cr_UIKeyModifierNone |
| 572 title:nil | 566 title:nil |
| 573 action:^{ | 567 action:^{ |
| 574 [weakSelf closeSettings]; | 568 [weakSelf closeSettings]; |
| 575 }], | 569 }], |
| 576 ]; | 570 ]; |
| 577 } | 571 } |
| 578 | 572 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 606 #pragma mark - AppBar Containment | 600 #pragma mark - AppBar Containment |
| 607 | 601 |
| 608 // If viewController doesn't implement the AppBarPresenting protocol, it is | 602 // If viewController doesn't implement the AppBarPresenting protocol, it is |
| 609 // wrapped in an MDCAppBarContainerViewController, which is returned. Otherwise, | 603 // wrapped in an MDCAppBarContainerViewController, which is returned. Otherwise, |
| 610 // viewController is returned. | 604 // viewController is returned. |
| 611 - (UIViewController*)wrappedControllerIfNeeded:(UIViewController*)controller { | 605 - (UIViewController*)wrappedControllerIfNeeded:(UIViewController*)controller { |
| 612 // If the controller can't be presented with an app bar, it needs to be | 606 // If the controller can't be presented with an app bar, it needs to be |
| 613 // wrapped in an MDCAppBarContainerViewController. | 607 // wrapped in an MDCAppBarContainerViewController. |
| 614 if (![controller conformsToProtocol:@protocol(AppBarPresenting)]) { | 608 if (![controller conformsToProtocol:@protocol(AppBarPresenting)]) { |
| 615 MDCAppBarContainerViewController* appBarContainer = | 609 MDCAppBarContainerViewController* appBarContainer = |
| 616 [[[SettingsAppBarContainerViewController alloc] | 610 [[SettingsAppBarContainerViewController alloc] |
| 617 initWithContentViewController:controller] autorelease]; | 611 initWithContentViewController:controller]; |
| 618 | 612 |
| 619 // Configure the style. | 613 // Configure the style. |
| 620 ConfigureAppBarWithCardStyle(appBarContainer.appBar); | 614 ConfigureAppBarWithCardStyle(appBarContainer.appBar); |
| 621 | 615 |
| 622 // Adjust the frame of the contained view controller's view to be below the | 616 // Adjust the frame of the contained view controller's view to be below the |
| 623 // app bar. | 617 // app bar. |
| 624 CGRect contentFrame = controller.view.frame; | 618 CGRect contentFrame = controller.view.frame; |
| 625 CGSize headerSize = [appBarContainer.appBar.headerViewController.headerView | 619 CGSize headerSize = [appBarContainer.appBar.headerViewController.headerView |
| 626 sizeThatFits:contentFrame.size]; | 620 sizeThatFits:contentFrame.size]; |
| 627 contentFrame = UIEdgeInsetsInsetRect( | 621 contentFrame = UIEdgeInsetsInsetRect( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 647 return [potentialAppBarController contentViewController]; | 641 return [potentialAppBarController contentViewController]; |
| 648 } else { | 642 } else { |
| 649 return controller; | 643 return controller; |
| 650 } | 644 } |
| 651 } | 645 } |
| 652 | 646 |
| 653 // Adds an app bar container in a dictionary mapping its content view | 647 // Adds an app bar container in a dictionary mapping its content view |
| 654 // controller's pointer to itself. | 648 // controller's pointer to itself. |
| 655 - (void)registerAppBarContainer:(MDCAppBarContainerViewController*)container { | 649 - (void)registerAppBarContainer:(MDCAppBarContainerViewController*)container { |
| 656 if (!appBarContainedViewControllers_) { | 650 if (!appBarContainedViewControllers_) { |
| 657 appBarContainedViewControllers_.reset([[NSMutableDictionary alloc] init]); | 651 appBarContainedViewControllers_ = [[NSMutableDictionary alloc] init]; |
| 658 } | 652 } |
| 659 NSValue* key = [self keyForController:[container contentViewController]]; | 653 NSValue* key = [self keyForController:[container contentViewController]]; |
| 660 [appBarContainedViewControllers_ setObject:container forKey:key]; | 654 [appBarContainedViewControllers_ setObject:container forKey:key]; |
| 661 } | 655 } |
| 662 | 656 |
| 663 // Removes the app bar container entry from the aforementioned dictionary. | 657 // Removes the app bar container entry from the aforementioned dictionary. |
| 664 - (void)unregisterAppBarContainer:(MDCAppBarContainerViewController*)container { | 658 - (void)unregisterAppBarContainer:(MDCAppBarContainerViewController*)container { |
| 665 NSValue* key = [self keyForController:[container contentViewController]]; | 659 NSValue* key = [self keyForController:[container contentViewController]]; |
| 666 [appBarContainedViewControllers_ removeObjectForKey:key]; | 660 [appBarContainedViewControllers_ removeObjectForKey:key]; |
| 667 } | 661 } |
| 668 | 662 |
| 669 // Returns the app bar container containing |controller| if it is contained. | 663 // Returns the app bar container containing |controller| if it is contained. |
| 670 // Otherwise, returns nil. | 664 // Otherwise, returns nil. |
| 671 - (MDCAppBarContainerViewController*)appBarContainerForController: | 665 - (MDCAppBarContainerViewController*)appBarContainerForController: |
| 672 (UIViewController*)controller { | 666 (UIViewController*)controller { |
| 673 NSValue* key = [self keyForController:controller]; | 667 NSValue* key = [self keyForController:controller]; |
| 674 return [appBarContainedViewControllers_ objectForKey:key]; | 668 return [appBarContainedViewControllers_ objectForKey:key]; |
| 675 } | 669 } |
| 676 | 670 |
| 677 // Returns the dictionary key to use when dealing with |controller|. | 671 // Returns the dictionary key to use when dealing with |controller|. |
| 678 - (NSValue*)keyForController:(UIViewController*)controller { | 672 - (NSValue*)keyForController:(UIViewController*)controller { |
| 679 return [NSValue valueWithPointer:controller]; | 673 return [NSValue valueWithNonretainedObject:controller]; |
| 680 } | 674 } |
| 681 | 675 |
| 682 #pragma mark - UIResponder | 676 #pragma mark - UIResponder |
| 683 | 677 |
| 684 - (BOOL)canBecomeFirstResponder { | 678 - (BOOL)canBecomeFirstResponder { |
| 685 return YES; | 679 return YES; |
| 686 } | 680 } |
| 687 | 681 |
| 688 @end | 682 @end |
| OLD | NEW |