[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 8d4cc15e | 2012-08-30 00:33:10 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 5 | #include "chrome/browser/ui/autofill/chrome_autofill_client.h" |
[email protected] | 8d4cc15e | 2012-08-30 00:33:10 | [diff] [blame] | 6 | |
dcheng | 4a9d982 | 2015-12-26 22:35:30 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
jdonnelly | 8d70954 | 2015-04-29 21:58:22 | [diff] [blame] | 9 | #include "base/bind.h" |
bondd | 2ee9bd1d | 2015-12-11 02:56:05 | [diff] [blame] | 10 | #include "base/command_line.h" |
[email protected] | 8d4cc15e | 2012-08-30 00:33:10 | [diff] [blame] | 11 | #include "base/logging.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 12 | #include "base/prefs/pref_service.h" |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 6f3ccf5 | 2013-02-21 03:55:23 | [diff] [blame] | 14 | #include "chrome/browser/autofill/personal_data_manager_factory.h" |
jdonnelly | 8d70954 | 2015-04-29 21:58:22 | [diff] [blame] | 15 | #include "chrome/browser/autofill/risk_util.h" |
mathp | 94e3f0b | 2015-03-18 00:16:16 | [diff] [blame] | 16 | #include "chrome/browser/browser_process.h" |
[email protected] | 4a8adfa0 | 2013-03-19 22:37:46 | [diff] [blame] | 17 | #include "chrome/browser/infobars/infobar_service.h" |
[email protected] | 7d7e0b7 | 2014-02-10 18:36:05 | [diff] [blame] | 18 | #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
[email protected] | 8d4cc15e | 2012-08-30 00:33:10 | [diff] [blame] | 19 | #include "chrome/browser/profiles/profile.h" |
estade | 494f8e6 | 2015-01-26 23:28:13 | [diff] [blame] | 20 | #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 21 | #include "chrome/browser/signin/signin_manager_factory.h" |
[email protected] | a55c674 | 2013-08-10 07:28:48 | [diff] [blame] | 22 | #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
[email protected] | bfd4b81 | 2013-04-11 02:02:11 | [diff] [blame] | 23 | #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
jdonnelly | 982b06f | 2015-05-19 17:14:20 | [diff] [blame] | 24 | #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h" |
rouslan | 497109da | 2014-11-26 20:30:34 | [diff] [blame] | 25 | #include "chrome/browser/ui/autofill/credit_card_scanner_controller.h" |
bondd | 052b5f8 | 2015-10-28 22:39:32 | [diff] [blame] | 26 | #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" |
[email protected] | cc5419d | 2012-08-30 02:29:46 | [diff] [blame] | 27 | #include "chrome/browser/ui/browser.h" |
| 28 | #include "chrome/browser/ui/browser_finder.h" |
| 29 | #include "chrome/browser/ui/browser_window.h" |
| 30 | #include "chrome/browser/ui/chrome_pages.h" |
[email protected] | 10090d5 | 2013-07-25 20:41:37 | [diff] [blame] | 31 | #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
tfarina | bf215a6f | 2015-06-15 22:24:05 | [diff] [blame] | 32 | #include "chrome/browser/web_data_service_factory.h" |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 33 | #include "chrome/common/features.h" |
[email protected] | cc5419d | 2012-08-30 02:29:46 | [diff] [blame] | 34 | #include "chrome/common/url_constants.h" |
[email protected] | e13549e | 2014-03-12 20:34:36 | [diff] [blame] | 35 | #include "components/autofill/content/browser/content_autofill_driver.h" |
[email protected] | 45b53fb | 2013-12-12 19:28:06 | [diff] [blame] | 36 | #include "components/autofill/content/common/autofill_messages.h" |
pritam.nikam | 2cd65ab9 | 2015-01-13 08:13:02 | [diff] [blame] | 37 | #include "components/autofill/core/browser/autofill_cc_infobar_delegate.h" |
jdonnelly | 982b06f | 2015-05-19 17:14:20 | [diff] [blame] | 38 | #include "components/autofill/core/browser/ui/card_unmask_prompt_view.h" |
[email protected] | 6c7dcb2f2 | 2013-06-22 00:57:48 | [diff] [blame] | 39 | #include "components/autofill/core/common/autofill_pref_names.h" |
bondd | 2ee9bd1d | 2015-12-11 02:56:05 | [diff] [blame] | 40 | #include "components/autofill/core/common/autofill_switches.h" |
estade | b1bc9bd | 2014-12-02 22:44:11 | [diff] [blame] | 41 | #include "components/password_manager/content/browser/content_password_manager_driver.h" |
droger | 7758c11 | 2015-07-15 18:02:26 | [diff] [blame] | 42 | #include "components/signin/core/browser/profile_identity_provider.h" |
jdonnelly | 8d70954 | 2015-04-29 21:58:22 | [diff] [blame] | 43 | #include "components/user_prefs/user_prefs.h" |
sigbjorn | 337de86e | 2015-07-08 10:11:12 | [diff] [blame] | 44 | #include "content/public/browser/navigation_entry.h" |
estade | 1dbe123 | 2015-01-06 22:45:04 | [diff] [blame] | 45 | #include "content/public/browser/render_frame_host.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 46 | #include "ui/gfx/geometry/rect.h" |
[email protected] | 8d4cc15e | 2012-08-30 00:33:10 | [diff] [blame] | 47 | |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 48 | #if BUILDFLAG(ANDROID_JAVA_UI) |
aurimas | 87d357eb | 2015-06-30 17:07:32 | [diff] [blame] | 49 | #include "chrome/browser/android/chrome_application.h" |
[email protected] | 5b466c4 | 2014-02-25 17:56:36 | [diff] [blame] | 50 | #include "chrome/browser/ui/android/autofill/autofill_logger_android.h" |
thestig | 2c8c41e | 2014-10-23 02:56:50 | [diff] [blame] | 51 | #else |
estade | 494f8e6 | 2015-01-26 23:28:13 | [diff] [blame] | 52 | #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
wjmaclean | 7f63c6b | 2014-12-09 14:59:55 | [diff] [blame] | 53 | #include "components/ui/zoom/zoom_controller.h" |
[email protected] | 5b466c4 | 2014-02-25 17:56:36 | [diff] [blame] | 54 | #endif |
| 55 | |
rouslan | acfb6cff | 2016-01-14 20:10:42 | [diff] [blame^] | 56 | #if defined(OS_ANDROID) || defined(OS_IOS) |
| 57 | #include "components/autofill/core/browser/autofill_save_card_infobar_delegate_mobile.h" |
| 58 | #include "components/autofill/core/browser/autofill_save_card_infobar_mobile.h" |
| 59 | #include "components/infobars/core/infobar.h" |
| 60 | #endif |
| 61 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 62 | DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::ChromeAutofillClient); |
[email protected] | bfb4d6721 | 2013-02-14 20:32:29 | [diff] [blame] | 63 | |
| 64 | namespace autofill { |
[email protected] | 698bdf74 | 2012-10-01 21:13:50 | [diff] [blame] | 65 | |
bondd | 2ee9bd1d | 2015-12-11 02:56:05 | [diff] [blame] | 66 | namespace { |
| 67 | |
| 68 | #if !defined(OS_ANDROID) |
| 69 | bool IsSaveCardBubbleEnabled() { |
| 70 | #if defined(OS_MACOSX) |
| 71 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 72 | switches::kEnableSaveCardBubble); |
| 73 | #else |
| 74 | return true; |
| 75 | #endif |
| 76 | } |
| 77 | #endif // !defined(OS_ANDROID) |
| 78 | |
| 79 | } // namespace |
| 80 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 81 | ChromeAutofillClient::ChromeAutofillClient(content::WebContents* web_contents) |
estade | 7c369d4 | 2014-12-18 01:46:23 | [diff] [blame] | 82 | : content::WebContentsObserver(web_contents), |
jdonnelly | 8d70954 | 2015-04-29 21:58:22 | [diff] [blame] | 83 | unmask_controller_( |
jdonnelly | 8d70954 | 2015-04-29 21:58:22 | [diff] [blame] | 84 | user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()), |
| 85 | Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
| 86 | ->IsOffTheRecord()), |
estade | 1dbe123 | 2015-01-06 22:45:04 | [diff] [blame] | 87 | last_rfh_to_rac_(nullptr) { |
[email protected] | 698bdf74 | 2012-10-01 21:13:50 | [diff] [blame] | 88 | DCHECK(web_contents); |
thestig | 2c8c41e | 2014-10-23 02:56:50 | [diff] [blame] | 89 | |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 90 | #if !BUILDFLAG(ANDROID_JAVA_UI) |
[email protected] | 76a5450 | 2014-07-10 22:59:34 | [diff] [blame] | 91 | // Since ZoomController is also a WebContentsObserver, we need to be careful |
| 92 | // about disconnecting from it since the relative order of destruction of |
| 93 | // WebContentsObservers is not guaranteed. ZoomController silently clears |
| 94 | // its ZoomObserver list during WebContentsDestroyed() so there's no need |
| 95 | // to explicitly remove ourselves on destruction. |
wjmaclean | 7f63c6b | 2014-12-09 14:59:55 | [diff] [blame] | 96 | ui_zoom::ZoomController* zoom_controller = |
| 97 | ui_zoom::ZoomController::FromWebContents(web_contents); |
thestig | 2c8c41e | 2014-10-23 02:56:50 | [diff] [blame] | 98 | // There may not always be a ZoomController, e.g. in tests. |
[email protected] | 76a5450 | 2014-07-10 22:59:34 | [diff] [blame] | 99 | if (zoom_controller) |
| 100 | zoom_controller->AddObserver(this); |
thestig | 2c8c41e | 2014-10-23 02:56:50 | [diff] [blame] | 101 | #endif |
[email protected] | 8d4cc15e | 2012-08-30 00:33:10 | [diff] [blame] | 102 | } |
| 103 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 104 | ChromeAutofillClient::~ChromeAutofillClient() { |
[email protected] | 9256a936 | 2013-07-04 22:11:48 | [diff] [blame] | 105 | // NOTE: It is too late to clean up the autofill popup; that cleanup process |
| 106 | // requires that the WebContents instance still be valid and it is not at |
| 107 | // this point (in particular, the WebContentsImpl destructor has already |
| 108 | // finished running and we are now in the base class destructor). |
| 109 | DCHECK(!popup_controller_); |
[email protected] | 8ac8bfd | 2013-02-27 05:18:08 | [diff] [blame] | 110 | } |
| 111 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 112 | void ChromeAutofillClient::TabActivated() { |
[email protected] | 10090d5 | 2013-07-25 20:41:37 | [diff] [blame] | 113 | if (dialog_controller_.get()) |
| 114 | dialog_controller_->TabActivated(); |
| 115 | } |
| 116 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 117 | PersonalDataManager* ChromeAutofillClient::GetPersonalDataManager() { |
[email protected] | 6f3ccf5 | 2013-02-21 03:55:23 | [diff] [blame] | 118 | Profile* profile = |
estade | ecb659d | 2014-12-11 03:53:16 | [diff] [blame] | 119 | Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
[email protected] | 6f3ccf5 | 2013-02-21 03:55:23 | [diff] [blame] | 120 | return PersonalDataManagerFactory::GetForProfile( |
| 121 | profile->GetOriginalProfile()); |
| 122 | } |
| 123 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 124 | scoped_refptr<AutofillWebDataService> ChromeAutofillClient::GetDatabase() { |
[email protected] | 34b5946 | 2013-12-03 14:08:32 | [diff] [blame] | 125 | Profile* profile = |
estade | ecb659d | 2014-12-11 03:53:16 | [diff] [blame] | 126 | Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
[email protected] | 34b5946 | 2013-12-03 14:08:32 | [diff] [blame] | 127 | return WebDataServiceFactory::GetAutofillWebDataForProfile( |
sdefresne | e9ea3c2 | 2015-01-10 10:10:04 | [diff] [blame] | 128 | profile, ServiceAccessType::EXPLICIT_ACCESS); |
[email protected] | 29079a27 | 2013-11-19 14:51:24 | [diff] [blame] | 129 | } |
| 130 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 131 | PrefService* ChromeAutofillClient::GetPrefs() { |
estade | ecb659d | 2014-12-11 03:53:16 | [diff] [blame] | 132 | return Profile::FromBrowserContext(web_contents()->GetBrowserContext()) |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 133 | ->GetPrefs(); |
[email protected] | 8d4cc15e | 2012-08-30 00:33:10 | [diff] [blame] | 134 | } |
| 135 | |
estade | 494f8e6 | 2015-01-26 23:28:13 | [diff] [blame] | 136 | IdentityProvider* ChromeAutofillClient::GetIdentityProvider() { |
| 137 | if (!identity_provider_) { |
| 138 | Profile* profile = |
estade | 1baedb1 | 2015-03-23 22:59:29 | [diff] [blame] | 139 | Profile::FromBrowserContext(web_contents()->GetBrowserContext()) |
| 140 | ->GetOriginalProfile(); |
droger | 7758c11 | 2015-07-15 18:02:26 | [diff] [blame] | 141 | base::Closure login_callback; |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 142 | #if !BUILDFLAG(ANDROID_JAVA_UI) |
droger | 7758c11 | 2015-07-15 18:02:26 | [diff] [blame] | 143 | login_callback = |
| 144 | LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile); |
estade | 494f8e6 | 2015-01-26 23:28:13 | [diff] [blame] | 145 | #endif |
| 146 | identity_provider_.reset(new ProfileIdentityProvider( |
| 147 | SigninManagerFactory::GetForProfile(profile), |
| 148 | ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
droger | 7758c11 | 2015-07-15 18:02:26 | [diff] [blame] | 149 | login_callback)); |
estade | 494f8e6 | 2015-01-26 23:28:13 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | return identity_provider_.get(); |
| 153 | } |
| 154 | |
mathp | 94e3f0b | 2015-03-18 00:16:16 | [diff] [blame] | 155 | rappor::RapporService* ChromeAutofillClient::GetRapporService() { |
| 156 | return g_browser_process->rappor_service(); |
| 157 | } |
| 158 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 159 | void ChromeAutofillClient::ShowAutofillSettings() { |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 160 | #if BUILDFLAG(ANDROID_JAVA_UI) |
aurimas | 87d357eb | 2015-06-30 17:07:32 | [diff] [blame] | 161 | chrome::android::ChromeApplication::ShowAutofillSettings(); |
[email protected] | cc5419d | 2012-08-30 02:29:46 | [diff] [blame] | 162 | #else |
estade | ecb659d | 2014-12-11 03:53:16 | [diff] [blame] | 163 | Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
[email protected] | cc5419d | 2012-08-30 02:29:46 | [diff] [blame] | 164 | if (browser) |
| 165 | chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage); |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 166 | #endif // #if BUILDFLAG(ANDROID_JAVA_UI) |
[email protected] | cc5419d | 2012-08-30 02:29:46 | [diff] [blame] | 167 | } |
| 168 | |
estade | 39f6049 | 2014-12-30 23:35:19 | [diff] [blame] | 169 | void ChromeAutofillClient::ShowUnmaskPrompt( |
| 170 | const CreditCard& card, |
| 171 | base::WeakPtr<CardUnmaskDelegate> delegate) { |
jdonnelly | 982b06f | 2015-05-19 17:14:20 | [diff] [blame] | 172 | unmask_controller_.ShowPrompt( |
| 173 | CreateCardUnmaskPromptView(&unmask_controller_, web_contents()), |
| 174 | card, delegate); |
estade | ecb659d | 2014-12-11 03:53:16 | [diff] [blame] | 175 | } |
| 176 | |
jdonnelly | 171e51e | 2015-11-10 21:45:38 | [diff] [blame] | 177 | void ChromeAutofillClient::OnUnmaskVerificationResult( |
| 178 | PaymentsRpcResult result) { |
estade | fb1d774 | 2015-03-03 02:57:07 | [diff] [blame] | 179 | unmask_controller_.OnVerificationResult(result); |
estade | ecb659d | 2014-12-11 03:53:16 | [diff] [blame] | 180 | } |
| 181 | |
jdonnelly | 171e51e | 2015-11-10 21:45:38 | [diff] [blame] | 182 | void ChromeAutofillClient::ConfirmSaveCreditCardLocally( |
rouslan | acfb6cff | 2016-01-14 20:10:42 | [diff] [blame^] | 183 | const CreditCard& card, |
jdonnelly | 171e51e | 2015-11-10 21:45:38 | [diff] [blame] | 184 | const base::Closure& callback) { |
rouslan | acfb6cff | 2016-01-14 20:10:42 | [diff] [blame^] | 185 | #if defined(OS_ANDROID) || defined(OS_IOS) |
| 186 | InfoBarService::FromWebContents(web_contents())->AddInfoBar( |
| 187 | CreateSaveCardInfoBarMobile( |
| 188 | make_scoped_ptr(new AutofillSaveCardInfoBarDelegateMobile( |
| 189 | false, card, scoped_ptr<base::DictionaryValue>(nullptr), |
| 190 | callback)))); |
| 191 | #else |
bondd | 2ee9bd1d | 2015-12-11 02:56:05 | [diff] [blame] | 192 | if (IsSaveCardBubbleEnabled()) { |
| 193 | // Do lazy initialization of SaveCardBubbleControllerImpl. |
| 194 | autofill::SaveCardBubbleControllerImpl::CreateForWebContents( |
| 195 | web_contents()); |
| 196 | autofill::SaveCardBubbleControllerImpl* controller = |
| 197 | autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents()); |
| 198 | controller->ShowBubbleForLocalSave(callback); |
| 199 | return; |
| 200 | } |
rouslan | acfb6cff | 2016-01-14 20:10:42 | [diff] [blame^] | 201 | |
rouslan | 752b87c | 2015-12-17 23:08:50 | [diff] [blame] | 202 | AutofillCCInfoBarDelegate::CreateForLocalSave( |
| 203 | InfoBarService::FromWebContents(web_contents()), callback); |
rouslan | acfb6cff | 2016-01-14 20:10:42 | [diff] [blame^] | 204 | #endif |
[email protected] | 90804a50 | 2013-03-06 22:07:18 | [diff] [blame] | 205 | } |
| 206 | |
jdonnelly | 171e51e | 2015-11-10 21:45:38 | [diff] [blame] | 207 | void ChromeAutofillClient::ConfirmSaveCreditCardToCloud( |
rouslan | acfb6cff | 2016-01-14 20:10:42 | [diff] [blame^] | 208 | const CreditCard& card, |
| 209 | scoped_ptr<base::DictionaryValue> legal_message, |
| 210 | const base::Closure& callback) { |
| 211 | #if defined(OS_ANDROID) || defined(OS_IOS) |
| 212 | InfoBarService::FromWebContents(web_contents())->AddInfoBar( |
| 213 | CreateSaveCardInfoBarMobile( |
| 214 | make_scoped_ptr(new AutofillSaveCardInfoBarDelegateMobile( |
| 215 | true, card, std::move(legal_message), callback)))); |
rouslan | 752b87c | 2015-12-17 23:08:50 | [diff] [blame] | 216 | #else |
jdonnelly | b417226c | 2015-11-18 00:38:23 | [diff] [blame] | 217 | // Do lazy initialization of SaveCardBubbleControllerImpl. |
| 218 | autofill::SaveCardBubbleControllerImpl::CreateForWebContents(web_contents()); |
| 219 | autofill::SaveCardBubbleControllerImpl* controller = |
| 220 | autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents()); |
dcheng | 4a9d982 | 2015-12-26 22:35:30 | [diff] [blame] | 221 | controller->ShowBubbleForUpload(callback, std::move(legal_message)); |
jdonnelly | b417226c | 2015-11-18 00:38:23 | [diff] [blame] | 222 | #endif |
jdonnelly | 171e51e | 2015-11-10 21:45:38 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | void ChromeAutofillClient::LoadRiskData( |
| 226 | const base::Callback<void(const std::string&)>& callback) { |
| 227 | ::autofill::LoadRiskData(0, web_contents(), callback); |
| 228 | } |
| 229 | |
rouslan | 497109da | 2014-11-26 20:30:34 | [diff] [blame] | 230 | bool ChromeAutofillClient::HasCreditCardScanFeature() { |
| 231 | return CreditCardScannerController::HasCreditCardScanFeature(); |
| 232 | } |
| 233 | |
| 234 | void ChromeAutofillClient::ScanCreditCard( |
| 235 | const CreditCardScanCallback& callback) { |
| 236 | CreditCardScannerController::ScanCreditCard(web_contents(), callback); |
| 237 | } |
| 238 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 239 | void ChromeAutofillClient::ShowRequestAutocompleteDialog( |
[email protected] | 4ff3252 | 2013-01-26 00:37:58 | [diff] [blame] | 240 | const FormData& form, |
estade | 1dbe123 | 2015-01-06 22:45:04 | [diff] [blame] | 241 | content::RenderFrameHost* render_frame_host, |
[email protected] | ce24d87 | 2014-04-11 20:45:28 | [diff] [blame] | 242 | const ResultCallback& callback) { |
[email protected] | 364481b | 2013-01-29 01:52:28 | [diff] [blame] | 243 | HideRequestAutocompleteDialog(); |
estade | 1dbe123 | 2015-01-06 22:45:04 | [diff] [blame] | 244 | last_rfh_to_rac_ = render_frame_host; |
| 245 | GURL frame_url = render_frame_host->GetLastCommittedURL(); |
estade | ecb659d | 2014-12-11 03:53:16 | [diff] [blame] | 246 | dialog_controller_ = AutofillDialogController::Create(web_contents(), form, |
estade | 1dbe123 | 2015-01-06 22:45:04 | [diff] [blame] | 247 | frame_url, callback); |
[email protected] | a55c674 | 2013-08-10 07:28:48 | [diff] [blame] | 248 | if (dialog_controller_) { |
| 249 | dialog_controller_->Show(); |
| 250 | } else { |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 251 | callback.Run(AutofillClient::AutocompleteResultErrorDisabled, |
[email protected] | dbdd6027 | 2014-04-14 22:48:40 | [diff] [blame] | 252 | base::string16(), |
[email protected] | ce24d87 | 2014-04-11 20:45:28 | [diff] [blame] | 253 | NULL); |
[email protected] | a55c674 | 2013-08-10 07:28:48 | [diff] [blame] | 254 | NOTIMPLEMENTED(); |
| 255 | } |
[email protected] | 364481b | 2013-01-29 01:52:28 | [diff] [blame] | 256 | } |
| 257 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 258 | void ChromeAutofillClient::ShowAutofillPopup( |
[email protected] | 8ac8bfd | 2013-02-27 05:18:08 | [diff] [blame] | 259 | const gfx::RectF& element_bounds, |
[email protected] | 46cb7e9 | 2013-06-12 15:32:31 | [diff] [blame] | 260 | base::i18n::TextDirection text_direction, |
brettw | 5f88815 | 2014-12-15 23:31:26 | [diff] [blame] | 261 | const std::vector<autofill::Suggestion>& suggestions, |
[email protected] | 1f66a389 | 2013-04-22 18:57:14 | [diff] [blame] | 262 | base::WeakPtr<AutofillPopupDelegate> delegate) { |
[email protected] | 8ac8bfd | 2013-02-27 05:18:08 | [diff] [blame] | 263 | // Convert element_bounds to be in screen space. |
estade | ecb659d | 2014-12-11 03:53:16 | [diff] [blame] | 264 | gfx::Rect client_area = web_contents()->GetContainerBounds(); |
[email protected] | 8ac8bfd | 2013-02-27 05:18:08 | [diff] [blame] | 265 | gfx::RectF element_bounds_in_screen_space = |
| 266 | element_bounds + client_area.OffsetFromOrigin(); |
| 267 | |
| 268 | // Will delete or reuse the old |popup_controller_|. |
noms | 9139a6a | 2015-02-19 19:42:29 | [diff] [blame] | 269 | popup_controller_ = |
| 270 | AutofillPopupControllerImpl::GetOrCreate(popup_controller_, |
| 271 | delegate, |
| 272 | web_contents(), |
| 273 | web_contents()->GetNativeView(), |
| 274 | element_bounds_in_screen_space, |
| 275 | text_direction); |
[email protected] | 8ac8bfd | 2013-02-27 05:18:08 | [diff] [blame] | 276 | |
brettw | 5f88815 | 2014-12-15 23:31:26 | [diff] [blame] | 277 | popup_controller_->Show(suggestions); |
[email protected] | 8ac8bfd | 2013-02-27 05:18:08 | [diff] [blame] | 278 | } |
| 279 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 280 | void ChromeAutofillClient::UpdateAutofillPopupDataListValues( |
[email protected] | ead7fb0 | 2013-07-18 18:50:12 | [diff] [blame] | 281 | const std::vector<base::string16>& values, |
| 282 | const std::vector<base::string16>& labels) { |
| 283 | if (popup_controller_.get()) |
| 284 | popup_controller_->UpdateDataListValues(values, labels); |
| 285 | } |
| 286 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 287 | void ChromeAutofillClient::HideAutofillPopup() { |
[email protected] | e8dad9b | 2013-06-04 04:43:45 | [diff] [blame] | 288 | if (popup_controller_.get()) |
[email protected] | 8ac8bfd | 2013-02-27 05:18:08 | [diff] [blame] | 289 | popup_controller_->Hide(); |
[email protected] | 3cbdf936 | 2014-01-31 23:12:23 | [diff] [blame] | 290 | |
| 291 | // Password generation popups behave in the same fashion and should also |
| 292 | // be hidden. |
[email protected] | 53e4e6d | 2014-02-25 14:09:43 | [diff] [blame] | 293 | ChromePasswordManagerClient* password_client = |
estade | ecb659d | 2014-12-11 03:53:16 | [diff] [blame] | 294 | ChromePasswordManagerClient::FromWebContents(web_contents()); |
[email protected] | 53e4e6d | 2014-02-25 14:09:43 | [diff] [blame] | 295 | if (password_client) |
| 296 | password_client->HidePasswordGenerationPopup(); |
[email protected] | 364481b | 2013-01-29 01:52:28 | [diff] [blame] | 297 | } |
| 298 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 299 | bool ChromeAutofillClient::IsAutocompleteEnabled() { |
[email protected] | 6c7dcb2f2 | 2013-06-22 00:57:48 | [diff] [blame] | 300 | // For browser, Autocomplete is always enabled as part of Autofill. |
| 301 | return GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
| 302 | } |
| 303 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 304 | void ChromeAutofillClient::HideRequestAutocompleteDialog() { |
estade | 1dbe123 | 2015-01-06 22:45:04 | [diff] [blame] | 305 | if (dialog_controller_) |
[email protected] | 8ac8bfd | 2013-02-27 05:18:08 | [diff] [blame] | 306 | dialog_controller_->Hide(); |
[email protected] | 364481b | 2013-01-29 01:52:28 | [diff] [blame] | 307 | } |
| 308 | |
estade | 1dbe123 | 2015-01-06 22:45:04 | [diff] [blame] | 309 | void ChromeAutofillClient::RenderFrameDeleted( |
| 310 | content::RenderFrameHost* render_frame_host) { |
| 311 | if (dialog_controller_ && render_frame_host == last_rfh_to_rac_) |
| 312 | HideRequestAutocompleteDialog(); |
| 313 | } |
| 314 | |
| 315 | void ChromeAutofillClient::DidNavigateAnyFrame( |
| 316 | content::RenderFrameHost* render_frame_host, |
| 317 | const content::LoadCommittedDetails& details, |
| 318 | const content::FrameNavigateParams& params) { |
| 319 | if (dialog_controller_ && render_frame_host == last_rfh_to_rac_) |
| 320 | HideRequestAutocompleteDialog(); |
| 321 | } |
| 322 | |
rouslan | 2f5993f | 2015-01-29 00:18:31 | [diff] [blame] | 323 | void ChromeAutofillClient::MainFrameWasResized(bool width_changed) { |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 324 | #if BUILDFLAG(ANDROID_JAVA_UI) |
rouslan | 2f5993f | 2015-01-29 00:18:31 | [diff] [blame] | 325 | // Ignore virtual keyboard showing and hiding a strip of suggestions. |
| 326 | if (!width_changed) |
| 327 | return; |
| 328 | #endif |
| 329 | |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 330 | HideAutofillPopup(); |
| 331 | } |
| 332 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 333 | void ChromeAutofillClient::WebContentsDestroyed() { |
[email protected] | 9256a936 | 2013-07-04 22:11:48 | [diff] [blame] | 334 | HideAutofillPopup(); |
| 335 | } |
| 336 | |
[email protected] | 76a5450 | 2014-07-10 22:59:34 | [diff] [blame] | 337 | void ChromeAutofillClient::OnZoomChanged( |
wjmaclean | 7f63c6b | 2014-12-09 14:59:55 | [diff] [blame] | 338 | const ui_zoom::ZoomController::ZoomChangedEventData& data) { |
[email protected] | 76a5450 | 2014-07-10 22:59:34 | [diff] [blame] | 339 | HideAutofillPopup(); |
| 340 | } |
| 341 | |
dvadym | 89bccb1e | 2015-04-01 17:43:59 | [diff] [blame] | 342 | void ChromeAutofillClient::PropagateAutofillPredictions( |
estade | b1bc9bd | 2014-12-02 22:44:11 | [diff] [blame] | 343 | content::RenderFrameHost* rfh, |
[email protected] | 375564a | 2013-09-06 20:36:40 | [diff] [blame] | 344 | const std::vector<autofill::FormStructure*>& forms) { |
estade | cde16351 | 2014-12-04 22:14:05 | [diff] [blame] | 345 | password_manager::ContentPasswordManagerDriver* driver = |
| 346 | password_manager::ContentPasswordManagerDriver::GetForRenderFrameHost( |
| 347 | rfh); |
dvadym | 89bccb1e | 2015-04-01 17:43:59 | [diff] [blame] | 348 | if (driver) { |
dvadym | 189e588d | 2015-12-14 12:57:52 | [diff] [blame] | 349 | driver->GetPasswordGenerationManager()->DetectFormsEligibleForGeneration( |
| 350 | forms); |
dvadym | 89bccb1e | 2015-04-01 17:43:59 | [diff] [blame] | 351 | driver->GetPasswordManager()->ProcessAutofillPredictions(driver, forms); |
| 352 | } |
[email protected] | 375564a | 2013-09-06 20:36:40 | [diff] [blame] | 353 | } |
| 354 | |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 355 | void ChromeAutofillClient::DidFillOrPreviewField( |
[email protected] | 5b466c4 | 2014-02-25 17:56:36 | [diff] [blame] | 356 | const base::string16& autofilled_value, |
| 357 | const base::string16& profile_full_name) { |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 358 | #if BUILDFLAG(ANDROID_JAVA_UI) |
[email protected] | b4db6d4 | 2014-06-07 04:36:58 | [diff] [blame] | 359 | AutofillLoggerAndroid::DidFillOrPreviewField(autofilled_value, |
| 360 | profile_full_name); |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 361 | #endif // BUILDFLAG(ANDROID_JAVA_UI) |
[email protected] | 5b466c4 | 2014-02-25 17:56:36 | [diff] [blame] | 362 | } |
| 363 | |
estade | b1bc9bd | 2014-12-02 22:44:11 | [diff] [blame] | 364 | void ChromeAutofillClient::OnFirstUserGestureObserved() { |
| 365 | web_contents()->SendToAllFrames( |
| 366 | new AutofillMsg_FirstUserGestureObservedInTab(routing_id())); |
| 367 | } |
| 368 | |
sigbjorn | 337de86e | 2015-07-08 10:11:12 | [diff] [blame] | 369 | bool ChromeAutofillClient::IsContextSecure(const GURL& form_origin) { |
| 370 | content::SSLStatus ssl_status; |
| 371 | content::NavigationEntry* navigation_entry = |
| 372 | web_contents()->GetController().GetLastCommittedEntry(); |
| 373 | if (!navigation_entry) |
| 374 | return false; |
| 375 | |
| 376 | ssl_status = navigation_entry->GetSSL(); |
| 377 | // Note: If changing the implementation below, also change |
| 378 | // AwAutofillClient::IsContextSecure. See crbug.com/505388 |
| 379 | return ssl_status.security_style == |
| 380 | content::SECURITY_STYLE_AUTHENTICATED && |
| 381 | ssl_status.content_status == content::SSLStatus::NORMAL_CONTENT; |
| 382 | } |
| 383 | |
[email protected] | bfb4d6721 | 2013-02-14 20:32:29 | [diff] [blame] | 384 | } // namespace autofill |