Commit cdcb232b authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[ios] Add access to management page to settings UI info bubble

When the settings are managed by enterprise policy, a "learn more" link
should be shown in the popup bubble triggered by the information icon
by the end of the settings item. Clicking "Learn More" will navigate to
chrome://management page.

Added access to settings below:
- Settings -> Password -> Save password
- Settings -> Payment Method -> Save and Fill Payment Methods
- Settings -> Address and More -> Save and Fill Addresses
- Settings -> Search Engine
- Settings -> Content Settings -> Block Pop-ups

Bug: 1109002
Change-Id: I4bdba99c1a4d2451a99ddeb8f048af77a2aaa334
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337719
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795470}
parent 5d5bc0f2
......@@ -35,6 +35,7 @@
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h"
#include "ios/chrome/grit/ios_strings.h"
#import "net/base/mac/url_conversions.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -61,7 +62,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
#pragma mark - AutofillCreditCardTableViewController
@interface AutofillCreditCardTableViewController () <
PersonalDataManagerObserver> {
PersonalDataManagerObserver,
PopoverLabelViewControllerDelegate> {
autofill::PersonalDataManager* _personalDataManager;
Browser* _browser;
......@@ -292,6 +294,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)didTapManagedUIInfoButton:(UIButton*)buttonView {
EnterpriseInfoPopoverViewController* bubbleViewController =
[[EnterpriseInfoPopoverViewController alloc] initWithEnterpriseName:nil];
bubbleViewController.delegate = self;
[self presentViewController:bubbleViewController animated:YES completion:nil];
// Disable the button when showing the bubble.
......@@ -574,4 +577,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
[self setToolbarItems:customToolbarItems animated:YES];
}
#pragma mark - PopoverLabelViewControllerDelegate
- (void)didTapLinkURL:(NSURL*)URL {
GURL convertedURL = net::GURLWithNSURL(URL);
[self view:nil didTapLinkURL:convertedURL];
}
@end
......@@ -34,6 +34,7 @@
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h"
#include "ios/chrome/grit/ios_strings.h"
#import "net/base/mac/url_conversions.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -59,7 +60,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
#pragma mark - AutofillProfileTableViewController
@interface AutofillProfileTableViewController () <PersonalDataManagerObserver> {
@interface AutofillProfileTableViewController () <
PersonalDataManagerObserver,
PopoverLabelViewControllerDelegate> {
autofill::PersonalDataManager* _personalDataManager;
ChromeBrowserState* _browserState;
......@@ -303,6 +306,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)didTapManagedUIInfoButton:(UIButton*)buttonView {
EnterpriseInfoPopoverViewController* bubbleViewController =
[[EnterpriseInfoPopoverViewController alloc] initWithEnterpriseName:nil];
bubbleViewController.delegate = self;
[self presentViewController:bubbleViewController animated:YES completion:nil];
// Disable the button when showing the bubble.
......@@ -498,4 +502,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
}
}
#pragma mark - PopoverLabelViewControllerDelegate
- (void)didTapLinkURL:(NSURL*)URL {
GURL convertedURL = net::GURLWithNSURL(URL);
[self view:nil didTapLinkURL:convertedURL];
}
@end
......@@ -27,6 +27,7 @@
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h"
#include "ios/chrome/browser/ui/ui_feature_flags.h"
#include "ios/chrome/grit/ios_strings.h"
#import "net/base/mac/url_conversions.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
......@@ -50,7 +51,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
} // namespace
@interface BlockPopupsTableViewController ()<BooleanObserver> {
@interface BlockPopupsTableViewController () <
BooleanObserver,
PopoverLabelViewControllerDelegate> {
ChromeBrowserState* _browserState; // weak
// List of url patterns that are allowed to display popups.
......@@ -257,6 +260,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)didTapManagedUIInfoButton:(UIButton*)buttonView {
EnterpriseInfoPopoverViewController* bubbleViewController =
[[EnterpriseInfoPopoverViewController alloc] initWithEnterpriseName:nil];
bubbleViewController.delegate = self;
[self presentViewController:bubbleViewController animated:YES completion:nil];
// Disable the button when showing the bubble.
......@@ -405,4 +409,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
}
}
#pragma mark - PopoverLabelViewControllerDelegate
- (void)didTapLinkURL:(NSURL*)URL {
GURL convertedURL = net::GURLWithNSURL(URL);
[self view:nil didTapLinkURL:convertedURL];
}
@end
......@@ -228,8 +228,10 @@ typedef NS_ENUM(NSInteger, ItemType) {
NSInteger itemType = [self.tableViewModel itemTypeForIndexPath:indexPath];
switch (itemType) {
case ItemTypeSettingsBlockPopups: {
UIViewController* controller = [[BlockPopupsTableViewController alloc]
initWithBrowserState:_browserState];
BlockPopupsTableViewController* controller =
[[BlockPopupsTableViewController alloc]
initWithBrowserState:_browserState];
controller.dispatcher = self.dispatcher;
[self.navigationController pushViewController:controller animated:YES];
break;
}
......
......@@ -21,6 +21,8 @@ namespace {
NSString* const kEnterpriseIconName = @"enterprise_icon";
NSString* const kChromeManagementURL = @"chrome://management";
NSAttributedString* PrimaryMessage() {
NSString* fullText =
l10n_util::GetNSString(IDS_IOS_ENTERPRISE_MANAGED_SETTING_MESSAGE);
......@@ -47,6 +49,9 @@ NSAttributedString* SecondaryMessage(NSString* enterpriseName) {
// Add a space to have a distanse with the leading icon.
NSString* fullText = [@" " stringByAppendingString:message];
NSRange range;
fullText = ParseStringWithLink(fullText, &range);
NSDictionary* generalAttributes = @{
NSForegroundColorAttributeName : [UIColor colorNamed:kTextSecondaryColor],
NSFontAttributeName :
......@@ -56,8 +61,13 @@ NSAttributedString* SecondaryMessage(NSString* enterpriseName) {
[[NSMutableAttributedString alloc] initWithString:fullText
attributes:generalAttributes];
// TODO(crbug.com/1092544): add "Learn more" link when the link page is
// ready.
NSDictionary* linkAttributes = @{
NSForegroundColorAttributeName : [UIColor colorNamed:kBlueColor],
NSFontAttributeName :
[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote],
NSLinkAttributeName : kChromeManagementURL,
};
[attributedString setAttributes:linkAttributes range:range];
// Create the leading enterprise icon.
NSTextAttachment* attachment = [[NSTextAttachment alloc] init];
......
......@@ -676,6 +676,7 @@ std::vector<std::unique_ptr<autofill::PasswordForm>> CopyOf(
- (void)didTapManagedUIInfoButton:(UIButton*)buttonView {
EnterpriseInfoPopoverViewController* bubbleViewController =
[[EnterpriseInfoPopoverViewController alloc] initWithEnterpriseName:nil];
bubbleViewController.delegate = self;
[self presentViewController:bubbleViewController animated:YES completion:nil];
// Disable the button when showing the bubble.
......
......@@ -87,6 +87,7 @@
#import "ios/public/provider/chrome/browser/signin/signin_presenter.h"
#import "ios/public/provider/chrome/browser/signin/signin_resources_provider.h"
#include "ios/public/provider/chrome/browser/voice/voice_search_prefs.h"
#import "net/base/mac/url_conversions.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -167,6 +168,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
ChromeIdentityServiceObserver,
GoogleServicesSettingsCoordinatorDelegate,
IdentityManagerObserverBridgeDelegate,
PopoverLabelViewControllerDelegate,
PrefObserverDelegate,
PrivacyCoordinatorDelegate,
SafetyCheckCoordinatorDelegate,
......@@ -965,6 +967,7 @@ NSString* kDevViewSourceKey = @"DevViewSource";
- (void)didTapManagedUIInfoButton:(UIButton*)buttonView {
EnterpriseInfoPopoverViewController* bubbleViewController =
[[EnterpriseInfoPopoverViewController alloc] initWithEnterpriseName:nil];
bubbleViewController.delegate = self;
// Disable the button when showing the bubble.
// The button will be enabled when close the bubble in
......@@ -1475,4 +1478,11 @@ NSString* kDevViewSourceKey = @"DevViewSource";
base::RecordAction(base::UserMetricsAction("IOSSettingsCloseWithSwipe"));
}
#pragma mark - PopoverLabelViewControllerDelegate
- (void)didTapLinkURL:(NSURL*)URL {
GURL convertedURL = net::GURLWithNSURL(URL);
[self view:nil didTapLinkURL:convertedURL];
}
@end
......@@ -115,18 +115,24 @@ constexpr CGFloat kVerticalDistance = 24;
[_scrollView addSubview:textView];
UILabel* secondaryLabel = [[UILabel alloc] init];
secondaryLabel.numberOfLines = 0;
secondaryLabel.textColor = [UIColor colorNamed:kTextSecondaryColor];
secondaryLabel.textAlignment = NSTextAlignmentNatural;
secondaryLabel.adjustsFontForContentSizeCategory = YES;
UITextView* secondaryTextView = [[UITextView alloc] init];
secondaryTextView.scrollEnabled = NO;
secondaryTextView.editable = NO;
secondaryTextView.delegate = self;
secondaryTextView.backgroundColor = [UIColor clearColor];
secondaryTextView.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
secondaryTextView.adjustsFontForContentSizeCategory = YES;
secondaryTextView.translatesAutoresizingMaskIntoConstraints = NO;
secondaryTextView.textColor = [UIColor colorNamed:kTextSecondaryColor];
secondaryTextView.linkTextAttributes =
@{NSForegroundColorAttributeName : [UIColor colorNamed:kBlueColor]};
if (self.secondaryAttributedString) {
secondaryLabel.attributedText = self.secondaryAttributedString;
secondaryTextView.attributedText = self.secondaryAttributedString;
}
secondaryLabel.translatesAutoresizingMaskIntoConstraints = NO;
secondaryLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
[_scrollView addSubview:secondaryLabel];
[_scrollView addSubview:secondaryTextView];
NSLayoutConstraint* heightConstraint = [_scrollView.heightAnchor
constraintEqualToAnchor:_scrollView.contentLayoutGuide.heightAnchor
......@@ -139,9 +145,9 @@ constexpr CGFloat kVerticalDistance = 24;
heightConstraint.active = YES;
CGFloat verticalOffset =
(secondaryLabel.attributedText) ? -kVerticalDistance : 0;
(secondaryTextView.attributedText) ? -kVerticalDistance : 0;
NSLayoutConstraint* verticalConstraint =
[textView.bottomAnchor constraintEqualToAnchor:secondaryLabel.topAnchor
[textView.bottomAnchor constraintEqualToAnchor:secondaryTextView.topAnchor
constant:verticalOffset];
[NSLayoutConstraint activateConstraints:@[
......@@ -151,19 +157,19 @@ constexpr CGFloat kVerticalDistance = 24;
constraintEqualToAnchor:textView.leadingAnchor
constant:-kHorizontalInsetValue],
[textContainerView.leadingAnchor
constraintEqualToAnchor:secondaryLabel.leadingAnchor
constraintEqualToAnchor:secondaryTextView.leadingAnchor
constant:-kHorizontalInsetValue],
[textContainerView.trailingAnchor
constraintEqualToAnchor:textView.trailingAnchor
constant:kHorizontalInsetValue],
[textContainerView.trailingAnchor
constraintEqualToAnchor:secondaryLabel.trailingAnchor
constraintEqualToAnchor:secondaryTextView.trailingAnchor
constant:kHorizontalInsetValue],
verticalConstraint,
[textContainerView.topAnchor constraintEqualToAnchor:textView.topAnchor
constant:-kVerticalInsetValue],
[textContainerView.bottomAnchor
constraintEqualToAnchor:secondaryLabel.bottomAnchor
constraintEqualToAnchor:secondaryTextView.bottomAnchor
constant:kVerticalInsetValue],
]];
}
......
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