Commit 2392523d authored by Ewann's avatar Ewann Committed by Commit Bot

[iOS] Adds coordinator to Privacy files

This CL adds a coordinator to the privacy table view controller.
Before that the controller was also the coordinator.

Bug: 1064961
Change-Id: I781924cc24b4c8aae0e957e1e504e95ece8953b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2120423
Commit-Queue: Ewann Pellé <ewannpv@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754849}
parent 378bd98c
......@@ -7,6 +7,8 @@ source_set("privacy") {
sources = [
"handoff_table_view_controller.h",
"handoff_table_view_controller.mm",
"privacy_coordinator.h",
"privacy_coordinator.mm",
"privacy_table_view_controller.h",
"privacy_table_view_controller.mm",
]
......@@ -24,6 +26,7 @@ source_set("privacy") {
"//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/settings:constants",
"//ios/chrome/browser/ui/settings:settings_root",
"//ios/chrome/browser/ui/settings/cells",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_PRIVACY_PRIVACY_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_PRIVACY_PRIVACY_COORDINATOR_H_
#import <Foundation/Foundation.h>
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
@class PrivacyCoordinator;
// Delegate that allows to dereference the PrivacyCoordinator.
@protocol PrivacyCoordinatorDelegate
// Called when the view controller is removed from navigation controller.
- (void)privacyCoordinatorViewControllerWasRemoved:
(PrivacyCoordinator*)coordinator;
@end
// The coordinator for the Privacy screen.
@interface PrivacyCoordinator : ChromeCoordinator
@property(nonatomic, weak) id<PrivacyCoordinatorDelegate> delegate;
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
NS_UNAVAILABLE;
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browserState:(ChromeBrowserState*)browserState
NS_UNAVAILABLE;
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browser:(Browser*)browser NS_UNAVAILABLE;
- (instancetype)initWithBaseNavigationController:
(UINavigationController*)navigationController
browser:(Browser*)browser
NS_DESIGNATED_INITIALIZER;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_PRIVACY_PRIVACY_COORDINATOR_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/settings/privacy/privacy_coordinator.h"
#include "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/settings/privacy/privacy_table_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface PrivacyCoordinator () <
PrivacyTableViewControllerPresentationDelegate>
@property(nonatomic, strong) PrivacyTableViewController* viewController;
@end
@implementation PrivacyCoordinator
@synthesize baseNavigationController = _baseNavigationController;
- (instancetype)initWithBaseNavigationController:
(UINavigationController*)navigationController
browser:(Browser*)browser {
if ([super initWithBaseViewController:navigationController browser:browser]) {
_baseNavigationController = navigationController;
}
return self;
}
#pragma mark - ChromeCoordinator
- (void)start {
self.viewController =
[[PrivacyTableViewController alloc] initWithBrowser:self.browser];
DCHECK(self.baseNavigationController);
[self.baseNavigationController pushViewController:self.viewController
animated:YES];
self.viewController.presentationDelegate = self;
self.viewController.dispatcher = static_cast<
id<ApplicationCommands, BrowserCommands, BrowsingDataCommands>>(
self.browser->GetCommandDispatcher());
}
- (void)stop {
self.viewController = nil;
}
#pragma mark - PrivacyTableViewControllerPresentationDelegate
- (void)privacyTableViewControllerViewControllerWasRemoved:
(PrivacyTableViewController*)controller {
DCHECK_EQ(self.viewController, controller);
[self.delegate privacyCoordinatorViewControllerWasRemoved:self];
}
@end
......@@ -8,12 +8,27 @@
#import "ios/chrome/browser/ui/settings/settings_root_table_view_controller.h"
class Browser;
@class PrivacyTableViewController;
// The accessibility identifier of the privacy settings collection view.
extern NSString* const kPrivacyTableViewId;
// Delegate for presentation events related to
// PrivacyTableViewController.
@protocol PrivacyTableViewControllerPresentationDelegate
// Called when the view controller is removed from its parent.
- (void)privacyTableViewControllerViewControllerWasRemoved:
(PrivacyTableViewController*)controller;
@end
@interface PrivacyTableViewController : SettingsRootTableViewController
// Presentation delegate.
@property(nonatomic, weak) id<PrivacyTableViewControllerPresentationDelegate>
presentationDelegate;
// |browserState| cannot be nil
- (instancetype)initWithBrowser:(Browser*)browser NS_DESIGNATED_INITIALIZER;
......
......@@ -113,6 +113,14 @@ const char kGoogleServicesSettingsURL[] = "settings://open_google_services";
[self loadModel];
}
- (void)didMoveToParentViewController:(UIViewController*)parent {
[super didMoveToParentViewController:parent];
if (!parent) {
[self.presentationDelegate
privacyTableViewControllerViewControllerWasRemoved:self];
}
}
#pragma mark - ChromeTableViewController
- (void)loadModel {
......
......@@ -57,6 +57,7 @@
#import "ios/chrome/browser/ui/settings/language/language_settings_mediator.h"
#import "ios/chrome/browser/ui/settings/language/language_settings_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/password/passwords_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/privacy/privacy_coordinator.h"
#import "ios/chrome/browser/ui/settings/privacy/privacy_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/search_engine_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_table_view_controller_constants.h"
......@@ -160,6 +161,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
GoogleServicesSettingsCoordinatorDelegate,
IdentityManagerObserverBridgeDelegate,
PrefObserverDelegate,
PrivacyCoordinatorDelegate,
SettingsControllerProtocol,
SearchEngineObserving,
SigninPresenter,
......@@ -190,6 +192,9 @@ NSString* kDevViewSourceKey = @"DevViewSource";
SigninPromoViewMediator* _signinPromoViewMediator;
GoogleServicesSettingsCoordinator* _googleServicesSettingsCoordinator;
// Privacy coordinator.
PrivacyCoordinator* _privacyCoordinator;
// Cached resized profile image.
UIImage* _resizedImage;
__weak UIImage* _oldImage;
......@@ -825,8 +830,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
initWithPrefs:_browserState->GetPrefs()];
break;
case ItemTypePrivacy:
controller =
[[PrivacyTableViewController alloc] initWithBrowser:_browser];
[self showPrivacy];
break;
case ItemTypeLanguageSettings: {
LanguageSettingsMediator* mediator =
......@@ -929,6 +933,16 @@ NSString* kDevViewSourceKey = @"DevViewSource";
[_googleServicesSettingsCoordinator start];
}
// Shows Privacy screen.
- (void)showPrivacy {
DCHECK(!_privacyCoordinator);
_privacyCoordinator = [[PrivacyCoordinator alloc]
initWithBaseNavigationController:self.navigationController
browser:_browser];
_privacyCoordinator.delegate = self;
[_privacyCoordinator start];
}
// Sets the NSUserDefaults BOOL |value| for |key|.
- (void)setBooleanNSUserDefaultsValue:(BOOL)value forKey:(NSString*)key {
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
......@@ -1087,9 +1101,14 @@ NSString* kDevViewSourceKey = @"DevViewSource";
- (void)settingsWillBeDismissed {
DCHECK(!_settingsHasBeenDismissed);
[_googleServicesSettingsCoordinator stop];
_googleServicesSettingsCoordinator.delegate = nil;
_googleServicesSettingsCoordinator = nil;
[_privacyCoordinator stop];
_privacyCoordinator = nil;
_settingsHasBeenDismissed = YES;
[self.signinInteractionCoordinator cancel];
[_signinPromoViewMediator signinPromoViewIsRemoved];
......@@ -1269,6 +1288,15 @@ NSString* kDevViewSourceKey = @"DevViewSource";
_googleServicesSettingsCoordinator = nil;
}
#pragma mark - PrivacyCoordinatorDelegate
- (void)privacyCoordinatorViewControllerWasRemoved:
(PrivacyCoordinator*)coordinator {
DCHECK_EQ(_privacyCoordinator, coordinator);
[_privacyCoordinator stop];
_privacyCoordinator = nil;
}
#pragma mark - IdentityManagerObserverBridgeDelegate
// Notifies this controller that the sign in state has changed.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment