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 @@
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") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
......@@ -24,6 +30,7 @@ source_set("incognito_reauth_scene_agent") {
"incognito_reauth_scene_agent.mm",
]
deps = [
":incognito_reauth_commands",
"//base",
"//components/pref_registry",
"//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 @@
#import "ios/chrome/browser/ui/main/scene_state.h"
#import "ios/chrome/browser/ui/incognito_reauth/incognito_reauth_commands.h"
@class IncognitoReauthSceneAgent;
class PrefRegistrySimple;
class PrefService;
......@@ -24,7 +26,8 @@ class PrefService;
// A scene agent that tracks the incognito authentication status for the current
// scene.
@interface IncognitoReauthSceneAgent : NSObject <SceneAgent>
@interface IncognitoReauthSceneAgent
: NSObject <IncognitoReauthCommands, SceneAgent>
// Designated initializer.
// The |reauthModule| is used for authentication.
......@@ -48,11 +51,6 @@ class PrefService;
// ApplicationContext, but is settable for overriding.
@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
- (void)addObserver:(id<IncognitoReauthObserver>)observer;
......
......@@ -71,13 +71,11 @@
!self.authenticatedSinceLastForeground;
}
- (void)authenticateWithCompletion:(void (^)(BOOL))completion {
- (void)authenticateIncognitoContent {
DCHECK(self.reauthModule);
if (!self.isAuthenticationRequired) {
if (completion) {
completion(YES);
}
[self notifyObservers];
return;
}
......@@ -93,9 +91,6 @@
ReauthenticationResult::kSuccess);
weakSelf.authenticatedSinceLastForeground =
success;
if (completion) {
completion(success);
}
}];
}
......
......@@ -166,9 +166,7 @@ TEST_F(IncognitoReauthSceneAgentTest, SuccessfulAuth) {
EXPECT_TRUE(agent_.authenticationRequired);
[agent_ authenticateWithCompletion:^(BOOL result) {
EXPECT_TRUE(result);
}];
[agent_ authenticateIncognitoContent];
// Auth not required
EXPECT_FALSE(agent_.authenticationRequired);
......@@ -190,16 +188,12 @@ TEST_F(IncognitoReauthSceneAgentTest, FailedSkippedAuth) {
stub_reauth_module_.returnedResult = ReauthenticationResult::kFailure;
[agent_ authenticateWithCompletion:^(BOOL result) {
EXPECT_FALSE(result);
}];
[agent_ authenticateIncognitoContent];
// Auth still required
EXPECT_TRUE(agent_.authenticationRequired);
stub_reauth_module_.returnedResult = ReauthenticationResult::kSkipped;
[agent_ authenticateWithCompletion:^(BOOL result) {
EXPECT_FALSE(result);
}];
[agent_ authenticateIncognitoContent];
// Auth still required
EXPECT_TRUE(agent_.authenticationRequired);
}
......
......@@ -89,6 +89,7 @@ const CGFloat kButtonSpacing = 16.0f;
backgroundView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2];
backgroundView.layer.cornerRadius = kButtonHeight / 2;
backgroundView.translatesAutoresizingMaskIntoConstraints = NO;
backgroundView.userInteractionEnabled = NO;
[button addSubview:backgroundView];
AddSameConstraints(backgroundView, button);
......
......@@ -53,6 +53,7 @@ source_set("grid_ui") {
"//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/elements",
"//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/tab_switcher",
"//ios/chrome/browser/ui/tab_switcher/tab_grid/transitions",
......
......@@ -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_theme.h"
@protocol IncognitoReauthCommands;
@protocol GridDragDropHandler;
@protocol GridEmptyView;
@protocol GridImageDataSource;
......@@ -62,6 +63,8 @@
@property(nonatomic, readonly, getter=isGridEmpty) BOOL gridEmpty;
// The visual look of the grid.
@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.
@property(nonatomic, weak) id<GridViewControllerDelegate> delegate;
// Handles drag and drop interactions that involved the model layer.
......
......@@ -15,6 +15,7 @@
#import "base/numerics/safe_conversions.h"
#include "ios/chrome/browser/drag_and_drop/drag_and_drop_flag.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/tab_switcher/tab_grid/grid/grid_cell.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_constants.h"
......@@ -630,6 +631,11 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
self.blockingView.layer.zPosition = FLT_MAX;
// No need to show tab switcher button when already in the tab switcher.
self.blockingView.tabSwitcherButton.hidden = YES;
[self.blockingView.authenticateButton
addTarget:self.handler
action:@selector(authenticateIncognitoContent)
forControlEvents:UIControlEventTouchUpInside];
}
[self.view addSubview:self.blockingView];
......
......@@ -303,10 +303,24 @@
#pragma mark - ChromeCoordinator
- (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 alloc] init];
baseViewController.handler =
HandlerForProtocol(self.dispatcher, ApplicationCommands);
baseViewController.reauthHandler =
HandlerForProtocol(self.dispatcher, IncognitoReauthCommands);
baseViewController.tabPresentationDelegate = self;
_baseViewController = baseViewController;
......@@ -326,15 +340,6 @@
regularBrowserState);
}
IncognitoReauthSceneAgent* reauthAgent = nil;
for (id agent in SceneStateBrowserAgent::FromBrowser(_incognitoBrowser)
->GetSceneState()
.connectedAgents) {
if ([agent isKindOfClass:[IncognitoReauthSceneAgent class]]) {
reauthAgent = agent;
}
}
self.incognitoTabsMediator = [[TabGridMediator alloc]
initWithConsumer:baseViewController.incognitoTabsConsumer
reauthAgent:reauthAgent];
......
......@@ -13,6 +13,7 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/transitions/grid_transition_animation_layout_providing.h"
@protocol ApplicationCommands;
@protocol IncognitoReauthCommands;
@protocol GridConsumer;
@protocol GridCommands;
@protocol GridDragDropHandler;
......@@ -37,6 +38,7 @@
ViewRevealingAnimatee>
@property(nonatomic, weak) id<ApplicationCommands> handler;
@property(nonatomic, weak) id<IncognitoReauthCommands> reauthHandler;
// Delegate for this view controller to handle presenting tab UI.
@property(nonatomic, weak) id<TabPresentationDelegate> tabPresentationDelegate;
......
......@@ -202,6 +202,11 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
[self setInsetForGridViews];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.incognitoTabsViewController.handler = self.reauthHandler;
}
- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:
(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