Commit 01c8891f authored by edchin's avatar edchin

[ios] Remove use of rootViewController from autofill

[UIApplication sharedApplication].keyWindow.rootViewController was
used to present UI. Now, the appropriate view controller is
plumbed into autofill to present UI.

Bug: 791793, 692525
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: If82b5a5ee37d2ea9778d0332dd6686949d6bbfab
Reviewed-on: https://chromium-review.googlesource.com/882400Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531991}
parent ba12dcb8
...@@ -63,6 +63,9 @@ passwordGenerationManager: ...@@ -63,6 +63,9 @@ passwordGenerationManager:
- (void)sendAutofillTypePredictionsToRenderer: - (void)sendAutofillTypePredictionsToRenderer:
(const std::vector<autofill::FormStructure*>&)forms; (const std::vector<autofill::FormStructure*>&)forms;
// Sets a weak reference to the view controller used to present UI.
- (void)setBaseViewController:(UIViewController*)baseViewController;
@end @end
#endif // IOS_CHROME_BROWSER_AUTOFILL_AUTOFILL_CONTROLLER_H_ #endif // IOS_CHROME_BROWSER_AUTOFILL_AUTOFILL_CONTROLLER_H_
...@@ -43,7 +43,7 @@ using autofill::AutofillPopupDelegate; ...@@ -43,7 +43,7 @@ using autofill::AutofillPopupDelegate;
@interface AutofillController ()<AutofillClientIOSBridge, @interface AutofillController ()<AutofillClientIOSBridge,
AutofillDriverIOSBridge> { AutofillDriverIOSBridge> {
AutofillAgent* _autofillAgent; AutofillAgent* _autofillAgent;
std::unique_ptr<autofill::AutofillClient> _autofillClient; std::unique_ptr<autofill::ChromeAutofillClientIOS> _autofillClient;
autofill::AutofillManager* _autofillManager; // weak autofill::AutofillManager* _autofillManager; // weak
} }
...@@ -125,6 +125,10 @@ using autofill::AutofillPopupDelegate; ...@@ -125,6 +125,10 @@ using autofill::AutofillPopupDelegate;
_autofillAgent = nil; _autofillAgent = nil;
} }
- (void)setBaseViewController:(UIViewController*)baseViewController {
_autofillClient->SetBaseViewController(baseViewController);
}
#pragma mark - AutofillClientIOSBridge #pragma mark - AutofillClientIOSBridge
- (void) - (void)
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
@class AutofillController; @class AutofillController;
@protocol FormSuggestionProvider; @protocol FormSuggestionProvider;
@class UIViewController;
namespace password_manager { namespace password_manager {
class PasswordGenerationManager; class PasswordGenerationManager;
...@@ -27,6 +28,9 @@ class AutofillTabHelper : public web::WebStateObserver, ...@@ -27,6 +28,9 @@ class AutofillTabHelper : public web::WebStateObserver,
web::WebState* web_state, web::WebState* web_state,
password_manager::PasswordGenerationManager* password_generation_manager); password_manager::PasswordGenerationManager* password_generation_manager);
// Sets a weak reference to the view controller used to present UI.
void SetBaseViewController(UIViewController* base_view_controller);
// Returns an object that can provide suggestions from the PasswordController. // Returns an object that can provide suggestions from the PasswordController.
// May return nil. // May return nil.
id<FormSuggestionProvider> GetSuggestionProvider(); id<FormSuggestionProvider> GetSuggestionProvider();
......
...@@ -29,6 +29,11 @@ void AutofillTabHelper::CreateForWebState( ...@@ -29,6 +29,11 @@ void AutofillTabHelper::CreateForWebState(
} }
} }
void AutofillTabHelper::SetBaseViewController(
UIViewController* base_view_controller) {
[controller_ setBaseViewController:base_view_controller];
}
id<FormSuggestionProvider> AutofillTabHelper::GetSuggestionProvider() { id<FormSuggestionProvider> AutofillTabHelper::GetSuggestionProvider() {
return controller_.suggestionProvider; return controller_.suggestionProvider;
} }
......
...@@ -295,6 +295,7 @@ source_set("ui_internal") { ...@@ -295,6 +295,7 @@ source_set("ui_internal") {
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/app_launcher", "//ios/chrome/browser/app_launcher",
"//ios/chrome/browser/autofill:autofill_internal",
"//ios/chrome/browser/bookmarks", "//ios/chrome/browser/bookmarks",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/download", "//ios/chrome/browser/download",
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
extern NSString* const kCardUnmaskPromptCollectionViewAccessibilityID; extern NSString* const kCardUnmaskPromptCollectionViewAccessibilityID;
@class CardUnmaskPromptViewController; @class CardUnmaskPromptViewController;
@class UIViewController;
namespace autofill { namespace autofill {
...@@ -21,7 +22,10 @@ class CardUnmaskPromptController; ...@@ -21,7 +22,10 @@ class CardUnmaskPromptController;
// iOS implementation of the unmask prompt UI. // iOS implementation of the unmask prompt UI.
class CardUnmaskPromptViewBridge : public CardUnmaskPromptView { class CardUnmaskPromptViewBridge : public CardUnmaskPromptView {
public: public:
explicit CardUnmaskPromptViewBridge(CardUnmaskPromptController* controller); // |base_view_controller| is a weak reference to the view controller used to
// present UI.
CardUnmaskPromptViewBridge(CardUnmaskPromptController* controller,
UIViewController* base_view_controller);
~CardUnmaskPromptViewBridge() override; ~CardUnmaskPromptViewBridge() override;
// CardUnmaskPromptView: // CardUnmaskPromptView:
...@@ -47,6 +51,9 @@ class CardUnmaskPromptViewBridge : public CardUnmaskPromptView { ...@@ -47,6 +51,9 @@ class CardUnmaskPromptViewBridge : public CardUnmaskPromptView {
// The controller |this| queries for logic and state. // The controller |this| queries for logic and state.
CardUnmaskPromptController* controller_; // weak CardUnmaskPromptController* controller_; // weak
// Weak reference to the view controller used to present UI.
__weak UIViewController* base_view_controller_;
base::WeakPtrFactory<CardUnmaskPromptViewBridge> weak_ptr_factory_; base::WeakPtrFactory<CardUnmaskPromptViewBridge> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBridge); DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBridge);
......
...@@ -53,8 +53,11 @@ namespace autofill { ...@@ -53,8 +53,11 @@ namespace autofill {
#pragma mark CardUnmaskPromptViewBridge #pragma mark CardUnmaskPromptViewBridge
CardUnmaskPromptViewBridge::CardUnmaskPromptViewBridge( CardUnmaskPromptViewBridge::CardUnmaskPromptViewBridge(
CardUnmaskPromptController* controller) CardUnmaskPromptController* controller,
: controller_(controller), weak_ptr_factory_(this) { UIViewController* base_view_controller)
: controller_(controller),
base_view_controller_(base_view_controller),
weak_ptr_factory_(this) {
DCHECK(controller_); DCHECK(controller_);
} }
...@@ -69,14 +72,9 @@ void CardUnmaskPromptViewBridge::Show() { ...@@ -69,14 +72,9 @@ void CardUnmaskPromptViewBridge::Show() {
[view_controller_ setModalPresentationStyle:UIModalPresentationFormSheet]; [view_controller_ setModalPresentationStyle:UIModalPresentationFormSheet];
[view_controller_ [view_controller_
setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
// Present the view controller. [base_view_controller_ presentViewController:view_controller_
// TODO(crbug.com/692525): Find an alternative to presenting the view animated:YES
// controller on the root view controller. completion:nil];
UIViewController* rootController =
[UIApplication sharedApplication].keyWindow.rootViewController;
[rootController presentViewController:view_controller_
animated:YES
completion:nil];
} }
void CardUnmaskPromptViewBridge::ControllerGone() { void CardUnmaskPromptViewBridge::ControllerGone() {
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
@class UIViewController;
namespace autofill { namespace autofill {
// Chrome iOS implementation of AutofillClient. // Chrome iOS implementation of AutofillClient.
...@@ -39,6 +41,9 @@ class ChromeAutofillClientIOS : public AutofillClient { ...@@ -39,6 +41,9 @@ class ChromeAutofillClientIOS : public AutofillClient {
std::unique_ptr<IdentityProvider> identity_provider); std::unique_ptr<IdentityProvider> identity_provider);
~ChromeAutofillClientIOS() override; ~ChromeAutofillClientIOS() override;
// Sets a weak reference to the view controller used to present UI.
void SetBaseViewController(UIViewController* base_view_controller);
// AutofillClientIOS implementation. // AutofillClientIOS implementation.
PersonalDataManager* GetPersonalDataManager() override; PersonalDataManager* GetPersonalDataManager() override;
PrefService* GetPrefs() override; PrefService* GetPrefs() override;
...@@ -98,6 +103,9 @@ class ChromeAutofillClientIOS : public AutofillClient { ...@@ -98,6 +103,9 @@ class ChromeAutofillClientIOS : public AutofillClient {
password_manager::PasswordGenerationManager* password_generation_manager_; password_manager::PasswordGenerationManager* password_generation_manager_;
CardUnmaskPromptControllerImpl unmask_controller_; CardUnmaskPromptControllerImpl unmask_controller_;
// A weak reference to the view controller used to present UI.
__weak UIViewController* base_view_controller_;
DISALLOW_COPY_AND_ASSIGN(ChromeAutofillClientIOS); DISALLOW_COPY_AND_ASSIGN(ChromeAutofillClientIOS);
}; };
......
...@@ -60,6 +60,11 @@ ChromeAutofillClientIOS::~ChromeAutofillClientIOS() { ...@@ -60,6 +60,11 @@ ChromeAutofillClientIOS::~ChromeAutofillClientIOS() {
HideAutofillPopup(); HideAutofillPopup();
} }
void ChromeAutofillClientIOS::SetBaseViewController(
UIViewController* base_view_controller) {
base_view_controller_ = base_view_controller;
}
PersonalDataManager* ChromeAutofillClientIOS::GetPersonalDataManager() { PersonalDataManager* ChromeAutofillClientIOS::GetPersonalDataManager() {
return personal_data_manager_; return personal_data_manager_;
} }
...@@ -103,8 +108,9 @@ void ChromeAutofillClientIOS::ShowUnmaskPrompt( ...@@ -103,8 +108,9 @@ void ChromeAutofillClientIOS::ShowUnmaskPrompt(
unmask_controller_.ShowPrompt( unmask_controller_.ShowPrompt(
// autofill::CardUnmaskPromptViewBridge manages its own lifetime, so // autofill::CardUnmaskPromptViewBridge manages its own lifetime, so
// do not use std::unique_ptr<> here. // do not use std::unique_ptr<> here.
new autofill::CardUnmaskPromptViewBridge(&unmask_controller_), card, new autofill::CardUnmaskPromptViewBridge(&unmask_controller_,
reason, delegate); base_view_controller_),
card, reason, delegate);
} }
void ChromeAutofillClientIOS::OnUnmaskVerificationResult( void ChromeAutofillClientIOS::OnUnmaskVerificationResult(
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include "components/toolbar/toolbar_model_impl.h" #include "components/toolbar/toolbar_model_impl.h"
#include "ios/chrome/app/tests_hook.h" #include "ios/chrome/app/tests_hook.h"
#import "ios/chrome/browser/app_launcher/app_launcher_tab_helper.h" #import "ios/chrome/browser/app_launcher/app_launcher_tab_helper.h"
#import "ios/chrome/browser/autofill/autofill_tab_helper.h"
#include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
...@@ -2844,6 +2845,11 @@ bubblePresenterForFeature:(const base::Feature&)feature ...@@ -2844,6 +2845,11 @@ bubblePresenterForFeature:(const base::Feature&)feature
passwordTabHelper->SetPasswordControllerDelegate(self); passwordTabHelper->SetPasswordControllerDelegate(self);
} }
if (AutofillTabHelper* autofillTabHelper =
AutofillTabHelper::FromWebState(tab.webState)) {
autofillTabHelper->SetBaseViewController(self);
}
tab.dialogDelegate = self; tab.dialogDelegate = self;
tab.passKitDialogProvider = self; tab.passKitDialogProvider = self;
if (!base::FeatureList::IsEnabled(fullscreen::features::kNewFullscreen)) { if (!base::FeatureList::IsEnabled(fullscreen::features::kNewFullscreen)) {
......
...@@ -12,36 +12,6 @@ ...@@ -12,36 +12,6 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
namespace {
// The unmask prompt UI for Payment Request.
class PRCardUnmaskPromptViewBridge
: public autofill::CardUnmaskPromptViewBridge {
public:
PRCardUnmaskPromptViewBridge(autofill::CardUnmaskPromptController* controller,
UIViewController* base_view_controller)
: autofill::CardUnmaskPromptViewBridge(controller),
base_view_controller_(base_view_controller) {}
// autofill::CardUnmaskPromptView:
void Show() override {
view_controller_ =
[[CardUnmaskPromptViewController alloc] initWithBridge:this];
[view_controller_ setModalPresentationStyle:UIModalPresentationFormSheet];
[view_controller_
setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[base_view_controller_ presentViewController:view_controller_
animated:YES
completion:nil];
};
private:
__weak UIViewController* base_view_controller_;
DISALLOW_COPY_AND_ASSIGN(PRCardUnmaskPromptViewBridge);
};
} // namespace
FullCardRequester::FullCardRequester(UIViewController* base_view_controller, FullCardRequester::FullCardRequester(UIViewController* base_view_controller,
ios::ChromeBrowserState* browser_state) ios::ChromeBrowserState* browser_state)
: base_view_controller_(base_view_controller), : base_view_controller_(base_view_controller),
...@@ -64,11 +34,9 @@ void FullCardRequester::ShowUnmaskPrompt( ...@@ -64,11 +34,9 @@ void FullCardRequester::ShowUnmaskPrompt(
const autofill::CreditCard& card, const autofill::CreditCard& card,
autofill::AutofillClient::UnmaskCardReason reason, autofill::AutofillClient::UnmaskCardReason reason,
base::WeakPtr<autofill::CardUnmaskDelegate> delegate) { base::WeakPtr<autofill::CardUnmaskDelegate> delegate) {
unmask_controller_.ShowPrompt( unmask_controller_.ShowPrompt(new autofill::CardUnmaskPromptViewBridge(
// PRCardUnmaskPromptViewBridge manages its own lifetime. &unmask_controller_, base_view_controller_),
new PRCardUnmaskPromptViewBridge(&unmask_controller_, card, reason, delegate);
base_view_controller_),
card, reason, delegate);
} }
void FullCardRequester::OnUnmaskVerificationResult( void FullCardRequester::OnUnmaskVerificationResult(
......
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