Commit 51f2d432 authored by marq's avatar marq Committed by Commit Bot

[ObjC ARC] Converts ios/chrome/browser/passwords:passwords_internal to ARC.

Automatically generated ARCMigrate commit
Notable issues:None
BUG=624363
TEST=None

Review-Url: https://codereview.chromium.org/2932333002
Cr-Commit-Position: refs/heads/master@{#478659}
parent e5ee4f9d
......@@ -136,6 +136,7 @@ js_compile_unchecked("injected_js") {
}
source_set("passwords_internal") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"password_generation_prompt_view.h",
"password_generation_prompt_view.mm",
......
......@@ -6,8 +6,6 @@
#include <memory>
#include "base/ios/weak_nsobject.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/passwords/password_generation_prompt_delegate.h"
......@@ -22,6 +20,10 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Material Design Component constraints.
......@@ -84,10 +86,10 @@ const CGFloat kDescriptionLabelTopPadding = 10.0f;
@end
@implementation PasswordGenerationPromptView {
base::scoped_nsobject<NSString> _password;
base::WeakNSProtocol<id<PasswordGenerationPromptDelegate>> _delegate;
base::scoped_nsobject<NSURL> _URL;
base::scoped_nsobject<UILabel> _title;
NSString* _password;
__weak id<PasswordGenerationPromptDelegate> _delegate;
NSURL* _URL;
UILabel* _title;
}
- (instancetype)initWithPassword:(NSString*)password
......@@ -95,22 +97,21 @@ const CGFloat kDescriptionLabelTopPadding = 10.0f;
(id<PasswordGenerationPromptDelegate>)delegate {
self = [super initWithFrame:CGRectZero];
if (self) {
_URL.reset(
[[NSURL URLWithString:@"chromeinternal://showpasswords"] retain]);
_delegate.reset(delegate);
_password.reset([password copy]);
_URL = [NSURL URLWithString:@"chromeinternal://showpasswords"];
_delegate = delegate;
_password = [password copy];
}
return self;
}
- (void)configure {
UIView* headerView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
UIView* headerView = [[UIView alloc] initWithFrame:CGRectZero];
UIImageView* icon = [self keyIconView];
UILabel* title = [self titleLabel];
UILabel* password = [self passwordLabel:_password];
UITextView* description = [self description];
_title.reset([title retain]);
_title = title;
[headerView addSubview:icon];
[headerView addSubview:title];
......@@ -190,27 +191,27 @@ const CGFloat kDescriptionLabelTopPadding = 10.0f;
[attrsDictionary setObject:UIColorFromRGB(kTitleLabelFontColor)
forKey:NSForegroundColorAttributeName];
NSMutableAttributedString* string = [[[NSMutableAttributedString alloc]
NSMutableAttributedString* string = [[NSMutableAttributedString alloc]
initWithString:l10n_util::GetNSString(
IDS_IOS_GENERATED_PASSWORD_PROMPT_TITLE)
attributes:attrsDictionary] autorelease];
attributes:attrsDictionary];
base::scoped_nsobject<UILabel> titleLabel([[UILabel alloc] init]);
UILabel* titleLabel = [[UILabel alloc] init];
[titleLabel setAttributedText:string];
[titleLabel setNumberOfLines:0];
[titleLabel sizeToFit];
return titleLabel.autorelease();
return titleLabel = nil;
}
- (UILabel*)passwordLabel:(NSString*)password {
base::scoped_nsobject<UILabel> passwordLabel([[UILabel alloc] init]);
UILabel* passwordLabel = [[UILabel alloc] init];
[passwordLabel setText:password];
[passwordLabel setTextColor:UIColorFromRGB(kPasswordLabelFontColor)];
[passwordLabel setFont:[[MDCTypography fontLoader]
regularFontOfSize:kPasswordLabelFontSize]];
[passwordLabel setNumberOfLines:1];
[passwordLabel sizeToFit];
return passwordLabel.autorelease();
return passwordLabel = nil;
}
- (UITextView*)description {
......@@ -219,26 +220,25 @@ const CGFloat kDescriptionLabelTopPadding = 10.0f;
l10n_util::GetNSString(IDS_IOS_GENERATED_PASSWORD_PROMPT_DESCRIPTION),
&linkRange);
base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
[[NSMutableParagraphStyle alloc] init]);
NSMutableParagraphStyle* paragraphStyle =
[[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:kDescriptionLabelLineSpacing];
NSDictionary* attributeDictionary =
[NSDictionary dictionaryWithObjectsAndKeys:
UIColorFromRGB(kDescriptionLabelFontColor),
NSForegroundColorAttributeName, paragraphStyle.get(),
NSForegroundColorAttributeName, paragraphStyle,
NSParagraphStyleAttributeName,
[[MDCTypography fontLoader]
regularFontOfSize:kDescriptionLabelFontSize],
NSFontAttributeName, nil];
base::scoped_nsobject<NSMutableAttributedString> attributedString(
NSMutableAttributedString* attributedString =
[[NSMutableAttributedString alloc] initWithString:description
attributes:attributeDictionary]);
attributes:attributeDictionary];
UITextView* descriptionView =
[[[UITextView alloc] initWithFrame:CGRectZero textContainer:nil]
autorelease];
[[UITextView alloc] initWithFrame:CGRectZero textContainer:nil];
descriptionView.scrollEnabled = NO;
descriptionView.selectable = YES;
descriptionView.editable = NO;
......@@ -260,8 +260,7 @@ const CGFloat kDescriptionLabelTopPadding = 10.0f;
UIImage* keyIcon = ui::ResourceBundle::GetSharedInstance()
.GetImageNamed(IDR_IOS_INFOBAR_AUTOLOGIN)
.ToUIImage();
UIImageView* keyIconView =
[[[UIImageView alloc] initWithImage:keyIcon] autorelease];
UIImageView* keyIconView = [[UIImageView alloc] initWithImage:keyIcon];
[keyIconView setFrame:{CGPointZero, keyIcon.size}];
return keyIconView;
}
......@@ -272,7 +271,7 @@ const CGFloat kDescriptionLabelTopPadding = 10.0f;
shouldInteractWithURL:(NSURL*)URL
inRange:(NSRange)characterRange
interaction:(UITextItemInteraction)interaction {
DCHECK([URL isEqual:_URL.get()]);
DCHECK([URL isEqual:_URL]);
[_delegate showSavedPasswords:self];
return NO;
}
......@@ -282,8 +281,8 @@ const CGFloat kDescriptionLabelTopPadding = 10.0f;
#pragma mark - Classes emulating MDCDialog
@interface PasswordGenerationPromptDialog () {
base::WeakNSObject<UIViewController> _viewController;
base::WeakNSProtocol<id<PasswordGenerationPromptDelegate>> _weakDelegate;
__weak UIViewController* _viewController;
__weak id<PasswordGenerationPromptDelegate> _weakDelegate;
}
// Dismiss the dialog.
......@@ -301,8 +300,8 @@ const CGFloat kDescriptionLabelTopPadding = 10.0f;
viewController:(UIViewController*)viewController {
self = [super initWithFrame:CGRectZero];
if (self) {
_viewController.reset(viewController);
_weakDelegate.reset(delegate);
_viewController = viewController;
_weakDelegate = delegate;
}
return self;
}
......@@ -318,10 +317,10 @@ const CGFloat kDescriptionLabelTopPadding = 10.0f;
// Creates the view containing the buttons.
- (UIView*)createButtons {
UIView* view = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
NSString* cancelTitle = l10n_util::GetNSString(IDS_CANCEL);
MDCFlatButton* cancelButton = [[[MDCFlatButton alloc] init] autorelease];
MDCFlatButton* cancelButton = [[MDCFlatButton alloc] init];
[cancelButton setTitle:cancelTitle forState:UIControlStateNormal];
[cancelButton sizeToFit];
[cancelButton setCustomTitleColor:[UIColor blackColor]];
......@@ -331,7 +330,7 @@ const CGFloat kDescriptionLabelTopPadding = 10.0f;
NSString* acceptTitle =
l10n_util::GetNSString(IDS_IOS_GENERATED_PASSWORD_ACCEPT);
MDCFlatButton* OKButton = [[[MDCFlatButton alloc] init] autorelease];
MDCFlatButton* OKButton = [[MDCFlatButton alloc] init];
[OKButton setTitle:acceptTitle forState:UIControlStateNormal];
[OKButton sizeToFit];
[OKButton setCustomTitleColor:[UIColor blackColor]];
......@@ -363,9 +362,8 @@ const CGFloat kDescriptionLabelTopPadding = 10.0f;
// Creates the view containing the password text and the buttons.
- (void)configureGlobalViewWithPassword:(NSString*)password {
PasswordGenerationPromptView* passwordContentView =
[[[PasswordGenerationPromptView alloc] initWithPassword:password
delegate:_weakDelegate]
autorelease];
[[PasswordGenerationPromptView alloc] initWithPassword:password
delegate:_weakDelegate];
[passwordContentView configure];
......
......@@ -6,13 +6,15 @@
#import <UIKit/UIKit.h>
#include "base/ios/weak_nsobject.h"
#include "base/mac/scoped_nsobject.h"
#import "ios/chrome/browser/passwords/password_generation_prompt_view.h"
#import "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/third_party/material_components_ios/src/components/Dialogs/src/MaterialDialogs.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Material Design Component constraints.
const CGFloat kMDCPadding = 24;
......@@ -25,9 +27,10 @@ const CGFloat kPrefHeight = 500;
} // namespace
@interface PasswordGenerationPromptViewController () {
base::scoped_nsobject<NSString> _password;
base::WeakNSObject<UIViewController> _viewController;
base::WeakNSObject<PasswordGenerationPromptDialog> _contentView;
NSString* _password;
__weak UIViewController* _viewController;
__weak PasswordGenerationPromptDialog* _contentView;
MDCDialogTransitionController* _dialogTransitionController;
}
// Returns the maximum size of the dialog.
......@@ -47,12 +50,12 @@ const CGFloat kPrefHeight = 500;
viewController:(UIViewController*)viewController {
self = [super initWithNibName:nil bundle:nil];
if (self) {
_password.reset([password copy]);
_viewController.reset(viewController);
_contentView.reset(contentView);
_password = [password copy];
_viewController = viewController;
_contentView = contentView;
_dialogTransitionController = [[MDCDialogTransitionController alloc] init];
self.modalPresentationStyle = UIModalPresentationCustom;
self.transitioningDelegate =
[[[MDCDialogTransitionController alloc] init] autorelease];
self.transitioningDelegate = _dialogTransitionController;
}
return self;
}
......
......@@ -7,6 +7,10 @@
#import "ios/chrome/browser/passwords/password_generation_prompt_view.h"
#import "ios/chrome/browser/passwords/password_generation_prompt_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation PasswordsUiDelegateImpl
#pragma mark -
......@@ -31,15 +35,15 @@
}
PasswordGenerationPromptDialog* contentView =
[[[PasswordGenerationPromptDialog alloc]
[[PasswordGenerationPromptDialog alloc]
initWithDelegate:delegate
viewController:topViewController] autorelease];
viewController:topViewController];
UIViewController* viewController =
[[[PasswordGenerationPromptViewController alloc]
[[PasswordGenerationPromptViewController alloc]
initWithPassword:password
contentView:contentView
viewController:topViewController] autorelease];
viewController:topViewController];
[topViewController presentViewController:viewController
animated:YES
......
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