1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
// Copyright (c) 2012 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.
#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/webdata/web_data_service_factory.h"
#include "chrome/common/url_constants.h"
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/content/common/autofill_messages.h"
#include "components/autofill/core/common/autofill_pref_names.h"
#include "content/public/browser/render_view_host.h"
#include "ui/gfx/rect.h"
#if defined(OS_ANDROID)
#include "chrome/browser/ui/android/autofill/autofill_logger_android.h"
#endif
DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::TabAutofillManagerDelegate);
namespace autofill {
TabAutofillManagerDelegate::TabAutofillManagerDelegate(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
web_contents_(web_contents) {
DCHECK(web_contents);
}
TabAutofillManagerDelegate::~TabAutofillManagerDelegate() {
// NOTE: It is too late to clean up the autofill popup; that cleanup process
// requires that the WebContents instance still be valid and it is not at
// this point (in particular, the WebContentsImpl destructor has already
// finished running and we are now in the base class destructor).
DCHECK(!popup_controller_);
}
void TabAutofillManagerDelegate::TabActivated() {
if (dialog_controller_.get())
dialog_controller_->TabActivated();
}
PersonalDataManager* TabAutofillManagerDelegate::GetPersonalDataManager() {
Profile* profile =
Profile::FromBrowserContext(web_contents_->GetBrowserContext());
return PersonalDataManagerFactory::GetForProfile(
profile->GetOriginalProfile());
}
scoped_refptr<AutofillWebDataService>
TabAutofillManagerDelegate::GetDatabase() {
Profile* profile =
Profile::FromBrowserContext(web_contents_->GetBrowserContext());
return WebDataServiceFactory::GetAutofillWebDataForProfile(
profile, Profile::EXPLICIT_ACCESS);
}
PrefService* TabAutofillManagerDelegate::GetPrefs() {
return Profile::FromBrowserContext(web_contents_->GetBrowserContext())->
GetPrefs();
}
void TabAutofillManagerDelegate::ShowAutofillSettings() {
#if defined(OS_ANDROID)
NOTIMPLEMENTED();
#else
Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
if (browser)
chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage);
#endif // #if defined(OS_ANDROID)
}
void TabAutofillManagerDelegate::ConfirmSaveCreditCard(
const AutofillMetrics& metric_logger,
const base::Closure& save_card_callback) {
InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents_);
AutofillCCInfoBarDelegate::Create(
infobar_service, &metric_logger, save_card_callback);
}
void TabAutofillManagerDelegate::ShowRequestAutocompleteDialog(
const FormData& form,
const GURL& source_url,
const ResultCallback& callback) {
HideRequestAutocompleteDialog();
dialog_controller_ = AutofillDialogController::Create(web_contents_,
form,
source_url,
callback);
if (dialog_controller_) {
dialog_controller_->Show();
} else {
callback.Run(AutofillManagerDelegate::AutocompleteResultErrorDisabled,
base::string16(),
NULL);
NOTIMPLEMENTED();
}
}
void TabAutofillManagerDelegate::ShowAutofillPopup(
const gfx::RectF& element_bounds,
base::i18n::TextDirection text_direction,
const std::vector<base::string16>& values,
const std::vector<base::string16>& labels,
const std::vector<base::string16>& icons,
const std::vector<int>& identifiers,
base::WeakPtr<AutofillPopupDelegate> delegate) {
// Convert element_bounds to be in screen space.
gfx::Rect client_area = web_contents_->GetContainerBounds();
gfx::RectF element_bounds_in_screen_space =
element_bounds + client_area.OffsetFromOrigin();
// Will delete or reuse the old |popup_controller_|.
popup_controller_ = AutofillPopupControllerImpl::GetOrCreate(
popup_controller_,
delegate,
web_contents(),
web_contents()->GetNativeView(),
element_bounds_in_screen_space,
text_direction);
popup_controller_->Show(values, labels, icons, identifiers);
}
void TabAutofillManagerDelegate::UpdateAutofillPopupDataListValues(
const std::vector<base::string16>& values,
const std::vector<base::string16>& labels) {
if (popup_controller_.get())
popup_controller_->UpdateDataListValues(values, labels);
}
void TabAutofillManagerDelegate::HideAutofillPopup() {
if (popup_controller_.get())
popup_controller_->Hide();
// Password generation popups behave in the same fashion and should also
// be hidden.
ChromePasswordManagerClient* password_client =
ChromePasswordManagerClient::FromWebContents(web_contents_);
if (password_client)
password_client->HidePasswordGenerationPopup();
}
bool TabAutofillManagerDelegate::IsAutocompleteEnabled() {
// For browser, Autocomplete is always enabled as part of Autofill.
return GetPrefs()->GetBoolean(prefs::kAutofillEnabled);
}
void TabAutofillManagerDelegate::HideRequestAutocompleteDialog() {
if (dialog_controller_.get())
dialog_controller_->Hide();
}
void TabAutofillManagerDelegate::WebContentsDestroyed(
content::WebContents* web_contents) {
HideAutofillPopup();
}
void TabAutofillManagerDelegate::DetectAccountCreationForms(
const std::vector<autofill::FormStructure*>& forms) {
password_manager::PasswordGenerationManager* manager =
ChromePasswordManagerClient::GetGenerationManagerFromWebContents(
web_contents_);
if (manager)
manager->DetectAccountCreationForms(forms);
}
void TabAutofillManagerDelegate::DidFillOrPreviewField(
const base::string16& autofilled_value,
const base::string16& profile_full_name) {
#if defined(OS_ANDROID)
AutofillLoggerAndroid::DidFillOrPreviewField(
autofilled_value, profile_full_name);
#endif // defined(OS_ANDROID)
}
} // namespace autofill
|