Commit 06a48741 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][Password-Breach] Add view controller and coordinator

Adds a simple view controller and coordinator for the password breach
screen. To be tweaked once UX is done with the details.

Bug: 1008862
Change-Id: I3cc49d5de7f33e453a4a9504b7d976672427a71c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832817
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701989}
parent 700397df
......@@ -120,6 +120,7 @@ source_set("browser_view") {
"//ios/chrome/browser/ui/overscroll_actions",
"//ios/chrome/browser/ui/page_info:coordinator",
"//ios/chrome/browser/ui/page_info/requirements",
"//ios/chrome/browser/ui/passwords",
"//ios/chrome/browser/ui/payments",
"//ios/chrome/browser/ui/popup_menu",
"//ios/chrome/browser/ui/presenters",
......
......@@ -35,6 +35,7 @@
#import "ios/chrome/browser/ui/download/pass_kit_coordinator.h"
#import "ios/chrome/browser/ui/open_in/open_in_mediator.h"
#import "ios/chrome/browser/ui/page_info/page_info_legacy_coordinator.h"
#import "ios/chrome/browser/ui/passwords/password_breach_coordinator.h"
#import "ios/chrome/browser/ui/print/print_controller.h"
#import "ios/chrome/browser/ui/qr_scanner/qr_scanner_legacy_coordinator.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_coordinator.h"
......@@ -115,6 +116,10 @@
// Coordinator for the PassKit UI presentation.
@property(nonatomic, strong) PassKitCoordinator* passKitCoordinator;
// Coordinator for the password breach UI presentation.
@property(nonatomic, strong)
PasswordBreachCoordinator* passwordBreachCoordinator;
// Used to display the Print UI. Nil if not visible.
// TODO(crbug.com/910017): Convert to coordinator.
@property(nonatomic, strong) PrintController* printController;
......@@ -215,6 +220,8 @@
[self.readingListCoordinator stop];
self.readingListCoordinator = nil;
[self.passwordBreachCoordinator stop];
[self.viewController clearPresentedStateWithCompletion:completion
dismissOmnibox:dismissOmnibox];
}
......@@ -313,6 +320,9 @@
self.passKitCoordinator = [[PassKitCoordinator alloc]
initWithBaseViewController:self.viewController];
self.passwordBreachCoordinator = [[PasswordBreachCoordinator alloc]
initWithBaseViewController:self.viewController];
self.printController = [[PrintController alloc]
initWithContextGetter:self.browserState->GetRequestContext()];
......@@ -361,6 +371,9 @@
[self.passKitCoordinator stop];
self.passKitCoordinator = nil;
[self.passwordBreachCoordinator stop];
self.passwordBreachCoordinator = nil;
self.printController = nil;
[self.qrScannerCoordinator stop];
......
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("passwords") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"password_breach_coordinator.h",
"password_breach_coordinator.mm",
"password_breach_view_controller.h",
"password_breach_view_controller.mm",
]
deps = [
"resources",
"//base",
"//components/password_manager/core/browser",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/common/colors",
"//ios/chrome/common/ui_util",
"//ui/base",
]
libs = [ "UIKit.framework" ]
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// 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_PASSWORDS_PASSWORD_BREACH_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_PASSWORDS_PASSWORD_BREACH_COORDINATOR_H_
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
// Presents and stops the Password Breach feature, which consists in alerting
// the user that Chrome detected a leaked credential. In some scenarios it
// prompts for a checkup of the stored passwords.
@interface PasswordBreachCoordinator : ChromeCoordinator
@end
#endif // IOS_CHROME_BROWSER_UI_PASSWORDS_PASSWORD_BREACH_COORDINATOR_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// 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/passwords/password_breach_coordinator.h"
#import "ios/chrome/browser/ui/passwords/password_breach_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface PasswordBreachCoordinator ()
// The main view controller for this coordinator.
@property(nonatomic, strong) PasswordBreachViewController* viewController;
@end
@implementation PasswordBreachCoordinator
- (void)start {
[super start];
self.viewController = [[PasswordBreachViewController alloc] init];
[self.baseViewController presentViewController:self.viewController
animated:YES
completion:nil];
}
- (void)stop {
[self.viewController.presentingViewController
dismissViewControllerAnimated:YES
completion:nil];
self.viewController = nil;
[super stop];
}
@end
// Copyright 2019 The Chromium Authors. All rights reserved.
// 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_PASSWORDS_PASSWORD_BREACH_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_PASSWORDS_PASSWORD_BREACH_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
@interface PasswordBreachViewController : UIViewController
@end
#endif // IOS_CHROME_BROWSER_UI_PASSWORDS_PASSWORD_BREACH_VIEW_CONTROLLER_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// 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/passwords/password_breach_view_controller.h"
#include "base/strings/sys_string_conversions.h"
#include "components/password_manager/core/browser/leak_detection_dialog_utils.h"
#import "ios/chrome/common/colors/semantic_color_names.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using base::SysUTF16ToNSString;
using password_manager::GetAcceptButtonLabel;
using password_manager::GetCancelButtonLabel;
using password_manager::GetDescription;
using password_manager::GetTitle;
using password_manager::CredentialLeakType;
namespace {
constexpr CGFloat kStackViewSpacing = 16.0;
} // namespace
@implementation PasswordBreachViewController
#pragma mark - Public
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorNamed:kBackgroundColor];
// TODO(crbug.com/1008862): Pass these at init instead of using these empty
// ones.
CredentialLeakType leakType = CredentialLeakType();
GURL URL = GURL();
UIButton* doneButton = [UIButton buttonWithType:UIButtonTypeSystem];
[doneButton addTarget:self
action:@selector(didTapDoneButton)
forControlEvents:UIControlEventTouchUpInside];
NSString* doneTitle = SysUTF16ToNSString(GetCancelButtonLabel());
[doneButton setTitle:doneTitle forState:UIControlStateNormal];
doneButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:doneButton];
UIImage* image = [UIImage imageNamed:@"password_breach_illustration"];
UIImageView* imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.translatesAutoresizingMaskIntoConstraints = NO;
UILabel* title = [[UILabel alloc] init];
title.numberOfLines = 0;
title.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
title.textColor = [UIColor colorNamed:kTextPrimaryColor];
title.text = SysUTF16ToNSString(GetTitle(leakType));
title.translatesAutoresizingMaskIntoConstraints = NO;
UILabel* subtitle = [[UILabel alloc] init];
subtitle.numberOfLines = 0;
subtitle.textColor = [UIColor colorNamed:kTextSecondaryColor];
subtitle.text = SysUTF16ToNSString(GetDescription(leakType, URL));
subtitle.translatesAutoresizingMaskIntoConstraints = NO;
UIStackView* stackView = [[UIStackView alloc]
initWithArrangedSubviews:@[ imageView, title, subtitle ]];
stackView.axis = UILayoutConstraintAxisVertical;
stackView.alignment = UIStackViewAlignmentFill;
stackView.translatesAutoresizingMaskIntoConstraints = NO;
stackView.spacing = kStackViewSpacing;
[self.view addSubview:stackView];
UIButton* primaryActionButton = [UIButton buttonWithType:UIButtonTypeSystem];
[primaryActionButton addTarget:self
action:@selector(didTapPrimaryActionButton)
forControlEvents:UIControlEventTouchUpInside];
NSString* primaryActionTitle =
SysUTF16ToNSString(GetAcceptButtonLabel(leakType));
[primaryActionButton setTitle:primaryActionTitle
forState:UIControlStateNormal];
primaryActionButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:primaryActionButton];
UILayoutGuide* margins = self.view.layoutMarginsGuide;
// Primary Action Button constraints.
AddSameConstraintsToSides(margins, doneButton,
LayoutSides::kTrailing | LayoutSides::kTop);
// Stack View (and its contents) constraints.
CGFloat imageAspectRatio = image.size.width / image.size.height;
[imageView.widthAnchor constraintEqualToAnchor:imageView.heightAnchor
multiplier:imageAspectRatio]
.active = YES;
AddSameCenterConstraints(margins, stackView);
AddSameConstraintsToSides(margins, stackView,
LayoutSides::kLeading | LayoutSides::kTrailing);
// Primary Action Button constraints.
AddSameConstraintsToSides(
margins, primaryActionButton,
LayoutSides::kLeading | LayoutSides::kTrailing | LayoutSides::kBottom);
}
#pragma mark - Private
// Handle taps on the done button.
- (void)didTapDoneButton {
// TODO(crbug.com/1008862): Hook up with a mediator.
}
// Handle taps on the primary action button.
- (void)didTapPrimaryActionButton {
// TODO(crbug.com/1008862): Hook up with a mediator.
}
@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