Commit 32d5ab93 authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Commit Bot

[iOS] Present the user consent bump at startup if needed

Adds a call from -[MainController scheduleLowPriorityStartupTasks] to
the BrowserViewController, to present the ConsentBumpCoordinater if
needed.

Bug: 866506
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: If27ff2e61659489da6e61a48b9d1e252ad43f9e8
Reviewed-on: https://chromium-review.googlesource.com/1163506
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581871}
parent 3992b358
......@@ -1398,6 +1398,7 @@ enum class ShowTabSwitcherSnapshotResult {
#pragma mark - Promo support
- (void)scheduleShowPromo {
[self.mainBVC.dispatcher showConsentBumpIfNeeded];
// Don't show promos if first run is shown. (Note: This flag is only YES
// while the first run UI is visible. However, as this function is called
// immediately after the UI is shown, it's a safe check.)
......
......@@ -345,6 +345,7 @@ source_set("ui_internal") {
"//ios/chrome/browser/ui/alert_coordinator",
"//ios/chrome/browser/ui/app_launcher",
"//ios/chrome/browser/ui/authentication",
"//ios/chrome/browser/ui/authentication/consent_bump",
"//ios/chrome/browser/ui/autofill:autofill",
"//ios/chrome/browser/ui/bookmarks",
"//ios/chrome/browser/ui/browser_container",
......
......@@ -19,9 +19,11 @@ source_set("consent_bump") {
":consent_bump_ui",
"//base",
"//components/strings",
"//components/unified_consent",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/authentication/unified_consent",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/unified_consent",
"//ui/base",
]
}
......
......@@ -7,6 +7,9 @@
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
namespace ios {
class ChromeBrowserState;
} // namespace ios
@protocol ConsentBumpCoordinatorDelegate;
// Coordinator handling the consent bump.
......@@ -18,6 +21,10 @@
// Delegate for this coordinator.
@property(nonatomic, weak) id<ConsentBumpCoordinatorDelegate> delegate;
// Returns YES if the consent bump should be presented to the user.
+ (BOOL)shouldShowConsentBumpWithBrowserState:
(ios::ChromeBrowserState*)browserState;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTHENTICATION_CONSENT_BUMP_CONSENT_BUMP_COORDINATOR_H_
......@@ -5,12 +5,14 @@
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator.h"
#include "base/logging.h"
#include "components/unified_consent/unified_consent_service.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator_delegate.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_mediator.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_personalization_coordinator.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_view_controller.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_view_controller_delegate.h"
#import "ios/chrome/browser/ui/authentication/unified_consent/unified_consent_coordinator.h"
#include "ios/chrome/browser/unified_consent/unified_consent_service_factory.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -46,6 +48,13 @@
@synthesize personalizationCoordinator = _personalizationCoordinator;
@synthesize mediator = _mediator;
+ (BOOL)shouldShowConsentBumpWithBrowserState:
(ios::ChromeBrowserState*)browserState {
unified_consent::UnifiedConsentService* consent_service =
UnifiedConsentServiceFactory::GetForBrowserState(browserState);
return consent_service && consent_service->ShouldShowConsentBump();
}
#pragma mark - Properties
- (UIViewController*)viewController {
......
......@@ -117,6 +117,8 @@
#import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
#import "ios/chrome/browser/ui/alert_coordinator/repost_form_coordinator.h"
#import "ios/chrome/browser/ui/app_launcher/app_launcher_coordinator.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator.h"
#import "ios/chrome/browser/ui/authentication/consent_bump/consent_bump_coordinator_delegate.h"
#import "ios/chrome/browser/ui/authentication/re_signin_infobar_delegate.h"
#import "ios/chrome/browser/ui/autofill/form_input_accessory_coordinator.h"
#import "ios/chrome/browser/ui/background_generator.h"
......@@ -424,6 +426,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
AppRatingPromptDelegate,
BubblePresenterDelegate,
CaptivePortalDetectorTabHelperDelegate,
ConsentBumpCoordinatorDelegate,
CRWNativeContentProvider,
CRWWebStateDelegate,
DialogPresenterDelegate,
......@@ -737,6 +740,9 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Whether the safe area insets should be used to adjust the viewport.
@property(nonatomic, readonly) BOOL usesSafeInsetsForViewportAdjustments;
// Coordinator to ask the user for the new consent.
@property(nonatomic, strong) ConsentBumpCoordinator* consentBumpCoordinator;
// BVC initialization
// ------------------
// If the BVC is initialized with a valid browser state & tab model immediately,
......@@ -944,6 +950,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// DialogPresenterDelegate property
@synthesize dialogPresenterDelegateIsPresenting =
_dialogPresenterDelegateIsPresenting;
@synthesize consentBumpCoordinator = _consentBumpCoordinator;
#pragma mark - Object lifecycle
......@@ -5046,6 +5053,21 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
}
}
- (void)showConsentBumpIfNeeded {
DCHECK(!self.consentBumpCoordinator);
if (![ConsentBumpCoordinator
shouldShowConsentBumpWithBrowserState:_browserState]) {
return;
}
self.consentBumpCoordinator =
[[ConsentBumpCoordinator alloc] initWithBaseViewController:self];
self.consentBumpCoordinator.delegate = self;
[self.consentBumpCoordinator start];
[self presentViewController:self.consentBumpCoordinator.viewController
animated:YES
completion:nil];
}
#pragma mark - ToolbarOwner (Public)
- (CGRect)toolbarFrame {
......@@ -5972,4 +5994,20 @@ nativeContentHeaderHeightForPreloadController:(PreloadController*)controller
[self.dispatcher showSignin:command baseViewController:self];
}
#pragma mark - ConsentBumpCoordinatorDelegate
- (void)consentBumpCoordinator:(ConsentBumpCoordinator*)coordinator
didFinishNeedingToShowSettings:(BOOL)shouldShowSettings {
DCHECK(self.consentBumpCoordinator);
DCHECK(self.consentBumpCoordinator.viewController);
[self.consentBumpCoordinator.viewController
dismissViewControllerAnimated:YES
completion:nil];
self.consentBumpCoordinator = nil;
if (shouldShowSettings) {
// TODO(crbug.com/827072): Needs to open the sync and Google services
// panel from the settings.
}
}
@end
......@@ -119,6 +119,9 @@
// Prepares the browser to display a popup menu.
- (void)prepareForPopupMenuPresentation:(PopupMenuCommandType)type;
// Shows the consent bump if it is required.
- (void)showConsentBumpIfNeeded;
@end
#endif // IOS_CHROME_BROWSER_UI_COMMANDS_BROWSER_COMMANDS_H_
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