| Index: ios/chrome/browser/ui/tab_switcher/tab_switcher_controller.mm
|
| diff --git a/ios/chrome/browser/ui/tab_switcher/tab_switcher_controller.mm b/ios/chrome/browser/ui/tab_switcher/tab_switcher_controller.mm
|
| index 073ecc9b6e8130aa2806302a4c2e421d2d0cb49a..9e2ac2e12c0105e0f00fc714fe60dd725d8fbf0b 100644
|
| --- a/ios/chrome/browser/ui/tab_switcher/tab_switcher_controller.mm
|
| +++ b/ios/chrome/browser/ui/tab_switcher/tab_switcher_controller.mm
|
| @@ -5,8 +5,6 @@
|
| #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_controller.h"
|
|
|
| #include "base/ios/block_types.h"
|
| -#include "base/ios/weak_nsobject.h"
|
| -#include "base/mac/scoped_nsobject.h"
|
| #include "base/metrics/user_metrics.h"
|
| #include "base/metrics/user_metrics_action.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| @@ -53,6 +51,10 @@
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/l10n/l10n_util_mac.h"
|
|
|
| +#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| +#error "This file requires ARC support."
|
| +#endif
|
| +
|
| namespace {
|
|
|
| // Offsets for computing the panels' indexes in the TabSwitcherView.
|
| @@ -91,21 +93,21 @@ enum class SnapshotViewOption {
|
| // weak.
|
| TabModel* _onLoadActiveModel;
|
| // The view this controller manages.
|
| - base::scoped_nsobject<TabSwitcherView> _tabSwitcherView;
|
| + TabSwitcherView* _tabSwitcherView;
|
| // The list of panels controllers for distant sessions.
|
| - base::scoped_nsobject<NSMutableArray> _controllersOfDistantSessions;
|
| + NSMutableArray* _controllersOfDistantSessions;
|
| // The panel controllers for the local sessions.
|
| - base::scoped_nsobject<TabSwitcherPanelController> _onTheRecordSession;
|
| - base::scoped_nsobject<TabSwitcherPanelController> _offTheRecordSession;
|
| + TabSwitcherPanelController* _onTheRecordSession;
|
| + TabSwitcherPanelController* _offTheRecordSession;
|
| // The model storing the state of what is shown by the tab switcher.
|
| - base::scoped_nsobject<TabSwitcherModel> _tabSwitcherModel;
|
| + TabSwitcherModel* _tabSwitcherModel;
|
| // Stores the current sign-in panel type.
|
| TabSwitcherSignInPanelsType _signInPanelType;
|
| // Cache for the panel's cells.
|
| - base::scoped_nsobject<TabSwitcherCache> _cache;
|
| + TabSwitcherCache* _cache;
|
| // Stores the background color of the window when the tab switcher was
|
| // presented.
|
| - base::scoped_nsobject<UIColor> _initialWindowBackgroundColor;
|
| + UIColor* _initialWindowBackgroundColor;
|
| // Indicate whether a previous promo panel header cell should be removed or
|
| // added.
|
| BOOL _shouldRemovePromoPanelHeaderCell;
|
| @@ -193,27 +195,27 @@ enum class SnapshotViewOption {
|
| if (self) {
|
| _browserState = browserState;
|
| _onLoadActiveModel = activeTabModel;
|
| - _cache.reset([[TabSwitcherCache alloc] init]);
|
| + _cache = [[TabSwitcherCache alloc] init];
|
| [_cache setMainTabModel:mainTabModel otrTabModel:otrTabModel];
|
| - _tabSwitcherModel.reset([[TabSwitcherModel alloc]
|
| - initWithBrowserState:browserState
|
| - delegate:self
|
| - mainTabModel:mainTabModel
|
| - otrTabModel:otrTabModel
|
| - withCache:_cache]);
|
| - _controllersOfDistantSessions.reset([[NSMutableArray alloc] init]);
|
| + _tabSwitcherModel =
|
| + [[TabSwitcherModel alloc] initWithBrowserState:browserState
|
| + delegate:self
|
| + mainTabModel:mainTabModel
|
| + otrTabModel:otrTabModel
|
| + withCache:_cache];
|
| + _controllersOfDistantSessions = [[NSMutableArray alloc] init];
|
| [self loadTabSwitcherView];
|
| - _onTheRecordSession.reset([[TabSwitcherPanelController alloc]
|
| + _onTheRecordSession = [[TabSwitcherPanelController alloc]
|
| initWithModel:_tabSwitcherModel
|
| forLocalSessionOfType:TabSwitcherSessionType::REGULAR_SESSION
|
| withCache:_cache
|
| - browserState:_browserState]);
|
| + browserState:_browserState];
|
| [_onTheRecordSession setDelegate:self];
|
| - _offTheRecordSession.reset([[TabSwitcherPanelController alloc]
|
| + _offTheRecordSession = [[TabSwitcherPanelController alloc]
|
| initWithModel:_tabSwitcherModel
|
| forLocalSessionOfType:TabSwitcherSessionType::OFF_THE_RECORD_SESSION
|
| withCache:_cache
|
| - browserState:_browserState]);
|
| + browserState:_browserState];
|
| [_offTheRecordSession setDelegate:self];
|
| [_tabSwitcherView addPanelView:[_offTheRecordSession view]
|
| atIndex:kLocalTabsOffTheRecordPanelIndex];
|
| @@ -243,8 +245,8 @@ enum class SnapshotViewOption {
|
|
|
| - (void)loadTabSwitcherView {
|
| DCHECK(![_tabSwitcherView superview]);
|
| - _tabSwitcherView.reset(
|
| - [[TabSwitcherView alloc] initWithFrame:[self tabSwitcherInitialFrame]]);
|
| + _tabSwitcherView =
|
| + [[TabSwitcherView alloc] initWithFrame:[self tabSwitcherInitialFrame]];
|
| [_tabSwitcherView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
|
| UIViewAutoresizingFlexibleHeight];
|
| [_tabSwitcherView setDelegate:self];
|
| @@ -263,7 +265,7 @@ enum class SnapshotViewOption {
|
| #pragma mark - UIResponder
|
|
|
| - (NSArray*)keyCommands {
|
| - base::WeakNSObject<TabSwitcherController> weakSelf(self);
|
| + __weak TabSwitcherController* weakSelf = self;
|
| return @[
|
| [UIKeyCommand
|
| cr_keyCommandWithInput:@"t"
|
| @@ -271,8 +273,7 @@ enum class SnapshotViewOption {
|
| title:l10n_util::GetNSStringWithFixup(
|
| IDS_IOS_TOOLS_MENU_NEW_TAB)
|
| action:^{
|
| - base::scoped_nsobject<TabSwitcherController>
|
| - strongSelf([weakSelf retain]);
|
| + TabSwitcherController* strongSelf = weakSelf;
|
| if (!strongSelf)
|
| return;
|
| if ([strongSelf currentPanelIndex] ==
|
| @@ -306,8 +307,7 @@ enum class SnapshotViewOption {
|
| modifierFlags:UIKeyModifierCommand
|
| title:nil
|
| action:^{
|
| - base::scoped_nsobject<TabSwitcherController>
|
| - strongSelf([weakSelf retain]);
|
| + TabSwitcherController* strongSelf = weakSelf;
|
| if (!strongSelf)
|
| return;
|
| if ([strongSelf currentPanelIndex] ==
|
| @@ -410,14 +410,13 @@ enum class SnapshotViewOption {
|
|
|
| - (void)updateWindowBackgroundColor {
|
| DCHECK(!_initialWindowBackgroundColor);
|
| - _initialWindowBackgroundColor.reset(
|
| - [self.view.window.backgroundColor retain]);
|
| + _initialWindowBackgroundColor = self.view.window.backgroundColor;
|
| self.view.window.backgroundColor = [[MDCPalette greyPalette] tint900];
|
| }
|
|
|
| - (void)restoreWindowBackgroundColor {
|
| self.view.window.backgroundColor = _initialWindowBackgroundColor;
|
| - _initialWindowBackgroundColor.reset();
|
| + _initialWindowBackgroundColor = nil;
|
| }
|
|
|
| - (UIView*)snapshotViewForView:(UIView*)inputView
|
| @@ -438,7 +437,7 @@ enum class SnapshotViewOption {
|
| [inputView.layer renderInContext:UIGraphicsGetCurrentContext()];
|
| UIImage* screenshot = UIGraphicsGetImageFromCurrentImageContext();
|
| UIGraphicsEndImageContext();
|
| - UIView* view = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
|
| + UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
| [view layer].contents = static_cast<id>(screenshot.CGImage);
|
| return view;
|
| } else {
|
| @@ -447,8 +446,7 @@ enum class SnapshotViewOption {
|
| UIColor* backgroundColor = [tabModel isOffTheRecord]
|
| ? [[MDCPalette greyPalette] tint700]
|
| : [[MDCPalette greyPalette] tint100];
|
| - UIView* placeholdView =
|
| - [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
|
| + UIView* placeholdView = [[UIView alloc] initWithFrame:CGRectZero];
|
| placeholdView.backgroundColor = backgroundColor;
|
| return placeholdView;
|
| }
|
| @@ -557,28 +555,26 @@ enum class SnapshotViewOption {
|
| CGRect finalToolbarScreenshotFrame =
|
| CGRectMake(0, 0, selectedCellFrame.size.width, cellTopBarHeight);
|
|
|
| - base::scoped_nsobject<UIImageView> tabScreenshotImageView(
|
| - [[UIImageView alloc] initWithFrame:CGRectZero]);
|
| + UIImageView* tabScreenshotImageView =
|
| + [[UIImageView alloc] initWithFrame:CGRectZero];
|
|
|
| - base::WeakNSObject<UIImageView> weakTabScreenshotImageView(
|
| - tabScreenshotImageView.get());
|
| + __weak UIImageView* weakTabScreenshotImageView = tabScreenshotImageView;
|
|
|
| if ([self initialTabModelAndTabIDMatchesTabModel:tabModel
|
| tabID:selectedTab.tabId]) {
|
| - tabScreenshotImageView.get().image =
|
| - self.transitionContext.tabSnapshotImage;
|
| + tabScreenshotImageView.image = self.transitionContext.tabSnapshotImage;
|
| } else {
|
| // If transitioning to a different tab than the one animated in
|
| // from, a new snapshot should be generated instead of using the transition
|
| // context
|
| - tabScreenshotImageView.get().image =
|
| + tabScreenshotImageView.image =
|
| [self updateScreenshotForCellIfNeeded:selectedCell tabModel:tabModel];
|
| [selectedTab retrieveSnapshot:^(UIImage* snapshot) {
|
| [weakTabScreenshotImageView setImage:snapshot];
|
| }];
|
| }
|
|
|
| - const CGSize tabScreenshotImageSize = tabScreenshotImageView.get().image.size;
|
| + const CGSize tabScreenshotImageSize = tabScreenshotImageView.image.size;
|
|
|
| CGRect initialTabScreenshotFrame = CGRectZero;
|
| const CGSize toolbarSize = toolbarController.view.bounds.size;
|
| @@ -636,14 +632,13 @@ enum class SnapshotViewOption {
|
| tabStripPlaceholderView.frame = tabStripInitialFrame;
|
|
|
| // Create and setup placeholder view and subviews.
|
| - base::scoped_nsobject<UIView> placeholderView(
|
| - [[UIView alloc] initWithFrame:initialTabFrame]);
|
| + UIView* placeholderView = [[UIView alloc] initWithFrame:initialTabFrame];
|
| [placeholderView setClipsToBounds:YES];
|
| [placeholderView setUserInteractionEnabled:NO];
|
|
|
| - tabScreenshotImageView.get().frame = initialTabScreenshotFrame;
|
| - tabScreenshotImageView.get().contentMode = UIViewContentModeScaleToFill;
|
| - tabScreenshotImageView.get().autoresizingMask = UIViewAutoresizingNone;
|
| + tabScreenshotImageView.frame = initialTabScreenshotFrame;
|
| + tabScreenshotImageView.contentMode = UIViewContentModeScaleToFill;
|
| + tabScreenshotImageView.autoresizingMask = UIViewAutoresizingNone;
|
| [placeholderView addSubview:tabScreenshotImageView];
|
|
|
| // Try using a snapshot view for dismissal animation because it's faster and
|
| @@ -667,8 +662,8 @@ enum class SnapshotViewOption {
|
| toolbarScreenshotImageView.frame = initialToolbarScreenshotFrame;
|
| [placeholderView addSubview:toolbarScreenshotImageView];
|
|
|
| - base::scoped_nsobject<UIImageView> toolbarShadowImageView(
|
| - [[UIImageView alloc] initWithFrame:shadowInitialFrame]);
|
| + UIImageView* toolbarShadowImageView =
|
| + [[UIImageView alloc] initWithFrame:shadowInitialFrame];
|
| [toolbarShadowImageView setAutoresizingMask:UIViewAutoresizingNone];
|
| [toolbarShadowImageView setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW)];
|
| [placeholderView addSubview:toolbarShadowImageView];
|
| @@ -679,9 +674,9 @@ enum class SnapshotViewOption {
|
| toolbarScreenshotImageView.alpha =
|
| (transitionType == TransitionType::TRANSITION_DISMISS) ? 0 : 1.0;
|
|
|
| - base::WeakNSObject<TabSwitcherController> weakSelf(self);
|
| + __weak TabSwitcherController* weakSelf = self;
|
| void (^completionBlock)(BOOL) = ^(BOOL finished) {
|
| - base::scoped_nsobject<TabSwitcherController> strongSelf([weakSelf retain]);
|
| + TabSwitcherController* strongSelf = weakSelf;
|
|
|
| [tabStripPlaceholderView removeFromSuperview];
|
| [toolbarScreenshotImageView removeFromSuperview];
|
| @@ -704,11 +699,11 @@ enum class SnapshotViewOption {
|
| toolbarScreenshotImageView.alpha =
|
| transitionType == TransitionType::TRANSITION_DISMISS ? 1.0 : 0;
|
| tabStripPlaceholderView.frame = tabStripFinalFrame;
|
| - toolbarShadowImageView.get().frame = shadowFinalFrame;
|
| - placeholderView.get().frame = finalTabFrame;
|
| + toolbarShadowImageView.frame = shadowFinalFrame;
|
| + placeholderView.frame = finalTabFrame;
|
| toolbarScreenshotImageView.frame = finalToolbarScreenshotFrame;
|
| finalToolbarScreenshotImageView.frame = finalToolbarScreenshotFrame;
|
| - tabScreenshotImageView.get().frame = finalTabScreenshotFrame;
|
| + tabScreenshotImageView.frame = finalTabScreenshotFrame;
|
| };
|
|
|
| [UIView animateWithDuration:animated ? kTransitionAnimationDuration : 0
|
| @@ -792,9 +787,9 @@ enum class SnapshotViewOption {
|
| DCHECK(tabModel == [_tabSwitcherModel mainTabModel] ||
|
| tabModel == [_tabSwitcherModel otrTabModel]);
|
| if (tabModel == [_tabSwitcherModel mainTabModel])
|
| - return _onTheRecordSession.get();
|
| + return _onTheRecordSession;
|
| if (tabModel == [_tabSwitcherModel otrTabModel])
|
| - return _offTheRecordSession.get();
|
| + return _offTheRecordSession;
|
| return nil;
|
| }
|
|
|
| @@ -952,15 +947,14 @@ enum class SnapshotViewOption {
|
| for (NSNumber* objCIndex in insertedIndexes) {
|
| int index = [objCIndex intValue];
|
| std::string tag = [_tabSwitcherModel tagOfDistantSessionAtIndex:index];
|
| - base::scoped_nsobject<TabSwitcherPanelController> panelController(
|
| + TabSwitcherPanelController* panelController =
|
| [[TabSwitcherPanelController alloc] initWithModel:_tabSwitcherModel
|
| forDistantSessionWithTag:tag
|
| - browserState:_browserState]);
|
| + browserState:_browserState];
|
| [panelController setDelegate:self];
|
| [_tabSwitcherView addPanelView:[panelController view]
|
| atIndex:index + offset];
|
| - [_controllersOfDistantSessions insertObject:panelController.get()
|
| - atIndex:index];
|
| + [_controllersOfDistantSessions insertObject:panelController atIndex:index];
|
| }
|
|
|
| // Update the header view.
|
| @@ -969,8 +963,7 @@ enum class SnapshotViewOption {
|
| }
|
|
|
| - (void)distantSessionMayNeedUpdate:(std::string const&)tag {
|
| - for (TabSwitcherPanelController* panel in _controllersOfDistantSessions
|
| - .get()) {
|
| + for (TabSwitcherPanelController* panel in _controllersOfDistantSessions) {
|
| DCHECK([panel isKindOfClass:[TabSwitcherPanelController class]]);
|
| if ([panel sessionTag] == tag) {
|
| [panel updateCollectionViewIfNeeded];
|
| @@ -1009,9 +1002,8 @@ enum class SnapshotViewOption {
|
| _signInPanelType = panelType;
|
| if (panelType != TabSwitcherSignInPanelsType::NO_PANEL) {
|
| TabSwitcherPanelOverlayView* panelView =
|
| - [[[TabSwitcherPanelOverlayView alloc] initWithFrame:CGRectZero
|
| - browserState:_browserState]
|
| - autorelease];
|
| + [[TabSwitcherPanelOverlayView alloc] initWithFrame:CGRectZero
|
| + browserState:_browserState];
|
| [panelView setOverlayType:PanelOverlayTypeFromSignInPanelsType(panelType)];
|
| [_tabSwitcherView addPanelView:panelView atIndex:kSignInPromoPanelIndex];
|
| }
|
| @@ -1078,7 +1070,7 @@ enum class SnapshotViewOption {
|
| sync_sessions::SyncedSession::TYPE_UNSET;
|
| NSString* cellTitle = nil;
|
|
|
| - if (index < _controllersOfDistantSessions.get().count) {
|
| + if (index < _controllersOfDistantSessions.count) {
|
| TabSwitcherPanelController* panel =
|
| [_controllersOfDistantSessions objectAtIndex:index];
|
| const synced_sessions::DistantSession* distantSession =
|
| @@ -1099,8 +1091,7 @@ enum class SnapshotViewOption {
|
| break;
|
| }
|
| TabSwitcherSessionCellData* sessionData =
|
| - [[[TabSwitcherSessionCellData alloc] initWithSessionCellType:cellType]
|
| - autorelease];
|
| + [[TabSwitcherSessionCellData alloc] initWithSessionCellType:cellType];
|
| sessionData.title = cellTitle;
|
| return sessionData;
|
| }
|
| @@ -1127,8 +1118,8 @@ enum class SnapshotViewOption {
|
| base::UserMetricsAction("MobileTabSwitcherCreateNonIncognitoTab"));
|
| }
|
| // Create and execute command to create the tab.
|
| - base::scoped_nsobject<GenericChromeCommand> command(
|
| - [[GenericChromeCommand alloc] initWithTag:tag]);
|
| + GenericChromeCommand* command =
|
| + [[GenericChromeCommand alloc] initWithTag:tag];
|
| [self chromeExecuteCommand:command];
|
| }
|
|
|
|
|