File: android_autofill_client.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (307 lines) | stat: -rw-r--r-- 10,394 bytes parent folder | download | duplicates (3)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/android_autofill/browser/android_autofill_client.h"

#include <utility>

#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/functional/function_ref.h"
#include "base/notimplemented.h"
#include "base/notreached.h"
#include "base/types/cxx23_to_underlying.h"
#include "components/android_autofill/browser/android_autofill_manager.h"
#include "components/android_autofill/browser/android_autofill_provider.h"
#include "components/autofill/content/browser/content_autofill_client.h"
#include "components/autofill/core/browser/crowdsourcing/autofill_crowdsourcing_manager.h"
#include "components/autofill/core/browser/payments/legal_message_line.h"
#include "components/autofill/core/browser/suggestions/suggestion.h"
#include "components/autofill/core/browser/suggestions/suggestion_type.h"
#include "components/autofill/core/browser/ui/autofill_suggestion_delegate.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/aliases.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/credential_management/android/features.h"
#include "components/credential_management/android/third_party_credential_manager_impl.h"
#include "components/prefs/pref_service.h"
#include "components/security_state/content/security_state_tab_helper.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/ssl_status.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "ui/android/view_android.h"
#include "ui/gfx/geometry/rect_f.h"

namespace android_autofill {

void AndroidAutofillClient::CreateForWebContents(
    content::WebContents* contents) {
  DCHECK(contents);
  if (!FromWebContents(contents)) {
    contents->SetUserData(
        UserDataKey(), base::WrapUnique(new AndroidAutofillClient(contents)));
  }
}

AndroidAutofillClient::AndroidAutofillClient(content::WebContents* web_contents)
    : autofill::ContentAutofillClient(web_contents),
      content_credential_manager_(
          std::make_unique<
              credential_management::ThirdPartyCredentialManagerImpl>(
              web_contents)) {}

AndroidAutofillClient::~AndroidAutofillClient() {
  HideAutofillSuggestions(autofill::SuggestionHidingReason::kTabGone);
}

base::WeakPtr<autofill::AutofillClient> AndroidAutofillClient::GetWeakPtr() {
  return weak_ptr_factory_.GetWeakPtr();
}

const std::string& AndroidAutofillClient::GetAppLocale() const {
  NOTREACHED();
}

bool AndroidAutofillClient::IsOffTheRecord() const {
  auto* mutable_this = const_cast<AndroidAutofillClient*>(this);
  return mutable_this->GetWebContents().GetBrowserContext()->IsOffTheRecord();
}

scoped_refptr<network::SharedURLLoaderFactory>
AndroidAutofillClient::GetURLLoaderFactory() {
  return GetWebContents()
      .GetBrowserContext()
      ->GetDefaultStoragePartition()
      ->GetURLLoaderFactoryForBrowserProcess();
}

autofill::AutofillCrowdsourcingManager&
AndroidAutofillClient::GetCrowdsourcingManager() {
  if (!crowdsourcing_manager_) {
    // Lazy initialization to avoid virtual function calls in the constructor.
    crowdsourcing_manager_ =
        std::make_unique<autofill::AutofillCrowdsourcingManager>(this,
                                                                 GetChannel());
  }
  return *crowdsourcing_manager_;
}

autofill::VotesUploader& AndroidAutofillClient::GetVotesUploader() {
  return votes_uploader_;
}

autofill::PersonalDataManager& AndroidAutofillClient::GetPersonalDataManager() {
  NOTREACHED();
}

autofill::ValuablesDataManager*
AndroidAutofillClient::GetValuablesDataManager() {
  return nullptr;
}

autofill::EntityDataManager* AndroidAutofillClient::GetEntityDataManager() {
  return nullptr;
}

autofill::SingleFieldFillRouter&
AndroidAutofillClient::GetSingleFieldFillRouter() {
  NOTREACHED();
}

autofill::AutocompleteHistoryManager*
AndroidAutofillClient::GetAutocompleteHistoryManager() {
  NOTREACHED();
}

PrefService* AndroidAutofillClient::GetPrefs() {
  return const_cast<PrefService*>(std::as_const(*this).GetPrefs());
}

const PrefService* AndroidAutofillClient::GetPrefs() const {
  return user_prefs::UserPrefs::Get(GetWebContents().GetBrowserContext());
}

syncer::SyncService* AndroidAutofillClient::GetSyncService() {
  // TODO(crbug.com/321949351): Move this and other stubs into AutofillClient.
  return nullptr;
}

signin::IdentityManager* AndroidAutofillClient::GetIdentityManager() {
  return nullptr;
}

const signin::IdentityManager* AndroidAutofillClient::GetIdentityManager()
    const {
  return nullptr;
}

autofill::FormDataImporter* AndroidAutofillClient::GetFormDataImporter() {
  return nullptr;
}

autofill::StrikeDatabase* AndroidAutofillClient::GetStrikeDatabase() {
  return nullptr;
}

ukm::UkmRecorder* AndroidAutofillClient::GetUkmRecorder() {
  return nullptr;
}

autofill::AddressNormalizer* AndroidAutofillClient::GetAddressNormalizer() {
  return nullptr;
}

const GURL& AndroidAutofillClient::GetLastCommittedPrimaryMainFrameURL() const {
  return GetWebContents().GetPrimaryMainFrame()->GetLastCommittedURL();
}

url::Origin AndroidAutofillClient::GetLastCommittedPrimaryMainFrameOrigin()
    const {
  return GetWebContents().GetPrimaryMainFrame()->GetLastCommittedOrigin();
}

security_state::SecurityLevel
AndroidAutofillClient::GetSecurityLevelForUmaHistograms() {
  if (SecurityStateTabHelper* helper =
          ::SecurityStateTabHelper::FromWebContents(&GetWebContents())) {
    return helper->GetSecurityLevel();
  }

  // If there is no helper, it means we are not in a "web" state or the embedder
  // doesn't support the state helper. Return SECURITY_LEVEL_COUNT which will
  //  not be logged.
  return security_state::SecurityLevel::SECURITY_LEVEL_COUNT;
}

const translate::LanguageState* AndroidAutofillClient::GetLanguageState() {
  return nullptr;
}

translate::TranslateDriver* AndroidAutofillClient::GetTranslateDriver() {
  return nullptr;
}

void AndroidAutofillClient::ShowAutofillSettings(
    autofill::SuggestionType suggestion_type) {
  NOTIMPLEMENTED();
}

void AndroidAutofillClient::ConfirmSaveAddressProfile(
    const autofill::AutofillProfile& profile,
    const autofill::AutofillProfile* original_profile,
    bool is_migration_to_account,
    AddressProfileSavePromptCallback callback) {
  NOTIMPLEMENTED();
}

autofill::AutofillClient::SuggestionUiSessionId
AndroidAutofillClient::ShowAutofillSuggestions(
    const autofill::AutofillClient::PopupOpenArgs& open_args,
    base::WeakPtr<autofill::AutofillSuggestionDelegate> delegate) {
  NOTIMPLEMENTED();
  return SuggestionUiSessionId();
}

void AndroidAutofillClient::UpdateAutofillDataListValues(
    base::span<const autofill::SelectOption> datalist) {
  // Leaving as an empty method since updating autofill popup window
  // dynamically does not seem to be a useful feature when delegating to Android
  // APIs.
}

void AndroidAutofillClient::HideAutofillSuggestions(
    autofill::SuggestionHidingReason reason) {
  // TODO(321950502): Analyze hiding the datalist popup here.
}

bool AndroidAutofillClient::IsAutofillEnabled() const {
  NOTREACHED();
}

bool AndroidAutofillClient::IsAutofillProfileEnabled() const {
  NOTREACHED();
}

bool AndroidAutofillClient::IsAutofillPaymentMethodsEnabled() const {
  NOTREACHED();
}

bool AndroidAutofillClient::IsAutocompleteEnabled() const {
  return false;
}

bool AndroidAutofillClient::IsPasswordManagerEnabled() const {
  // Android 3P mode and WebView rely on the AndroidAutofillManager which
  // doesn't call this function. If it ever does, the function needs to
  // be implemented in a meaningful way.
  NOTREACHED();
}

void AndroidAutofillClient::DidFillForm(
    autofill::AutofillTriggerSource trigger_source,
    bool is_refill) {}

bool AndroidAutofillClient::IsContextSecure() const {
  // Note: As of crbug.com/701018, Chrome relies on ChromeSecurityStateTabHelper
  // to determine whether the page is secure, but WebView can only access a
  // small part of the functionality so the helper will be null for now.
  if (SecurityStateTabHelper* helper =
          SecurityStateTabHelper::FromWebContents(&GetWebContents())) {
    return security_state::IsSslCertificateValid(helper->GetSecurityLevel());
  }

  content::NavigationEntry* navigation_entry =
      GetWebContents().GetController().GetLastCommittedEntry();
  if (!navigation_entry ||
      !navigation_entry->GetURL().SchemeIsCryptographic()) {
    return false;
  }

  content::SSLStatus ssl_status = navigation_entry->GetSSL();
  return ssl_status.certificate &&
         !net::IsCertStatusError(ssl_status.cert_status) &&
         !(ssl_status.content_status &
           content::SSLStatus::RAN_INSECURE_CONTENT);
}

autofill::FormInteractionsFlowId
AndroidAutofillClient::GetCurrentFormInteractionsFlowId() {
  // Currently not in use here. See `ChromeAutofillClient` for a proper
  // implementation.
  return {};
}

autofill::autofill_metrics::FormInteractionsUkmLogger&
AndroidAutofillClient::GetFormInteractionsUkmLogger() {
  return form_interactions_ukm_logger_;
}

content::WebContents& AndroidAutofillClient::GetWebContents() const {
  // While a const_cast is not ideal. The Autofill API uses const in various
  // spots and the content public API doesn't have const accessors. So the const
  // cast is the lesser of two evils.
  return const_cast<content::WebContents&>(
      ContentAutofillClient::GetWebContents());
}

std::unique_ptr<autofill::AutofillManager> AndroidAutofillClient::CreateManager(
    base::PassKey<autofill::ContentAutofillDriver> pass_key,
    autofill::ContentAutofillDriver& driver) {
  return base::WrapUnique(new autofill::AndroidAutofillManager(&driver));
}

credential_management::ContentCredentialManager*
AndroidAutofillClient::GetContentCredentialManager() {
  if (base::FeatureList::IsEnabled(
          credential_management::features::
              kCredentialManagementThirdPartyWebApiRequestForwarding)) {
    return &content_credential_manager_;
  }
  return nullptr;
}

}  // namespace android_autofill