Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / chrome / browser / ui / autofill / autofill_client_ios.mm
blob30533e33b580dbdecde55a3a6b9b1e88d2814451
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "ios/chrome/browser/ui/autofill/autofill_client_ios.h"
7 #include "base/bind.h"
8 #include "base/prefs/pref_service.h"
9 #include "components/autofill/core/browser/autofill_cc_infobar_delegate.h"
10 #include "components/autofill/core/browser/ui/card_unmask_prompt_view.h"
11 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
12 #include "components/autofill/core/common/autofill_pref_names.h"
13 #include "components/infobars/core/infobar_manager.h"
14 #include "components/keyed_service/core/service_access_type.h"
15 #include "components/password_manager/core/browser/password_generation_manager.h"
16 #include "google_apis/gaia/identity_provider.h"
17 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
18 #include "ios/chrome/browser/web_data_service_factory.h"
19 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
20 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
22 namespace autofill {
24 void GetRiskDataWithCallback(
25     const base::Callback<void(const std::string&)>& callback) {
26   callback.Run(ios::GetChromeBrowserProvider()->GetRiskData());
29 AutofillClientIOS::AutofillClientIOS(
30     ios::ChromeBrowserState* browser_state,
31     infobars::InfoBarManager* infobar_manager,
32     id<AutofillClientIOSBridge> bridge,
33     password_manager::PasswordGenerationManager* password_generation_manager,
34     scoped_ptr<IdentityProvider> identity_provider)
35     : browser_state_(browser_state),
36       infobar_manager_(infobar_manager),
37       bridge_(bridge),
38       password_generation_manager_(password_generation_manager),
39       identity_provider_(identity_provider.Pass()),
40       unmask_controller_(base::Bind(&GetRiskDataWithCallback),
41                          browser_state->GetPrefs(),
42                          browser_state->IsOffTheRecord()) {
45 AutofillClientIOS::~AutofillClientIOS() {
46   HideAutofillPopup();
49 PersonalDataManager* AutofillClientIOS::GetPersonalDataManager() {
50   return PersonalDataManagerFactory::GetForBrowserState(
51       browser_state_->GetOriginalChromeBrowserState());
54 PrefService* AutofillClientIOS::GetPrefs() {
55   return browser_state_->GetPrefs();
58 IdentityProvider* AutofillClientIOS::GetIdentityProvider() {
59   return identity_provider_.get();
62 // TODO(dconnelly): [Merge] Does this need a real implementation?
63 // http://crbug.com/468326
64 rappor::RapporService* AutofillClientIOS::GetRapporService() {
65   NOTIMPLEMENTED();
66   return nullptr;
69 void AutofillClientIOS::ShowAutofillSettings() {
70   NOTREACHED();
73 void AutofillClientIOS::ShowUnmaskPrompt(
74     const CreditCard& card,
75     base::WeakPtr<CardUnmaskDelegate> delegate) {
76   ios::ChromeBrowserProvider* provider = ios::GetChromeBrowserProvider();
77   unmask_controller_.ShowPrompt(
78       provider->CreateCardUnmaskPromptView(&unmask_controller_), card,
79       delegate);
82 void AutofillClientIOS::OnUnmaskVerificationResult(GetRealPanResult result) {
83   unmask_controller_.OnVerificationResult(result);
86 void AutofillClientIOS::ConfirmSaveCreditCard(
87     const base::Closure& save_card_callback) {
88   // This method is invoked synchronously from
89   // AutofillManager::OnFormSubmitted(); at the time of detecting that a form
90   // was submitted, the WebContents is guaranteed to be live. Since the
91   // InfoBarService is a WebContentsUserData, it must also be alive at this
92   // time.
93   AutofillCCInfoBarDelegate::Create(infobar_manager_, this, save_card_callback);
96 bool AutofillClientIOS::HasCreditCardScanFeature() {
97   return false;
100 void AutofillClientIOS::ScanCreditCard(const CreditCardScanCallback& callback) {
101   NOTREACHED();
104 void AutofillClientIOS::ShowRequestAutocompleteDialog(
105     const FormData& form,
106     content::RenderFrameHost* render_frame_host,
107     const ResultCallback& callback) {
108   NOTREACHED();
111 void AutofillClientIOS::ShowAutofillPopup(
112     const gfx::RectF& element_bounds,
113     base::i18n::TextDirection text_direction,
114     const std::vector<Suggestion>& suggestions,
115     base::WeakPtr<AutofillPopupDelegate> delegate) {
116   [bridge_ showAutofillPopup:suggestions popupDelegate:delegate];
119 void AutofillClientIOS::HideAutofillPopup() {
120   [bridge_ hideAutofillPopup];
123 bool AutofillClientIOS::IsAutocompleteEnabled() {
124   // For browser, Autocomplete is always enabled as part of Autofill.
125   return GetPrefs()->GetBoolean(prefs::kAutofillEnabled);
128 void AutofillClientIOS::HideRequestAutocompleteDialog() {
129   NOTREACHED();
132 void AutofillClientIOS::UpdateAutofillPopupDataListValues(
133     const std::vector<base::string16>& values,
134     const std::vector<base::string16>& labels) {
135   NOTREACHED();
138 void AutofillClientIOS::PropagateAutofillPredictions(
139     content::RenderFrameHost* rfh,
140     const std::vector<FormStructure*>& forms) {
141   if (password_generation_manager_) {
142     password_generation_manager_->DetectAccountCreationForms(forms);
143   }
146 void AutofillClientIOS::DidFillOrPreviewField(
147     const base::string16& autofilled_value,
148     const base::string16& profile_full_name) {
151 scoped_refptr<AutofillWebDataService> AutofillClientIOS::GetDatabase() {
152   return ios::WebDataServiceFactory::GetAutofillWebDataForBrowserState(
153       browser_state_, ServiceAccessType::EXPLICIT_ACCESS);
156 bool AutofillClientIOS::IsContextSecure(const GURL& form_origin) {
157   // TODO (sigbjorn): Return if the context is secure, not just
158   // the form_origin. See crbug.com/505388.
159   return form_origin.SchemeIsCryptographic();
162 void AutofillClientIOS::OnFirstUserGestureObserved() {
163   // TODO(gcasto): [Merge 306796] http://crbug.com/439425 Verify if this method
164   // needs a real implementation or not.
165   NOTIMPLEMENTED();
168 void AutofillClientIOS::LinkClicked(const GURL& url,
169                                     WindowOpenDisposition disposition) {
170   NOTIMPLEMENTED();
173 }  // namespace autofill