Commit ea5c5de7 authored by Ewann's avatar Ewann Committed by Commit Bot

[iOS] Implements the page info site security view controller

- Implements the page info site security view controller.
- Fixes stop [pageInfoCoordinator stop].
- Renames PageInfoButtonAction to PageInfoSiteSecurityButtonAction.

screenshots: https://drive.google.com/drive/folders/1ilG-PTprtWe3QO7sbJUhv_ilwWNmXPwx?usp=sharing

Bug: 1038919
Change-Id: I09a492c31cf50c3472903017e871fd8a0757d54d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2093218Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Ewann Pellé <ewannpv@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749591}
parent 55c1af17
......@@ -37,6 +37,7 @@ source_set("page_info") {
"//ios/chrome/browser/ui/util",
"//ios/chrome/common",
"//ios/chrome/common/ui/colors",
"//ios/chrome/common/ui/util",
"//ios/web",
"//ios/web/public/security",
"//ui/base",
......
......@@ -481,7 +481,7 @@ const CGFloat kButtonXOffset = kTextXPosition;
}
// Returns a button with title and action configured for |buttonAction|.
- (UIButton*)buttonForAction:(PageInfoButtonAction)buttonAction {
- (UIButton*)buttonForAction:(PageInfoSiteSecurityButtonAction)buttonAction {
if (buttonAction == PageInfoSiteSecurityButtonActionNone) {
return nil;
}
......@@ -519,7 +519,7 @@ const CGFloat kButtonXOffset = kTextXPosition;
// Adds the the button |buttonAction| that explains the icons. Returns the y
// position delta for the next offset.
- (CGFloat)addButton:(PageInfoButtonAction)buttonAction
- (CGFloat)addButton:(PageInfoSiteSecurityButtonAction)buttonAction
toSubviews:(NSMutableArray*)subviews
atOffset:(CGFloat)offset {
UIButton* button = [self buttonForAction:buttonAction];
......
......@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/reading_list/offline_page_tab_helper.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/page_info/page_info_mediator.h"
#import "ios/chrome/browser/ui/page_info/page_info_navigation_commands.h"
......@@ -65,7 +66,7 @@
- (void)stop {
[self.dispatcher stopDispatchingToTarget:self];
[self.baseViewController.presentingViewController
[self.baseViewController.presentedViewController
dismissViewControllerAnimated:YES
completion:nil];
self.dispatcher = nil;
......@@ -95,6 +96,7 @@
[[PageInfoSiteSecurityViewController alloc]
initWitDescription:description];
viewController.handler = HandlerForProtocol(self.dispatcher, BrowserCommands);
[self.navigationController pushViewController:viewController animated:YES];
}
......
......@@ -8,7 +8,7 @@
#import <UIKit/UIKit.h>
// Types of the different actions the page info site security button can have.
typedef NS_ENUM(NSUInteger, PageInfoButtonAction) {
typedef NS_ENUM(NSUInteger, PageInfoSiteSecurityButtonAction) {
// No action.
PageInfoSiteSecurityButtonActionNone,
// Show the help page.
......@@ -23,7 +23,7 @@ typedef NS_ENUM(NSUInteger, PageInfoButtonAction) {
@property(nonatomic, copy) NSString* title;
@property(nonatomic, copy) NSString* message;
@property(nonatomic, strong) UIImage* image;
@property(nonatomic, assign) PageInfoButtonAction buttonAction;
@property(nonatomic, assign) PageInfoSiteSecurityButtonAction buttonAction;
@end
......
......@@ -9,6 +9,8 @@
#import "ios/chrome/browser/ui/page_info/page_info_site_security_description.h"
@protocol BrowserCommands;
// View Controller for displaying the site security.
@interface PageInfoSiteSecurityViewController : UIViewController
......@@ -20,6 +22,9 @@
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;
// Handler used to navigate outside the page info.
@property(nonatomic, weak) id<BrowserCommands> handler;
@end
#endif // IOS_CHROME_BROWSER_UI_PAGE_INFO_PAGE_INFO_SITE_SECURITY_VIEW_CONTROLLER_H_
......@@ -4,6 +4,12 @@
#import "ios/chrome/browser/ui/page_info/page_info_site_security_view_controller.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/ui/colors/UIColor+cr_semantic_colors.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h"
#import "ios/chrome/common/ui/util/constraints_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -11,6 +17,16 @@
#error "This file requires ARC support."
#endif
namespace {
const CGFloat kHorizontalSpacing = 16.0f;
const CGFloat kVerticalSpacing = 20.0f;
const CGFloat kIconSize = 20.0f;
} // namespace
@interface PageInfoSiteSecurityViewController ()
@property(nonatomic, strong)
......@@ -32,10 +48,171 @@
#pragma mark - UIViewController
- (void)viewDidLoad {
// TODO(crbug.com/1038919): Implement this.
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorNamed:kBackgroundColor];
self.title = l10n_util::GetNSString(IDS_IOS_PAGE_INFO_SITE_SECURITY);
// ScrollView that contains site security information.
UIScrollView* scrollView = [[UIScrollView alloc] init];
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:scrollView];
AddSameConstraints(self.view, scrollView);
// Site security information.
UILabel* securitySummary = [[UILabel alloc] init];
securitySummary.textColor = UIColor.cr_labelColor;
securitySummary.numberOfLines = 0;
securitySummary.adjustsFontForContentSizeCategory = YES;
securitySummary.text = self.pageInfoSecurityDescription.message;
securitySummary.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
securitySummary.translatesAutoresizingMaskIntoConstraints = NO;
[scrollView addSubview:securitySummary];
// Security icon.
UIImage* securityIcon = [self.pageInfoSecurityDescription.image
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView* securityIconView =
[[UIImageView alloc] initWithImage:securityIcon];
securityIconView.tintColor = UIColor.cr_labelColor;
securityIconView.translatesAutoresizingMaskIntoConstraints = NO;
[scrollView addSubview:securityIconView];
// Website URL.
UILabel* securityURL = [[UILabel alloc] init];
securityURL.textColor = UIColor.cr_labelColor;
securityURL.adjustsFontForContentSizeCategory = YES;
securityURL.text = self.pageInfoSecurityDescription.title;
securityURL.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
securityURL.translatesAutoresizingMaskIntoConstraints = NO;
[scrollView addSubview:securityURL];
// In some cases the icon can be nil.
// e.g, if the URL scheme corresponds to chrome webUI, the icon is not set.
CGFloat iconSize = self.pageInfoSecurityDescription.image ? kIconSize : 0;
CGFloat iconToURLMargin =
self.pageInfoSecurityDescription.image ? kHorizontalSpacing : 0;
NSArray* constraints = @[
// SecuritySummary constraints.
[securitySummary.leadingAnchor
constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor
constant:kHorizontalSpacing],
[securitySummary.trailingAnchor
constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor
constant:-kHorizontalSpacing],
[securitySummary.topAnchor constraintEqualToAnchor:scrollView.topAnchor
constant:kVerticalSpacing],
// SecurityIcon constraints.
[securityIconView.leadingAnchor
constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor
constant:kHorizontalSpacing],
[securityIconView.topAnchor
constraintGreaterThanOrEqualToAnchor:securitySummary.bottomAnchor
constant:kVerticalSpacing],
[securityIconView.heightAnchor constraintEqualToConstant:iconSize],
[securityIconView.widthAnchor
constraintEqualToAnchor:securityIconView.heightAnchor],
[securityIconView.bottomAnchor
constraintLessThanOrEqualToAnchor:scrollView.bottomAnchor
constant:-kVerticalSpacing],
// securityURL constraints.
[securityURL.leadingAnchor
constraintEqualToAnchor:securityIconView.trailingAnchor
constant:iconToURLMargin],
[securityURL.trailingAnchor
constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor
constant:-kHorizontalSpacing],
[securityURL.topAnchor
constraintGreaterThanOrEqualToAnchor:securitySummary.bottomAnchor
constant:kVerticalSpacing],
[securityURL.centerYAnchor
constraintEqualToAnchor:securityIconView.centerYAnchor],
[securityURL.bottomAnchor
constraintLessThanOrEqualToAnchor:scrollView.bottomAnchor
constant:-kVerticalSpacing],
];
[NSLayoutConstraint activateConstraints:constraints];
[self addButtonActionToScrollView:scrollView
securityIconView:securityIconView
securityURL:securityURL];
}
#pragma mark - Private
// Adds a button and his constrainsts based on the |securityIconView| and the
// |securityURL| to the |scrollView|.
- (void)addButtonActionToScrollView:(UIScrollView*)scrollView
securityIconView:(UIImageView*)securityIconView
securityURL:(UILabel*)securityURL {
UIButton* buttonAction =
[self buttonForAction:self.pageInfoSecurityDescription.buttonAction];
// In some cases there is no actions.
// e.g, if the URL scheme corresponds to chrome webUI, the button is not set.
if (!buttonAction)
return;
buttonAction.titleLabel.adjustsFontForContentSizeCategory = YES;
buttonAction.titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
[buttonAction setTitleColor:[UIColor colorNamed:kBlueColor]
forState:UIControlStateNormal];
buttonAction.translatesAutoresizingMaskIntoConstraints = NO;
[scrollView addSubview:buttonAction];
NSArray* buttonConstraints = @[
[buttonAction.leadingAnchor
constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor
constant:kHorizontalSpacing],
[buttonAction.leadingAnchor
constraintLessThanOrEqualToAnchor:self.view.safeAreaLayoutGuide
.trailingAnchor
constant:kHorizontalSpacing],
[buttonAction.topAnchor
constraintGreaterThanOrEqualToAnchor:securityIconView.bottomAnchor
constant:kVerticalSpacing],
[buttonAction.topAnchor
constraintGreaterThanOrEqualToAnchor:securityURL.bottomAnchor
constant:kVerticalSpacing],
[buttonAction.bottomAnchor constraintEqualToAnchor:scrollView.bottomAnchor
constant:-kVerticalSpacing],
];
[NSLayoutConstraint activateConstraints:buttonConstraints];
}
// Returns a button with title and action configured for |buttonAction|.
- (UIButton*)buttonForAction:(PageInfoSiteSecurityButtonAction)buttonAction {
UIButton* button = [UIButton buttonWithType:UIButtonTypeSystem];
int messageId;
switch (buttonAction) {
case PageInfoSiteSecurityButtonActionNone:
return nil;
case PageInfoSiteSecurityButtonActionShowHelp:
messageId = IDS_LEARN_MORE;
[button addTarget:self.handler
action:@selector(showSecurityHelpPage)
forControlEvents:UIControlEventTouchUpInside];
break;
case PageInfoSiteSecurityButtonActionReload:
messageId = IDS_IOS_PAGE_INFO_RELOAD;
[button addTarget:self.handler
action:@selector(hidePageInfo)
forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self.handler
action:@selector(reload)
forControlEvents:UIControlEventTouchUpInside];
break;
};
NSString* title = l10n_util::GetNSStringWithFixup(messageId);
[button setTitle:title forState:UIControlStateNormal];
return button;
}
@end
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