Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: ios/chrome/browser/ui/dialogs/dialog_presenter.mm

Issue 2822933004: [ObjC ARC] Converts ios/chrome/browser/ui/dialogs:dialogs_internal to ARC. (Closed)
Patch Set: Remove presentedDialogWebState ivar Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/dialogs/dialog_presenter.mm
diff --git a/ios/chrome/browser/ui/dialogs/dialog_presenter.mm b/ios/chrome/browser/ui/dialogs/dialog_presenter.mm
index 552826677beb7442a653a12a7ccbe3d29e17e0a4..5be1336d79c6197da14be2bf9134ffb2e13f5a03 100644
--- a/ios/chrome/browser/ui/dialogs/dialog_presenter.mm
+++ b/ios/chrome/browser/ui/dialogs/dialog_presenter.mm
@@ -8,7 +8,6 @@
#include <map>
#import "base/ios/block_types.h"
-#import "base/ios/weak_nsobject.h"
#include "base/logging.h"
#import "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
@@ -24,6 +23,10 @@
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
// Externed accessibility identifier.
NSString* const kJavaScriptDialogTextFieldAccessibiltyIdentifier =
@"JavaScriptDialogTextFieldAccessibiltyIdentifier";
@@ -35,26 +38,19 @@ const char kAboutNullHostname[] = "about:null";
} // namespace
@interface DialogPresenter () {
- // Backing objects for properties of the same name.
- base::WeakNSProtocol<id<DialogPresenterDelegate>> _delegate;
- base::WeakNSObject<UIViewController> _viewController;
// Queue of WebStates which correspond to the keys in
// |_dialogCoordinatorsForWebStates|.
std::deque<web::WebState*> _queuedWebStates;
// A map associating queued webStates with their coordinators.
std::map<web::WebState*, base::scoped_nsobject<AlertCoordinator>>
_dialogCoordinatorsForWebStates;
- web::WebState* _presentedDialogWebState;
- base::scoped_nsobject<AlertCoordinator> _presentedDialogCoordinator;
- base::scoped_nsobject<ActionSheetCoordinator>
- _blockingConfirmationCoordinator;
}
// The delegate passed on initialization.
-@property(nonatomic, readonly) id<DialogPresenterDelegate> delegate;
+@property(weak, nonatomic, readonly) id<DialogPresenterDelegate> delegate;
// The presenting view controller passed on initialization.
-@property(nonatomic, readonly) UIViewController* viewController;
+@property(weak, nonatomic, readonly) UIViewController* viewController;
// Whether a modal dialog is currently being shown.
@property(nonatomic, readonly, getter=isShowingDialog) BOOL showingDialog;
@@ -63,10 +59,10 @@ const char kAboutNullHostname[] = "about:null";
@property(nonatomic) web::WebState* presentedDialogWebState;
// The dialog that's currently being shown, if any.
-@property(nonatomic, retain) AlertCoordinator* presentedDialogCoordinator;
+@property(nonatomic, strong) AlertCoordinator* presentedDialogCoordinator;
// The JavaScript dialog blocking confirmation action sheet being shown, if any.
-@property(nonatomic, retain) AlertCoordinator* blockingConfirmationCoordinator;
+@property(nonatomic, strong) AlertCoordinator* blockingConfirmationCoordinator;
// Adds |context| and |coordinator| to the queue. If a dialog is not already
// being shown, |coordinator| will be presented. Otherwise, |coordinator| will
@@ -106,14 +102,19 @@ const char kAboutNullHostname[] = "about:null";
@implementation DialogPresenter
@synthesize active = _active;
+@synthesize delegate = _delegate;
+@synthesize viewController = _viewController;
+@synthesize presentedDialogCoordinator = _presentedDialogCoordinator;
+@synthesize blockingConfirmationCoordinator = _blockingConfirmationCoordinator;
+@synthesize presentedDialogWebState = _presentedDialogWebState;
- (instancetype)initWithDelegate:(id<DialogPresenterDelegate>)delegate
presentingViewController:(UIViewController*)viewController {
if ((self = [super init])) {
DCHECK(delegate);
DCHECK(viewController);
- _delegate.reset(delegate);
- _viewController.reset(viewController);
+ _delegate = delegate;
+ _viewController = viewController;
}
return self;
}
@@ -127,47 +128,12 @@ const char kAboutNullHostname[] = "about:null";
}
}
-- (id<DialogPresenterDelegate>)delegate {
- return _delegate;
-}
-
-- (UIViewController*)viewController {
- return _viewController;
-}
-
- (BOOL)isShowingDialog {
DCHECK_EQ(self.presentedDialogWebState != nullptr,
self.presentedDialogCoordinator != nil);
return self.presentedDialogCoordinator != nil;
}
-- (web::WebState*)presentedDialogWebState {
- return _presentedDialogWebState;
-}
-
-- (void)setPresentedDialogWebState:(web::WebState*)presentedDialogWebState {
- _presentedDialogWebState = presentedDialogWebState;
-}
-
-- (AlertCoordinator*)presentedDialogCoordinator {
- return _presentedDialogCoordinator;
-}
-
-- (void)setPresentedDialogCoordinator:
- (AlertCoordinator*)presentedDialogCoordinator {
- _presentedDialogCoordinator.reset([presentedDialogCoordinator retain]);
-}
-
-- (ActionSheetCoordinator*)blockingConfirmationCoordinator {
- return _blockingConfirmationCoordinator;
-}
-
-- (void)setBlockingConfirmationCoordinator:
- (ActionSheetCoordinator*)blockingConfirmationActionSheetCoordinator {
- _blockingConfirmationCoordinator.reset(
- [blockingConfirmationActionSheetCoordinator retain]);
-}
-
#pragma mark - Public
- (void)runJavaScriptAlertPanelWithMessage:(NSString*)message
@@ -176,14 +142,14 @@ const char kAboutNullHostname[] = "about:null";
completionHandler:(void (^)(void))completionHandler {
NSString* title =
[DialogPresenter localizedTitleForJavaScriptAlertFromPage:requestURL];
- AlertCoordinator* alertCoordinator = [[[AlertCoordinator alloc]
- initWithBaseViewController:self.viewController
- title:title
- message:message] autorelease];
+ AlertCoordinator* alertCoordinator =
+ [[AlertCoordinator alloc] initWithBaseViewController:self.viewController
+ title:title
+ message:message];
// Handler.
- base::WeakNSObject<DialogPresenter> weakSelf(self);
- base::WeakNSObject<AlertCoordinator> weakCoordinator(alertCoordinator);
+ __weak DialogPresenter* weakSelf = self;
+ __weak AlertCoordinator* weakCoordinator = alertCoordinator;
ProceduralBlock OKHandler = ^{
if (completionHandler)
completionHandler();
@@ -212,10 +178,10 @@ const char kAboutNullHostname[] = "about:null";
(void (^)(BOOL isConfirmed))completionHandler {
NSString* title =
[DialogPresenter localizedTitleForJavaScriptAlertFromPage:requestURL];
- AlertCoordinator* alertCoordinator = [[[AlertCoordinator alloc]
- initWithBaseViewController:self.viewController
- title:title
- message:message] autorelease];
+ AlertCoordinator* alertCoordinator =
+ [[AlertCoordinator alloc] initWithBaseViewController:self.viewController
+ title:title
+ message:message];
// Actions.
ProceduralBlock confirmAction = ^{
@@ -249,13 +215,13 @@ const char kAboutNullHostname[] = "about:null";
(void (^)(NSString* input))completionHandler {
NSString* title =
[DialogPresenter localizedTitleForJavaScriptAlertFromPage:requestURL];
- InputAlertCoordinator* alertCoordinator = [[[InputAlertCoordinator alloc]
+ InputAlertCoordinator* alertCoordinator = [[InputAlertCoordinator alloc]
initWithBaseViewController:self.viewController
title:title
- message:message] autorelease];
+ message:message];
// Actions.
- base::WeakNSObject<InputAlertCoordinator> weakCoordinator(alertCoordinator);
+ __weak InputAlertCoordinator* weakCoordinator = alertCoordinator;
ProceduralBlock confirmAction = ^{
if (completionHandler) {
NSString* textInput = [weakCoordinator textFields].firstObject.text;
@@ -299,13 +265,13 @@ const char kAboutNullHostname[] = "about:null";
ios_internal::nsurlprotectionspace_util::MessageForHTTPAuth(
protectionSpace);
- InputAlertCoordinator* alertCoordinator = [[[InputAlertCoordinator alloc]
+ InputAlertCoordinator* alertCoordinator = [[InputAlertCoordinator alloc]
initWithBaseViewController:self.viewController
title:title
- message:message] autorelease];
+ message:message];
// Actions.
- base::WeakNSObject<InputAlertCoordinator> weakCoordinator(alertCoordinator);
+ __weak InputAlertCoordinator* weakCoordinator = alertCoordinator;
ProceduralBlock confirmAction = ^{
if (handler) {
NSString* username = [[weakCoordinator textFields] objectAtIndex:0].text;
@@ -398,7 +364,7 @@ const char kAboutNullHostname[] = "about:null";
DCHECK(!_dialogCoordinatorsForWebStates[webState]);
_queuedWebStates.push_back(webState);
_dialogCoordinatorsForWebStates[webState] =
- base::scoped_nsobject<AlertCoordinator>([coordinator retain]);
+ base::scoped_nsobject<AlertCoordinator>(coordinator);
if (self.active && !self.showingDialog && !self.delegate.presenting)
[self showNextDialog];
@@ -435,8 +401,8 @@ const char kAboutNullHostname[] = "about:null";
cancelAction:(ProceduralBlock)cancelAction
OKLabel:(NSString*)label {
// Handlers.
- base::WeakNSObject<DialogPresenter> weakSelf(self);
- base::WeakNSObject<AlertCoordinator> weakCoordinator(alertCoordinator);
+ __weak DialogPresenter* weakSelf = self;
+ __weak AlertCoordinator* weakCoordinator = alertCoordinator;
ProceduralBlock confirmHandler = ^{
if (confirmAction)
@@ -469,8 +435,6 @@ const char kAboutNullHostname[] = "about:null";
DCHECK(webState);
// Set up the start action.
- base::WeakNSObject<DialogPresenter> weakSelf(self);
- base::WeakNSObject<AlertCoordinator> weakCoordinator(alertCoordinator);
ProceduralBlock originalStartAction = alertCoordinator.startAction;
alertCoordinator.startAction = ^{
if (originalStartAction)
@@ -492,33 +456,32 @@ const char kAboutNullHostname[] = "about:null";
}
- (ProceduralBlock)blockingActionForCoordinator:(AlertCoordinator*)coordinator {
- base::WeakNSObject<DialogPresenter> weakSelf(self);
- base::WeakNSObject<AlertCoordinator> weakCoordinator(coordinator);
- base::WeakNSObject<UIViewController> weakBaseViewController(
- coordinator.baseViewController);
+ __weak DialogPresenter* weakSelf = self;
+ __weak AlertCoordinator* weakCoordinator = coordinator;
+ __weak UIViewController* weakBaseViewController =
+ coordinator.baseViewController;
ProceduralBlock cancelAction = coordinator.cancelAction;
- return [[^{
+ return [^{
// Create the confirmation coordinator. Use an action sheet on iPhone and
// an alert on iPhone.
NSString* confirmMessage =
l10n_util::GetNSString(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION);
AlertCoordinator* confirmationCoordinator =
- IsIPadIdiom()
- ? [[[AlertCoordinator alloc]
- initWithBaseViewController:weakBaseViewController
- title:nil
- message:confirmMessage] autorelease]
- : [[[ActionSheetCoordinator alloc]
- initWithBaseViewController:weakBaseViewController
- title:nil
- message:confirmMessage
- rect:CGRectZero
- view:nil] autorelease];
+ IsIPadIdiom() ? [[AlertCoordinator alloc]
+ initWithBaseViewController:weakBaseViewController
+ title:nil
+ message:confirmMessage]
+ : [[ActionSheetCoordinator alloc]
+ initWithBaseViewController:weakBaseViewController
+ title:nil
+ message:confirmMessage
+ rect:CGRectZero
+ view:nil];
// Set up button actions.
ProceduralBlock confirmHandler = ^{
if (cancelAction)
cancelAction();
- base::scoped_nsobject<DialogPresenter> strongSelf([weakSelf retain]);
+ DialogPresenter* strongSelf = weakSelf;
if (!strongSelf)
return;
DialogBlockingOptionSelected([strongSelf presentedDialogWebState]);
@@ -539,7 +502,7 @@ const char kAboutNullHostname[] = "about:null";
style:UIAlertActionStyleCancel];
[weakSelf setBlockingConfirmationCoordinator:confirmationCoordinator];
[[weakSelf blockingConfirmationCoordinator] start];
- } copy] autorelease];
+ } copy];
}
@end
« no previous file with comments | « ios/chrome/browser/ui/dialogs/BUILD.gn ('k') | ios/chrome/browser/ui/dialogs/java_script_dialog_presenter_impl.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698