Commit aabb568f authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

Re-land: [iOS] Plumb Browser into RecentTabsViewController""

This reverts commit d5af0a22.

Revert prior revert for re-land.

Original CL: https://chromium-review.googlesource.com/c/chromium/src/+/2078452

Bug: 1057621
Change-Id: Ib8875dedd510d078660c7cb37edb5823530e3fc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2082913Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746304}
parent 0cbe4d42
......@@ -69,7 +69,7 @@ TEST_F(ApplicationBreadcrumbsLoggerTest, SkipInProductHelpUserActions) {
// Tests that memory pressure events are logged by ApplicationBreadcrumbsLogger.
// TODO(crbug.com/1046588): This test is flaky.
TEST_F(ApplicationBreadcrumbsLoggerTest, FLAKY_MemoryPressure) {
TEST_F(ApplicationBreadcrumbsLoggerTest, DISABLED_MemoryPressure) {
base::MemoryPressureListener::SimulatePressureNotification(
MemoryPressureLevel::MEMORY_PRESSURE_LEVEL_MODERATE);
base::MemoryPressureListener::SimulatePressureNotification(
......
......@@ -71,6 +71,7 @@ source_set("recent_tabs_ui") {
"//components/sync",
"//ios/chrome/app/strings",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/main:public",
"//ios/chrome/browser/metrics:metrics_internal",
"//ios/chrome/browser/sessions",
"//ios/chrome/browser/sessions:serialisation",
......
......@@ -47,14 +47,13 @@
// Initialize and configure RecentTabsTableViewController.
RecentTabsTableViewController* recentTabsTableViewController =
[[RecentTabsTableViewController alloc] init];
recentTabsTableViewController.browserState = self.browserState;
recentTabsTableViewController.browser = self.browser;
recentTabsTableViewController.loadStrategy = self.loadStrategy;
CommandDispatcher* dispatcher = self.browser->GetCommandDispatcher();
id<ApplicationCommands> handler =
HandlerForProtocol(dispatcher, ApplicationCommands);
recentTabsTableViewController.handler = handler;
recentTabsTableViewController.presentationDelegate = self;
recentTabsTableViewController.webStateList = self.browser->GetWebStateList();
// Adds the "Done" button and hooks it up to |stop|.
UIBarButtonItem* dismissButton = [[UIBarButtonItem alloc]
......
......@@ -9,9 +9,8 @@
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
#include "ui/base/window_open_disposition.h"
class ChromeBrowserState;
class Browser;
enum class UrlLoadStrategy;
class WebStateList;
@protocol ApplicationCommands;
@protocol RecentTabsTableViewControllerDelegate;
......@@ -21,8 +20,9 @@ class WebStateList;
@interface RecentTabsTableViewController
: ChromeTableViewController <RecentTabsConsumer,
UIAdaptivePresentationControllerDelegate>
// The coordinator's BrowserState.
@property(nonatomic, assign) ChromeBrowserState* browserState;
// The Browser for the tabs being restored. It's an error to pass a nullptr
// Browser.
@property(nonatomic, assign) Browser* browser;
// The command handler used by this ViewController.
@property(nonatomic, weak) id<ApplicationCommands> handler;
// Opaque instructions on how to open urls.
......@@ -31,8 +31,6 @@ class WebStateList;
@property(nonatomic, assign) WindowOpenDisposition restoredTabDisposition;
// RecentTabsTableViewControllerDelegate delegate.
@property(nonatomic, weak) id<RecentTabsTableViewControllerDelegate> delegate;
// WebStateList for tabs restored by this object.
@property(nonatomic, assign) WebStateList* webStateList;
// Whether the updates of the RecentTabs should be ignored. Setting this to NO
// would trigger a reload of the TableView.
@property(nonatomic, assign) BOOL preventUpdates;
......
......@@ -16,6 +16,7 @@
#include "components/sync_sessions/open_tabs_ui_delegate.h"
#include "components/sync_sessions/session_sync_service.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/metrics/new_tab_page_uma.h"
#include "ios/chrome/browser/sessions/session_util.h"
#include "ios/chrome/browser/sessions/tab_restore_service_delegate_impl_ios.h"
......@@ -117,8 +118,13 @@ const int kRecentlyClosedTabsSectionIndex = 0;
// Handles displaying the context menu for all form factors.
@property(nonatomic, strong) ContextMenuCoordinator* contextMenuCoordinator;
@property(nonatomic, strong) SigninPromoViewMediator* signinPromoViewMediator;
// The browser state used for many operations, derived from the one provided by
// |self.browser|.
@property(nonatomic, readonly) ChromeBrowserState* browserState;
// YES if this ViewController is being presented on incognito mode.
@property(nonatomic, assign, getter=isIncognito) BOOL incognito;
@property(nonatomic, readonly, getter=isIncognito) BOOL incognito;
// Convenience getter for |self.browser|'s WebStateList
@property(nonatomic, readonly) WebStateList* webStateList;
@end
@implementation RecentTabsTableViewController : ChromeTableViewController
......@@ -174,15 +180,20 @@ const int kRecentlyClosedTabsSectionIndex = 0;
#pragma mark - Setters & Getters
// Some RecentTabs services depend on objects not present in the OffTheRecord
// BrowserState, in order to prevent crashes set |_browserState| to
// |browserState|->OriginalChromeBrowserState. While doing this check if
// incognito or not so that pages are loaded accordingly.
- (void)setBrowserState:(ChromeBrowserState*)browserState {
if (browserState) {
_browserState = browserState->GetOriginalChromeBrowserState();
_incognito = browserState->IsOffTheRecord();
}
- (void)setBrowser:(Browser*)browser {
DCHECK(browser);
_browser = browser;
ChromeBrowserState* browserState = browser->GetBrowserState();
// Some RecentTabs services depend on objects not present in the OffTheRecord
// BrowserState, in order to prevent crashes set |_browserState| to
// |browserState|->OriginalChromeBrowserState. While doing this check if
// incognito or not so that pages are loaded accordingly.
_browserState = browserState->GetOriginalChromeBrowserState();
_incognito = browserState->IsOffTheRecord();
}
- (WebStateList*)webStateList {
return self.browser->GetWebStateList();
}
- (void)setPreventUpdates:(BOOL)preventUpdates {
......
......@@ -146,8 +146,8 @@
- (void)start {
TabGridViewController* baseViewController =
[[TabGridViewController alloc] init];
baseViewController.dispatcher =
static_cast<id<ApplicationCommands>>(self.dispatcher);
baseViewController.handler =
HandlerForProtocol(self.dispatcher, ApplicationCommands);
self.legacyTransitionHandler = [[LegacyTabGridTransitionHandler alloc] init];
self.legacyTransitionHandler.provider = baseViewController;
baseViewController.modalPresentationStyle = UIModalPresentationCustom;
......@@ -182,8 +182,7 @@
// TODO(crbug.com/845192) : Remove RecentTabsTableViewController dependency on
// ChromeBrowserState so that we don't need to expose the view controller.
baseViewController.remoteTabsViewController.browserState =
regularBrowserState;
baseViewController.remoteTabsViewController.browser = self.regularBrowser;
self.remoteTabsMediator = [[RecentTabsMediator alloc] init];
self.remoteTabsMediator.browserState = regularBrowserState;
self.remoteTabsMediator.consumer = baseViewController.remoteTabsConsumer;
......@@ -201,8 +200,6 @@
UrlLoadStrategy::ALWAYS_NEW_FOREGROUND_TAB;
baseViewController.remoteTabsViewController.restoredTabDisposition =
WindowOpenDisposition::NEW_FOREGROUND_TAB;
baseViewController.remoteTabsViewController.webStateList =
regularWebStateList;
baseViewController.remoteTabsViewController.presentationDelegate = self;
if (!base::FeatureList::IsEnabled(kContainedBVC)) {
......@@ -237,6 +234,10 @@
}
- (void)stop {
// The TabGridViewController may still message its application commands
// handler after this coordinator has stopped; make this action a no-op by
// setting the handler to nil.
self.baseViewController.handler = nil;
[self.dispatcher stopDispatchingForProtocol:@protocol(ApplicationCommands)];
[self.dispatcher
stopDispatchingForProtocol:@protocol(ApplicationSettingsCommands)];
......
......@@ -7,9 +7,11 @@
#import <UIKit/UIKit.h>
#import "base/test/ios/wait_util.h"
#import "ios/chrome/browser/main/test_browser.h"
#import "ios/chrome/browser/ui/commands/browsing_data_commands.h"
#import "ios/chrome/browser/ui/tab_grid/tab_switcher.h"
#import "ios/chrome/test/block_cleanup_test.h"
#include "ios/web/public/test/web_task_environment.h"
#include "testing/gtest_mac.h"
#include "third_party/ocmock/OCMock/OCMock.h"
......@@ -39,6 +41,7 @@ namespace {
class TabGridCoordinatorTest : public BlockCleanupTest {
public:
TabGridCoordinatorTest() {
browser_ = std::make_unique<TestBrowser>();
UIWindow* window = [UIApplication sharedApplication].keyWindow;
coordinator_ = [[TabGridCoordinator alloc]
initWithWindow:window
......@@ -47,6 +50,7 @@ class TabGridCoordinatorTest : public BlockCleanupTest {
browsingDataCommandEndpoint:OCMProtocolMock(
@protocol(BrowsingDataCommands))];
coordinator_.animationsDisabledForTesting = YES;
coordinator_.regularBrowser = browser_.get();
// TabGirdCoordinator will make its view controller the root, so stash the
// original root view controller before starting |coordinator_|.
original_root_view_controller_ =
......@@ -72,9 +76,14 @@ class TabGridCoordinatorTest : public BlockCleanupTest {
original_root_view_controller_;
original_root_view_controller_ = nil;
}
[coordinator_ stop];
}
protected:
web::WebTaskEnvironment task_environment_;
// Browser for the coordinator.
std::unique_ptr<Browser> browser_;
// The TabGridCoordinator that is under test. The test fixture sets
// this VC as the root VC for the window.
TabGridCoordinator* coordinator_;
......@@ -206,7 +215,6 @@ TEST_F(TabGridCoordinatorTest, CompletionHandlers) {
// Test that the tab grid coordinator sizes its view controller to the window.
TEST_F(TabGridCoordinatorTest, SizeTabGridCoordinatorViewController) {
CGRect rect = [UIScreen mainScreen].bounds;
[coordinator_ start];
EXPECT_TRUE(
CGRectEqualToRect(rect, coordinator_.baseViewController.view.frame));
}
......
......@@ -30,7 +30,7 @@
@interface TabGridViewController
: UIViewController <TabGridPaging, GridTransitionAnimationLayoutProviding>
@property(nonatomic, weak) id<ApplicationCommands> dispatcher;
@property(nonatomic, weak) id<ApplicationCommands> handler;
// Delegate for this view controller to handle presenting tab UI.
@property(nonatomic, weak) id<TabPresentationDelegate> tabPresentationDelegate;
......
......@@ -1078,7 +1078,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
BOOL incognitoContentVisible =
(self.currentPage == TabGridPageIncognitoTabs &&
!self.incognitoTabsViewController.gridEmpty);
[self.dispatcher setIncognitoContentVisible:incognitoContentVisible];
[self.handler setIncognitoContentVisible:incognitoContentVisible];
}
// Returns the approximate number of grid cells that will be visible on this
......
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