Commit 6941b849 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Remove -rootViewController from /passwords

The infobar controller needs a base view controller, from which to
present the accounts selector.

Bug: 785319
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: If1e4b70f58d0cb47b83524f064039cc1e2c2d607
Reviewed-on: https://chromium-review.googlesource.com/802457Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarVaclav Brozek <vabr@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521002}
parent 6c8f3b9c
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ios/chrome/browser/passwords/ios_chrome_password_manager_infobar_delegate.h" #include "ios/chrome/browser/passwords/ios_chrome_password_manager_infobar_delegate.h"
@protocol ApplicationCommands; @protocol ApplicationCommands;
@class UIViewController;
namespace password_manager { namespace password_manager {
class PasswordFormManager; class PasswordFormManager;
...@@ -25,12 +26,14 @@ class IOSChromeUpdatePasswordInfoBarDelegate ...@@ -25,12 +26,14 @@ class IOSChromeUpdatePasswordInfoBarDelegate
: public IOSChromePasswordManagerInfoBarDelegate { : public IOSChromePasswordManagerInfoBarDelegate {
public: public:
// Creates the infobar for |form_to_save| and adds it to |infobar_manager|. // Creates the infobar for |form_to_save| and adds it to |infobar_manager|.
// |is_smart_lock_enabled| controls the branding string. |dispatcher| is not // |is_smart_lock_enabled| controls the branding string. |baseViewController|
// retained. // is the base view controller from which to present UI, and is not retained.
// |dispatcher| is not retained.
static void Create( static void Create(
bool is_smart_lock_branding_enabled, bool is_smart_lock_branding_enabled,
infobars::InfoBarManager* infobar_manager, infobars::InfoBarManager* infobar_manager,
std::unique_ptr<password_manager::PasswordFormManager> form_to_save, std::unique_ptr<password_manager::PasswordFormManager> form_to_save,
UIViewController* baseViewController,
id<ApplicationCommands> dispatcher); id<ApplicationCommands> dispatcher);
~IOSChromeUpdatePasswordInfoBarDelegate() override; ~IOSChromeUpdatePasswordInfoBarDelegate() override;
......
...@@ -31,6 +31,7 @@ void IOSChromeUpdatePasswordInfoBarDelegate::Create( ...@@ -31,6 +31,7 @@ void IOSChromeUpdatePasswordInfoBarDelegate::Create(
bool is_smart_lock_branding_enabled, bool is_smart_lock_branding_enabled,
infobars::InfoBarManager* infobar_manager, infobars::InfoBarManager* infobar_manager,
std::unique_ptr<PasswordFormManager> form_manager, std::unique_ptr<PasswordFormManager> form_manager,
UIViewController* baseViewController,
id<ApplicationCommands> dispatcher) { id<ApplicationCommands> dispatcher) {
DCHECK(infobar_manager); DCHECK(infobar_manager);
auto delegate = base::WrapUnique(new IOSChromeUpdatePasswordInfoBarDelegate( auto delegate = base::WrapUnique(new IOSChromeUpdatePasswordInfoBarDelegate(
...@@ -39,6 +40,7 @@ void IOSChromeUpdatePasswordInfoBarDelegate::Create( ...@@ -39,6 +40,7 @@ void IOSChromeUpdatePasswordInfoBarDelegate::Create(
std::unique_ptr<InfoBarIOS> infobar(new InfoBarIOS(std::move(delegate))); std::unique_ptr<InfoBarIOS> infobar(new InfoBarIOS(std::move(delegate)));
UpdatePasswordInfoBarController* controller = UpdatePasswordInfoBarController* controller =
[[UpdatePasswordInfoBarController alloc] initWithDelegate:infobar.get()]; [[UpdatePasswordInfoBarController alloc] initWithDelegate:infobar.get()];
[controller setBaseViewController:baseViewController];
infobar->SetController(controller); infobar->SetController(controller);
infobar_manager->AddInfoBar(std::move(infobar)); infobar_manager->AddInfoBar(std::move(infobar));
} }
......
...@@ -54,6 +54,9 @@ class PasswordManagerDriver; ...@@ -54,6 +54,9 @@ class PasswordManagerDriver;
// The PasswordFormFiller owned by this PasswordController. // The PasswordFormFiller owned by this PasswordController.
@property(nonatomic, readonly) id<PasswordFormFiller> passwordFormFiller; @property(nonatomic, readonly) id<PasswordFormFiller> passwordFormFiller;
// The base view controller from which to present UI.
@property(nonatomic, readwrite, weak) UIViewController* baseViewController;
// The dispatcher used for the PasswordController. This property can return nil // The dispatcher used for the PasswordController. This property can return nil
// even after being set to a non-nil object. // even after being set to a non-nil object.
@property(nonatomic, weak) id<ApplicationCommands> dispatcher; @property(nonatomic, weak) id<ApplicationCommands> dispatcher;
......
...@@ -296,6 +296,8 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { ...@@ -296,6 +296,8 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) {
@synthesize isWebStateDestroyed = _isWebStateDestroyed; @synthesize isWebStateDestroyed = _isWebStateDestroyed;
@synthesize baseViewController = _baseViewController;
@synthesize dispatcher = _dispatcher; @synthesize dispatcher = _dispatcher;
@synthesize delegate = _delegate; @synthesize delegate = _delegate;
...@@ -1011,7 +1013,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { ...@@ -1011,7 +1013,7 @@ bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) {
case PasswordInfoBarType::UPDATE: case PasswordInfoBarType::UPDATE:
IOSChromeUpdatePasswordInfoBarDelegate::Create( IOSChromeUpdatePasswordInfoBarDelegate::Create(
isSmartLockBrandingEnabled, infoBarManager, std::move(form), isSmartLockBrandingEnabled, infoBarManager, std::move(form),
self.dispatcher); self.baseViewController, self.dispatcher);
break; break;
} }
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
@protocol PasswordControllerDelegate; @protocol PasswordControllerDelegate;
@protocol PasswordFormFiller; @protocol PasswordFormFiller;
@protocol PasswordsUiDelegate; @protocol PasswordsUiDelegate;
@class UIViewController;
// Class binding a PasswordController to a WebState. // Class binding a PasswordController to a WebState.
class PasswordTabHelper : public web::WebStateObserver, class PasswordTabHelper : public web::WebStateObserver,
...@@ -25,6 +26,9 @@ class PasswordTabHelper : public web::WebStateObserver, ...@@ -25,6 +26,9 @@ class PasswordTabHelper : public web::WebStateObserver,
// Creates a PasswordTabHelper and attaches it to the given |web_state|. // Creates a PasswordTabHelper and attaches it to the given |web_state|.
static void CreateForWebState(web::WebState* web_state); static void CreateForWebState(web::WebState* web_state);
// Sets the BaseViewController from which to present UI.
void SetBaseViewController(UIViewController* baseViewController);
// Sets the PasswordController dispatcher. // Sets the PasswordController dispatcher.
void SetDispatcher(id<ApplicationCommands> dispatcher); void SetDispatcher(id<ApplicationCommands> dispatcher);
......
...@@ -25,6 +25,11 @@ void PasswordTabHelper::CreateForWebState(web::WebState* web_state) { ...@@ -25,6 +25,11 @@ void PasswordTabHelper::CreateForWebState(web::WebState* web_state) {
} }
} }
void PasswordTabHelper::SetBaseViewController(
UIViewController* baseViewController) {
controller_.baseViewController = baseViewController;
}
void PasswordTabHelper::SetDispatcher(id<ApplicationCommands> dispatcher) { void PasswordTabHelper::SetDispatcher(id<ApplicationCommands> dispatcher) {
controller_.dispatcher = dispatcher; controller_.dispatcher = dispatcher;
} }
......
...@@ -13,6 +13,9 @@ class IOSChromeUpdatePasswordInfoBarDelegate; ...@@ -13,6 +13,9 @@ class IOSChromeUpdatePasswordInfoBarDelegate;
// the user whether they want to update their password. // the user whether they want to update their password.
@interface UpdatePasswordInfoBarController : ConfirmInfoBarController @interface UpdatePasswordInfoBarController : ConfirmInfoBarController
// The base view controller from which to present UI.
@property(nonatomic, readwrite, weak) UIViewController* baseViewController;
- (InfoBarView*)viewForDelegate: - (InfoBarView*)viewForDelegate:
(IOSChromeUpdatePasswordInfoBarDelegate*)delegate (IOSChromeUpdatePasswordInfoBarDelegate*)delegate
frame:(CGRect)frame; frame:(CGRect)frame;
......
...@@ -28,7 +28,7 @@ NSUInteger kAccountTag = 10; ...@@ -28,7 +28,7 @@ NSUInteger kAccountTag = 10;
@end @end
@implementation UpdatePasswordInfoBarController @implementation UpdatePasswordInfoBarController
@synthesize baseViewController = _baseViewController;
@synthesize selectorCoordinator = _selectorCoordinator; @synthesize selectorCoordinator = _selectorCoordinator;
- (InfoBarView*)viewForDelegate: - (InfoBarView*)viewForDelegate:
...@@ -65,10 +65,9 @@ NSUInteger kAccountTag = 10; ...@@ -65,10 +65,9 @@ NSUInteger kAccountTag = 10;
if (tag != kAccountTag) if (tag != kAccountTag)
return; return;
UIViewController* baseViewController = DCHECK(self.baseViewController);
[[UIApplication sharedApplication] keyWindow].rootViewController;
self.selectorCoordinator = [[SelectorCoordinator alloc] self.selectorCoordinator = [[SelectorCoordinator alloc]
initWithBaseViewController:baseViewController]; initWithBaseViewController:self.baseViewController];
self.selectorCoordinator.delegate = self; self.selectorCoordinator.delegate = self;
self.selectorCoordinator.options = self.selectorCoordinator.options =
[NSOrderedSet orderedSetWithArray:_delegate->GetAccounts()]; [NSOrderedSet orderedSetWithArray:_delegate->GetAccounts()];
......
...@@ -2449,6 +2449,7 @@ bubblePresenterForFeature:(const base::Feature&)feature ...@@ -2449,6 +2449,7 @@ bubblePresenterForFeature:(const base::Feature&)feature
// TODO(crbug.com/777557): do not pass the dispatcher to PasswordTabHelper. // TODO(crbug.com/777557): do not pass the dispatcher to PasswordTabHelper.
if (PasswordTabHelper* passwordTabHelper = if (PasswordTabHelper* passwordTabHelper =
PasswordTabHelper::FromWebState(tab.webState)) { PasswordTabHelper::FromWebState(tab.webState)) {
passwordTabHelper->SetBaseViewController(self);
passwordTabHelper->SetDispatcher(self.dispatcher); passwordTabHelper->SetDispatcher(self.dispatcher);
passwordTabHelper->SetPasswordControllerDelegate(self); passwordTabHelper->SetPasswordControllerDelegate(self);
} }
......
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