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 502ca999b4879314f9fad173413e4af586913740..f6c72267b6d0db115e72a72019e955de9da51e83 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] == |
@@ -414,14 +414,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 |
@@ -442,7 +441,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 { |
@@ -451,8 +450,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; |
} |
@@ -561,28 +559,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; |
@@ -640,14 +636,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 |
@@ -671,8 +666,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]; |
@@ -683,9 +678,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]; |
@@ -708,11 +703,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 |
@@ -796,9 +791,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; |
} |
@@ -956,15 +951,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. |
@@ -973,8 +967,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]; |
@@ -1013,9 +1006,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]; |
} |
@@ -1082,7 +1074,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 = |
@@ -1103,8 +1095,7 @@ enum class SnapshotViewOption { |
break; |
} |
TabSwitcherSessionCellData* sessionData = |
- [[[TabSwitcherSessionCellData alloc] initWithSessionCellType:cellType] |
- autorelease]; |
+ [[TabSwitcherSessionCellData alloc] initWithSessionCellType:cellType]; |
sessionData.title = cellTitle; |
return sessionData; |
} |
@@ -1131,8 +1122,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]; |
} |