Commit 1dc59a74 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

[iOS] Move AutofillController ownership to a tab helper.

Introduce a new tab helper AutofillTabHelper that owns AutofillController
and forward access to the public API of AutofillController and change all
code to use the AutofillTabHelper instead of accessing it via Tab.

Bug: 760556
Change-Id: Ic986c22f60f016658258c6f7b6591633ded167ac
Reviewed-on: https://chromium-review.googlesource.com/647588
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarmahmadi (Moe) <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#499975}
parent e1a63252
......@@ -77,6 +77,8 @@ source_set("autofill_internal") {
"autofill_agent.mm",
"autofill_controller.h",
"autofill_controller.mm",
"autofill_tab_helper.h",
"autofill_tab_helper.mm",
]
deps = [
":autofill",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_AUTOFILL_AUTOFILL_TAB_HELPER_H_
#define IOS_CHROME_BROWSER_AUTOFILL_AUTOFILL_TAB_HELPER_H_
#include "base/macros.h"
#import "ios/web/public/web_state/web_state_observer.h"
#import "ios/web/public/web_state/web_state_user_data.h"
@class AutofillController;
@protocol FormSuggestionProvider;
namespace password_manager {
class PasswordGenerationManager;
}
// Class binding an AutofillController to a WebState.
class AutofillTabHelper : public web::WebStateObserver,
public web::WebStateUserData<AutofillTabHelper> {
public:
~AutofillTabHelper() override;
// Create an AutofillTabHelper and attaches it to the given |web_state|.
static void CreateForWebState(
web::WebState* web_state,
password_manager::PasswordGenerationManager* password_generation_manager);
// Returns an object that can provide suggestions from the PasswordController.
// May return nil.
id<FormSuggestionProvider> GetSuggestionProvider();
private:
AutofillTabHelper(
web::WebState* web_state,
password_manager::PasswordGenerationManager* password_generation_manager);
// web::WebStateObserver implementation.
void WebStateDestroyed() override;
// The Objective-C autofill controller instance.
__strong AutofillController* controller_;
DISALLOW_COPY_AND_ASSIGN(AutofillTabHelper);
};
#endif // IOS_CHROME_BROWSER_AUTOFILL_AUTOFILL_TAB_HELPER_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/autofill/autofill_tab_helper.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#import "ios/chrome/browser/autofill/autofill_controller.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
DEFINE_WEB_STATE_USER_DATA_KEY(AutofillTabHelper);
AutofillTabHelper::~AutofillTabHelper() = default;
// static
void AutofillTabHelper::CreateForWebState(
web::WebState* web_state,
password_manager::PasswordGenerationManager* password_generation_manager) {
DCHECK(web_state);
DCHECK(!FromWebState(web_state));
web_state->SetUserData(UserDataKey(),
base::WrapUnique(new AutofillTabHelper(
web_state, password_generation_manager)));
}
id<FormSuggestionProvider> AutofillTabHelper::GetSuggestionProvider() {
return controller_.suggestionProvider;
}
AutofillTabHelper::AutofillTabHelper(
web::WebState* web_state,
password_manager::PasswordGenerationManager* password_generation_manager)
: web::WebStateObserver(web_state),
controller_([[AutofillController alloc]
initWithBrowserState:ios::ChromeBrowserState::FromBrowserState(
web_state->GetBrowserState())
passwordGenerationManager:password_generation_manager
webState:web_state]) {
DCHECK(web::WebStateObserver::web_state());
}
void AutofillTabHelper::WebStateDestroyed() {
[controller_ detachFromWebState];
controller_ = nil;
}
......@@ -45,7 +45,7 @@
#include "components/strings/grit/components_strings.h"
#include "components/url_formatter/url_formatter.h"
#include "ios/chrome/browser/application_context.h"
#import "ios/chrome/browser/autofill/autofill_controller.h"
#import "ios/chrome/browser/autofill/autofill_tab_helper.h"
#import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h"
#import "ios/chrome/browser/autofill/form_suggestion_controller.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
......@@ -221,9 +221,6 @@ class TabHistoryContext : public history::Context {
// Manages the input accessory view during form input.
FormInputAccessoryViewController* _inputAccessoryViewController;
// Handles autofill.
AutofillController* _autofillController;
// Handles retrieving, generating and updating snapshots of CRWWebController's
// web page.
WebControllerSnapshotHelper* _webControllerSnapshotHelper;
......@@ -439,11 +436,6 @@ void TabInfoBarObserver::OnInfoBarReplaced(infobars::InfoBar* old_infobar,
if (experimental_flags::IsAutoReloadEnabled())
_autoReloadBridge = [[AutoReloadBridge alloc] initWithTab:self];
_autofillController = [[AutofillController alloc]
initWithBrowserState:_browserState
passwordGenerationManager:PasswordTabHelper::FromWebState(self.webState)
->GetPasswordGenerationManager()
webState:self.webState];
_suggestionController = [[FormSuggestionController alloc]
initWithWebState:self.webState
providers:[self suggestionProviders]];
......@@ -477,7 +469,8 @@ void TabInfoBarObserver::OnInfoBarReplaced(infobars::InfoBar* old_infobar,
NSMutableArray* providers = [NSMutableArray array];
[providers addObject:PasswordTabHelper::FromWebState(self.webState)
->GetSuggestionProvider()];
[providers addObject:[_autofillController suggestionProvider]];
[providers addObject:AutofillTabHelper::FromWebState(self.webState)
->GetSuggestionProvider()];
return providers;
}
......@@ -869,8 +862,6 @@ void TabInfoBarObserver::OnInfoBarReplaced(infobars::InfoBar* old_infobar,
_faviconDriverObserverBridge.reset();
[_openInController detachFromWebController];
_openInController = nil;
[_autofillController detachFromWebState];
_autofillController = nil;
[_suggestionController detachFromWebState];
_suggestionController = nil;
if (_fullScreenController)
......
......@@ -13,6 +13,7 @@
#import "components/history/ios/browser/web_state_top_sites_observer.h"
#include "components/keyed_service/core/service_access_type.h"
#import "components/signin/ios/browser/account_consistency_service.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/favicon/favicon_service_factory.h"
......@@ -97,6 +98,10 @@ void AttachTabHelpers(web::WebState* web_state) {
PasswordTabHelper::CreateForWebState(web_state,
[[PasswordsUiDelegateImpl alloc] init]);
AutofillTabHelper::CreateForWebState(
web_state, PasswordTabHelper::FromWebState(web_state)
->GetPasswordGenerationManager());
// Allow the embedder to attach tab helpers.
ios::GetChromeBrowserProvider()->AttachTabHelpers(web_state, tab);
......
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