Commit 491cb3c5 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[mulitball] Move user feedback delegate to scene controller.

Moves the user feedback delegate protocol implementation to the scene
controller.

Bug: none
Change-Id: I5255321c4182f0d85c2ac4beccf92178b437f56a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1865312
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720935}
parent f4ee960f
......@@ -290,8 +290,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
PrefObserverDelegate,
SettingsNavigationControllerDelegate,
TabSwitcherDelegate,
WebStateListObserving,
UserFeedbackDataSource> {
WebStateListObserving> {
IBOutlet UIWindow* _window;
// Weak; owned by the ChromeBrowserProvider.
......@@ -319,9 +318,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// of tab switcher dismissal.
TabSwitcherDismissalMode _modeToDisplayOnTabSwitcherDismissal;
// If YES, the tab switcher is currently active.
BOOL _tabSwitcherIsActive;
// True if the current session began from a cold start. False if the app has
// entered the background at least once since start up.
BOOL _isColdStart;
......@@ -535,6 +531,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
@synthesize mainCoordinator = _mainCoordinator;
@synthesize NTPActionAfterTabSwitcherDismissal =
_NTPActionAfterTabSwitcherDismissal;
@synthesize tabSwitcherIsActive;
#pragma mark - Application lifecycle
......@@ -945,10 +942,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
_chromeMain.reset();
}
- (BOOL)isTabSwitcherActive {
return _tabSwitcherIsActive;
}
#pragma mark - Startup tasks
- (void)sendQueuedFeedback {
......@@ -1351,7 +1344,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
tabModel = mainTabModel;
[self setCurrentInterfaceForMode:ApplicationMode::NORMAL];
}
if (_tabSwitcherIsActive) {
if (self.tabSwitcherIsActive) {
DCHECK(!_dismissingTabSwitcher);
[self beginDismissingTabSwitcherWithCurrentModel:self.mainTabModel
focusOmnibox:NO];
......@@ -1591,7 +1584,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// Nothing to do here. The next user action (like clicking on an existing
// regular tab or creating a new incognito tab from the settings menu) will
// take care of the logic to mode switch.
if (_tabSwitcherIsActive || ![self.currentTabModel isOffTheRecord]) {
if (self.tabSwitcherIsActive || ![self.currentTabModel isOffTheRecord]) {
return;
}
......@@ -1609,7 +1602,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// closure of tabs from the main tab model when the main tab model is not
// current.
// Nothing to do here.
if (_tabSwitcherIsActive || [self.currentTabModel isOffTheRecord]) {
if (self.tabSwitcherIsActive || [self.currentTabModel isOffTheRecord]) {
return;
}
......@@ -1664,14 +1657,14 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
[_tabSwitcher restoreInternalStateWithMainTabModel:self.mainTabModel
otrTabModel:self.otrTabModel
activeTabModel:self.currentTabModel];
_tabSwitcherIsActive = YES;
self.tabSwitcherIsActive = YES;
[_tabSwitcher setDelegate:self];
[self.mainCoordinator showTabSwitcher:_tabSwitcher];
}
- (BOOL)shouldOpenNTPTabOnActivationOfTabModel:(TabModel*)tabModel {
if (_tabSwitcherIsActive) {
if (self.tabSwitcherIsActive) {
// Only attempt to dismiss the tab switcher and open a new tab if:
// - there are no tabs open in either tab model, and
// - the tab switcher controller is not directly or indirectly presenting
......@@ -1753,7 +1746,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// display. The only appropriate action is to dismiss the BVC and return the
// user to the tab switcher.
if (self.currentTabModel.count == 0U) {
_tabSwitcherIsActive = NO;
self.tabSwitcherIsActive = NO;
_dismissingTabSwitcher = NO;
_modeToDisplayOnTabSwitcherDismissal = TabSwitcherDismissalMode::NONE;
self.NTPActionAfterTabSwitcherDismissal = NO_ACTION;
......@@ -1783,7 +1776,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
action();
}
_tabSwitcherIsActive = NO;
self.tabSwitcherIsActive = NO;
_dismissingTabSwitcher = NO;
}
......@@ -1963,7 +1956,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
tabOpenedCompletion = completion;
}
if (_tabSwitcherIsActive) {
if (self.tabSwitcherIsActive) {
// If the tab switcher is already being dismissed, simply add the tab and
// note that when the tab switcher finishes dismissing, the current BVC
// should be switched to be the main BVC if necessary.
......@@ -2033,7 +2026,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// it.
ProceduralBlock completionWithBVC = ^{
DCHECK(self.currentBVC);
DCHECK(![self isTabSwitcherActive]);
DCHECK(!self.tabSwitcherIsActive);
DCHECK(!self.signinInteractionCoordinator.isActive);
// This will dismiss the SSO view controller.
[self.interfaceProvider.currentInterface
......@@ -2042,7 +2035,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
};
ProceduralBlock completionWithoutBVC = ^{
// |self.currentBVC| may exist but tab switcher should be active.
DCHECK([self isTabSwitcherActive]);
DCHECK(self.tabSwitcherIsActive);
// This will dismiss the SSO view controller.
[self.signinInteractionCoordinator cancelAndDismiss];
// History coordinator can be started on top of the tab grid. This is not
......@@ -2054,7 +2047,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// As a top level rule, if the settings are showing, they need to be
// dismissed. Then, based on whether the BVC is present or not, a different
// completion callback is called.
if (![self isTabSwitcherActive] && self.isSettingsViewPresented) {
if (!self.tabSwitcherIsActive && self.isSettingsViewPresented) {
// In this case, the settings are up and the BVC is showing. Close the
// settings then call the BVC completion.
[self closeSettingsAnimated:NO completion:completionWithBVC];
......@@ -2203,46 +2196,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
return self.mainBVC.dispatcher;
}
#pragma mark - UserFeedbackDataSource
- (NSString*)currentPageDisplayURL {
if (_tabSwitcherIsActive)
return nil;
web::WebState* webState =
self.currentTabModel.webStateList->GetActiveWebState();
if (!webState)
return nil;
// Returns URL of browser tab that is currently showing.
GURL url = webState->GetVisibleURL();
base::string16 urlText = url_formatter::FormatUrl(url);
return base::SysUTF16ToNSString(urlText);
}
- (UIImage*)currentPageScreenshot {
UIView* lastView = self.mainCoordinator.activeViewController.view;
DCHECK(lastView);
CGFloat scale = 0.0;
// For screenshots of the tab switcher we need to use a scale of 1.0 to avoid
// spending too much time since the tab switcher can have lots of subviews.
if (_tabSwitcherIsActive)
scale = 1.0;
return CaptureView(lastView, scale);
}
- (NSString*)currentPageSyncedUserName {
ios::ChromeBrowserState* browserState = [self currentBrowserState];
if (browserState->IsOffTheRecord())
return nil;
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForBrowserState(browserState);
std::string username = identity_manager->GetPrimaryAccountInfo().email;
return username.empty() ? nil : base::SysUTF8ToNSString(username);
}
- (BOOL)currentPageIsIncognito {
return [self currentBrowserState] -> IsOffTheRecord();
}
#pragma mark - ApplicationCommands helpers
- (void)startVoiceSearchInCurrentBVC {
......@@ -2258,6 +2211,10 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
#pragma mark - SceneController plumbing
- (BOOL)currentPageIsIncognito {
return [self currentBrowserState] -> IsOffTheRecord();
}
// This method is temporarily both required in the scene controller and here.
- (void)closeSettingsUI {
[self closeSettingsAnimated:YES completion:nullptr];
......@@ -2306,7 +2263,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
}
- (void)setTabSwitcherActive:(BOOL)active {
_tabSwitcherIsActive = active;
self.tabSwitcherIsActive = active;
}
- (BOOL)dismissingTabSwitcher {
......
......@@ -21,8 +21,7 @@ class AppUrlLoadingService;
// TODO(crbug.com/1012697): Remove this protocol when SceneController is
// operational. Move the private internals back into MainController, and pass
// ownership of Scene-related objects to SceneController.
@protocol MainControllerGuts <SettingsNavigationControllerDelegate,
UserFeedbackDataSource>
@protocol MainControllerGuts <SettingsNavigationControllerDelegate>
// Coordinator for displaying history.
@property(nonatomic, strong) HistoryCoordinator* historyCoordinator;
......@@ -50,8 +49,12 @@ class AppUrlLoadingService;
@property(nonatomic, strong)
SigninInteractionCoordinator* signinInteractionCoordinator;
- (BOOL)isTabSwitcherActive;
// If YES, the tab switcher is currently active.
@property(nonatomic, assign, getter=isTabSwitcherActive)
BOOL tabSwitcherIsActive;
- (id<TabSwitcher>)tabSwitcher;
- (TabModel*)currentTabModel;
- (id<TabSwitcher>)tabSwitcher;
- (ios::ChromeBrowserState*)mainBrowserState;
- (ios::ChromeBrowserState*)currentBrowserState;
......
......@@ -18,11 +18,14 @@ source_set("scene") {
deps = [
":main",
"//base",
"//components/signin/public/identity_manager",
"//components/url_formatter",
"//ios/chrome/app:app",
"//ios/chrome/app/application_delegate:application_delegate_internal",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/browsing_data",
"//ios/chrome/browser/main",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/snapshots",
"//ios/chrome/browser/tabs:tabs",
"//ios/chrome/browser/ui/browser_view",
......@@ -31,9 +34,11 @@ source_set("scene") {
"//ios/chrome/browser/ui/settings:settings_root",
"//ios/chrome/browser/ui/signin_interaction",
"//ios/chrome/browser/ui/tab_grid",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/chrome/browser/url_loading",
"//ios/chrome/browser/web_state_list",
"//ios/public/provider/chrome/browser/user_feedback",
]
libs = [ "UIKit.framework" ]
......
......@@ -7,6 +7,9 @@
#import "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/sys_string_conversions.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/url_formatter/url_formatter.h"
#include "ios/chrome/app/application_delegate/tab_opening.h"
#import "ios/chrome/app/chrome_overlay_window.h"
#import "ios/chrome/app/deferred_initialization_runner.h"
......@@ -16,6 +19,7 @@
#include "ios/chrome/browser/browsing_data/browsing_data_remover.h"
#include "ios/chrome/browser/browsing_data/browsing_data_remover_factory.h"
#include "ios/chrome/browser/main/browser.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/chrome/browser/snapshots/snapshot_tab_helper.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/browser_view/browser_view_controller.h"
......@@ -29,9 +33,11 @@
#import "ios/chrome/browser/ui/signin_interaction/signin_interaction_coordinator.h"
#include "ios/chrome/browser/ui/tab_grid/tab_grid_coordinator.h"
#import "ios/chrome/browser/ui/util/multi_window_support.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/browser/url_loading/app_url_loading_service.h"
#import "ios/chrome/browser/url_loading/url_loading_params.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider.h"
#import "ios/web/public/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -67,7 +73,7 @@ enum class EnterTabSwitcherSnapshotResult {
} // namespace
@interface SceneController ()
@interface SceneController () <UserFeedbackDataSource>
// A flag that keeps track of the UI initialization for the controlled scene.
@property(nonatomic, assign) BOOL hasInitializedUI;
......@@ -216,7 +222,7 @@ enum class EnterTabSwitcherSnapshotResult {
[SettingsNavigationController
userFeedbackControllerForBrowser:browser
delegate:self.mainController
feedbackDataSource:self.mainController
feedbackDataSource:self
dispatcher:self];
[baseViewController
presentViewController:self.mainController.settingsNavigationController
......@@ -583,4 +589,42 @@ enum class EnterTabSwitcherSnapshotResult {
[self.mainController closeSettingsAnimated:YES completion:completion];
}
#pragma mark - UserFeedbackDataSource
- (NSString*)currentPageDisplayURL {
if (self.mainController.tabSwitcherIsActive)
return nil;
web::WebState* webState =
self.mainController.currentTabModel.webStateList->GetActiveWebState();
if (!webState)
return nil;
// Returns URL of browser tab that is currently showing.
GURL url = webState->GetVisibleURL();
base::string16 urlText = url_formatter::FormatUrl(url);
return base::SysUTF16ToNSString(urlText);
}
- (UIImage*)currentPageScreenshot {
UIView* lastView =
self.mainController.mainCoordinator.activeViewController.view;
DCHECK(lastView);
CGFloat scale = 0.0;
// For screenshots of the tab switcher we need to use a scale of 1.0 to avoid
// spending too much time since the tab switcher can have lots of subviews.
if (self.mainController.tabSwitcherIsActive)
scale = 1.0;
return CaptureView(lastView, scale);
}
- (NSString*)currentPageSyncedUserName {
ios::ChromeBrowserState* browserState =
self.mainController.currentBrowserState;
if (browserState->IsOffTheRecord())
return nil;
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForBrowserState(browserState);
std::string username = identity_manager->GetPrimaryAccountInfo().email;
return username.empty() ? nil : base::SysUTF8ToNSString(username);
}
@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