Commit 6a9ccb15 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[iOS][Getaway] Wire up the authentication button

Connects the auth button, through the dispatcher, to the scene agent,
which allows the tab switcher to actually authenticate.

Bug: none
Change-Id: Ic6c30f74e55bd6f1b143c00e9c41b2154e142531
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2547680
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#831023}
parent b25c33c8
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
import("//ios/build/chrome_build.gni") import("//ios/build/chrome_build.gni")
source_set("incognito_reauth_commands") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [ "incognito_reauth_commands.h" ]
frameworks = [ "UIKit.framework" ]
}
source_set("incognito_reauth_ui") { source_set("incognito_reauth_ui") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
...@@ -24,6 +30,7 @@ source_set("incognito_reauth_scene_agent") { ...@@ -24,6 +30,7 @@ source_set("incognito_reauth_scene_agent") {
"incognito_reauth_scene_agent.mm", "incognito_reauth_scene_agent.mm",
] ]
deps = [ deps = [
":incognito_reauth_commands",
"//base", "//base",
"//components/pref_registry", "//components/pref_registry",
"//components/prefs", "//components/prefs",
......
// Copyright 2020 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_INCOGNITO_REAUTH_INCOGNITO_REAUTH_COMMANDS_H_
#define IOS_CHROME_BROWSER_UI_INCOGNITO_REAUTH_INCOGNITO_REAUTH_COMMANDS_H_
#import <UIKit/UIKit.h>
// Commands related to incognito authentication.
// Should only be registered in a per-scene dispatcher, never in the global app
// dispatcher.
@protocol IncognitoReauthCommands
// Requests authentication and marks the scene as authenticated until the next
// scene foregrounding.
// The authentication will require user interaction. To know when it changes, a
// IncognitoReauthObserver callback will be called.
- (void)authenticateIncognitoContent;
@end
#endif // IOS_CHROME_BROWSER_UI_INCOGNITO_REAUTH_INCOGNITO_REAUTH_COMMANDS_H_
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#import "ios/chrome/browser/ui/main/scene_state.h" #import "ios/chrome/browser/ui/main/scene_state.h"
#import "ios/chrome/browser/ui/incognito_reauth/incognito_reauth_commands.h"
@class IncognitoReauthSceneAgent; @class IncognitoReauthSceneAgent;
class PrefRegistrySimple; class PrefRegistrySimple;
class PrefService; class PrefService;
...@@ -24,7 +26,8 @@ class PrefService; ...@@ -24,7 +26,8 @@ class PrefService;
// A scene agent that tracks the incognito authentication status for the current // A scene agent that tracks the incognito authentication status for the current
// scene. // scene.
@interface IncognitoReauthSceneAgent : NSObject <SceneAgent> @interface IncognitoReauthSceneAgent
: NSObject <IncognitoReauthCommands, SceneAgent>
// Designated initializer. // Designated initializer.
// The |reauthModule| is used for authentication. // The |reauthModule| is used for authentication.
...@@ -48,11 +51,6 @@ class PrefService; ...@@ -48,11 +51,6 @@ class PrefService;
// ApplicationContext, but is settable for overriding. // ApplicationContext, but is settable for overriding.
@property(nonatomic, assign) PrefService* localState; @property(nonatomic, assign) PrefService* localState;
// Requests authentication and marks this scene as authenticated until the next
// scene foregrounding. The callback will receive the result of the
// authentication attempt. It will be called on main thread, asynchronously.
- (void)authenticateWithCompletion:(void (^)(BOOL))completion;
#pragma mark observation #pragma mark observation
- (void)addObserver:(id<IncognitoReauthObserver>)observer; - (void)addObserver:(id<IncognitoReauthObserver>)observer;
......
...@@ -71,13 +71,11 @@ ...@@ -71,13 +71,11 @@
!self.authenticatedSinceLastForeground; !self.authenticatedSinceLastForeground;
} }
- (void)authenticateWithCompletion:(void (^)(BOOL))completion { - (void)authenticateIncognitoContent {
DCHECK(self.reauthModule); DCHECK(self.reauthModule);
if (!self.isAuthenticationRequired) { if (!self.isAuthenticationRequired) {
if (completion) { [self notifyObservers];
completion(YES);
}
return; return;
} }
...@@ -93,9 +91,6 @@ ...@@ -93,9 +91,6 @@
ReauthenticationResult::kSuccess); ReauthenticationResult::kSuccess);
weakSelf.authenticatedSinceLastForeground = weakSelf.authenticatedSinceLastForeground =
success; success;
if (completion) {
completion(success);
}
}]; }];
} }
......
...@@ -166,9 +166,7 @@ TEST_F(IncognitoReauthSceneAgentTest, SuccessfulAuth) { ...@@ -166,9 +166,7 @@ TEST_F(IncognitoReauthSceneAgentTest, SuccessfulAuth) {
EXPECT_TRUE(agent_.authenticationRequired); EXPECT_TRUE(agent_.authenticationRequired);
[agent_ authenticateWithCompletion:^(BOOL result) { [agent_ authenticateIncognitoContent];
EXPECT_TRUE(result);
}];
// Auth not required // Auth not required
EXPECT_FALSE(agent_.authenticationRequired); EXPECT_FALSE(agent_.authenticationRequired);
...@@ -190,16 +188,12 @@ TEST_F(IncognitoReauthSceneAgentTest, FailedSkippedAuth) { ...@@ -190,16 +188,12 @@ TEST_F(IncognitoReauthSceneAgentTest, FailedSkippedAuth) {
stub_reauth_module_.returnedResult = ReauthenticationResult::kFailure; stub_reauth_module_.returnedResult = ReauthenticationResult::kFailure;
[agent_ authenticateWithCompletion:^(BOOL result) { [agent_ authenticateIncognitoContent];
EXPECT_FALSE(result);
}];
// Auth still required // Auth still required
EXPECT_TRUE(agent_.authenticationRequired); EXPECT_TRUE(agent_.authenticationRequired);
stub_reauth_module_.returnedResult = ReauthenticationResult::kSkipped; stub_reauth_module_.returnedResult = ReauthenticationResult::kSkipped;
[agent_ authenticateWithCompletion:^(BOOL result) { [agent_ authenticateIncognitoContent];
EXPECT_FALSE(result);
}];
// Auth still required // Auth still required
EXPECT_TRUE(agent_.authenticationRequired); EXPECT_TRUE(agent_.authenticationRequired);
} }
......
...@@ -89,6 +89,7 @@ const CGFloat kButtonSpacing = 16.0f; ...@@ -89,6 +89,7 @@ const CGFloat kButtonSpacing = 16.0f;
backgroundView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2]; backgroundView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2];
backgroundView.layer.cornerRadius = kButtonHeight / 2; backgroundView.layer.cornerRadius = kButtonHeight / 2;
backgroundView.translatesAutoresizingMaskIntoConstraints = NO; backgroundView.translatesAutoresizingMaskIntoConstraints = NO;
backgroundView.userInteractionEnabled = NO;
[button addSubview:backgroundView]; [button addSubview:backgroundView];
AddSameConstraints(backgroundView, button); AddSameConstraints(backgroundView, button);
......
...@@ -53,6 +53,7 @@ source_set("grid_ui") { ...@@ -53,6 +53,7 @@ source_set("grid_ui") {
"//ios/chrome/browser/ui:feature_flags", "//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/elements", "//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/gestures", "//ios/chrome/browser/ui/gestures",
"//ios/chrome/browser/ui/incognito_reauth:incognito_reauth_commands",
"//ios/chrome/browser/ui/incognito_reauth:incognito_reauth_ui", "//ios/chrome/browser/ui/incognito_reauth:incognito_reauth_ui",
"//ios/chrome/browser/ui/tab_switcher", "//ios/chrome/browser/ui/tab_switcher",
"//ios/chrome/browser/ui/tab_switcher/tab_grid/transitions", "//ios/chrome/browser/ui/tab_switcher/tab_grid/transitions",
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_consumer.h" #import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_consumer.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_theme.h" #import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_theme.h"
@protocol IncognitoReauthCommands;
@protocol GridDragDropHandler; @protocol GridDragDropHandler;
@protocol GridEmptyView; @protocol GridEmptyView;
@protocol GridImageDataSource; @protocol GridImageDataSource;
...@@ -62,6 +63,8 @@ ...@@ -62,6 +63,8 @@
@property(nonatomic, readonly, getter=isGridEmpty) BOOL gridEmpty; @property(nonatomic, readonly, getter=isGridEmpty) BOOL gridEmpty;
// The visual look of the grid. // The visual look of the grid.
@property(nonatomic, assign) GridTheme theme; @property(nonatomic, assign) GridTheme theme;
// Handler for reauth commands.
@property(nonatomic, weak) id<IncognitoReauthCommands> handler;
// Delegate is informed of user interactions in the grid UI. // Delegate is informed of user interactions in the grid UI.
@property(nonatomic, weak) id<GridViewControllerDelegate> delegate; @property(nonatomic, weak) id<GridViewControllerDelegate> delegate;
// Handles drag and drop interactions that involved the model layer. // Handles drag and drop interactions that involved the model layer.
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#import "base/numerics/safe_conversions.h" #import "base/numerics/safe_conversions.h"
#include "ios/chrome/browser/drag_and_drop/drag_and_drop_flag.h" #include "ios/chrome/browser/drag_and_drop/drag_and_drop_flag.h"
#include "ios/chrome/browser/procedural_block_types.h" #include "ios/chrome/browser/procedural_block_types.h"
#import "ios/chrome/browser/ui/incognito_reauth/incognito_reauth_commands.h"
#import "ios/chrome/browser/ui/incognito_reauth/incognito_reauth_view.h" #import "ios/chrome/browser/ui/incognito_reauth/incognito_reauth_view.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_cell.h" #import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_cell.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_constants.h" #import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_constants.h"
...@@ -630,6 +631,11 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -630,6 +631,11 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
self.blockingView.layer.zPosition = FLT_MAX; self.blockingView.layer.zPosition = FLT_MAX;
// No need to show tab switcher button when already in the tab switcher. // No need to show tab switcher button when already in the tab switcher.
self.blockingView.tabSwitcherButton.hidden = YES; self.blockingView.tabSwitcherButton.hidden = YES;
[self.blockingView.authenticateButton
addTarget:self.handler
action:@selector(authenticateIncognitoContent)
forControlEvents:UIControlEventTouchUpInside];
} }
[self.view addSubview:self.blockingView]; [self.view addSubview:self.blockingView];
......
...@@ -303,10 +303,24 @@ ...@@ -303,10 +303,24 @@
#pragma mark - ChromeCoordinator #pragma mark - ChromeCoordinator
- (void)start { - (void)start {
IncognitoReauthSceneAgent* reauthAgent = nil;
for (id agent in SceneStateBrowserAgent::FromBrowser(_incognitoBrowser)
->GetSceneState()
.connectedAgents) {
if ([agent isKindOfClass:[IncognitoReauthSceneAgent class]]) {
reauthAgent = agent;
}
}
[self.dispatcher startDispatchingToTarget:reauthAgent
forProtocol:@protocol(IncognitoReauthCommands)];
TabGridViewController* baseViewController = TabGridViewController* baseViewController =
[[TabGridViewController alloc] init]; [[TabGridViewController alloc] init];
baseViewController.handler = baseViewController.handler =
HandlerForProtocol(self.dispatcher, ApplicationCommands); HandlerForProtocol(self.dispatcher, ApplicationCommands);
baseViewController.reauthHandler =
HandlerForProtocol(self.dispatcher, IncognitoReauthCommands);
baseViewController.tabPresentationDelegate = self; baseViewController.tabPresentationDelegate = self;
_baseViewController = baseViewController; _baseViewController = baseViewController;
...@@ -326,15 +340,6 @@ ...@@ -326,15 +340,6 @@
regularBrowserState); regularBrowserState);
} }
IncognitoReauthSceneAgent* reauthAgent = nil;
for (id agent in SceneStateBrowserAgent::FromBrowser(_incognitoBrowser)
->GetSceneState()
.connectedAgents) {
if ([agent isKindOfClass:[IncognitoReauthSceneAgent class]]) {
reauthAgent = agent;
}
}
self.incognitoTabsMediator = [[TabGridMediator alloc] self.incognitoTabsMediator = [[TabGridMediator alloc]
initWithConsumer:baseViewController.incognitoTabsConsumer initWithConsumer:baseViewController.incognitoTabsConsumer
reauthAgent:reauthAgent]; reauthAgent:reauthAgent];
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/transitions/grid_transition_animation_layout_providing.h" #import "ios/chrome/browser/ui/tab_switcher/tab_grid/transitions/grid_transition_animation_layout_providing.h"
@protocol ApplicationCommands; @protocol ApplicationCommands;
@protocol IncognitoReauthCommands;
@protocol GridConsumer; @protocol GridConsumer;
@protocol GridCommands; @protocol GridCommands;
@protocol GridDragDropHandler; @protocol GridDragDropHandler;
...@@ -37,6 +38,7 @@ ...@@ -37,6 +38,7 @@
ViewRevealingAnimatee> ViewRevealingAnimatee>
@property(nonatomic, weak) id<ApplicationCommands> handler; @property(nonatomic, weak) id<ApplicationCommands> handler;
@property(nonatomic, weak) id<IncognitoReauthCommands> reauthHandler;
// Delegate for this view controller to handle presenting tab UI. // Delegate for this view controller to handle presenting tab UI.
@property(nonatomic, weak) id<TabPresentationDelegate> tabPresentationDelegate; @property(nonatomic, weak) id<TabPresentationDelegate> tabPresentationDelegate;
......
...@@ -202,6 +202,11 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -202,6 +202,11 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
[self setInsetForGridViews]; [self setInsetForGridViews];
} }
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.incognitoTabsViewController.handler = self.reauthHandler;
}
- (void)viewWillTransitionToSize:(CGSize)size - (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator: withTransitionCoordinator:
(id<UIViewControllerTransitionCoordinator>)coordinator { (id<UIViewControllerTransitionCoordinator>)coordinator {
......
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