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