Chromium Code Reviews| 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/card_unmask_prompt_view.h" |
| 17 #include "chrome/browser/ui/autofill/credit_card_scanner_controller.h" | 17 #include "chrome/browser/ui/autofill/credit_card_scanner_controller.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
| 20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 21 #include "chrome/browser/ui/chrome_pages.h" | 21 #include "chrome/browser/ui/chrome_pages.h" |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 23 #include "chrome/browser/webdata/web_data_service_factory.h" | 23 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "components/autofill/content/browser/content_autofill_driver.h" | 25 #include "components/autofill/content/browser/content_autofill_driver.h" |
| 26 #include "components/autofill/content/common/autofill_messages.h" | 26 #include "components/autofill/content/common/autofill_messages.h" |
| 27 #include "components/autofill/core/common/autofill_pref_names.h" | 27 #include "components/autofill/core/common/autofill_pref_names.h" |
| 28 #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" |
| 29 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_frame_host.h" |
| 30 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
| 31 | 31 |
| 32 #if defined(OS_ANDROID) | 32 #if defined(OS_ANDROID) |
| 33 #include "chrome/browser/android/chromium_application.h" | 33 #include "chrome/browser/android/chromium_application.h" |
| 34 #include "chrome/browser/ui/android/autofill/autofill_logger_android.h" | 34 #include "chrome/browser/ui/android/autofill/autofill_logger_android.h" |
| 35 #else | 35 #else |
| 36 #include "components/ui/zoom/zoom_controller.h" | 36 #include "components/ui/zoom/zoom_controller.h" |
| 37 #endif | 37 #endif |
| 38 | 38 |
| 39 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::ChromeAutofillClient); | 39 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::ChromeAutofillClient); |
| 40 | 40 |
| 41 namespace autofill { | 41 namespace autofill { |
| 42 | 42 |
| 43 ChromeAutofillClient::ChromeAutofillClient(content::WebContents* web_contents) | 43 ChromeAutofillClient::ChromeAutofillClient(content::WebContents* web_contents) |
| 44 : content::WebContentsObserver(web_contents), | 44 : content::WebContentsObserver(web_contents), |
| 45 last_rfh_to_rac_(nullptr), | |
| 45 card_unmask_view_(nullptr), | 46 card_unmask_view_(nullptr), |
| 46 weak_pointer_factory_(this) { | 47 weak_pointer_factory_(this) { |
| 47 DCHECK(web_contents); | 48 DCHECK(web_contents); |
| 48 | 49 |
| 49 #if !defined(OS_ANDROID) | 50 #if !defined(OS_ANDROID) |
| 50 // Since ZoomController is also a WebContentsObserver, we need to be careful | 51 // Since ZoomController is also a WebContentsObserver, we need to be careful |
| 51 // about disconnecting from it since the relative order of destruction of | 52 // about disconnecting from it since the relative order of destruction of |
| 52 // WebContentsObservers is not guaranteed. ZoomController silently clears | 53 // WebContentsObservers is not guaranteed. ZoomController silently clears |
| 53 // its ZoomObserver list during WebContentsDestroyed() so there's no need | 54 // its ZoomObserver list during WebContentsDestroyed() so there's no need |
| 54 // to explicitly remove ourselves on destruction. | 55 // to explicitly remove ourselves on destruction. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 return CreditCardScannerController::HasCreditCardScanFeature(); | 148 return CreditCardScannerController::HasCreditCardScanFeature(); |
| 148 } | 149 } |
| 149 | 150 |
| 150 void ChromeAutofillClient::ScanCreditCard( | 151 void ChromeAutofillClient::ScanCreditCard( |
| 151 const CreditCardScanCallback& callback) { | 152 const CreditCardScanCallback& callback) { |
| 152 CreditCardScannerController::ScanCreditCard(web_contents(), callback); | 153 CreditCardScannerController::ScanCreditCard(web_contents(), callback); |
| 153 } | 154 } |
| 154 | 155 |
| 155 void ChromeAutofillClient::ShowRequestAutocompleteDialog( | 156 void ChromeAutofillClient::ShowRequestAutocompleteDialog( |
| 156 const FormData& form, | 157 const FormData& form, |
| 157 const GURL& source_url, | 158 content::RenderFrameHost* render_frame_host, |
| 158 const ResultCallback& callback) { | 159 const ResultCallback& callback) { |
| 159 HideRequestAutocompleteDialog(); | 160 HideRequestAutocompleteDialog(); |
| 160 | 161 last_rfh_to_rac_ = render_frame_host; |
| 162 GURL frame_url = render_frame_host->GetLastCommittedURL(); | |
| 161 dialog_controller_ = AutofillDialogController::Create(web_contents(), form, | 163 dialog_controller_ = AutofillDialogController::Create(web_contents(), form, |
| 162 source_url, callback); | 164 frame_url, callback); |
| 163 if (dialog_controller_) { | 165 if (dialog_controller_) { |
| 164 dialog_controller_->Show(); | 166 dialog_controller_->Show(); |
| 165 } else { | 167 } else { |
| 166 callback.Run(AutofillClient::AutocompleteResultErrorDisabled, | 168 callback.Run(AutofillClient::AutocompleteResultErrorDisabled, |
| 167 base::string16(), | 169 base::string16(), |
| 168 NULL); | 170 NULL); |
| 169 NOTIMPLEMENTED(); | 171 NOTIMPLEMENTED(); |
| 170 } | 172 } |
| 171 } | 173 } |
| 172 | 174 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 if (password_client) | 212 if (password_client) |
| 211 password_client->HidePasswordGenerationPopup(); | 213 password_client->HidePasswordGenerationPopup(); |
| 212 } | 214 } |
| 213 | 215 |
| 214 bool ChromeAutofillClient::IsAutocompleteEnabled() { | 216 bool ChromeAutofillClient::IsAutocompleteEnabled() { |
| 215 // For browser, Autocomplete is always enabled as part of Autofill. | 217 // For browser, Autocomplete is always enabled as part of Autofill. |
| 216 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 218 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
| 217 } | 219 } |
| 218 | 220 |
| 219 void ChromeAutofillClient::HideRequestAutocompleteDialog() { | 221 void ChromeAutofillClient::HideRequestAutocompleteDialog() { |
| 220 if (dialog_controller_.get()) | 222 if (dialog_controller_) |
| 221 dialog_controller_->Hide(); | 223 dialog_controller_->Hide(); |
| 222 } | 224 } |
| 223 | 225 |
| 226 void ChromeAutofillClient::RenderFrameDeleted( | |
| 227 content::RenderFrameHost* render_frame_host) { | |
| 228 if (dialog_controller_ && render_frame_host == last_rfh_to_rac_) | |
| 229 HideRequestAutocompleteDialog(); | |
|
Dan Beam
2014/12/20 01:10:51
nit: create a HideIfLastRfhToRac(render_frame_host
| |
| 230 } | |
| 231 | |
| 232 void ChromeAutofillClient::DidNavigateAnyFrame( | |
| 233 content::RenderFrameHost* render_frame_host, | |
| 234 const content::LoadCommittedDetails& details, | |
| 235 const content::FrameNavigateParams& params) { | |
| 236 if (dialog_controller_ && render_frame_host == last_rfh_to_rac_) | |
| 237 HideRequestAutocompleteDialog(); | |
| 238 } | |
| 239 | |
| 224 void ChromeAutofillClient::WebContentsDestroyed() { | 240 void ChromeAutofillClient::WebContentsDestroyed() { |
| 225 HideAutofillPopup(); | 241 HideAutofillPopup(); |
| 226 } | 242 } |
| 227 | 243 |
| 228 void ChromeAutofillClient::OnZoomChanged( | 244 void ChromeAutofillClient::OnZoomChanged( |
| 229 const ui_zoom::ZoomController::ZoomChangedEventData& data) { | 245 const ui_zoom::ZoomController::ZoomChangedEventData& data) { |
| 230 HideAutofillPopup(); | 246 HideAutofillPopup(); |
| 231 } | 247 } |
| 232 | 248 |
| 233 void ChromeAutofillClient::DetectAccountCreationForms( | 249 void ChromeAutofillClient::DetectAccountCreationForms( |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 248 profile_full_name); | 264 profile_full_name); |
| 249 #endif // defined(OS_ANDROID) | 265 #endif // defined(OS_ANDROID) |
| 250 } | 266 } |
| 251 | 267 |
| 252 void ChromeAutofillClient::OnFirstUserGestureObserved() { | 268 void ChromeAutofillClient::OnFirstUserGestureObserved() { |
| 253 web_contents()->SendToAllFrames( | 269 web_contents()->SendToAllFrames( |
| 254 new AutofillMsg_FirstUserGestureObservedInTab(routing_id())); | 270 new AutofillMsg_FirstUserGestureObservedInTab(routing_id())); |
| 255 } | 271 } |
| 256 | 272 |
| 257 } // namespace autofill | 273 } // namespace autofill |
| OLD | NEW |