forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios][userpolicy] User policy prompt half sheet
The prompt is used to notify the user that from now on their administrator may push policies to their browser when they use a managed account. The user is offered 2 options: - Continue - Sign Out and Clear Data The User Policy feature isn't yet released. There is still UX work to be done on the prompt, but this initial iteration is a good start. The layout will probably remain as is and the text is subject to change. User Policy isn't a policy in itself where it adds a new provider to get policies using a managed account. Mock: http://shortn/_YimzhZuC57 Implementation: http://shortn/_QYMgdC3T59 Demo Video: http://shortn/_Csim1j4PoY Bug: 1410811 Change-Id: Idcc1df3cafd0164309c315d70503236a0b3342de Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4198119 Commit-Queue: Vincent Boisselle <vincb@google.com> Reviewed-by: Mark Cogan <marq@chromium.org> Cr-Commit-Position: refs/heads/main@{#1099282}
- Loading branch information
Showing
20 changed files
with
553 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2023 The Chromium Authors | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
source_set("user_policy") { | ||
configs += [ "//build/config/compiler:enable_arc" ] | ||
sources = [ | ||
"user_policy_prompt_coordinator.h", | ||
"user_policy_prompt_coordinator.mm", | ||
"user_policy_prompt_coordinator_delegate.h", | ||
"user_policy_prompt_mediator.h", | ||
"user_policy_prompt_mediator.mm", | ||
"user_policy_prompt_presenter.h", | ||
"user_policy_prompt_view_controller.h", | ||
"user_policy_prompt_view_controller.mm", | ||
] | ||
deps = [ | ||
"//base", | ||
"//components/signin/public/base", | ||
"//ios/chrome/app/strings", | ||
"//ios/chrome/browser/main:public", | ||
"//ios/chrome/browser/policy", | ||
"//ios/chrome/browser/policy/resources:enterprise_grey_icon_large", | ||
"//ios/chrome/browser/signin", | ||
"//ios/chrome/browser/ui/authentication", | ||
"//ios/chrome/browser/ui/authentication/signin", | ||
"//ios/chrome/browser/ui/authentication/signin:signin_headers", | ||
"//ios/chrome/browser/ui/commands", | ||
"//ios/chrome/browser/ui/coordinators:chrome_coordinators", | ||
"//ios/chrome/browser/ui/elements:activity_overlay", | ||
"//ios/chrome/common/ui/colors", | ||
"//ios/chrome/common/ui/confirmation_alert", | ||
"//ui/base", | ||
] | ||
frameworks = [ "UIKit.framework" ] | ||
} |
20 changes: 20 additions & 0 deletions
20
ios/chrome/browser/ui/policy/user_policy/user_policy_prompt_coordinator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// 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_POLICY_USER_POLICY_USER_POLICY_PROMPT_COORDINATOR_H_ | ||
#define IOS_CHROME_BROWSER_UI_POLICY_USER_POLICY_USER_POLICY_PROMPT_COORDINATOR_H_ | ||
|
||
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h" | ||
|
||
@protocol UserPolicyPromptCoordinatorDelegate; | ||
|
||
@interface UserPolicyPromptCoordinator : ChromeCoordinator | ||
|
||
// Delegate for the coordinator. Can be a parent coordinator that owns this | ||
// coordinator or a scene agent. | ||
@property(nonatomic, weak) id<UserPolicyPromptCoordinatorDelegate> delegate; | ||
|
||
@end | ||
|
||
#endif // IOS_CHROME_BROWSER_UI_POLICY_USER_POLICY_USER_POLICY_PROMPT_COORDINATOR_H_ |
129 changes: 129 additions & 0 deletions
129
ios/chrome/browser/ui/policy/user_policy/user_policy_prompt_coordinator.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// 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/policy/user_policy/user_policy_prompt_coordinator.h" | ||
|
||
#import "base/strings/sys_string_conversions.h" | ||
#import "ios/chrome/browser/main/browser.h" | ||
#import "ios/chrome/browser/signin/authentication_service.h" | ||
#import "ios/chrome/browser/signin/authentication_service_factory.h" | ||
#import "ios/chrome/browser/ui/authentication/authentication_ui_util.h" | ||
#import "ios/chrome/browser/ui/elements/activity_overlay_coordinator.h" | ||
#import "ios/chrome/browser/ui/policy/user_policy/user_policy_prompt_coordinator_delegate.h" | ||
#import "ios/chrome/browser/ui/policy/user_policy/user_policy_prompt_mediator.h" | ||
#import "ios/chrome/browser/ui/policy/user_policy/user_policy_prompt_presenter.h" | ||
#import "ios/chrome/browser/ui/policy/user_policy/user_policy_prompt_view_controller.h" | ||
#import "ios/chrome/common/ui/confirmation_alert/confirmation_alert_action_handler.h" | ||
|
||
#if !defined(__has_feature) || !__has_feature(objc_arc) | ||
#error "This file requires ARC support." | ||
#endif | ||
|
||
class ChromeBrowserState; | ||
|
||
namespace { | ||
constexpr CGFloat kHalfSheetCornerRadius = 20; | ||
} // namespace | ||
|
||
@interface UserPolicyPromptCoordinator () <UserPolicyPromptPresenter> | ||
|
||
// View controller for the User Policy prompt. | ||
@property(nonatomic, strong) | ||
UserPolicyPromptViewController* presentedViewController; | ||
|
||
// Mediator for the User Policy prompt. | ||
@property(nonatomic, strong) UserPolicyPromptMediator* mediator; | ||
|
||
// Child coordinator than handles the activity overlay shown on top of the view | ||
// when there is an ongoing activity. | ||
@property(nonatomic, strong) | ||
ActivityOverlayCoordinator* activityOverlayCoordinator; | ||
|
||
@end | ||
|
||
@implementation UserPolicyPromptCoordinator | ||
|
||
#pragma mark - Internal | ||
|
||
// Returns the domain of the administrator hosting the primary account. | ||
// Returns an empty string if the account isn't managed OR isn't syncing. | ||
- (NSString*)managedDomain { | ||
return base::SysUTF16ToNSString(HostedDomainForPrimaryAccount(self.browser)); | ||
} | ||
|
||
// Returns the AuthenticationService of the browser. | ||
- (AuthenticationService*)authService { | ||
ChromeBrowserState* browserState = self.browser->GetBrowserState(); | ||
DCHECK(browserState); | ||
AuthenticationService* authService = | ||
AuthenticationServiceFactory::GetForBrowserState(browserState); | ||
return authService; | ||
} | ||
|
||
#pragma mark - ChromeCoordinator | ||
|
||
- (void)start { | ||
self.mediator = | ||
[[UserPolicyPromptMediator alloc] initWithPresenter:self | ||
authService:[self authService]]; | ||
|
||
self.presentedViewController = [[UserPolicyPromptViewController alloc] | ||
initWithManagedDomain:[self managedDomain]]; | ||
self.presentedViewController.actionHandler = self.mediator; | ||
self.presentedViewController.presentationController.delegate = self.mediator; | ||
|
||
if (@available(iOS 15, *)) { | ||
self.presentedViewController.modalPresentationStyle = | ||
UIModalPresentationPageSheet; | ||
UISheetPresentationController* presentationController = | ||
self.presentedViewController.sheetPresentationController; | ||
presentationController.prefersEdgeAttachedInCompactHeight = YES; | ||
presentationController.detents = @[ | ||
UISheetPresentationControllerDetent.mediumDetent, | ||
UISheetPresentationControllerDetent.largeDetent | ||
]; | ||
presentationController.preferredCornerRadius = kHalfSheetCornerRadius; | ||
} else { | ||
self.presentedViewController.modalPresentationStyle = | ||
UIModalPresentationFormSheet; | ||
} | ||
|
||
self.presentedViewController.modalInPresentation = YES; | ||
|
||
[self.baseViewController presentViewController:self.presentedViewController | ||
animated:YES | ||
completion:nil]; | ||
} | ||
|
||
- (void)stop { | ||
[self hideActivityOverlay]; | ||
if (self.presentedViewController) { | ||
[self.baseViewController.presentedViewController | ||
dismissViewControllerAnimated:YES | ||
completion:nil]; | ||
self.presentedViewController = nil; | ||
} | ||
} | ||
|
||
#pragma mark - UserPolicyPromptPresenter | ||
|
||
- (void)stopPresenting { | ||
[self.delegate didCompletePresentation:self]; | ||
} | ||
|
||
- (void)showActivityOverlay { | ||
self.activityOverlayCoordinator = [[ActivityOverlayCoordinator alloc] | ||
initWithBaseViewController:self.presentedViewController | ||
browser:self.browser]; | ||
[self.activityOverlayCoordinator start]; | ||
} | ||
|
||
- (void)hideActivityOverlay { | ||
if (self.activityOverlayCoordinator) { | ||
[self.activityOverlayCoordinator stop]; | ||
self.activityOverlayCoordinator = nil; | ||
} | ||
} | ||
|
||
@end |
16 changes: 16 additions & 0 deletions
16
ios/chrome/browser/ui/policy/user_policy/user_policy_prompt_coordinator_delegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// 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_POLICY_USER_POLICY_USER_POLICY_PROMPT_COORDINATOR_DELEGATE_H_ | ||
#define IOS_CHROME_BROWSER_UI_POLICY_USER_POLICY_USER_POLICY_PROMPT_COORDINATOR_DELEGATE_H_ | ||
|
||
@protocol UserPolicyPromptCoordinatorDelegate <NSObject> | ||
|
||
// Called when the presentation did complete. Usually called when the action the | ||
// user did on the prompt is completed (e.g. after sign out). | ||
- (void)didCompletePresentation:(UserPolicyPromptCoordinator*)coordinator; | ||
|
||
@end | ||
|
||
#endif // IOS_CHROME_BROWSER_UI_POLICY_USER_POLICY_USER_POLICY_PROMPT_COORDINATOR_DELEGATE_H_ |
27 changes: 27 additions & 0 deletions
27
ios/chrome/browser/ui/policy/user_policy/user_policy_prompt_mediator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// 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_POLICY_USER_POLICY_USER_POLICY_PROMPT_MEDIATOR_H_ | ||
#define IOS_CHROME_BROWSER_UI_POLICY_USER_POLICY_USER_POLICY_PROMPT_MEDIATOR_H_ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import "ios/chrome/common/ui/confirmation_alert/confirmation_alert_action_handler.h" | ||
|
||
@protocol UserPolicyPromptPresenter; | ||
class AuthenticationService; | ||
|
||
@interface UserPolicyPromptMediator | ||
: NSObject <ConfirmationAlertActionHandler, | ||
UIAdaptivePresentationControllerDelegate> | ||
|
||
- (instancetype)initWithPresenter:(id<UserPolicyPromptPresenter>)presenter | ||
authService:(AuthenticationService*)authService | ||
NS_DESIGNATED_INITIALIZER; | ||
|
||
- (instancetype)init NS_UNAVAILABLE; | ||
|
||
@end | ||
|
||
#endif // IOS_CHROME_BROWSER_UI_POLICY_USER_POLICY_USER_POLICY_PROMPT_MEDIATOR_H_ |
65 changes: 65 additions & 0 deletions
65
ios/chrome/browser/ui/policy/user_policy/user_policy_prompt_mediator.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// 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/policy/user_policy/user_policy_prompt_mediator.h" | ||
|
||
#import "components/signin/public/base/signin_metrics.h" | ||
#import "ios/chrome/browser/signin/authentication_service.h" | ||
#import "ios/chrome/browser/ui/policy/user_policy/user_policy_prompt_presenter.h" | ||
|
||
#if !defined(__has_feature) || !__has_feature(objc_arc) | ||
#error "This file requires ARC support." | ||
#endif | ||
|
||
@interface UserPolicyPromptMediator () | ||
|
||
// Presenter of the User Policy prompt view. | ||
@property(nonatomic, weak, readonly) id<UserPolicyPromptPresenter> presenter; | ||
|
||
// AuthenticationService for handling authentication (e.g. sign out). | ||
@property(nonatomic, assign, readonly) AuthenticationService* authService; | ||
|
||
@end | ||
|
||
@implementation UserPolicyPromptMediator | ||
|
||
- (instancetype)initWithPresenter:(id<UserPolicyPromptPresenter>)presenter | ||
authService:(AuthenticationService*)authService { | ||
if (self = [super init]) { | ||
_presenter = presenter; | ||
_authService = authService; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)stopPresentation { | ||
[self.presenter stopPresenting]; | ||
} | ||
|
||
#pragma mark - ConfirmationAlertActionHandler | ||
|
||
- (void)confirmationAlertPrimaryAction { | ||
[self stopPresentation]; | ||
} | ||
|
||
- (void)confirmationAlertSecondaryAction { | ||
DCHECK(self.authService); | ||
__weak __typeof(self) weakSelf = self; | ||
[self.presenter showActivityOverlay]; | ||
self.authService->SignOut( | ||
signin_metrics::ProfileSignout:: | ||
kUserClickedSignoutFromUserPolicyNotificationDialog, | ||
false, ^{ | ||
[weakSelf stopPresentation]; | ||
}); | ||
} | ||
|
||
#pragma mark - UIAdaptivePresentationControllerDelegate | ||
|
||
- (void)presentationControllerDidDismiss: | ||
(UIPresentationController*)presentationController { | ||
[self stopPresentation]; | ||
} | ||
|
||
@end |
21 changes: 21 additions & 0 deletions
21
ios/chrome/browser/ui/policy/user_policy/user_policy_prompt_presenter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// 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_POLICY_USER_POLICY_USER_POLICY_PROMPT_PRESENTER_H_ | ||
#define IOS_CHROME_BROWSER_UI_POLICY_USER_POLICY_USER_POLICY_PROMPT_PRESENTER_H_ | ||
|
||
@protocol UserPolicyPromptPresenter <NSObject> | ||
|
||
// Stop presenting the view. | ||
- (void)stopPresenting; | ||
|
||
// Show the actvity overlay on the view. | ||
- (void)showActivityOverlay; | ||
|
||
// Hide the activity overlay on the view. | ||
- (void)hideActivityOverlay; | ||
|
||
@end | ||
|
||
#endif // IOS_CHROME_BROWSER_UI_POLICY_USER_POLICY_USER_POLICY_PROMPT_PRESENTER_H_ |
Oops, something went wrong.