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