summaryrefslogtreecommitdiffstats
path: root/ios/chrome/browser/ui/autofill/autofill_client_ios.mm
blob: 37387a8a44869524466581835a352da8a93330c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/ui/autofill/autofill_client_ios.h"

#include "base/bind.h"
#include "base/prefs/pref_service.h"
#include "components/autofill/core/browser/autofill_cc_infobar_delegate.h"
#include "components/autofill/core/browser/ui/card_unmask_prompt_view.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_pref_names.h"
#include "components/infobars/core/infobar_manager.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/password_manager/core/browser/password_generation_manager.h"
#include "google_apis/gaia/identity_provider.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#include "ios/chrome/browser/web_data_service_factory.h"
#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"

namespace autofill {

AutofillClientIOS::AutofillClientIOS(
    ios::ChromeBrowserState* browser_state,
    infobars::InfoBarManager* infobar_manager,
    id<AutofillClientIOSBridge> bridge,
    password_manager::PasswordGenerationManager* password_generation_manager,
    scoped_ptr<IdentityProvider> identity_provider)
    : browser_state_(browser_state),
      infobar_manager_(infobar_manager),
      bridge_(bridge),
      password_generation_manager_(password_generation_manager),
      identity_provider_(identity_provider.Pass()),
      unmask_controller_(browser_state->GetPrefs(),
                         browser_state->IsOffTheRecord()) {}

AutofillClientIOS::~AutofillClientIOS() {
  HideAutofillPopup();
}

PersonalDataManager* AutofillClientIOS::GetPersonalDataManager() {
  return PersonalDataManagerFactory::GetForBrowserState(
      browser_state_->GetOriginalChromeBrowserState());
}

PrefService* AutofillClientIOS::GetPrefs() {
  return browser_state_->GetPrefs();
}

IdentityProvider* AutofillClientIOS::GetIdentityProvider() {
  return identity_provider_.get();
}

// TODO(dconnelly): [Merge] Does this need a real implementation?
// http://crbug.com/468326
rappor::RapporService* AutofillClientIOS::GetRapporService() {
  NOTIMPLEMENTED();
  return nullptr;
}

void AutofillClientIOS::ShowAutofillSettings() {
  NOTREACHED();
}

void AutofillClientIOS::ShowUnmaskPrompt(
    const CreditCard& card,
    base::WeakPtr<CardUnmaskDelegate> delegate) {
  ios::ChromeBrowserProvider* provider = ios::GetChromeBrowserProvider();
  unmask_controller_.ShowPrompt(
      provider->CreateCardUnmaskPromptView(&unmask_controller_), card,
      delegate);
}

void AutofillClientIOS::OnUnmaskVerificationResult(PaymentsRpcResult result) {
  unmask_controller_.OnVerificationResult(result);
}

void AutofillClientIOS::ConfirmSaveCreditCardLocally(
    const base::Closure& callback) {
  // This method is invoked synchronously from
  // AutofillManager::OnFormSubmitted(); at the time of detecting that a form
  // was submitted, the WebContents is guaranteed to be live. Since the
  // InfoBarService is a WebContentsUserData, it must also be alive at this
  // time.
  AutofillCCInfoBarDelegate::CreateForLocalSave(infobar_manager_, callback);
}

void AutofillClientIOS::ConfirmSaveCreditCardToCloud(
    const base::Closure& callback,
    scoped_ptr<base::DictionaryValue> legal_message) {
  AutofillCCInfoBarDelegate::CreateForUpload(infobar_manager_, callback);
}

void AutofillClientIOS::LoadRiskData(
    const base::Callback<void(const std::string&)>& callback) {
  callback.Run(ios::GetChromeBrowserProvider()->GetRiskData());
}

bool AutofillClientIOS::HasCreditCardScanFeature() {
  return false;
}

void AutofillClientIOS::ScanCreditCard(const CreditCardScanCallback& callback) {
  NOTREACHED();
}

void AutofillClientIOS::ShowRequestAutocompleteDialog(
    const FormData& form,
    content::RenderFrameHost* render_frame_host,
    const ResultCallback& callback) {
  NOTREACHED();
}

void AutofillClientIOS::ShowAutofillPopup(
    const gfx::RectF& element_bounds,
    base::i18n::TextDirection text_direction,
    const std::vector<Suggestion>& suggestions,
    base::WeakPtr<AutofillPopupDelegate> delegate) {
  [bridge_ showAutofillPopup:suggestions popupDelegate:delegate];
}

void AutofillClientIOS::HideAutofillPopup() {
  [bridge_ hideAutofillPopup];
}

bool AutofillClientIOS::IsAutocompleteEnabled() {
  // For browser, Autocomplete is always enabled as part of Autofill.
  return GetPrefs()->GetBoolean(prefs::kAutofillEnabled);
}

void AutofillClientIOS::HideRequestAutocompleteDialog() {
  NOTREACHED();
}

void AutofillClientIOS::UpdateAutofillPopupDataListValues(
    const std::vector<base::string16>& values,
    const std::vector<base::string16>& labels) {
  NOTREACHED();
}

void AutofillClientIOS::PropagateAutofillPredictions(
    content::RenderFrameHost* rfh,
    const std::vector<FormStructure*>& forms) {
  if (password_generation_manager_) {
    password_generation_manager_->DetectFormsEligibleForGeneration(forms);
  }
}

void AutofillClientIOS::DidFillOrPreviewField(
    const base::string16& autofilled_value,
    const base::string16& profile_full_name) {
}

scoped_refptr<AutofillWebDataService> AutofillClientIOS::GetDatabase() {
  return ios::WebDataServiceFactory::GetAutofillWebDataForBrowserState(
      browser_state_, ServiceAccessType::EXPLICIT_ACCESS);
}

bool AutofillClientIOS::IsContextSecure(const GURL& form_origin) {
  // TODO (sigbjorn): Return if the context is secure, not just
  // the form_origin. See crbug.com/505388.
  return form_origin.SchemeIsCryptographic();
}

void AutofillClientIOS::OnFirstUserGestureObserved() {
  // TODO(gcasto): [Merge 306796] http://crbug.com/439425 Verify if this method
  // needs a real implementation or not.
  NOTIMPLEMENTED();
}

}  // namespace autofill