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 @@ ...@@ -55,7 +55,9 @@
- (void)updateIdentityPickerViewWithUserFullName:(NSString*)fullName - (void)updateIdentityPickerViewWithUserFullName:(NSString*)fullName
email:(NSString*)email; 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; - (void)updateIdentityPickerViewWithAvatar:(UIImage*)avatar;
// Hides the IdentityPickerView. // Hides the IdentityPickerView.
......
...@@ -80,6 +80,8 @@ const char* kSettingsSyncURL = "internal://settings-sync"; ...@@ -80,6 +80,8 @@ const char* kSettingsSyncURL = "internal://settings-sync";
@property(nonatomic, strong) NSLayoutConstraint* withIdentityConstraint; @property(nonatomic, strong) NSLayoutConstraint* withIdentityConstraint;
// Settings link controller. // Settings link controller.
@property(nonatomic, strong) LabelLinkController* settingsLinkController; @property(nonatomic, strong) LabelLinkController* settingsLinkController;
// Label related to customize sync text.
@property(nonatomic, strong) UILabel* customizeSyncLabel;
@end @end
...@@ -94,6 +96,7 @@ const char* kSettingsSyncURL = "internal://settings-sync"; ...@@ -94,6 +96,7 @@ const char* kSettingsSyncURL = "internal://settings-sync";
@synthesize scrollView = _scrollView; @synthesize scrollView = _scrollView;
@synthesize settingsLinkController = _settingsLinkController; @synthesize settingsLinkController = _settingsLinkController;
@synthesize withIdentityConstraint = _withIdentityConstraint; @synthesize withIdentityConstraint = _withIdentityConstraint;
@synthesize customizeSyncLabel = _customizeSyncLabel;
- (const std::vector<int>&)consentStringIds { - (const std::vector<int>&)consentStringIds {
return _consentStringIds; return _consentStringIds;
...@@ -106,9 +109,11 @@ const char* kSettingsSyncURL = "internal://settings-sync"; ...@@ -106,9 +109,11 @@ const char* kSettingsSyncURL = "internal://settings-sync";
self.noIdentityConstraint.active = NO; self.noIdentityConstraint.active = NO;
self.withIdentityConstraint.active = YES; self.withIdentityConstraint.active = YES;
[self.identityPickerView setIdentityName:fullName email:email]; [self.identityPickerView setIdentityName:fullName email:email];
[self setSettingsLinkURLShown:YES];
} }
- (void)updateIdentityPickerViewWithAvatar:(UIImage*)avatar { - (void)updateIdentityPickerViewWithAvatar:(UIImage*)avatar {
DCHECK(!self.identityPickerView.hidden);
[self.identityPickerView setIdentityAvatar:avatar]; [self.identityPickerView setIdentityAvatar:avatar];
} }
...@@ -116,6 +121,7 @@ const char* kSettingsSyncURL = "internal://settings-sync"; ...@@ -116,6 +121,7 @@ const char* kSettingsSyncURL = "internal://settings-sync";
self.identityPickerView.hidden = YES; self.identityPickerView.hidden = YES;
self.withIdentityConstraint.active = NO; self.withIdentityConstraint.active = NO;
self.noIdentityConstraint.active = YES; self.noIdentityConstraint.active = YES;
[self setSettingsLinkURLShown:NO];
} }
- (void)scrollToBottom { - (void)scrollToBottom {
...@@ -214,13 +220,11 @@ const char* kSettingsSyncURL = "internal://settings-sync"; ...@@ -214,13 +220,11 @@ const char* kSettingsSyncURL = "internal://settings-sync";
[UIColor colorWithWhite:0 alpha:kSeparatorColorAlpha]; [UIColor colorWithWhite:0 alpha:kSeparatorColorAlpha];
[container addSubview:separator]; [container addSubview:separator];
// Customize label. // 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.openSettingsStringId = IDS_IOS_ACCOUNT_UNIFIED_CONSENT_SETTINGS;
[self addSettingsLinkURLWithLabel:customizeLabel]; self.customizeSyncLabel = [self addLabelWithStringId:self.openSettingsStringId
withIcon:nil
iconVerticallyCentered:NO
parentView:container];
// Layouts // Layouts
NSDictionary* views = @{ NSDictionary* views = @{
...@@ -233,7 +237,7 @@ const char* kSettingsSyncURL = "internal://settings-sync"; ...@@ -233,7 +237,7 @@ const char* kSettingsSyncURL = "internal://settings-sync";
@"synctext" : syncBookmarkLabel, @"synctext" : syncBookmarkLabel,
@"personalizedtext" : morePersonalizedLabel, @"personalizedtext" : morePersonalizedLabel,
@"powerfultext" : powerfulGoogleLabel, @"powerfultext" : powerfulGoogleLabel,
@"customizetext" : customizeLabel, @"customizesynctext" : self.customizeSyncLabel,
}; };
NSDictionary* metrics = @{ NSDictionary* metrics = @{
@"TitlePickerMargin" : @(KTitlePickerMargin), @"TitlePickerMargin" : @(KTitlePickerMargin),
...@@ -259,7 +263,7 @@ const char* kSettingsSyncURL = "internal://settings-sync"; ...@@ -259,7 +263,7 @@ const char* kSettingsSyncURL = "internal://settings-sync";
@"V:[synctext]-(VBetweenText)-[personalizedtext]", @"V:[synctext]-(VBetweenText)-[personalizedtext]",
@"V:[personalizedtext]-(VBetweenText)-[powerfultext]", @"V:[personalizedtext]-(VBetweenText)-[powerfultext]",
@"V:[powerfultext]-(VTextMargin)-[separator]", @"V:[powerfultext]-(VTextMargin)-[separator]",
@"V:[separator]-(VBetweenText)-[customizetext]-(VTextMargin)-|", @"V:[separator]-(VBetweenText)-[customizesynctext]-(VTextMargin)-|",
// Size constraints. // Size constraints.
@"V:[header(HeaderHeight)]", @"V:[header(HeaderHeight)]",
@"V:[separator(SeparatorHeight)]", @"V:[separator(SeparatorHeight)]",
...@@ -392,24 +396,29 @@ const char* kSettingsSyncURL = "internal://settings-sync"; ...@@ -392,24 +396,29 @@ const char* kSettingsSyncURL = "internal://settings-sync";
return label; return label;
} }
// Adds settings link in the customize label. // Adds or removes the Settings link in |self.customizeSyncLabel|.
- (void)addSettingsLinkURLWithLabel:(UILabel*)label { - (void)setSettingsLinkURLShown:(BOOL)showLink {
DCHECK(!self.settingsLinkController); self.customizeSyncLabel.text =
l10n_util::GetNSString(self.openSettingsStringId);
GURL URL = google_util::AppendGoogleLocaleParam( GURL URL = google_util::AppendGoogleLocaleParam(
GURL(kSettingsSyncURL), GetApplicationContext()->GetApplicationLocale()); GURL(kSettingsSyncURL), GetApplicationContext()->GetApplicationLocale());
NSRange range; NSRange range;
NSString* text = label.text; NSString* text = self.customizeSyncLabel.text;
label.text = ParseStringWithLink(text, &range); self.customizeSyncLabel.text = ParseStringWithLink(text, &range);
DCHECK(range.location != NSNotFound && range.length != 0); DCHECK(range.location != NSNotFound && range.length != 0);
__weak UnifiedConsentViewController* weakSelf = self; if (!showLink) {
self.settingsLinkController = self.settingsLinkController = nil;
[[LabelLinkController alloc] initWithLabel:label } else {
action:^(const GURL& URL) { __weak UnifiedConsentViewController* weakSelf = self;
[weakSelf openSettings]; self.settingsLinkController =
}]; [[LabelLinkController alloc] initWithLabel:self.customizeSyncLabel
[self.settingsLinkController action:^(const GURL& URL) {
setLinkColor:[[MDCPalette cr_bluePalette] tint500]]; [weakSelf openSettings];
[self.settingsLinkController addLinkWithRange:range url:URL]; }];
[self.settingsLinkController
setLinkColor:[[MDCPalette cr_bluePalette] tint500]];
[self.settingsLinkController addLinkWithRange:range url:URL];
}
} }
// Updates constraints and content insets for the |scrollView| and // 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