Commit 8c6277bf authored by harrisonsean's avatar harrisonsean Committed by Commit Bot

[iOS][Safety Check] Add support for Safe Browsing Check

Add support for Safe Browsing check

Including adding managed state popover

Add header to safety check page

Bug: 1078782
Change-Id: I26dab9d679c5ecc14779d52bc3b4b13c52586ce4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346805Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Sean Harrison <harrisonsean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799020}
parent a1e402ac
...@@ -328,6 +328,9 @@ locale. The strings in this file are specific to iOS. ...@@ -328,6 +328,9 @@ locale. The strings in this file are specific to iOS.
<message name="IDS_IOS_UPGRADE_AVAILABLE" desc="Text to inform the user of the presence of a new version of the application"> <message name="IDS_IOS_UPGRADE_AVAILABLE" desc="Text to inform the user of the presence of a new version of the application">
Chromium just got better! A new version is available. Chromium just got better! A new version is available.
</message> </message>
<message name="IDS_IOS_SETTINGS_SAFETY_CHECK_PAGE_HEADER" desc="Informational header at the top of the safety check page">
Chromium can help keep you safe from data breaches, unsafe websites and more.
</message>
<message name="IDS_IOS_PASSWORD_CHECK_ERROR" desc="Description of the password check cell, explaining that Password Check failed. [iOS only]" meaning="Password Check failed due to some error."> <message name="IDS_IOS_PASSWORD_CHECK_ERROR" desc="Description of the password check cell, explaining that Password Check failed. [iOS only]" meaning="Password Check failed due to some error.">
Chromium can't check your passwords Chromium can't check your passwords
</message> </message>
......
28a503a39c906bc31debe24cd73ee1100fb1fe45
\ No newline at end of file
...@@ -328,6 +328,9 @@ locale. The strings in this file are specific to iOS. ...@@ -328,6 +328,9 @@ locale. The strings in this file are specific to iOS.
<message name="IDS_IOS_UPGRADE_AVAILABLE" desc="Text to inform the user of the presence of a new version of the application"> <message name="IDS_IOS_UPGRADE_AVAILABLE" desc="Text to inform the user of the presence of a new version of the application">
Chrome just got better! A new version is available. Chrome just got better! A new version is available.
</message> </message>
<message name="IDS_IOS_SETTINGS_SAFETY_CHECK_PAGE_HEADER" desc="Informational header at the top of the safety check page">
Chrome can help keep you safe from data breaches, unsafe websites and more.
</message>
<message name="IDS_IOS_PASSWORD_CHECK_ERROR" desc="Description of the password check cell, explaining that Password Check failed. [iOS only]" meaning="Password Check failed due to some error."> <message name="IDS_IOS_PASSWORD_CHECK_ERROR" desc="Description of the password check cell, explaining that Password Check failed. [iOS only]" meaning="Password Check failed due to some error.">
Chrome can't check your passwords Chrome can't check your passwords
</message> </message>
......
...@@ -1742,6 +1742,18 @@ While in incognito, sites can't use cookies to see your browsing activity across ...@@ -1742,6 +1742,18 @@ While in incognito, sites can't use cookies to see your browsing activity across
<message name="IDS_IOS_SETTINGS_SAFETY_CHECK_SAFE_BROWSING_TITLE" desc="Title for the safe browsing element of safety check" meaning="Row title to display the user's safe browsing status [CHAR_LIMIT=20]"> <message name="IDS_IOS_SETTINGS_SAFETY_CHECK_SAFE_BROWSING_TITLE" desc="Title for the safe browsing element of safety check" meaning="Row title to display the user's safe browsing status [CHAR_LIMIT=20]">
Safe Browsing Safe Browsing
</message> </message>
<message name="IDS_IOS_SETTINGS_SAFETY_CHECK_SAFE_BROWSING_DISABLED_DESC" desc="Detail text for the Safe Browsing check if the user has Safe Browsing disabled">
Off - Not recommended
</message>
<message name="IDS_IOS_SETTINGS_SAFETY_CHECK_SAFE_BROWSING_ENABLED_DESC" desc="Detail text for the Safe Browsing check if the user has Safe Browsing enabled">
Safe Browsing is on
</message>
<message name="IDS_IOS_SETTINGS_SAFETY_CHECK_SAFE_BROWSING_MANAGED_DESC" desc="Detail text for the Safe Browsing check if the user's Safe Browsing setting is managed by their administrator and disabled">
Turned off by your administrator
</message>
<message name="IDS_IOS_SETTINGS_SAFETY_CHECK_SAFE_BROWSING_DISABLED_INFO" desc="String in the popover for the Safe Browsing check to direct the user to the Sync and Google Services page if Safe Browsing is disabled">
To turn on Safe Browsing, open <ph name="BEGIN_LINK">BEGIN_LINK</ph>Sync and Google Services<ph name="END_LINK">END_LINK</ph> and tap Safe Browsing.
</message>
<message name="IDS_IOS_SETTINGS_SAFETY_CHECK_UPDATES_TITLE" desc="Title for the updates element of safety check" meaning="Row title to display the user's Chrome update status, and access upates [CHAR_LIMIT=20]"> <message name="IDS_IOS_SETTINGS_SAFETY_CHECK_UPDATES_TITLE" desc="Title for the updates element of safety check" meaning="Row title to display the user's Chrome update status, and access upates [CHAR_LIMIT=20]">
Updates Updates
</message> </message>
......
...@@ -53,6 +53,8 @@ source_set("safety_check") { ...@@ -53,6 +53,8 @@ source_set("safety_check") {
"//ios/chrome/browser/ui/settings:settings_root", "//ios/chrome/browser/ui/settings:settings_root",
"//ios/chrome/browser/ui/settings/cells", "//ios/chrome/browser/ui/settings/cells",
"//ios/chrome/browser/ui/settings/cells:public", "//ios/chrome/browser/ui/settings/cells:public",
"//ios/chrome/browser/ui/settings/elements:enterprise_info_popover_view_controller",
"//ios/chrome/browser/ui/settings/google_services",
"//ios/chrome/browser/ui/settings/password", "//ios/chrome/browser/ui/settings/password",
"//ios/chrome/browser/ui/settings/utils", "//ios/chrome/browser/ui/settings/utils",
"//ios/chrome/browser/ui/table_view", "//ios/chrome/browser/ui/table_view",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/table_view/cells/table_view_link_header_footer_item.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_consumer.h" #import "ios/chrome/browser/ui/table_view/chrome_table_view_consumer.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h" #import "ios/chrome/browser/ui/table_view/table_view_model.h"
...@@ -16,6 +17,9 @@ ...@@ -16,6 +17,9 @@
// Initializes the check types section with |items|. // Initializes the check types section with |items|.
- (void)setCheckItems:(NSArray<TableViewItem*>*)items; - (void)setCheckItems:(NSArray<TableViewItem*>*)items;
// Initializes the safety check header with |item|.
- (void)setSafetyCheckHeaderItem:(TableViewLinkHeaderFooterItem*)item;
// Initializes the check start section with |item|. // Initializes the check start section with |item|.
- (void)setCheckStartItem:(TableViewItem*)item; - (void)setCheckStartItem:(TableViewItem*)item;
......
...@@ -18,19 +18,26 @@ ...@@ -18,19 +18,26 @@
#import "ios/chrome/browser/ui/commands/application_commands.h" #import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h" #import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/settings/elements/enterprise_info_popover_view_controller.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_coordinator.h"
#import "ios/chrome/browser/ui/settings/password/password_issues_coordinator.h" #import "ios/chrome/browser/ui/settings/password/password_issues_coordinator.h"
#import "ios/chrome/browser/ui/settings/safety_check/safety_check_mediator.h" #import "ios/chrome/browser/ui/settings/safety_check/safety_check_mediator.h"
#import "ios/chrome/browser/ui/settings/safety_check/safety_check_navigation_commands.h" #import "ios/chrome/browser/ui/settings/safety_check/safety_check_navigation_commands.h"
#import "ios/chrome/browser/ui/settings/safety_check/safety_check_table_view_controller.h" #import "ios/chrome/browser/ui/settings/safety_check/safety_check_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#import "ios/chrome/common/ui/elements/popover_label_view_controller.h" #import "ios/chrome/common/ui/elements/popover_label_view_controller.h"
#import "net/base/mac/url_conversions.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface SafetyCheckCoordinator () < @interface SafetyCheckCoordinator () <
GoogleServicesSettingsCoordinatorDelegate,
PasswordIssuesCoordinatorDelegate, PasswordIssuesCoordinatorDelegate,
PopoverLabelViewControllerDelegate,
SafetyCheckNavigationCommands, SafetyCheckNavigationCommands,
SafetyCheckTableViewControllerPresentationDelegate> SafetyCheckTableViewControllerPresentationDelegate>
...@@ -47,6 +54,14 @@ ...@@ -47,6 +54,14 @@
// Dispatcher which can handle changing passwords on sites. // Dispatcher which can handle changing passwords on sites.
@property(nonatomic, strong) id<ApplicationCommands> handler; @property(nonatomic, strong) id<ApplicationCommands> handler;
// Coordinator for the Google Services screen (SafeBrowsing toggle location).
@property(nonatomic, strong)
GoogleServicesSettingsCoordinator* googleServicesSettingsCoordinator;
// Popover view controller with error information.
@property(nonatomic, strong)
PopoverLabelViewController* errorInfoPopoverViewController;
@end @end
@implementation SafetyCheckCoordinator @implementation SafetyCheckCoordinator
...@@ -102,6 +117,28 @@ ...@@ -102,6 +117,28 @@
[self.delegate safetyCheckCoordinatorDidRemove:self]; [self.delegate safetyCheckCoordinatorDidRemove:self];
} }
#pragma mark - PopoverLabelViewControllerDelegate
- (void)didTapLinkURL:(NSURL*)URL {
GURL convertedURL = net::GURLWithNSURL(URL);
const GURL safeBrowsingURL(kSafeBrowsingStringURL);
// Take the user to Sync and Google Services page in Bling instead of desktop
// settings.
if (convertedURL == safeBrowsingURL) {
[self.errorInfoPopoverViewController
dismissViewControllerAnimated:YES
completion:^{
[self showSafeBrowsingPreferencePage];
}];
return;
}
OpenNewTabCommand* command =
[OpenNewTabCommand commandWithURLFromChrome:convertedURL];
[self.handler closeSettingsUIAndOpenURL:command];
}
#pragma mark - SafetyCheckNavigationCommands #pragma mark - SafetyCheckNavigationCommands
- (void)showPasswordIssuesPage { - (void)showPasswordIssuesPage {
...@@ -120,15 +157,19 @@ ...@@ -120,15 +157,19 @@
- (void)showErrorInfoFrom:(UIButton*)buttonView - (void)showErrorInfoFrom:(UIButton*)buttonView
withText:(NSAttributedString*)text { withText:(NSAttributedString*)text {
PopoverLabelViewController* errorInfoPopover = self.errorInfoPopoverViewController =
[[PopoverLabelViewController alloc] initWithPrimaryAttributedString:text [[PopoverLabelViewController alloc] initWithPrimaryAttributedString:text
secondaryAttributedString:nil]; secondaryAttributedString:nil];
errorInfoPopover.popoverPresentationController.sourceView = buttonView; self.errorInfoPopoverViewController.delegate = self;
errorInfoPopover.popoverPresentationController.sourceRect = buttonView.bounds;
errorInfoPopover.popoverPresentationController.permittedArrowDirections = self.errorInfoPopoverViewController.popoverPresentationController.sourceView =
UIPopoverArrowDirectionAny; buttonView;
[self.viewController presentViewController:errorInfoPopover self.errorInfoPopoverViewController.popoverPresentationController.sourceRect =
buttonView.bounds;
self.errorInfoPopoverViewController.popoverPresentationController
.permittedArrowDirections = UIPopoverArrowDirectionAny;
[self.viewController presentViewController:self.errorInfoPopoverViewController
animated:YES animated:YES
completion:nil]; completion:nil];
} }
...@@ -138,7 +179,36 @@ ...@@ -138,7 +179,36 @@
} }
- (void)showSafeBrowsingPreferencePage { - (void)showSafeBrowsingPreferencePage {
// TODO(crbug.com/1078782): Add navigation to Safe Browsing preference page. DCHECK(!self.googleServicesSettingsCoordinator);
self.googleServicesSettingsCoordinator =
[[GoogleServicesSettingsCoordinator alloc]
initWithBaseNavigationController:self.baseNavigationController
browser:self.browser
mode:GoogleServicesSettingsModeSettings];
self.googleServicesSettingsCoordinator.handler = self.handler;
self.googleServicesSettingsCoordinator.delegate = self;
[self.googleServicesSettingsCoordinator start];
}
- (void)showManagedInfoFrom:(UIButton*)buttonView {
EnterpriseInfoPopoverViewController* bubbleViewController =
[[EnterpriseInfoPopoverViewController alloc] initWithEnterpriseName:nil];
[self.viewController presentViewController:bubbleViewController
animated:YES
completion:nil];
// Disable the button when showing the bubble.
// The button will be enabled when close the bubble in
// (void)popoverPresentationControllerDidDismissPopover: of
// EnterpriseInfoPopoverViewController.
buttonView.enabled = NO;
// Set the anchor and arrow direction of the bubble.
bubbleViewController.popoverPresentationController.sourceView = buttonView;
bubbleViewController.popoverPresentationController.sourceRect =
buttonView.bounds;
bubbleViewController.popoverPresentationController.permittedArrowDirections =
UIPopoverArrowDirectionAny;
} }
#pragma mark - PasswordIssuesCoordinatorDelegate #pragma mark - PasswordIssuesCoordinatorDelegate
...@@ -155,4 +225,14 @@ ...@@ -155,4 +225,14 @@
return NO; return NO;
} }
#pragma mark - GoogleServicesSettingsCoordinatorDelegate
- (void)googleServicesSettingsCoordinatorDidRemove:
(GoogleServicesSettingsCoordinator*)coordinator {
DCHECK_EQ(_googleServicesSettingsCoordinator, coordinator);
[self.googleServicesSettingsCoordinator stop];
self.googleServicesSettingsCoordinator.delegate = nil;
self.googleServicesSettingsCoordinator = nil;
}
@end @end
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
// Webpage with safe browsing toggle.
extern const char kSafeBrowsingStringURL[];
class AuthenticationService; class AuthenticationService;
class IOSChromePasswordCheckManager; class IOSChromePasswordCheckManager;
class PrefService; class PrefService;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#import "ios/chrome/browser/ui/settings/utils/observable_boolean.h" #import "ios/chrome/browser/ui/settings/utils/observable_boolean.h"
#import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h" #import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_link_header_footer_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_item.h"
#import "ios/chrome/browser/ui/ui_feature_flags.h" #import "ios/chrome/browser/ui/ui_feature_flags.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h" #import "ios/chrome/browser/ui/util/uikit_ui_util.h"
...@@ -46,20 +47,18 @@ ...@@ -46,20 +47,18 @@
using l10n_util::GetNSString; using l10n_util::GetNSString;
using safe_browsing::kSafeBrowsingAvailableOnIOS; using safe_browsing::kSafeBrowsingAvailableOnIOS;
constexpr char kSafeBrowsingStringURL[] = "chrome://settings/syncSetup";
namespace { namespace {
typedef NSArray<TableViewItem*>* ItemArray; typedef NSArray<TableViewItem*>* ItemArray;
typedef NS_ENUM(NSInteger, SectionIdentifier) {
SectionIdentifierCheckTypes = kSectionIdentifierEnumZero,
SectionIdentifierCheckStart,
};
typedef NS_ENUM(NSInteger, ItemType) { typedef NS_ENUM(NSInteger, ItemType) {
// CheckTypes section. // CheckTypes section.
UpdateItemType = kItemTypeEnumZero, UpdateItemType = kItemTypeEnumZero,
PasswordItemType, PasswordItemType,
SafeBrowsingItemType, SafeBrowsingItemType,
HeaderItem,
// CheckStart section. // CheckStart section.
CheckStartItemType, CheckStartItemType,
}; };
...@@ -99,7 +98,7 @@ typedef NS_ENUM(NSInteger, SafeBrowsingCheckRowStates) { ...@@ -99,7 +98,7 @@ typedef NS_ENUM(NSInteger, SafeBrowsingCheckRowStates) {
// When check was not run yet. // When check was not run yet.
SafeBrowsingCheckRowStateDefault, SafeBrowsingCheckRowStateDefault,
// When Safe Browsing is managed by admin. // When Safe Browsing is managed by admin.
SafeBrowsingCheckRowStateManged, SafeBrowsingCheckRowStateManaged,
// When the Safe Browsing check is running. // When the Safe Browsing check is running.
SafeBrowsingCheckRowStateRunning, SafeBrowsingCheckRowStateRunning,
// When Safe Browsing is enabled. // When Safe Browsing is enabled.
...@@ -124,6 +123,9 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -124,6 +123,9 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
std::unique_ptr<PasswordCheckObserverBridge> _passwordCheckObserver; std::unique_ptr<PasswordCheckObserverBridge> _passwordCheckObserver;
} }
// Header for the Safety Check page.
@property(nonatomic, strong) TableViewLinkHeaderFooterItem* headerItem;
// SettingsCheckItem used to display the state of the Safe Browsing check. // SettingsCheckItem used to display the state of the Safe Browsing check.
@property(nonatomic, strong) SettingsCheckItem* safeBrowsingCheckItem; @property(nonatomic, strong) SettingsCheckItem* safeBrowsingCheckItem;
...@@ -149,10 +151,13 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -149,10 +151,13 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
// Current state of the start safety check row button. // Current state of the start safety check row button.
@property(nonatomic, assign) CheckStartStates checkStartState; @property(nonatomic, assign) CheckStartStates checkStartState;
// Preference value for the "Safe Browsing" feature. // Preference value for Safe Browsing.
@property(nonatomic, strong, readonly) @property(nonatomic, strong, readonly)
PrefBackedBoolean* safeBrowsingPreference; PrefBackedBoolean* safeBrowsingPreference;
// If the Safe Browsing preference is managed.
@property(nonatomic, assign) BOOL safeBrowsingPreferenceManaged;
// The service responsible for password check feature. // The service responsible for password check feature.
@property(nonatomic, assign) scoped_refptr<IOSChromePasswordCheckManager> @property(nonatomic, assign) scoped_refptr<IOSChromePasswordCheckManager>
passwordCheckManager; passwordCheckManager;
...@@ -160,8 +165,8 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -160,8 +165,8 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
// Current state of password check. // Current state of password check.
@property(nonatomic, assign) PasswordCheckState currentPasswordCheckState; @property(nonatomic, assign) PasswordCheckState currentPasswordCheckState;
// How many safety check items are still running (max 3). // If any checks in safety check are still running.
@property(nonatomic, assign) int checkRunningRemaining; @property(nonatomic, assign, readonly) BOOL checksRemaining;
// Service used to check if user is signed in. // Service used to check if user is signed in.
@property(nonatomic, assign) AuthenticationService* authService; @property(nonatomic, assign) AuthenticationService* authService;
...@@ -199,8 +204,13 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -199,8 +204,13 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
initWithPrefService:userPrefService initWithPrefService:userPrefService
prefName:prefs::kSafeBrowsingEnabled]; prefName:prefs::kSafeBrowsingEnabled];
_safeBrowsingPreference.observer = self; _safeBrowsingPreference.observer = self;
_safeBrowsingPreferenceManaged =
userPrefService->IsManagedPreference(prefs::kSafeBrowsingEnabled);
_checkRunningRemaining = 0; _headerItem =
[[TableViewLinkHeaderFooterItem alloc] initWithType:HeaderItem];
_headerItem.text =
l10n_util::GetNSString(IDS_IOS_SETTINGS_SAFETY_CHECK_PAGE_HEADER);
_updateCheckRowState = UpdateCheckRowStateDefault; _updateCheckRowState = UpdateCheckRowStateDefault;
_updateCheckItem = [[SettingsCheckItem alloc] initWithType:UpdateItemType]; _updateCheckItem = [[SettingsCheckItem alloc] initWithType:UpdateItemType];
...@@ -210,6 +220,10 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -210,6 +220,10 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
_updateCheckItem.leadingImage = updateCheckIcon; _updateCheckItem.leadingImage = updateCheckIcon;
_updateCheckItem.leadingImageTintColor = [UIColor colorNamed:kGrey400Color]; _updateCheckItem.leadingImageTintColor = [UIColor colorNamed:kGrey400Color];
_updateCheckItem.enabled = YES;
_updateCheckItem.indicatorHidden = YES;
_updateCheckItem.infoButtonHidden = YES;
_updateCheckItem.trailingImage = nil;
_passwordCheckRowState = PasswordCheckRowStateDefault; _passwordCheckRowState = PasswordCheckRowStateDefault;
_passwordCheckItem = _passwordCheckItem =
...@@ -221,6 +235,10 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -221,6 +235,10 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
_passwordCheckItem.leadingImage = passwordCheckIcon; _passwordCheckItem.leadingImage = passwordCheckIcon;
_passwordCheckItem.leadingImageTintColor = _passwordCheckItem.leadingImageTintColor =
[UIColor colorNamed:kGrey400Color]; [UIColor colorNamed:kGrey400Color];
_passwordCheckItem.enabled = YES;
_passwordCheckItem.indicatorHidden = YES;
_passwordCheckItem.infoButtonHidden = YES;
_passwordCheckItem.trailingImage = nil;
_safeBrowsingCheckRowState = SafeBrowsingCheckRowStateDefault; _safeBrowsingCheckRowState = SafeBrowsingCheckRowStateDefault;
_safeBrowsingCheckItem = _safeBrowsingCheckItem =
...@@ -233,6 +251,10 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -233,6 +251,10 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
_safeBrowsingCheckItem.leadingImage = safeBrowsingCheckIcon; _safeBrowsingCheckItem.leadingImage = safeBrowsingCheckIcon;
_safeBrowsingCheckItem.leadingImageTintColor = _safeBrowsingCheckItem.leadingImageTintColor =
[UIColor colorNamed:kGrey400Color]; [UIColor colorNamed:kGrey400Color];
_safeBrowsingCheckItem.enabled = YES;
_safeBrowsingCheckItem.indicatorHidden = YES;
_safeBrowsingCheckItem.infoButtonHidden = YES;
_safeBrowsingCheckItem.trailingImage = nil;
_checkStartState = CheckStartStateDefault; _checkStartState = CheckStartStateDefault;
_checkStartItem = _checkStartItem =
...@@ -251,6 +273,7 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -251,6 +273,7 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
self.updateCheckItem, self.passwordCheckItem, self.safeBrowsingCheckItem self.updateCheckItem, self.passwordCheckItem, self.safeBrowsingCheckItem
]; ];
[_consumer setCheckItems:checkItems]; [_consumer setCheckItems:checkItems];
[_consumer setSafetyCheckHeaderItem:self.headerItem];
[_consumer setCheckStartItem:self.checkStartItem]; [_consumer setCheckStartItem:self.checkStartItem];
} }
...@@ -279,18 +302,16 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -279,18 +302,16 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
- (void)didSelectItem:(TableViewItem*)item { - (void)didSelectItem:(TableViewItem*)item {
ItemType type = static_cast<ItemType>(item.type); ItemType type = static_cast<ItemType>(item.type);
switch (type) { switch (type) {
// TODO(crbug.com/1078782): Handle row taps.
case UpdateItemType: { case UpdateItemType: {
switch (self.updateCheckRowState) { switch (self.updateCheckRowState) {
case UpdateCheckRowStateDefault: // No tap action. case UpdateCheckRowStateDefault: // No tap action.
case UpdateCheckRowStateRunning: // No tap action. case UpdateCheckRowStateRunning: // No tap action.
case UpdateCheckRowStateUpToDate: // No tap action. case UpdateCheckRowStateUpToDate: // No tap action.
break; break;
case UpdateCheckRowStateManaged: case UpdateCheckRowStateManaged: // Managed state popover handled by
// Show popover. // coordinator.
break; break;
case UpdateCheckRowStateOutOfDate: case UpdateCheckRowStateOutOfDate: // Link to app store.
// Show popover and link to update page.
break; break;
} }
break; break;
...@@ -304,8 +325,8 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -304,8 +325,8 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
case PasswordCheckRowStateUnSafe: case PasswordCheckRowStateUnSafe:
[self.handler showPasswordIssuesPage]; [self.handler showPasswordIssuesPage];
break; break;
case PasswordCheckRowStateDisabled: // Popover handled by cellitem. case PasswordCheckRowStateDisabled: // Popover handled by coordinator.
case PasswordCheckRowStateError: // Popover handled by cellitem. case PasswordCheckRowStateError: // Popover handled by coordinator.
break; break;
} }
break; break;
...@@ -316,12 +337,11 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -316,12 +337,11 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
case SafeBrowsingCheckRowStateRunning: // No tap action. case SafeBrowsingCheckRowStateRunning: // No tap action.
case SafeBrowsingCheckRowStateSafe: // No tap action. case SafeBrowsingCheckRowStateSafe: // No tap action.
break; break;
case SafeBrowsingCheckRowStateManged: case SafeBrowsingCheckRowStateManaged: // Managed state popover handled
// Managed state popover. // by coordinator.
break; break;
case SafeBrowsingCheckRowStateUnsafe: case SafeBrowsingCheckRowStateUnsafe:
// Subtext about non advised, i state (sans popover) links to [self.handler showSafeBrowsingPreferencePage];
// safebrowsing page.
break; break;
} }
break; break;
...@@ -330,6 +350,8 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -330,6 +350,8 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
[self checkStartOrCancel]; [self checkStartOrCancel];
break; break;
} }
case HeaderItem:
break;
} }
} }
...@@ -340,6 +362,11 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -340,6 +362,11 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
- (void)infoButtonWasTapped:(UIButton*)buttonView - (void)infoButtonWasTapped:(UIButton*)buttonView
usingItemType:(NSInteger)itemType { usingItemType:(NSInteger)itemType {
// Show the managed popover if needed.
if (self.safeBrowsingCheckRowState == SafeBrowsingCheckRowStateManaged) {
[self.handler showManagedInfoFrom:buttonView];
return;
}
NSAttributedString* info = [self getPopoverInfoForType:itemType]; NSAttributedString* info = [self getPopoverInfoForType:itemType];
// If |info| is empty there is no popover to display. // If |info| is empty there is no popover to display.
...@@ -366,9 +393,15 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -366,9 +393,15 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
switch (type) { switch (type) {
case PasswordItemType: case PasswordItemType:
return [self passwordCheckErrorInfo]; return [self passwordCheckErrorInfo];
case SafeBrowsingItemType: case SafeBrowsingItemType: {
NSString* message = l10n_util::GetNSString(
IDS_IOS_SETTINGS_SAFETY_CHECK_SAFE_BROWSING_DISABLED_INFO);
GURL safeBrowsingURL(kSafeBrowsingStringURL);
return [self attributedStringWithText:message link:safeBrowsingURL];
}
case UpdateItemType: case UpdateItemType:
case CheckStartItemType: case CheckStartItemType:
case HeaderItem:
return nil; return nil;
} }
} }
...@@ -457,7 +490,7 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -457,7 +490,7 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
!self.syncService->IsEncryptEverythingEnabled()); !self.syncService->IsEncryptEverythingEnabled());
} }
// Configures check passwords error info with a link. // Configures check error info with a link for popovers.
- (NSAttributedString*)attributedStringWithText:(NSString*)text - (NSAttributedString*)attributedStringWithText:(NSString*)text
link:(GURL)link { link:(GURL)link {
NSRange range; NSRange range;
...@@ -489,7 +522,7 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -489,7 +522,7 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
// Upon a tap of checkStartItem either starts or cancels a safety check. // Upon a tap of checkStartItem either starts or cancels a safety check.
- (void)checkStartOrCancel { - (void)checkStartOrCancel {
// If a check is already running cancel it. // If a check is already running cancel it.
if (self.checkRunningRemaining > 0) { if (self.checksRemaining) {
// Reset check items to default. // Reset check items to default.
self.updateCheckRowState = UpdateCheckRowStateDefault; self.updateCheckRowState = UpdateCheckRowStateDefault;
self.passwordCheckRowState = PasswordCheckRowStateDefault; self.passwordCheckRowState = PasswordCheckRowStateDefault;
...@@ -498,9 +531,6 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -498,9 +531,6 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
// Change checkStartItem to default state. // Change checkStartItem to default state.
self.checkStartState = CheckStartStateDefault; self.checkStartState = CheckStartStateDefault;
// Set remaining check running counter to 0.
self.checkRunningRemaining = 0;
// Stop any running checks. // Stop any running checks.
self.passwordCheckManager->StopPasswordCheck(); self.passwordCheckManager->StopPasswordCheck();
...@@ -514,9 +544,6 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -514,9 +544,6 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
// Change checkStartItem to cancel state. // Change checkStartItem to cancel state.
self.checkStartState = CheckStartStateCancel; self.checkStartState = CheckStartStateCancel;
// Set remaining check running counter to 3.
self.checkRunningRemaining = 3;
} }
// Update the display. // Update the display.
...@@ -527,7 +554,7 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -527,7 +554,7 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
// The display should be changed to loading icons before any checks are // The display should be changed to loading icons before any checks are
// started. // started.
if (self.checkRunningRemaining > 0) { if (self.checksRemaining) {
// This handles a discrepancy between password check and safety check. In // This handles a discrepancy between password check and safety check. In
// password check a user cannot start a check if they have no passwords, but // password check a user cannot start a check if they have no passwords, but
// in safety check they can, but the |passwordCheckManager| won't even start // in safety check they can, but the |passwordCheckManager| won't even start
...@@ -539,14 +566,65 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -539,14 +566,65 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
dispatch_after( dispatch_after(
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{ dispatch_get_main_queue(), ^{
[self reconfigurePasswordCheckItem]; // Check if the check was cancelled while waiting.
if (self.checksRemaining)
[self reconfigurePasswordCheckItem];
}); });
} else { } else {
self.passwordCheckManager->StartPasswordCheck(); self.passwordCheckManager->StartPasswordCheck();
} }
// Want to show the loading wheel momentarily.
dispatch_after(
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.75 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
// Check if the check was cancelled while waiting.
if (self.checksRemaining)
[self checkAndReconfigureSafeBrowsingState];
});
} }
} }
// Checks if any of the safety checks are still running, resets |checkStartItem|
// if all checks have finished..
- (void)resetsCheckStartItemIfNeeded {
if (self.checksRemaining) {
return;
}
// If no checks are still running, reset |checkStartItem|.
self.checkStartState = CheckStartStateDefault;
[self reconfigureCheckStartSection];
return;
}
// Computes if any of the safety checks are still running.
- (BOOL)checksRemaining {
BOOL passwordCheckRunning =
self.passwordCheckRowState == PasswordCheckRowStateRunning;
BOOL safeBrowsingCheckRunning =
self.safeBrowsingCheckRowState == SafeBrowsingCheckRowStateRunning;
BOOL updateCheckRunning =
self.updateCheckRowState == UpdateCheckRowStateRunning;
return updateCheckRunning || passwordCheckRunning || safeBrowsingCheckRunning;
}
// Performs the Safe Browsing check and triggers the display update/
- (void)checkAndReconfigureSafeBrowsingState {
if (!self.safeBrowsingPreferenceManaged) {
self.safeBrowsingCheckRowState = self.safeBrowsingPreference.value
? SafeBrowsingCheckRowStateSafe
: SafeBrowsingCheckRowStateUnsafe;
}
if (self.safeBrowsingCheckRowState == SafeBrowsingCheckRowStateUnsafe &&
self.safeBrowsingPreferenceManaged) {
self.safeBrowsingCheckRowState = SafeBrowsingCheckRowStateManaged;
}
// See if this was the last test.
[self resetsCheckStartItemIfNeeded];
// Update |safeBrowsingCheckItem| display.
[self reconfigureSafeBrowsingCheckItem];
}
// Reconfigures the display of the |updateCheckItem| based on current state of // Reconfigures the display of the |updateCheckItem| based on current state of
// |updateCheckRowState|. // |updateCheckRowState|.
- (void)reconfigureUpdateCheckItem { - (void)reconfigureUpdateCheckItem {
...@@ -558,6 +636,9 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -558,6 +636,9 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
self.updateCheckItem.trailingImage = nil; self.updateCheckItem.trailingImage = nil;
self.updateCheckItem.trailingImageTintColor = nil; self.updateCheckItem.trailingImageTintColor = nil;
// On any item update, see if any checks are still running.
[self resetsCheckStartItemIfNeeded];
switch (self.updateCheckRowState) { switch (self.updateCheckRowState) {
case UpdateCheckRowStateDefault: case UpdateCheckRowStateDefault:
break; break;
...@@ -586,6 +667,9 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -586,6 +667,9 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
self.passwordCheckItem.trailingImageTintColor = nil; self.passwordCheckItem.trailingImageTintColor = nil;
self.passwordCheckItem.accessoryType = UITableViewCellAccessoryNone; self.passwordCheckItem.accessoryType = UITableViewCellAccessoryNone;
// On any item update, see if any checks are still running.
[self resetsCheckStartItemIfNeeded];
switch (self.passwordCheckRowState) { switch (self.passwordCheckRowState) {
case PasswordCheckRowStateDefault: case PasswordCheckRowStateDefault:
break; break;
...@@ -642,6 +726,9 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -642,6 +726,9 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
self.safeBrowsingCheckItem.trailingImage = nil; self.safeBrowsingCheckItem.trailingImage = nil;
self.safeBrowsingCheckItem.trailingImageTintColor = nil; self.safeBrowsingCheckItem.trailingImageTintColor = nil;
// On any item update, see if any checks are still running.
[self resetsCheckStartItemIfNeeded];
switch (self.safeBrowsingCheckRowState) { switch (self.safeBrowsingCheckRowState) {
case SafeBrowsingCheckRowStateDefault: case SafeBrowsingCheckRowStateDefault:
break; break;
...@@ -649,10 +736,28 @@ typedef NS_ENUM(NSInteger, CheckStartStates) { ...@@ -649,10 +736,28 @@ typedef NS_ENUM(NSInteger, CheckStartStates) {
self.safeBrowsingCheckItem.indicatorHidden = NO; self.safeBrowsingCheckItem.indicatorHidden = NO;
break; break;
} }
case SafeBrowsingCheckRowStateManged: case SafeBrowsingCheckRowStateManaged: {
case SafeBrowsingCheckRowStateSafe: self.safeBrowsingCheckItem.infoButtonHidden = NO;
case SafeBrowsingCheckRowStateUnsafe: self.safeBrowsingCheckItem.detailText =
GetNSString(IDS_IOS_SETTINGS_SAFETY_CHECK_SAFE_BROWSING_MANAGED_DESC);
break; break;
}
case SafeBrowsingCheckRowStateSafe: {
UIImage* safeIconImage = [[UIImage imageNamed:@"settings_safe_state"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.safeBrowsingCheckItem.trailingImage = safeIconImage;
self.safeBrowsingCheckItem.trailingImageTintColor =
[UIColor colorNamed:kGreenColor];
self.safeBrowsingCheckItem.detailText =
GetNSString(IDS_IOS_SETTINGS_SAFETY_CHECK_SAFE_BROWSING_ENABLED_DESC);
break;
}
case SafeBrowsingCheckRowStateUnsafe: {
self.safeBrowsingCheckItem.infoButtonHidden = NO;
self.safeBrowsingCheckItem.detailText = GetNSString(
IDS_IOS_SETTINGS_SAFETY_CHECK_SAFE_BROWSING_DISABLED_DESC);
break;
}
} }
[self.consumer reconfigureCellsForItems:@[ self.safeBrowsingCheckItem ]]; [self.consumer reconfigureCellsForItems:@[ self.safeBrowsingCheckItem ]];
......
...@@ -22,6 +22,10 @@ ...@@ -22,6 +22,10 @@
- (void)showErrorInfoFrom:(UIButton*)buttonView - (void)showErrorInfoFrom:(UIButton*)buttonView
withText:(NSAttributedString*)text; withText:(NSAttributedString*)text;
// Called when the user clicks on the information button of the managed
// setting's UI. Shows a textual bubble with the information of the enterprise.
- (void)showManagedInfoFrom:(UIButton*)buttonView;
@end @end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_SAFETY_CHECK_SAFETY_CHECK_NAVIGATION_COMMANDS_H_ #endif // IOS_CHROME_BROWSER_UI_SETTINGS_SAFETY_CHECK_SAFETY_CHECK_NAVIGATION_COMMANDS_H_
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#import "ios/chrome/browser/ui/settings/safety_check/safety_check_navigation_commands.h" #import "ios/chrome/browser/ui/settings/safety_check/safety_check_navigation_commands.h"
#import "ios/chrome/browser/ui/settings/safety_check/safety_check_service_delegate.h" #import "ios/chrome/browser/ui/settings/safety_check/safety_check_service_delegate.h"
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_link_header_footer_item.h"
#include "ios/chrome/browser/ui/ui_feature_flags.h" #include "ios/chrome/browser/ui/ui_feature_flags.h"
#include "ios/chrome/grit/ios_chromium_strings.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
...@@ -34,6 +36,10 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) { ...@@ -34,6 +36,10 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
// Current state of array of items that form the safety check. // Current state of array of items that form the safety check.
@property(nonatomic, strong) NSArray<TableViewItem*>* checkTypesItems; @property(nonatomic, strong) NSArray<TableViewItem*>* checkTypesItems;
// Header for the safety check page.
@property(nonatomic, strong)
TableViewLinkHeaderFooterItem* safetyCheckHeaderItem;
// Current display state of the check start item. // Current display state of the check start item.
@property(nonatomic, strong) TableViewItem* checkStartItem; @property(nonatomic, strong) TableViewItem* checkStartItem;
...@@ -55,6 +61,11 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) { ...@@ -55,6 +61,11 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
[self reloadData]; [self reloadData];
} }
- (void)setSafetyCheckHeaderItem:(TableViewLinkHeaderFooterItem*)item {
_safetyCheckHeaderItem = item;
[self reloadData];
}
- (void)setCheckStartItem:(TableViewItem*)item { - (void)setCheckStartItem:(TableViewItem*)item {
_checkStartItem = item; _checkStartItem = item;
[self reloadData]; [self reloadData];
...@@ -71,6 +82,10 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) { ...@@ -71,6 +82,10 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
[self.tableViewModel addItem:item [self.tableViewModel addItem:item
toSectionWithIdentifier:SectionIdentifierCheckTypes]; toSectionWithIdentifier:SectionIdentifierCheckTypes];
} }
if (self.safetyCheckHeaderItem) {
[self.tableViewModel setHeader:self.safetyCheckHeaderItem
forSectionWithIdentifier:SectionIdentifierCheckTypes];
}
} }
if (self.checkStartItem) { if (self.checkStartItem) {
......
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