| 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/geometry/rect.h" | 30 #include "ui/gfx/geometry/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 unmask_controller_(web_contents) { | 45 unmask_controller_(web_contents), |
| 46 last_rfh_to_rac_(nullptr) { |
| 46 DCHECK(web_contents); | 47 DCHECK(web_contents); |
| 47 | 48 |
| 48 #if !defined(OS_ANDROID) | 49 #if !defined(OS_ANDROID) |
| 49 // Since ZoomController is also a WebContentsObserver, we need to be careful | 50 // Since ZoomController is also a WebContentsObserver, we need to be careful |
| 50 // about disconnecting from it since the relative order of destruction of | 51 // about disconnecting from it since the relative order of destruction of |
| 51 // WebContentsObservers is not guaranteed. ZoomController silently clears | 52 // WebContentsObservers is not guaranteed. ZoomController silently clears |
| 52 // its ZoomObserver list during WebContentsDestroyed() so there's no need | 53 // its ZoomObserver list during WebContentsDestroyed() so there's no need |
| 53 // to explicitly remove ourselves on destruction. | 54 // to explicitly remove ourselves on destruction. |
| 54 ui_zoom::ZoomController* zoom_controller = | 55 ui_zoom::ZoomController* zoom_controller = |
| 55 ui_zoom::ZoomController::FromWebContents(web_contents); | 56 ui_zoom::ZoomController::FromWebContents(web_contents); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 return CreditCardScannerController::HasCreditCardScanFeature(); | 130 return CreditCardScannerController::HasCreditCardScanFeature(); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void ChromeAutofillClient::ScanCreditCard( | 133 void ChromeAutofillClient::ScanCreditCard( |
| 133 const CreditCardScanCallback& callback) { | 134 const CreditCardScanCallback& callback) { |
| 134 CreditCardScannerController::ScanCreditCard(web_contents(), callback); | 135 CreditCardScannerController::ScanCreditCard(web_contents(), callback); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void ChromeAutofillClient::ShowRequestAutocompleteDialog( | 138 void ChromeAutofillClient::ShowRequestAutocompleteDialog( |
| 138 const FormData& form, | 139 const FormData& form, |
| 139 const GURL& source_url, | 140 content::RenderFrameHost* render_frame_host, |
| 140 const ResultCallback& callback) { | 141 const ResultCallback& callback) { |
| 141 HideRequestAutocompleteDialog(); | 142 HideRequestAutocompleteDialog(); |
| 142 | 143 last_rfh_to_rac_ = render_frame_host; |
| 144 GURL frame_url = render_frame_host->GetLastCommittedURL(); |
| 143 dialog_controller_ = AutofillDialogController::Create(web_contents(), form, | 145 dialog_controller_ = AutofillDialogController::Create(web_contents(), form, |
| 144 source_url, callback); | 146 frame_url, callback); |
| 145 if (dialog_controller_) { | 147 if (dialog_controller_) { |
| 146 dialog_controller_->Show(); | 148 dialog_controller_->Show(); |
| 147 } else { | 149 } else { |
| 148 callback.Run(AutofillClient::AutocompleteResultErrorDisabled, | 150 callback.Run(AutofillClient::AutocompleteResultErrorDisabled, |
| 149 base::string16(), | 151 base::string16(), |
| 150 NULL); | 152 NULL); |
| 151 NOTIMPLEMENTED(); | 153 NOTIMPLEMENTED(); |
| 152 } | 154 } |
| 153 } | 155 } |
| 154 | 156 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 if (password_client) | 194 if (password_client) |
| 193 password_client->HidePasswordGenerationPopup(); | 195 password_client->HidePasswordGenerationPopup(); |
| 194 } | 196 } |
| 195 | 197 |
| 196 bool ChromeAutofillClient::IsAutocompleteEnabled() { | 198 bool ChromeAutofillClient::IsAutocompleteEnabled() { |
| 197 // For browser, Autocomplete is always enabled as part of Autofill. | 199 // For browser, Autocomplete is always enabled as part of Autofill. |
| 198 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 200 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
| 199 } | 201 } |
| 200 | 202 |
| 201 void ChromeAutofillClient::HideRequestAutocompleteDialog() { | 203 void ChromeAutofillClient::HideRequestAutocompleteDialog() { |
| 202 if (dialog_controller_.get()) | 204 if (dialog_controller_) |
| 203 dialog_controller_->Hide(); | 205 dialog_controller_->Hide(); |
| 204 } | 206 } |
| 205 | 207 |
| 208 void ChromeAutofillClient::RenderFrameDeleted( |
| 209 content::RenderFrameHost* render_frame_host) { |
| 210 if (dialog_controller_ && render_frame_host == last_rfh_to_rac_) |
| 211 HideRequestAutocompleteDialog(); |
| 212 } |
| 213 |
| 214 void ChromeAutofillClient::DidNavigateAnyFrame( |
| 215 content::RenderFrameHost* render_frame_host, |
| 216 const content::LoadCommittedDetails& details, |
| 217 const content::FrameNavigateParams& params) { |
| 218 if (dialog_controller_ && render_frame_host == last_rfh_to_rac_) |
| 219 HideRequestAutocompleteDialog(); |
| 220 } |
| 221 |
| 206 void ChromeAutofillClient::WebContentsDestroyed() { | 222 void ChromeAutofillClient::WebContentsDestroyed() { |
| 207 HideAutofillPopup(); | 223 HideAutofillPopup(); |
| 208 } | 224 } |
| 209 | 225 |
| 210 void ChromeAutofillClient::OnZoomChanged( | 226 void ChromeAutofillClient::OnZoomChanged( |
| 211 const ui_zoom::ZoomController::ZoomChangedEventData& data) { | 227 const ui_zoom::ZoomController::ZoomChangedEventData& data) { |
| 212 HideAutofillPopup(); | 228 HideAutofillPopup(); |
| 213 } | 229 } |
| 214 | 230 |
| 215 void ChromeAutofillClient::DetectAccountCreationForms( | 231 void ChromeAutofillClient::DetectAccountCreationForms( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 230 profile_full_name); | 246 profile_full_name); |
| 231 #endif // defined(OS_ANDROID) | 247 #endif // defined(OS_ANDROID) |
| 232 } | 248 } |
| 233 | 249 |
| 234 void ChromeAutofillClient::OnFirstUserGestureObserved() { | 250 void ChromeAutofillClient::OnFirstUserGestureObserved() { |
| 235 web_contents()->SendToAllFrames( | 251 web_contents()->SendToAllFrames( |
| 236 new AutofillMsg_FirstUserGestureObservedInTab(routing_id())); | 252 new AutofillMsg_FirstUserGestureObservedInTab(routing_id())); |
| 237 } | 253 } |
| 238 | 254 |
| 239 } // namespace autofill | 255 } // namespace autofill |
| OLD | NEW |