Commit 96dede7d authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Commit Bot

[iOS] Open Google services settings from user consent

When unified consent flag is enabled, the settings link in the sign-in
dialog should open the Google services settings (instead of the sync
settings).
This patch adds the code to open the Google services settings when the
settings dialog is already opened and when the settings dialog is not
opened.

Bug: 827072
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I560a959d49f983943ec8d39e421ba28b8992e448
Reviewed-on: https://chromium-review.googlesource.com/1196519
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589508}
parent b1b8eb45
......@@ -126,6 +126,7 @@
#import "ios/chrome/browser/ui/main/view_controller_swapping.h"
#import "ios/chrome/browser/ui/orientation_limiting_navigation_controller.h"
#import "ios/chrome/browser/ui/promos/signin_promo_view_controller.h"
#import "ios/chrome/browser/ui/settings/google_services_navigation_coordinator.h"
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#import "ios/chrome/browser/ui/signin_interaction/signin_interaction_coordinator.h"
#import "ios/chrome/browser/ui/stack_view/stack_view_controller.h"
......@@ -298,6 +299,7 @@ enum class ShowTabSwitcherSnapshotResult {
} // namespace
@interface MainController ()<BrowserStateStorageSwitching,
GoogleServicesNavigationCoordinatorDelegate,
PrefObserverDelegate,
SettingsNavigationControllerDelegate,
TabModelObserver,
......@@ -325,6 +327,8 @@ enum class ShowTabSwitcherSnapshotResult {
// Navigation View controller for the settings.
SettingsNavigationController* _settingsNavigationController;
// Coordinator to display the Google services settings.
GoogleServicesNavigationCoordinator* _googleServicesNavigationCoordinator;
// TabSwitcher object -- the stack view, tablet switcher, etc.
id<TabSwitcher> _tabSwitcher;
......@@ -1666,6 +1670,35 @@ enum class ShowTabSwitcherSnapshotResult {
completion:nil];
}
// TODO(crbug.com/779791) : Remove show settings from MainController.
- (void)showGoogleServicesSettingsFromViewController:
(UIViewController*)baseViewController {
if (!baseViewController) {
DCHECK_EQ(self.currentBVC, self.viewControllerSwapper.activeViewController);
baseViewController = self.currentBVC;
}
DCHECK(![baseViewController presentedViewController]);
if ([self currentBrowserState]->IsOffTheRecord()) {
NOTREACHED();
return;
}
if (_settingsNavigationController) {
// Navigate to the Google services settings if the settings dialog is
// already opened.
[_settingsNavigationController
showGoogleServicesSettingsFromViewController:baseViewController];
return;
}
// If the settings dialog is not already opened, start a new
// GoogleServicesNavigationCoordinator.
_googleServicesNavigationCoordinator =
[[GoogleServicesNavigationCoordinator alloc]
initWithBaseViewController:baseViewController
browserState:_mainBrowserState];
_googleServicesNavigationCoordinator.delegate = self;
[_googleServicesNavigationCoordinator start];
}
// TODO(crbug.com/779791) : Remove show settings commands from MainController.
- (void)showSyncSettingsFromViewController:
(UIViewController*)baseViewController {
......@@ -2706,6 +2739,14 @@ enum class ShowTabSwitcherSnapshotResult {
}
}
#pragma mark - GoogleServicesNavigationCoordinatorDelegate
- (void)googleServicesNavigationCoordinatorDidClose:
(GoogleServicesNavigationCoordinator*)coordinator {
DCHECK_EQ(_googleServicesNavigationCoordinator, coordinator);
_googleServicesNavigationCoordinator = nil;
}
@end
#pragma mark - TestingOnly
......
......@@ -5988,14 +5988,15 @@ nativeContentHeaderHeightForPreloadController:(PreloadController*)controller
didFinishNeedingToShowSettings:(BOOL)shouldShowSettings {
DCHECK(self.consentBumpCoordinator);
DCHECK(self.consentBumpCoordinator.viewController);
auto completion = ^{
if (shouldShowSettings) {
[self.dispatcher showGoogleServicesSettingsFromViewController:self];
}
};
[self.consentBumpCoordinator.viewController
dismissViewControllerAnimated:YES
completion:nil];
completion:completion];
self.consentBumpCoordinator = nil;
if (shouldShowSettings) {
// TODO(crbug.com/827072): Needs to open the sync and Google services
// panel from the settings.
}
}
@end
......@@ -22,6 +22,10 @@
- (void)showAccountsSettingsFromViewController:
(UIViewController*)baseViewController;
// Shows the Google services settings UI, presenting from |baseViewController|.
- (void)showGoogleServicesSettingsFromViewController:
(UIViewController*)baseViewController;
// TODO(crbug.com/779791) : Do not pass baseViewController through dispatcher.
// Shows the sync settings UI, presenting from |baseViewController|.
- (void)showSyncSettingsFromViewController:
......
......@@ -42,6 +42,8 @@ source_set("settings") {
"content_settings_collection_view_controller.mm",
"dataplan_usage_collection_view_controller.h",
"dataplan_usage_collection_view_controller.mm",
"google_services_navigation_coordinator.h",
"google_services_navigation_coordinator.mm",
"google_services_settings_consumer.h",
"google_services_settings_coordinator.h",
"google_services_settings_coordinator.mm",
......
// Copyright 2018 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_GOOGLE_SERVICES_NAVIGATION_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_NAVIGATION_COORDINATOR_H_
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
@class GoogleServicesNavigationCoordinator;
// GoogleServicesNavigationCoordinator delegate.
@protocol GoogleServicesNavigationCoordinatorDelegate<NSObject>
// Called when the user closed GoogleServicesNavigationCoordinator.
- (void)googleServicesNavigationCoordinatorDidClose:
(GoogleServicesNavigationCoordinator*)coordinator;
@end
// Shows the Google services settings in a navigation controller.
@interface GoogleServicesNavigationCoordinator : ChromeCoordinator
// Delegate.
@property(nonatomic, weak) id<GoogleServicesNavigationCoordinatorDelegate>
delegate;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_NAVIGATION_COORDINATOR_H_
// Copyright 2018 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/google_services_navigation_coordinator.h"
#include "base/logging.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/icons/chrome_icon.h"
#import "ios/chrome/browser/ui/settings/google_services_settings_coordinator.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface GoogleServicesNavigationCoordinator ()
// Google services settings coordinator.
@property(nonatomic, strong)
GoogleServicesSettingsCoordinator* googleServicesSettingsCoordinator;
// Main view controller.
@property(nonatomic, strong) UINavigationController* navigationController;
@end
@implementation GoogleServicesNavigationCoordinator
@synthesize googleServicesSettingsCoordinator =
_googleServicesSettingsCoordinator;
@synthesize navigationController = _navigationController;
@synthesize delegate = _delegate;
- (void)start {
self.navigationController = [[UINavigationController alloc] init];
self.googleServicesSettingsCoordinator =
[[GoogleServicesSettingsCoordinator alloc]
initWithBaseViewController:self.navigationController
browserState:self.browserState];
self.googleServicesSettingsCoordinator.navigationController =
self.navigationController;
[self.googleServicesSettingsCoordinator start];
self.googleServicesSettingsCoordinator.viewController.navigationItem
.leftBarButtonItem = [self closeButton];
[self.baseViewController presentViewController:self.navigationController
animated:YES
completion:nil];
}
// This method should be moved to the view controller.
- (UIBarButtonItem*)closeButton {
UIBarButtonItem* closeButton =
[ChromeIcon templateBarButtonItemWithImage:[ChromeIcon closeIcon]
target:self
action:@selector(closeSettings)];
closeButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_CLOSE);
return closeButton;
}
- (void)closeSettings {
DCHECK_EQ(self.navigationController,
self.baseViewController.presentedViewController);
void (^completion)(void) = ^{
[self.delegate googleServicesNavigationCoordinatorDidClose:self];
};
[self.baseViewController dismissViewControllerAnimated:YES
completion:completion];
}
@end
......@@ -152,10 +152,18 @@ constexpr NSInteger kSectionOffset = 1000;
}
- (void)reloadSections:(NSIndexSet*)sections {
if (!self.collectionViewModel) {
// No need to reload since the model has not been loaded yet.
return;
}
[self.collectionView reloadSections:sections];
}
- (void)reloadItem:(CollectionViewItem*)item {
if (!self.collectionViewModel) {
// No need to reload since the model has not been loaded yet.
return;
}
NSIndexPath* indexPath = [self.collectionViewModel indexPathForItem:item];
[self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
}
......
......@@ -18,9 +18,12 @@
#import "ios/chrome/browser/ui/settings/accounts_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/autofill_profile_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/google_services_settings_coordinator.h"
#import "ios/chrome/browser/ui/settings/google_services_settings_view_controller.h"
#import "ios/chrome/browser/ui/settings/import_data_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_root_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_utils.h"
#import "ios/chrome/browser/ui/settings/sync_encryption_passphrase_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/sync_settings_collection_view_controller.h"
......@@ -31,7 +34,6 @@
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider.h"
#import "ios/third_party/material_components_ios/src/components/AppBar/src/MaterialAppBar.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -69,7 +71,13 @@
@end
@interface SettingsNavigationController ()<UIGestureRecognizerDelegate>
@interface SettingsNavigationController ()<
GoogleServicesSettingsCoordinatorDelegate,
UIGestureRecognizerDelegate>
// Google services settings coordinator.
@property(nonatomic, strong)
GoogleServicesSettingsCoordinator* googleServicesSettingsCoordinator;
// Sets up the UI. Used by both initializers.
- (void)configureUI;
......@@ -98,6 +106,8 @@
NSMutableDictionary* appBarContainedViewControllers_;
}
@synthesize googleServicesSettingsCoordinator =
_googleServicesSettingsCoordinator;
@synthesize shouldCommitSyncChangesOnDismissal =
shouldCommitSyncChangesOnDismissal_;
......@@ -392,6 +402,14 @@ initWithRootViewController:(UIViewController*)rootViewController
return [self.topViewController shouldAutorotate];
}
#pragma mark - GoogleServicesSettingsCoordinatorDelegate
- (void)googleServicesSettingsCoordinatorDidRemove:
(GoogleServicesSettingsCoordinator*)coordinator {
DCHECK_EQ(self.googleServicesSettingsCoordinator, coordinator);
self.googleServicesSettingsCoordinator = nil;
}
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {
......@@ -491,6 +509,26 @@ initWithRootViewController:(UIViewController*)rootViewController
[self pushViewController:controller animated:YES];
}
// TODO(crbug.com/779791) : Do not pass |baseViewController| through dispatcher.
- (void)showGoogleServicesSettingsFromViewController:
(UIViewController*)baseViewController {
if ([self.topViewController
isKindOfClass:[GoogleServicesSettingsViewController class]]) {
// The top view controller is already the Google services settings panel.
// No need to open it.
return;
}
self.googleServicesSettingsCoordinator =
[[GoogleServicesSettingsCoordinator alloc]
initWithBaseViewController:self
browserState:mainBrowserState_];
self.googleServicesSettingsCoordinator.dispatcher =
[delegate_ dispatcherForSettings];
self.googleServicesSettingsCoordinator.navigationController = self;
self.googleServicesSettingsCoordinator.delegate = self;
[self.googleServicesSettingsCoordinator start];
}
// TODO(crbug.com/779791) : Do not pass |baseViewController| through dispatcher.
- (void)showSyncSettingsFromViewController:
(UIViewController*)baseViewController {
......
......@@ -6,6 +6,7 @@
#import "base/ios/block_types.h"
#include "base/logging.h"
#include "components/unified_consent/feature.h"
#import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
#import "ios/chrome/browser/ui/authentication/authentication_ui_util.h"
#import "ios/chrome/browser/ui/commands/application_commands.h"
......@@ -171,8 +172,13 @@
}
- (void)showAccountsSettings {
[self.dispatcher
showAccountsSettingsFromViewController:self.presentingViewController];
if (unified_consent::IsUnifiedConsentFeatureEnabled()) {
[self.dispatcher showGoogleServicesSettingsFromViewController:
self.presentingViewController];
} else {
[self.dispatcher
showAccountsSettingsFromViewController:self.presentingViewController];
}
}
- (BOOL)isPresenting {
......
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