| Index: ios/chrome/browser/passwords/password_controller.mm
|
| diff --git a/ios/chrome/browser/passwords/password_controller.mm b/ios/chrome/browser/passwords/password_controller.mm
|
| index 2545cb32daa4731de8d79738b855fadfcc8b7946..2ec3ef82fcb57caa3b6eed0025bac854a90387ac 100644
|
| --- a/ios/chrome/browser/passwords/password_controller.mm
|
| +++ b/ios/chrome/browser/passwords/password_controller.mm
|
| @@ -12,11 +12,9 @@
|
| #include <utility>
|
| #include <vector>
|
|
|
| -#import "base/ios/weak_nsobject.h"
|
| #include "base/json/json_reader.h"
|
| #include "base/json/json_writer.h"
|
| #include "base/mac/foundation_util.h"
|
| -#include "base/mac/scoped_nsobject.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/strings/string16.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| @@ -46,6 +44,10 @@
|
| #import "ios/web/public/web_state/web_state.h"
|
| #include "url/gurl.h"
|
|
|
| +#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| +#error "This file requires ARC support."
|
| +#endif
|
| +
|
| using password_manager::PasswordFormManager;
|
| using password_manager::PasswordGenerationManager;
|
| using password_manager::PasswordManager;
|
| @@ -62,6 +64,9 @@ enum class PasswordInfoBarType { SAVE, UPDATE };
|
| // This is set to YES as soon as the associated WebState is destroyed.
|
| @property(readonly) BOOL isWebStateDestroyed;
|
|
|
| +// Accessor for property inside block.
|
| +@property(readonly) PasswordManager* passwordManager;
|
| +
|
| @end
|
|
|
| @interface PasswordController ()<FormSuggestionProvider>
|
| @@ -253,7 +258,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) {
|
| std::unique_ptr<PasswordGenerationManager> passwordGenerationManager_;
|
| std::unique_ptr<PasswordManagerClient> passwordManagerClient_;
|
| std::unique_ptr<PasswordManagerDriver> passwordManagerDriver_;
|
| - base::scoped_nsobject<PasswordGenerationAgent> passwordGenerationAgent_;
|
| + PasswordGenerationAgent* passwordGenerationAgent_;
|
|
|
| JsPasswordManager* passwordJsManager_; // weak
|
| web::WebState* webState_; // weak
|
| @@ -293,11 +298,11 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) {
|
| !passwordManagerClient_->IsIncognito()) {
|
| passwordGenerationManager_.reset(new PasswordGenerationManager(
|
| passwordManagerClient_.get(), passwordManagerDriver_.get()));
|
| - passwordGenerationAgent_.reset([[PasswordGenerationAgent alloc]
|
| + passwordGenerationAgent_ = [[PasswordGenerationAgent alloc]
|
| initWithWebState:webState
|
| passwordManager:passwordManager_.get()
|
| passwordManagerDriver:passwordManagerDriver_.get()
|
| - passwordsUiDelegate:UIDelegate]);
|
| + passwordsUiDelegate:UIDelegate];
|
| }
|
|
|
| passwordJsManager_ = base::mac::ObjCCastStrict<JsPasswordManager>(
|
| @@ -316,7 +321,6 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) {
|
|
|
| - (void)dealloc {
|
| [self detach];
|
| - [super dealloc];
|
| }
|
|
|
| - (ios::ChromeBrowserState*)browserState {
|
| @@ -334,7 +338,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) {
|
| - (void)detach {
|
| webState_ = nullptr;
|
| webStateObserverBridge_.reset();
|
| - passwordGenerationAgent_.reset();
|
| + passwordGenerationAgent_ = nil;
|
| passwordGenerationManager_.reset();
|
| passwordManagerDriver_.reset();
|
| passwordManager_.reset();
|
| @@ -391,7 +395,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) {
|
|
|
| // Read all password forms from the page and send them to the password
|
| // manager.
|
| - base::WeakNSObject<PasswordController> weakSelf(self);
|
| + __weak PasswordController* weakSelf = self;
|
| [self findPasswordFormsWithCompletionHandler:^(
|
| const std::vector<autofill::PasswordForm>& forms) {
|
| [weakSelf didFinishPasswordFormExtraction:forms];
|
| @@ -401,15 +405,16 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) {
|
| - (void)webState:(web::WebState*)webState
|
| didSubmitDocumentWithFormNamed:(const std::string&)formName
|
| userInitiated:(BOOL)userInitiated {
|
| - base::WeakNSObject<PasswordController> weakSelf(self);
|
| + __weak PasswordController* weakSelf = self;
|
| // This code is racing against the new page loading and will not get the
|
| // password form data if the page has changed. In most cases this code wins
|
| // the race.
|
| // TODO(crbug.com/418827): Fix this by passing in more data from the JS side.
|
| id completionHandler = ^(BOOL found, const autofill::PasswordForm& form) {
|
| - if (weakSelf && ![weakSelf isWebStateDestroyed]) {
|
| - weakSelf.get()->passwordManager_->OnPasswordFormSubmitted(
|
| - weakSelf.get()->passwordManagerDriver_.get(), form);
|
| + PasswordController* strongSelf = weakSelf;
|
| + if (strongSelf && ![strongSelf isWebStateDestroyed]) {
|
| + strongSelf.passwordManager->OnPasswordFormSubmitted(
|
| + strongSelf.passwordManagerDriver, form);
|
| }
|
| };
|
| [self extractSubmittedPasswordForm:formName
|
| @@ -434,7 +439,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) {
|
| return;
|
| }
|
|
|
| - base::WeakNSObject<PasswordController> weakSelf(self);
|
| + __weak PasswordController* weakSelf = self;
|
| [passwordJsManager_ findPasswordFormsWithCompletionHandler:^(
|
| NSString* jsonString) {
|
| std::vector<autofill::PasswordForm> forms;
|
| @@ -496,7 +501,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) {
|
| return;
|
| }
|
|
|
| - base::WeakNSObject<PasswordController> weakSelf(self);
|
| + __weak PasswordController* weakSelf = self;
|
| id extractSubmittedFormCompletionHandler = ^(NSString* jsonString) {
|
| autofill::PasswordForm form;
|
| BOOL found = [weakSelf getPasswordForm:&form
|
| @@ -827,7 +832,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) {
|
| }
|
|
|
| - (PasswordGenerationAgent*)passwordGenerationAgent {
|
| - return passwordGenerationAgent_.get();
|
| + return passwordGenerationAgent_;
|
| }
|
|
|
| - (PasswordGenerationManager*)passwordGenerationManager {
|
|
|