blob: b07197148b8ce6a0d9d4ad1adb1d3adf91f672f8 [file] [log] [blame]
[email protected]b4db6d42014-06-07 04:36:581// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]8d4cc15e2012-08-30 00:33:102// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]b4db6d42014-06-07 04:36:585#include "chrome/browser/ui/autofill/chrome_autofill_client.h"
[email protected]8d4cc15e2012-08-30 00:33:106
dcheng4a9d9822015-12-26 22:35:307#include <utility>
8
jdonnelly8d709542015-04-29 21:58:229#include "base/bind.h"
bondd2ee9bd1d2015-12-11 02:56:0510#include "base/command_line.h"
[email protected]8d4cc15e2012-08-30 00:33:1011#include "base/logging.h"
dcheng9603ab92016-04-08 04:17:3212#include "base/memory/ptr_util.h"
avi655876a2015-12-25 07:18:1513#include "build/build_config.h"
[email protected]6f3ccf52013-02-21 03:55:2314#include "chrome/browser/autofill/personal_data_manager_factory.h"
jdonnelly8d709542015-04-29 21:58:2215#include "chrome/browser/autofill/risk_util.h"
mathp94e3f0b2015-03-18 00:16:1616#include "chrome/browser/browser_process.h"
[email protected]7d7e0b72014-02-10 18:36:0517#include "chrome/browser/password_manager/chrome_password_manager_client.h"
[email protected]8d4cc15e2012-08-30 00:33:1018#include "chrome/browser/profiles/profile.h"
mathp664a4cf2016-07-19 22:07:0719#include "chrome/browser/profiles/profile_manager.h"
estade494f8e62015-01-26 23:28:1320#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
21#include "chrome/browser/signin/signin_manager_factory.h"
mathp664a4cf2016-07-19 22:07:0722#include "chrome/browser/signin/signin_promo_util.h"
jdonnelly066021e2016-01-15 16:27:5723#include "chrome/browser/sync/profile_sync_service_factory.h"
[email protected]bfd4b812013-04-11 02:02:1124#include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
jdonnelly982b06f2015-05-19 17:14:2025#include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h"
rouslan497109da2014-11-26 20:30:3426#include "chrome/browser/ui/autofill/credit_card_scanner_controller.h"
bondd052b5f82015-10-28 22:39:3227#include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
[email protected]cc5419d2012-08-30 02:29:4628#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]10090d52013-07-25 20:41:3732#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
tfarinabf215a6f2015-06-15 22:24:0533#include "chrome/browser/web_data_service_factory.h"
sievers2f1e8112015-12-04 18:43:5634#include "chrome/common/features.h"
[email protected]cc5419d2012-08-30 02:29:4635#include "chrome/common/url_constants.h"
[email protected]e13549e2014-03-12 20:34:3636#include "components/autofill/content/browser/content_autofill_driver.h"
leon.hande852902016-05-04 09:16:3837#include "components/autofill/content/browser/content_autofill_driver_factory.h"
[email protected]45b53fb2013-12-12 19:28:0638#include "components/autofill/content/common/autofill_messages.h"
jdonnelly982b06f2015-05-19 17:14:2039#include "components/autofill/core/browser/ui/card_unmask_prompt_view.h"
[email protected]6c7dcb2f22013-06-22 00:57:4840#include "components/autofill/core/common/autofill_pref_names.h"
bondd2ee9bd1d2015-12-11 02:56:0541#include "components/autofill/core/common/autofill_switches.h"
jdonnelly066021e2016-01-15 16:27:5742#include "components/browser_sync/browser/profile_sync_service.h"
estadeb1bc9bd2014-12-02 22:44:1143#include "components/password_manager/content/browser/content_password_manager_driver.h"
brettwb1fc1b82016-02-02 00:19:0844#include "components/prefs/pref_service.h"
droger7758c112015-07-15 18:02:2645#include "components/signin/core/browser/profile_identity_provider.h"
mathp4d08afd62016-07-08 19:54:1046#include "components/signin/core/browser/signin_header_helper.h"
47#include "components/signin/core/browser/signin_metrics.h"
jdonnelly8d709542015-04-29 21:58:2248#include "components/user_prefs/user_prefs.h"
sigbjorn337de86e2015-07-08 10:11:1249#include "content/public/browser/navigation_entry.h"
estade1dbe1232015-01-06 22:45:0450#include "content/public/browser/render_frame_host.h"
tfarina3b0452d2014-12-31 15:20:0951#include "ui/gfx/geometry/rect.h"
[email protected]8d4cc15e2012-08-30 00:33:1052
sievers2f1e8112015-12-04 18:43:5653#if BUILDFLAG(ANDROID_JAVA_UI)
aurimas87d357eb2015-06-30 17:07:3254#include "chrome/browser/android/chrome_application.h"
[email protected]5b466c42014-02-25 17:56:3655#include "chrome/browser/ui/android/autofill/autofill_logger_android.h"
thestig2c8c41e2014-10-23 02:56:5056#else
estade494f8e62015-01-26 23:28:1357#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
juncaia64f769c22016-06-04 00:55:3258#include "components/zoom/zoom_controller.h"
[email protected]5b466c42014-02-25 17:56:3659#endif
60
jam1c5a91492016-02-24 20:47:5361#if defined(OS_ANDROID)
mathp664a4cf2016-07-19 22:07:0762#include "base/android/context_utils.h"
63#include "chrome/browser/android/signin/signin_promo_util_android.h"
mathpf43ced42016-08-04 18:28:2364#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"
rouslanacfb6cff2016-01-14 20:10:4267#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"
mathp664a4cf2016-07-19 22:07:0770#include "content/public/browser/android/content_view_core.h"
rouslanacfb6cff2016-01-14 20:10:4271#endif
72
[email protected]b4db6d42014-06-07 04:36:5873DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::ChromeAutofillClient);
[email protected]bfb4d67212013-02-14 20:32:2974
75namespace autofill {
[email protected]698bdf742012-10-01 21:13:5076
[email protected]b4db6d42014-06-07 04:36:5877ChromeAutofillClient::ChromeAutofillClient(content::WebContents* web_contents)
estade7c369d42014-12-18 01:46:2378 : content::WebContentsObserver(web_contents),
jdonnelly8d709542015-04-29 21:58:2279 unmask_controller_(
jdonnelly8d709542015-04-29 21:58:2280 user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()),
81 Profile::FromBrowserContext(web_contents->GetBrowserContext())
estadee62c2a42016-05-05 16:27:2982 ->IsOffTheRecord()) {
[email protected]698bdf742012-10-01 21:13:5083 DCHECK(web_contents);
thestig2c8c41e2014-10-23 02:56:5084
sievers2f1e8112015-12-04 18:43:5685#if !BUILDFLAG(ANDROID_JAVA_UI)
[email protected]76a54502014-07-10 22:59:3486 // 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.
juncaia64f769c22016-06-04 00:55:3291 zoom::ZoomController* zoom_controller =
92 zoom::ZoomController::FromWebContents(web_contents);
thestig2c8c41e2014-10-23 02:56:5093 // There may not always be a ZoomController, e.g. in tests.
[email protected]76a54502014-07-10 22:59:3494 if (zoom_controller)
95 zoom_controller->AddObserver(this);
thestig2c8c41e2014-10-23 02:56:5096#endif
[email protected]8d4cc15e2012-08-30 00:33:1097}
98
[email protected]b4db6d42014-06-07 04:36:5899ChromeAutofillClient::~ChromeAutofillClient() {
[email protected]9256a9362013-07-04 22:11:48100 // 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]8ac8bfd2013-02-27 05:18:08105}
106
[email protected]b4db6d42014-06-07 04:36:58107PersonalDataManager* ChromeAutofillClient::GetPersonalDataManager() {
[email protected]6f3ccf52013-02-21 03:55:23108 Profile* profile =
estadeecb659d2014-12-11 03:53:16109 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
[email protected]6f3ccf52013-02-21 03:55:23110 return PersonalDataManagerFactory::GetForProfile(
111 profile->GetOriginalProfile());
112}
113
[email protected]b4db6d42014-06-07 04:36:58114scoped_refptr<AutofillWebDataService> ChromeAutofillClient::GetDatabase() {
[email protected]34b59462013-12-03 14:08:32115 Profile* profile =
estadeecb659d2014-12-11 03:53:16116 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
[email protected]34b59462013-12-03 14:08:32117 return WebDataServiceFactory::GetAutofillWebDataForProfile(
sdefresnee9ea3c22015-01-10 10:10:04118 profile, ServiceAccessType::EXPLICIT_ACCESS);
[email protected]29079a272013-11-19 14:51:24119}
120
[email protected]b4db6d42014-06-07 04:36:58121PrefService* ChromeAutofillClient::GetPrefs() {
estadeecb659d2014-12-11 03:53:16122 return Profile::FromBrowserContext(web_contents()->GetBrowserContext())
[email protected]b4db6d42014-06-07 04:36:58123 ->GetPrefs();
[email protected]8d4cc15e2012-08-30 00:33:10124}
125
jdonnelly066021e2016-01-15 16:27:57126sync_driver::SyncService* ChromeAutofillClient::GetSyncService() {
127 Profile* profile =
128 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
129 return ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
130}
131
estade494f8e62015-01-26 23:28:13132IdentityProvider* ChromeAutofillClient::GetIdentityProvider() {
133 if (!identity_provider_) {
134 Profile* profile =
estade1baedb12015-03-23 22:59:29135 Profile::FromBrowserContext(web_contents()->GetBrowserContext())
136 ->GetOriginalProfile();
droger7758c112015-07-15 18:02:26137 base::Closure login_callback;
sievers2f1e8112015-12-04 18:43:56138#if !BUILDFLAG(ANDROID_JAVA_UI)
droger7758c112015-07-15 18:02:26139 login_callback =
140 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile);
estade494f8e62015-01-26 23:28:13141#endif
142 identity_provider_.reset(new ProfileIdentityProvider(
143 SigninManagerFactory::GetForProfile(profile),
144 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
droger7758c112015-07-15 18:02:26145 login_callback));
estade494f8e62015-01-26 23:28:13146 }
147
148 return identity_provider_.get();
149}
150
mathp94e3f0b2015-03-18 00:16:16151rappor::RapporService* ChromeAutofillClient::GetRapporService() {
152 return g_browser_process->rappor_service();
153}
154
[email protected]b4db6d42014-06-07 04:36:58155void ChromeAutofillClient::ShowAutofillSettings() {
sievers2f1e8112015-12-04 18:43:56156#if BUILDFLAG(ANDROID_JAVA_UI)
aurimas87d357eb2015-06-30 17:07:32157 chrome::android::ChromeApplication::ShowAutofillSettings();
[email protected]cc5419d2012-08-30 02:29:46158#else
estadeecb659d2014-12-11 03:53:16159 Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
[email protected]cc5419d2012-08-30 02:29:46160 if (browser)
161 chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage);
sievers2f1e8112015-12-04 18:43:56162#endif // #if BUILDFLAG(ANDROID_JAVA_UI)
[email protected]cc5419d2012-08-30 02:29:46163}
164
estade39f60492014-12-30 23:35:19165void ChromeAutofillClient::ShowUnmaskPrompt(
166 const CreditCard& card,
rouslan23c6e8242016-04-20 00:04:19167 UnmaskCardReason reason,
estade39f60492014-12-30 23:35:19168 base::WeakPtr<CardUnmaskDelegate> delegate) {
jdonnelly982b06f2015-05-19 17:14:20169 unmask_controller_.ShowPrompt(
170 CreateCardUnmaskPromptView(&unmask_controller_, web_contents()),
rouslan23c6e8242016-04-20 00:04:19171 card, reason, delegate);
estadeecb659d2014-12-11 03:53:16172}
173
jdonnelly171e51e2015-11-10 21:45:38174void ChromeAutofillClient::OnUnmaskVerificationResult(
175 PaymentsRpcResult result) {
estadefb1d7742015-03-03 02:57:07176 unmask_controller_.OnVerificationResult(result);
estadeecb659d2014-12-11 03:53:16177}
178
jdonnelly171e51e2015-11-10 21:45:38179void ChromeAutofillClient::ConfirmSaveCreditCardLocally(
rouslanacfb6cff2016-01-14 20:10:42180 const CreditCard& card,
jdonnelly171e51e2015-11-10 21:45:38181 const base::Closure& callback) {
jam1c5a91492016-02-24 20:47:53182#if defined(OS_ANDROID)
dcheng9603ab92016-04-08 04:17:32183 InfoBarService::FromWebContents(web_contents())
184 ->AddInfoBar(CreateSaveCardInfoBarMobile(
185 base::WrapUnique(new AutofillSaveCardInfoBarDelegateMobile(
186 false, card, std::unique_ptr<base::DictionaryValue>(nullptr),
rouslanacfb6cff2016-01-14 20:10:42187 callback))));
188#else
jdonnellyf41a22112016-03-09 05:13:01189 // 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);
rouslanacfb6cff2016-01-14 20:10:42195#endif
[email protected]90804a502013-03-06 22:07:18196}
197
jdonnelly171e51e2015-11-10 21:45:38198void ChromeAutofillClient::ConfirmSaveCreditCardToCloud(
rouslanacfb6cff2016-01-14 20:10:42199 const CreditCard& card,
dcheng9603ab92016-04-08 04:17:32200 std::unique_ptr<base::DictionaryValue> legal_message,
rouslanacfb6cff2016-01-14 20:10:42201 const base::Closure& callback) {
jam1c5a91492016-02-24 20:47:53202#if defined(OS_ANDROID)
dcheng9603ab92016-04-08 04:17:32203 InfoBarService::FromWebContents(web_contents())
204 ->AddInfoBar(CreateSaveCardInfoBarMobile(
205 base::WrapUnique(new AutofillSaveCardInfoBarDelegateMobile(
rouslanacfb6cff2016-01-14 20:10:42206 true, card, std::move(legal_message), callback))));
rouslan752b87c2015-12-17 23:08:50207#else
jdonnellyb417226c2015-11-18 00:38:23208 // Do lazy initialization of SaveCardBubbleControllerImpl.
209 autofill::SaveCardBubbleControllerImpl::CreateForWebContents(web_contents());
210 autofill::SaveCardBubbleControllerImpl* controller =
211 autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents());
jdonnelly03a9d962016-01-15 01:11:42212 controller->ShowBubbleForUpload(card, std::move(legal_message), callback);
jdonnellyb417226c2015-11-18 00:38:23213#endif
jdonnelly171e51e2015-11-10 21:45:38214}
215
mathpf43ced42016-08-04 18:28:23216void 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
jdonnelly171e51e2015-11-10 21:45:38232void ChromeAutofillClient::LoadRiskData(
233 const base::Callback<void(const std::string&)>& callback) {
234 ::autofill::LoadRiskData(0, web_contents(), callback);
235}
236
rouslan497109da2014-11-26 20:30:34237bool ChromeAutofillClient::HasCreditCardScanFeature() {
238 return CreditCardScannerController::HasCreditCardScanFeature();
239}
240
241void ChromeAutofillClient::ScanCreditCard(
242 const CreditCardScanCallback& callback) {
243 CreditCardScannerController::ScanCreditCard(web_contents(), callback);
244}
245
[email protected]b4db6d42014-06-07 04:36:58246void ChromeAutofillClient::ShowAutofillPopup(
[email protected]8ac8bfd2013-02-27 05:18:08247 const gfx::RectF& element_bounds,
[email protected]46cb7e92013-06-12 15:32:31248 base::i18n::TextDirection text_direction,
brettw5f888152014-12-15 23:31:26249 const std::vector<autofill::Suggestion>& suggestions,
[email protected]1f66a3892013-04-22 18:57:14250 base::WeakPtr<AutofillPopupDelegate> delegate) {
[email protected]8ac8bfd2013-02-27 05:18:08251 // Convert element_bounds to be in screen space.
estadeecb659d2014-12-11 03:53:16252 gfx::Rect client_area = web_contents()->GetContainerBounds();
[email protected]8ac8bfd2013-02-27 05:18:08253 gfx::RectF element_bounds_in_screen_space =
254 element_bounds + client_area.OffsetFromOrigin();
255
256 // Will delete or reuse the old |popup_controller_|.
noms9139a6a2015-02-19 19:42:29257 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]8ac8bfd2013-02-27 05:18:08264
brettw5f888152014-12-15 23:31:26265 popup_controller_->Show(suggestions);
[email protected]8ac8bfd2013-02-27 05:18:08266}
267
[email protected]b4db6d42014-06-07 04:36:58268void ChromeAutofillClient::UpdateAutofillPopupDataListValues(
[email protected]ead7fb02013-07-18 18:50:12269 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]b4db6d42014-06-07 04:36:58275void ChromeAutofillClient::HideAutofillPopup() {
[email protected]e8dad9b2013-06-04 04:43:45276 if (popup_controller_.get())
[email protected]8ac8bfd2013-02-27 05:18:08277 popup_controller_->Hide();
[email protected]3cbdf9362014-01-31 23:12:23278
279 // Password generation popups behave in the same fashion and should also
280 // be hidden.
[email protected]53e4e6d2014-02-25 14:09:43281 ChromePasswordManagerClient* password_client =
estadeecb659d2014-12-11 03:53:16282 ChromePasswordManagerClient::FromWebContents(web_contents());
[email protected]53e4e6d2014-02-25 14:09:43283 if (password_client)
284 password_client->HidePasswordGenerationPopup();
[email protected]364481b2013-01-29 01:52:28285}
286
[email protected]b4db6d42014-06-07 04:36:58287bool ChromeAutofillClient::IsAutocompleteEnabled() {
[email protected]6c7dcb2f22013-06-22 00:57:48288 // For browser, Autocomplete is always enabled as part of Autofill.
289 return GetPrefs()->GetBoolean(prefs::kAutofillEnabled);
290}
291
rouslan2f5993f2015-01-29 00:18:31292void ChromeAutofillClient::MainFrameWasResized(bool width_changed) {
sievers2f1e8112015-12-04 18:43:56293#if BUILDFLAG(ANDROID_JAVA_UI)
rouslan2f5993f2015-01-29 00:18:31294 // Ignore virtual keyboard showing and hiding a strip of suggestions.
295 if (!width_changed)
296 return;
297#endif
298
estaded0a0c992015-01-21 14:12:06299 HideAutofillPopup();
300}
301
[email protected]b4db6d42014-06-07 04:36:58302void ChromeAutofillClient::WebContentsDestroyed() {
[email protected]9256a9362013-07-04 22:11:48303 HideAutofillPopup();
304}
305
[email protected]76a54502014-07-10 22:59:34306void ChromeAutofillClient::OnZoomChanged(
juncaia64f769c22016-06-04 00:55:32307 const zoom::ZoomController::ZoomChangedEventData& data) {
[email protected]76a54502014-07-10 22:59:34308 HideAutofillPopup();
309}
310
dvadym89bccb1e2015-04-01 17:43:59311void ChromeAutofillClient::PropagateAutofillPredictions(
estadeb1bc9bd2014-12-02 22:44:11312 content::RenderFrameHost* rfh,
[email protected]375564a2013-09-06 20:36:40313 const std::vector<autofill::FormStructure*>& forms) {
estadecde163512014-12-04 22:14:05314 password_manager::ContentPasswordManagerDriver* driver =
315 password_manager::ContentPasswordManagerDriver::GetForRenderFrameHost(
316 rfh);
dvadym89bccb1e2015-04-01 17:43:59317 if (driver) {
dvadym189e588d2015-12-14 12:57:52318 driver->GetPasswordGenerationManager()->DetectFormsEligibleForGeneration(
319 forms);
dvadym89bccb1e2015-04-01 17:43:59320 driver->GetPasswordManager()->ProcessAutofillPredictions(driver, forms);
321 }
[email protected]375564a2013-09-06 20:36:40322}
323
[email protected]b4db6d42014-06-07 04:36:58324void ChromeAutofillClient::DidFillOrPreviewField(
[email protected]5b466c42014-02-25 17:56:36325 const base::string16& autofilled_value,
326 const base::string16& profile_full_name) {
sievers2f1e8112015-12-04 18:43:56327#if BUILDFLAG(ANDROID_JAVA_UI)
[email protected]b4db6d42014-06-07 04:36:58328 AutofillLoggerAndroid::DidFillOrPreviewField(autofilled_value,
329 profile_full_name);
sievers2f1e8112015-12-04 18:43:56330#endif // BUILDFLAG(ANDROID_JAVA_UI)
[email protected]5b466c42014-02-25 17:56:36331}
332
estadeb1bc9bd2014-12-02 22:44:11333void ChromeAutofillClient::OnFirstUserGestureObserved() {
leon.hande852902016-05-04 09:16:38334 ContentAutofillDriverFactory* factory =
335 ContentAutofillDriverFactory::FromWebContents(web_contents());
336 DCHECK(factory);
337
338 for (content::RenderFrameHost* frame : web_contents()->GetAllFrames()) {
leon.han45256682016-05-06 21:09:19339 // 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.hande852902016-05-04 09:16:38343 ContentAutofillDriver* driver = factory->DriverForFrame(frame);
344 DCHECK(driver);
345 driver->NotifyFirstUserGestureObservedInTab();
346 }
estadeb1bc9bd2014-12-02 22:44:11347}
348
sigbjorn337de86e2015-07-08 10:11:12349bool 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
mathpaf4d5da2016-02-01 22:14:46359 return ssl_status.security_style == content::SECURITY_STYLE_AUTHENTICATED &&
360 !(ssl_status.content_status &
361 content::SSLStatus::RAN_INSECURE_CONTENT);
sigbjorn337de86e2015-07-08 10:11:12362}
363
mathp4d08afd62016-07-08 19:54:10364bool ChromeAutofillClient::ShouldShowSigninPromo() {
mathpf0f7ccc2016-07-21 18:04:01365#if !defined(OS_ANDROID)
mathp664a4cf2016-07-19 22:07:07366 // 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;
mathp4d08afd62016-07-08 19:54:10370#endif
mathp664a4cf2016-07-19 22:07:07371
372 return signin::ShouldShowPromo(
373 Profile::FromBrowserContext(web_contents()->GetBrowserContext()));
mathp4d08afd62016-07-08 19:54:10374}
375
376void ChromeAutofillClient::StartSigninFlow() {
mathpf0f7ccc2016-07-21 18:04:01377#if defined(OS_ANDROID)
mathp664a4cf2016-07-19 22:07:07378 chrome::android::SigninPromoUtilAndroid::StartAccountSigninActivityForPromo(
379 content::ContentViewCore::FromWebContents(web_contents()),
380 signin_metrics::AccessPoint::ACCESS_POINT_AUTOFILL_DROPDOWN);
381#else
mathp4d08afd62016-07-08 19:54:10382 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]bfb4d67212013-02-14 20:32:29391} // namespace autofill