OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" | 5 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 9 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
10 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 10 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
12 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 12 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | 14 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
15 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" | 15 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
| 16 #include "chrome/browser/ui/autofill/card_unmask_prompt_view.h" |
16 #include "chrome/browser/ui/autofill/credit_card_scanner_controller.h" | 17 #include "chrome/browser/ui/autofill/credit_card_scanner_controller.h" |
17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
19 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
20 #include "chrome/browser/ui/chrome_pages.h" | 21 #include "chrome/browser/ui/chrome_pages.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
22 #include "chrome/browser/webdata/web_data_service_factory.h" | 23 #include "chrome/browser/webdata/web_data_service_factory.h" |
23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
24 #include "components/autofill/content/browser/content_autofill_driver.h" | 25 #include "components/autofill/content/browser/content_autofill_driver.h" |
25 #include "components/autofill/content/common/autofill_messages.h" | 26 #include "components/autofill/content/common/autofill_messages.h" |
26 #include "components/autofill/core/common/autofill_pref_names.h" | 27 #include "components/autofill/core/common/autofill_pref_names.h" |
27 #include "components/password_manager/content/browser/content_password_manager_d
river.h" | 28 #include "components/password_manager/content/browser/content_password_manager_d
river.h" |
28 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
29 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
30 | 31 |
31 #if defined(OS_ANDROID) | 32 #if defined(OS_ANDROID) |
32 #include "chrome/browser/android/chromium_application.h" | 33 #include "chrome/browser/android/chromium_application.h" |
33 #include "chrome/browser/ui/android/autofill/autofill_logger_android.h" | 34 #include "chrome/browser/ui/android/autofill/autofill_logger_android.h" |
34 #else | 35 #else |
35 #include "components/ui/zoom/zoom_controller.h" | 36 #include "components/ui/zoom/zoom_controller.h" |
36 #endif | 37 #endif |
37 | 38 |
38 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::ChromeAutofillClient); | 39 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::ChromeAutofillClient); |
39 | 40 |
40 namespace autofill { | 41 namespace autofill { |
41 | 42 |
42 ChromeAutofillClient::ChromeAutofillClient(content::WebContents* web_contents) | 43 ChromeAutofillClient::ChromeAutofillClient(content::WebContents* web_contents) |
43 : content::WebContentsObserver(web_contents), web_contents_(web_contents) { | 44 : content::WebContentsObserver(web_contents), weak_pointer_factory_(this) { |
44 DCHECK(web_contents); | 45 DCHECK(web_contents); |
45 | 46 |
46 #if !defined(OS_ANDROID) | 47 #if !defined(OS_ANDROID) |
47 // Since ZoomController is also a WebContentsObserver, we need to be careful | 48 // Since ZoomController is also a WebContentsObserver, we need to be careful |
48 // about disconnecting from it since the relative order of destruction of | 49 // about disconnecting from it since the relative order of destruction of |
49 // WebContentsObservers is not guaranteed. ZoomController silently clears | 50 // WebContentsObservers is not guaranteed. ZoomController silently clears |
50 // its ZoomObserver list during WebContentsDestroyed() so there's no need | 51 // its ZoomObserver list during WebContentsDestroyed() so there's no need |
51 // to explicitly remove ourselves on destruction. | 52 // to explicitly remove ourselves on destruction. |
52 ui_zoom::ZoomController* zoom_controller = | 53 ui_zoom::ZoomController* zoom_controller = |
53 ui_zoom::ZoomController::FromWebContents(web_contents); | 54 ui_zoom::ZoomController::FromWebContents(web_contents); |
(...skipping 18 matching lines...) Expand all Loading... |
72 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 73 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
73 } | 74 } |
74 | 75 |
75 void ChromeAutofillClient::TabActivated() { | 76 void ChromeAutofillClient::TabActivated() { |
76 if (dialog_controller_.get()) | 77 if (dialog_controller_.get()) |
77 dialog_controller_->TabActivated(); | 78 dialog_controller_->TabActivated(); |
78 } | 79 } |
79 | 80 |
80 PersonalDataManager* ChromeAutofillClient::GetPersonalDataManager() { | 81 PersonalDataManager* ChromeAutofillClient::GetPersonalDataManager() { |
81 Profile* profile = | 82 Profile* profile = |
82 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 83 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
83 return PersonalDataManagerFactory::GetForProfile( | 84 return PersonalDataManagerFactory::GetForProfile( |
84 profile->GetOriginalProfile()); | 85 profile->GetOriginalProfile()); |
85 } | 86 } |
86 | 87 |
87 scoped_refptr<AutofillWebDataService> ChromeAutofillClient::GetDatabase() { | 88 scoped_refptr<AutofillWebDataService> ChromeAutofillClient::GetDatabase() { |
88 Profile* profile = | 89 Profile* profile = |
89 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 90 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
90 return WebDataServiceFactory::GetAutofillWebDataForProfile( | 91 return WebDataServiceFactory::GetAutofillWebDataForProfile( |
91 profile, Profile::EXPLICIT_ACCESS); | 92 profile, Profile::EXPLICIT_ACCESS); |
92 } | 93 } |
93 | 94 |
94 PrefService* ChromeAutofillClient::GetPrefs() { | 95 PrefService* ChromeAutofillClient::GetPrefs() { |
95 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 96 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()) |
96 ->GetPrefs(); | 97 ->GetPrefs(); |
97 } | 98 } |
98 | 99 |
99 void ChromeAutofillClient::ShowAutofillSettings() { | 100 void ChromeAutofillClient::ShowAutofillSettings() { |
100 #if defined(OS_ANDROID) | 101 #if defined(OS_ANDROID) |
101 chrome::android::ChromiumApplication::ShowAutofillSettings(); | 102 chrome::android::ChromiumApplication::ShowAutofillSettings(); |
102 #else | 103 #else |
103 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 104 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
104 if (browser) | 105 if (browser) |
105 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); | 106 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); |
106 #endif // #if defined(OS_ANDROID) | 107 #endif // #if defined(OS_ANDROID) |
107 } | 108 } |
108 | 109 |
| 110 void ChromeAutofillClient::ShowUnmaskPrompt() { |
| 111 // TODO(estade): we'll need to store the returned pointer at some point when |
| 112 // the view object gets more complicated. |
| 113 CardUnmaskPromptView::CreateAndShow( |
| 114 web_contents(), base::Bind(&ChromeAutofillClient::OnUnmaskResponse, |
| 115 weak_pointer_factory_.GetWeakPtr())); |
| 116 } |
| 117 |
| 118 void ChromeAutofillClient::OnUnmaskResponse(const base::string16& response) { |
| 119 NOTIMPLEMENTED() << " I should probably do something with this: " << response; |
| 120 } |
| 121 |
109 void ChromeAutofillClient::ConfirmSaveCreditCard( | 122 void ChromeAutofillClient::ConfirmSaveCreditCard( |
110 const base::Closure& save_card_callback) { | 123 const base::Closure& save_card_callback) { |
111 InfoBarService* infobar_service = | 124 InfoBarService* infobar_service = |
112 InfoBarService::FromWebContents(web_contents_); | 125 InfoBarService::FromWebContents(web_contents()); |
113 AutofillCCInfoBarDelegate::Create(infobar_service, save_card_callback); | 126 AutofillCCInfoBarDelegate::Create(infobar_service, save_card_callback); |
114 } | 127 } |
115 | 128 |
116 bool ChromeAutofillClient::HasCreditCardScanFeature() { | 129 bool ChromeAutofillClient::HasCreditCardScanFeature() { |
117 return CreditCardScannerController::HasCreditCardScanFeature(); | 130 return CreditCardScannerController::HasCreditCardScanFeature(); |
118 } | 131 } |
119 | 132 |
120 void ChromeAutofillClient::ScanCreditCard( | 133 void ChromeAutofillClient::ScanCreditCard( |
121 const CreditCardScanCallback& callback) { | 134 const CreditCardScanCallback& callback) { |
122 CreditCardScannerController::ScanCreditCard(web_contents(), callback); | 135 CreditCardScannerController::ScanCreditCard(web_contents(), callback); |
123 } | 136 } |
124 | 137 |
125 void ChromeAutofillClient::ShowRequestAutocompleteDialog( | 138 void ChromeAutofillClient::ShowRequestAutocompleteDialog( |
126 const FormData& form, | 139 const FormData& form, |
127 const GURL& source_url, | 140 const GURL& source_url, |
128 const ResultCallback& callback) { | 141 const ResultCallback& callback) { |
129 HideRequestAutocompleteDialog(); | 142 HideRequestAutocompleteDialog(); |
130 | 143 |
131 dialog_controller_ = AutofillDialogController::Create( | 144 dialog_controller_ = AutofillDialogController::Create(web_contents(), form, |
132 web_contents_, form, source_url, callback); | 145 source_url, callback); |
133 if (dialog_controller_) { | 146 if (dialog_controller_) { |
134 dialog_controller_->Show(); | 147 dialog_controller_->Show(); |
135 } else { | 148 } else { |
136 callback.Run(AutofillClient::AutocompleteResultErrorDisabled, | 149 callback.Run(AutofillClient::AutocompleteResultErrorDisabled, |
137 base::string16(), | 150 base::string16(), |
138 NULL); | 151 NULL); |
139 NOTIMPLEMENTED(); | 152 NOTIMPLEMENTED(); |
140 } | 153 } |
141 } | 154 } |
142 | 155 |
143 void ChromeAutofillClient::ShowAutofillPopup( | 156 void ChromeAutofillClient::ShowAutofillPopup( |
144 const gfx::RectF& element_bounds, | 157 const gfx::RectF& element_bounds, |
145 base::i18n::TextDirection text_direction, | 158 base::i18n::TextDirection text_direction, |
146 const std::vector<base::string16>& values, | 159 const std::vector<base::string16>& values, |
147 const std::vector<base::string16>& labels, | 160 const std::vector<base::string16>& labels, |
148 const std::vector<base::string16>& icons, | 161 const std::vector<base::string16>& icons, |
149 const std::vector<int>& identifiers, | 162 const std::vector<int>& identifiers, |
150 base::WeakPtr<AutofillPopupDelegate> delegate) { | 163 base::WeakPtr<AutofillPopupDelegate> delegate) { |
151 // Convert element_bounds to be in screen space. | 164 // Convert element_bounds to be in screen space. |
152 gfx::Rect client_area = web_contents_->GetContainerBounds(); | 165 gfx::Rect client_area = web_contents()->GetContainerBounds(); |
153 gfx::RectF element_bounds_in_screen_space = | 166 gfx::RectF element_bounds_in_screen_space = |
154 element_bounds + client_area.OffsetFromOrigin(); | 167 element_bounds + client_area.OffsetFromOrigin(); |
155 | 168 |
156 // Will delete or reuse the old |popup_controller_|. | 169 // Will delete or reuse the old |popup_controller_|. |
157 popup_controller_ = | 170 popup_controller_ = |
158 AutofillPopupControllerImpl::GetOrCreate(popup_controller_, | 171 AutofillPopupControllerImpl::GetOrCreate(popup_controller_, |
159 delegate, | 172 delegate, |
160 web_contents(), | 173 web_contents(), |
161 web_contents()->GetNativeView(), | 174 web_contents()->GetNativeView(), |
162 element_bounds_in_screen_space, | 175 element_bounds_in_screen_space, |
163 text_direction); | 176 text_direction); |
164 | 177 |
165 popup_controller_->Show(values, labels, icons, identifiers); | 178 popup_controller_->Show(values, labels, icons, identifiers); |
166 } | 179 } |
167 | 180 |
168 void ChromeAutofillClient::UpdateAutofillPopupDataListValues( | 181 void ChromeAutofillClient::UpdateAutofillPopupDataListValues( |
169 const std::vector<base::string16>& values, | 182 const std::vector<base::string16>& values, |
170 const std::vector<base::string16>& labels) { | 183 const std::vector<base::string16>& labels) { |
171 if (popup_controller_.get()) | 184 if (popup_controller_.get()) |
172 popup_controller_->UpdateDataListValues(values, labels); | 185 popup_controller_->UpdateDataListValues(values, labels); |
173 } | 186 } |
174 | 187 |
175 void ChromeAutofillClient::HideAutofillPopup() { | 188 void ChromeAutofillClient::HideAutofillPopup() { |
176 if (popup_controller_.get()) | 189 if (popup_controller_.get()) |
177 popup_controller_->Hide(); | 190 popup_controller_->Hide(); |
178 | 191 |
179 // Password generation popups behave in the same fashion and should also | 192 // Password generation popups behave in the same fashion and should also |
180 // be hidden. | 193 // be hidden. |
181 ChromePasswordManagerClient* password_client = | 194 ChromePasswordManagerClient* password_client = |
182 ChromePasswordManagerClient::FromWebContents(web_contents_); | 195 ChromePasswordManagerClient::FromWebContents(web_contents()); |
183 if (password_client) | 196 if (password_client) |
184 password_client->HidePasswordGenerationPopup(); | 197 password_client->HidePasswordGenerationPopup(); |
185 } | 198 } |
186 | 199 |
187 bool ChromeAutofillClient::IsAutocompleteEnabled() { | 200 bool ChromeAutofillClient::IsAutocompleteEnabled() { |
188 // For browser, Autocomplete is always enabled as part of Autofill. | 201 // For browser, Autocomplete is always enabled as part of Autofill. |
189 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 202 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
190 } | 203 } |
191 | 204 |
192 void ChromeAutofillClient::HideRequestAutocompleteDialog() { | 205 void ChromeAutofillClient::HideRequestAutocompleteDialog() { |
(...skipping 28 matching lines...) Expand all Loading... |
221 profile_full_name); | 234 profile_full_name); |
222 #endif // defined(OS_ANDROID) | 235 #endif // defined(OS_ANDROID) |
223 } | 236 } |
224 | 237 |
225 void ChromeAutofillClient::OnFirstUserGestureObserved() { | 238 void ChromeAutofillClient::OnFirstUserGestureObserved() { |
226 web_contents()->SendToAllFrames( | 239 web_contents()->SendToAllFrames( |
227 new AutofillMsg_FirstUserGestureObservedInTab(routing_id())); | 240 new AutofillMsg_FirstUserGestureObservedInTab(routing_id())); |
228 } | 241 } |
229 | 242 |
230 } // namespace autofill | 243 } // namespace autofill |
OLD | NEW |