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