| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/passwords/password_controller.h" | 5 #import "ios/chrome/browser/passwords/password_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 41 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
| 42 #import "ios/web/public/web_state/web_state.h" | 42 #import "ios/web/public/web_state/web_state.h" |
| 43 #include "url/gurl.h" | 43 #include "url/gurl.h" |
| 44 | 44 |
| 45 using password_manager::PasswordFormManager; | 45 using password_manager::PasswordFormManager; |
| 46 using password_manager::PasswordGenerationManager; | 46 using password_manager::PasswordGenerationManager; |
| 47 using password_manager::PasswordManager; | 47 using password_manager::PasswordManager; |
| 48 using password_manager::PasswordManagerClient; | 48 using password_manager::PasswordManagerClient; |
| 49 using password_manager::PasswordManagerDriver; | 49 using password_manager::PasswordManagerDriver; |
| 50 | 50 |
| 51 @interface PasswordController () |
| 52 |
| 53 // This is set to YES as soon as the associated WebState is destroyed. |
| 54 @property(readonly) BOOL isWebStateDestroyed; |
| 55 |
| 56 @end |
| 57 |
| 51 @interface PasswordController ()<FormSuggestionProvider> | 58 @interface PasswordController ()<FormSuggestionProvider> |
| 52 | 59 |
| 53 // Parses the |jsonString| which contatins the password forms found on a web | 60 // Parses the |jsonString| which contatins the password forms found on a web |
| 54 // page to populate the |forms| vector. | 61 // page to populate the |forms| vector. |
| 55 - (void)getPasswordForms:(std::vector<autofill::PasswordForm>*)forms | 62 - (void)getPasswordForms:(std::vector<autofill::PasswordForm>*)forms |
| 56 fromFormsJSON:(NSString*)jsonString | 63 fromFormsJSON:(NSString*)jsonString |
| 57 pageURL:(const GURL&)pageURL; | 64 pageURL:(const GURL&)pageURL; |
| 58 | 65 |
| 59 // Processes the JSON string returned as a result of extracting the submitted | 66 // Processes the JSON string returned as a result of extracting the submitted |
| 60 // form data and populates |form|. Returns YES on success. NO otherwise. | 67 // form data and populates |form|. Returns YES on success. NO otherwise. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 242 |
| 236 JsPasswordManager* passwordJsManager_; // weak | 243 JsPasswordManager* passwordJsManager_; // weak |
| 237 | 244 |
| 238 // The pending form data. | 245 // The pending form data. |
| 239 std::unique_ptr<autofill::PasswordFormFillData> formData_; | 246 std::unique_ptr<autofill::PasswordFormFillData> formData_; |
| 240 | 247 |
| 241 // Bridge to observe WebState from Objective-C. | 248 // Bridge to observe WebState from Objective-C. |
| 242 std::unique_ptr<web::WebStateObserverBridge> webStateObserverBridge_; | 249 std::unique_ptr<web::WebStateObserverBridge> webStateObserverBridge_; |
| 243 } | 250 } |
| 244 | 251 |
| 252 @synthesize isWebStateDestroyed = isWebStateDestroyed_; |
| 253 |
| 245 - (instancetype)initWithWebState:(web::WebState*)webState | 254 - (instancetype)initWithWebState:(web::WebState*)webState |
| 246 passwordsUiDelegate:(id<PasswordsUiDelegate>)UIDelegate { | 255 passwordsUiDelegate:(id<PasswordsUiDelegate>)UIDelegate { |
| 247 self = [self initWithWebState:webState | 256 self = [self initWithWebState:webState |
| 248 passwordsUiDelegate:UIDelegate | 257 passwordsUiDelegate:UIDelegate |
| 249 client:nullptr]; | 258 client:nullptr]; |
| 250 return self; | 259 return self; |
| 251 } | 260 } |
| 252 | 261 |
| 253 - (instancetype)initWithWebState:(web::WebState*)webState | 262 - (instancetype)initWithWebState:(web::WebState*)webState |
| 254 passwordsUiDelegate:(id<PasswordsUiDelegate>)UIDelegate | 263 passwordsUiDelegate:(id<PasswordsUiDelegate>)UIDelegate |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 385 |
| 377 - (void)webState:(web::WebState*)webState | 386 - (void)webState:(web::WebState*)webState |
| 378 didSubmitDocumentWithFormNamed:(const std::string&)formName | 387 didSubmitDocumentWithFormNamed:(const std::string&)formName |
| 379 userInitiated:(BOOL)userInitiated { | 388 userInitiated:(BOOL)userInitiated { |
| 380 base::WeakNSObject<PasswordController> weakSelf(self); | 389 base::WeakNSObject<PasswordController> weakSelf(self); |
| 381 // This code is racing against the new page loading and will not get the | 390 // This code is racing against the new page loading and will not get the |
| 382 // password form data if the page has changed. In most cases this code wins | 391 // password form data if the page has changed. In most cases this code wins |
| 383 // the race. | 392 // the race. |
| 384 // TODO(crbug.com/418827): Fix this by passing in more data from the JS side. | 393 // TODO(crbug.com/418827): Fix this by passing in more data from the JS side. |
| 385 id completionHandler = ^(BOOL found, const autofill::PasswordForm& form) { | 394 id completionHandler = ^(BOOL found, const autofill::PasswordForm& form) { |
| 386 if (weakSelf) { | 395 if (weakSelf && ![weakSelf isWebStateDestroyed]) { |
| 387 weakSelf.get()->passwordManager_->OnPasswordFormSubmitted( | 396 weakSelf.get()->passwordManager_->OnPasswordFormSubmitted( |
| 388 weakSelf.get()->passwordManagerDriver_.get(), form); | 397 weakSelf.get()->passwordManagerDriver_.get(), form); |
| 389 } | 398 } |
| 390 }; | 399 }; |
| 391 [self extractSubmittedPasswordForm:formName | 400 [self extractSubmittedPasswordForm:formName |
| 392 completionHandler:completionHandler]; | 401 completionHandler:completionHandler]; |
| 393 } | 402 } |
| 394 | 403 |
| 395 - (void)webStateDestroyed:(web::WebState*)webState { | 404 - (void)webStateDestroyed:(web::WebState*)webState { |
| 405 isWebStateDestroyed_ = YES; |
| 396 [self detach]; | 406 [self detach]; |
| 397 } | 407 } |
| 398 | 408 |
| 399 - (void)findPasswordFormsWithCompletionHandler: | 409 - (void)findPasswordFormsWithCompletionHandler: |
| 400 (void (^)(const std::vector<autofill::PasswordForm>&))completionHandler { | 410 (void (^)(const std::vector<autofill::PasswordForm>&))completionHandler { |
| 401 DCHECK(completionHandler); | 411 DCHECK(completionHandler); |
| 402 | 412 |
| 403 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state()) | 413 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state()) |
| 404 return; | 414 return; |
| 405 | 415 |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 | 821 |
| 812 - (PasswordManager*)passwordManager { | 822 - (PasswordManager*)passwordManager { |
| 813 return passwordManager_.get(); | 823 return passwordManager_.get(); |
| 814 } | 824 } |
| 815 | 825 |
| 816 - (JsPasswordManager*)passwordJsManager { | 826 - (JsPasswordManager*)passwordJsManager { |
| 817 return passwordJsManager_; | 827 return passwordJsManager_; |
| 818 } | 828 } |
| 819 | 829 |
| 820 @end | 830 @end |
| OLD | NEW |