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

Side by Side Diff: ios/chrome/browser/passwords/password_controller.mm

Issue 1967473002: PasswordController should give up on WebState destruction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 10 #include <utility>
(...skipping 30 matching lines...) Expand all
41 #import "ios/web/public/web_state/web_state.h" 41 #import "ios/web/public/web_state/web_state.h"
42 #import "ios/web/public/web_state/web_state_observer_bridge.h" 42 #import "ios/web/public/web_state/web_state_observer_bridge.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 ()<CRWWebStateObserver, FormSuggestionProvider> 58 @interface PasswordController ()<CRWWebStateObserver, 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
235 242
236 JsPasswordManager* passwordJsManager_; // weak 243 JsPasswordManager* passwordJsManager_; // weak
237 244
238 // The pending form data. 245 // The pending form data.
239 scoped_ptr<autofill::PasswordFormFillData> formData_; 246 scoped_ptr<autofill::PasswordFormFillData> formData_;
240 247
241 // Bridge to observe WebState from Objective-C. 248 // Bridge to observe WebState from Objective-C.
242 scoped_ptr<web::WebStateObserverBridge> webStateObserverBridge_; 249 scoped_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 DCHECK(webState); 256 DCHECK(webState);
248 self = [super init]; 257 self = [super init];
249 if (self) { 258 if (self) {
250 webStateObserverBridge_.reset( 259 webStateObserverBridge_.reset(
251 new web::WebStateObserverBridge(webState, self)); 260 new web::WebStateObserverBridge(webState, self));
252 passwordManagerClient_.reset(new IOSChromePasswordManagerClient(self)); 261 passwordManagerClient_.reset(new IOSChromePasswordManagerClient(self));
253 passwordManager_.reset(new PasswordManager(passwordManagerClient_.get())); 262 passwordManager_.reset(new PasswordManager(passwordManagerClient_.get()));
254 passwordManagerDriver_.reset(new IOSChromePasswordManagerDriver(self)); 263 passwordManagerDriver_.reset(new IOSChromePasswordManagerDriver(self));
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 366
358 - (void)webState:(web::WebState*)webState 367 - (void)webState:(web::WebState*)webState
359 didSubmitDocumentWithFormNamed:(const std::string&)formName 368 didSubmitDocumentWithFormNamed:(const std::string&)formName
360 userInitiated:(BOOL)userInitiated { 369 userInitiated:(BOOL)userInitiated {
361 base::WeakNSObject<PasswordController> weakSelf(self); 370 base::WeakNSObject<PasswordController> weakSelf(self);
362 // This code is racing against the new page loading and will not get the 371 // This code is racing against the new page loading and will not get the
363 // password form data if the page has changed. In most cases this code wins 372 // password form data if the page has changed. In most cases this code wins
364 // the race. 373 // the race.
365 // TODO(crbug.com/418827): Fix this by passing in more data from the JS side. 374 // TODO(crbug.com/418827): Fix this by passing in more data from the JS side.
366 id completionHandler = ^(BOOL found, const autofill::PasswordForm& form) { 375 id completionHandler = ^(BOOL found, const autofill::PasswordForm& form) {
367 if (weakSelf) { 376 if (weakSelf && ![weakSelf isWebStateDestroyed]) {
368 weakSelf.get()->passwordManager_->OnPasswordFormSubmitted( 377 weakSelf.get()->passwordManager_->OnPasswordFormSubmitted(
369 weakSelf.get()->passwordManagerDriver_.get(), form); 378 weakSelf.get()->passwordManagerDriver_.get(), form);
370 } 379 }
371 }; 380 };
372 [self extractSubmittedPasswordForm:formName 381 [self extractSubmittedPasswordForm:formName
373 completionHandler:completionHandler]; 382 completionHandler:completionHandler];
374 } 383 }
375 384
376 - (void)webStateDestroyed:(web::WebState*)webState { 385 - (void)webStateDestroyed:(web::WebState*)webState {
386 isWebStateDestroyed_ = YES;
377 [self detach]; 387 [self detach];
378 } 388 }
379 389
380 - (void)findPasswordFormsWithCompletionHandler: 390 - (void)findPasswordFormsWithCompletionHandler:
381 (void (^)(const std::vector<autofill::PasswordForm>&))completionHandler { 391 (void (^)(const std::vector<autofill::PasswordForm>&))completionHandler {
382 DCHECK(completionHandler); 392 DCHECK(completionHandler);
383 393
384 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state()) 394 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state())
385 return; 395 return;
386 396
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 800
791 - (PasswordManager*)passwordManager { 801 - (PasswordManager*)passwordManager {
792 return passwordManager_.get(); 802 return passwordManager_.get();
793 } 803 }
794 804
795 - (JsPasswordManager*)passwordJsManager { 805 - (JsPasswordManager*)passwordJsManager {
796 return passwordJsManager_; 806 return passwordJsManager_;
797 } 807 }
798 808
799 @end 809 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698