Commit 198dc253 authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Commit Bot

[iOS] Disable link when there is no account in the user consent

In the unified user consent dialog, if there is no Google account on the
device, then the Settings should not be shown since the user cannot
sign-in yet. Once an account is added the Settings link should visible
and usable.

A DCHECK and a comment has been added for -[UnifiedConsentViewController
updateIdentityPickerViewWithAvatar:] to make sure
-[UnifiedConsentViewController updateIdentityPickerViewWithUserFullName:
email:] is always called before to set an avatar to the identity view.

With the Settings link:
https://drive.google.com/open?id=1NjIsfv47GP_y2yMtxAvQcqVqGF-20USb
Without the Settings link:
https://drive.google.com/open?id=1pD0QFHNjki1OoC1ztW6CgPfW6iLWOdZf

Bug: 827072
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ia4c90c5e85790f0b0b3baa8974a7abc87c1dbf26
Reviewed-on: https://chromium-review.googlesource.com/1070663
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561530}
parent cbd86ffe
......@@ -55,7 +55,9 @@
- (void)updateIdentityPickerViewWithUserFullName:(NSString*)fullName
email:(NSString*)email;
// Updates the IdentityPickerView avatar.
// Updates the IdentityPickerView avatar. If the identity picker view is hidden,
// -[UnifiedConsentViewController updateIdentityPickerViewWithUserFullName:
// email:] has to be called before.
- (void)updateIdentityPickerViewWithAvatar:(UIImage*)avatar;
// Hides the IdentityPickerView.
......
......@@ -80,6 +80,8 @@ const char* kSettingsSyncURL = "internal://settings-sync";
@property(nonatomic, strong) NSLayoutConstraint* withIdentityConstraint;
// Settings link controller.
@property(nonatomic, strong) LabelLinkController* settingsLinkController;
// Label related to customize sync text.
@property(nonatomic, strong) UILabel* customizeSyncLabel;
@end
......@@ -94,6 +96,7 @@ const char* kSettingsSyncURL = "internal://settings-sync";
@synthesize scrollView = _scrollView;
@synthesize settingsLinkController = _settingsLinkController;
@synthesize withIdentityConstraint = _withIdentityConstraint;
@synthesize customizeSyncLabel = _customizeSyncLabel;
- (const std::vector<int>&)consentStringIds {
return _consentStringIds;
......@@ -106,9 +109,11 @@ const char* kSettingsSyncURL = "internal://settings-sync";
self.noIdentityConstraint.active = NO;
self.withIdentityConstraint.active = YES;
[self.identityPickerView setIdentityName:fullName email:email];
[self setSettingsLinkURLShown:YES];
}
- (void)updateIdentityPickerViewWithAvatar:(UIImage*)avatar {
DCHECK(!self.identityPickerView.hidden);
[self.identityPickerView setIdentityAvatar:avatar];
}
......@@ -116,6 +121,7 @@ const char* kSettingsSyncURL = "internal://settings-sync";
self.identityPickerView.hidden = YES;
self.withIdentityConstraint.active = NO;
self.noIdentityConstraint.active = YES;
[self setSettingsLinkURLShown:NO];
}
- (void)scrollToBottom {
......@@ -214,13 +220,11 @@ const char* kSettingsSyncURL = "internal://settings-sync";
[UIColor colorWithWhite:0 alpha:kSeparatorColorAlpha];
[container addSubview:separator];
// Customize label.
UILabel* customizeLabel =
[self addLabelWithStringId:IDS_IOS_ACCOUNT_UNIFIED_CONSENT_SETTINGS
withIcon:nil
iconVerticallyCentered:NO
parentView:container];
self.openSettingsStringId = IDS_IOS_ACCOUNT_UNIFIED_CONSENT_SETTINGS;
[self addSettingsLinkURLWithLabel:customizeLabel];
self.customizeSyncLabel = [self addLabelWithStringId:self.openSettingsStringId
withIcon:nil
iconVerticallyCentered:NO
parentView:container];
// Layouts
NSDictionary* views = @{
......@@ -233,7 +237,7 @@ const char* kSettingsSyncURL = "internal://settings-sync";
@"synctext" : syncBookmarkLabel,
@"personalizedtext" : morePersonalizedLabel,
@"powerfultext" : powerfulGoogleLabel,
@"customizetext" : customizeLabel,
@"customizesynctext" : self.customizeSyncLabel,
};
NSDictionary* metrics = @{
@"TitlePickerMargin" : @(KTitlePickerMargin),
......@@ -259,7 +263,7 @@ const char* kSettingsSyncURL = "internal://settings-sync";
@"V:[synctext]-(VBetweenText)-[personalizedtext]",
@"V:[personalizedtext]-(VBetweenText)-[powerfultext]",
@"V:[powerfultext]-(VTextMargin)-[separator]",
@"V:[separator]-(VBetweenText)-[customizetext]-(VTextMargin)-|",
@"V:[separator]-(VBetweenText)-[customizesynctext]-(VTextMargin)-|",
// Size constraints.
@"V:[header(HeaderHeight)]",
@"V:[separator(SeparatorHeight)]",
......@@ -392,24 +396,29 @@ const char* kSettingsSyncURL = "internal://settings-sync";
return label;
}
// Adds settings link in the customize label.
- (void)addSettingsLinkURLWithLabel:(UILabel*)label {
DCHECK(!self.settingsLinkController);
// Adds or removes the Settings link in |self.customizeSyncLabel|.
- (void)setSettingsLinkURLShown:(BOOL)showLink {
self.customizeSyncLabel.text =
l10n_util::GetNSString(self.openSettingsStringId);
GURL URL = google_util::AppendGoogleLocaleParam(
GURL(kSettingsSyncURL), GetApplicationContext()->GetApplicationLocale());
NSRange range;
NSString* text = label.text;
label.text = ParseStringWithLink(text, &range);
NSString* text = self.customizeSyncLabel.text;
self.customizeSyncLabel.text = ParseStringWithLink(text, &range);
DCHECK(range.location != NSNotFound && range.length != 0);
__weak UnifiedConsentViewController* weakSelf = self;
self.settingsLinkController =
[[LabelLinkController alloc] initWithLabel:label
action:^(const GURL& URL) {
[weakSelf openSettings];
}];
[self.settingsLinkController
setLinkColor:[[MDCPalette cr_bluePalette] tint500]];
[self.settingsLinkController addLinkWithRange:range url:URL];
if (!showLink) {
self.settingsLinkController = nil;
} else {
__weak UnifiedConsentViewController* weakSelf = self;
self.settingsLinkController =
[[LabelLinkController alloc] initWithLabel:self.customizeSyncLabel
action:^(const GURL& URL) {
[weakSelf openSettings];
}];
[self.settingsLinkController
setLinkColor:[[MDCPalette cr_bluePalette] tint500]];
[self.settingsLinkController addLinkWithRange:range url:URL];
}
}
// Updates constraints and content insets for the |scrollView| and
......
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