File: ios_password_manager_driver.mm

package info (click to toggle)
chromium 139.0.7258.138-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,120,676 kB
  • sloc: cpp: 35,100,869; 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 (201 lines) | stat: -rw-r--r-- 7,265 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
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "components/password_manager/ios/ios_password_manager_driver.h"

#import <string>

#import "base/hash/hash.h"
#include "base/notimplemented.h"
#import "components/autofill/core/common/password_form_fill_data.h"
#import "components/autofill/ios/common/field_data_manager_factory_ios.h"
#import "components/password_manager/core/browser/password_generation_frame_helper.h"
#import "components/password_manager/core/browser/password_manager.h"
#import "components/password_manager/ios/ios_password_manager_driver_factory.h"
#import "components/password_manager/ios/password_manager_java_script_feature.h"
#include "ui/gfx/geometry/rect_f.h"

using password_manager::PasswordAutofillManager;
using password_manager::PasswordManager;

namespace {
// Maximal number of pending forms for proactive generation that can be queued.
constexpr int kMaxPendingFormsForProactiveGeneration = 10;
}  // namespace

IOSPasswordManagerDriver::IOSPasswordManagerDriver(
    web::WebState* web_state,
    id<PasswordManagerDriverBridge> bridge,
    password_manager::PasswordManagerInterface* password_manager,
    web::WebFrame* web_frame,
    int driver_id)
    : web_state_(web_state->GetWeakPtr()),
      bridge_(bridge),
      password_manager_(password_manager),
      id_(driver_id),
      cached_frame_id_(base::FastHash(web_frame->GetFrameId())),
      frame_id_(web_frame->GetFrameId()),
      field_data_manager_(
          autofill::FieldDataManagerFactoryIOS::GetRetainable(web_frame)) {
  password_generation_helper_ =
      std::make_unique<password_manager::PasswordGenerationFrameHelper>(
          password_manager_->GetClient(), this);

  // Cache these values early, so that it can be accessed after frame deletion.
  is_in_main_frame_ = web_frame->IsMainFrame();
  security_origin_ = web_frame->GetSecurityOrigin();
}

IOSPasswordManagerDriver::~IOSPasswordManagerDriver() = default;

int IOSPasswordManagerDriver::GetId() const {
  return id_;
}

void IOSPasswordManagerDriver::PropagateFillDataOnParsingCompletion(
    const autofill::PasswordFormFillData& form_data) {
  // Disable proactive generation and clear the pending forms if it is known
  // that there are passwords available for the site. This signal won't work for
  // passwords added after the frame is loaded, TODO(crbug.com/316132527): fix
  // that.
  can_use_proactive_generation_ = false;
  pending_forms_for_proactive_generation_.clear();

  [bridge_ processPasswordFormFillData:form_data
                            forFrameId:frame_id_
                           isMainFrame:is_in_main_frame_
                     forSecurityOrigin:security_origin_];
}

void IOSPasswordManagerDriver::InformNoSavedCredentials(
    bool should_show_popup_without_passwords) {
  // Allow using the proactive password generation bottom sheet from now on
  // since it is now known that there are no credentials saved for this page.
  // This signal won't work if the passwords are removed after the frame is
  // loaded, TODO(crbug.com/316132527): fix that.
  can_use_proactive_generation_ = true;

  // Attach the listeners on forms that couldn't be processed yet.
  for (const auto& form : pending_forms_for_proactive_generation_) {
    [bridge_ attachListenersForPasswordGenerationFields:form
                                             forFrameId:frame_id_];
  }
  pending_forms_for_proactive_generation_.clear();

  [bridge_ onNoSavedCredentialsWithFrameId:frame_id_];
}

void IOSPasswordManagerDriver::FormEligibleForGenerationFound(
    const autofill::PasswordFormGenerationData& form) {
  if (GetPasswordGenerationHelper() &&
      GetPasswordGenerationHelper()->IsGenerationEnabled(
          /*log_debug_data*/ true)) {
    [bridge_ formEligibleForGenerationFound:form];
    if (can_use_proactive_generation_) {
      [bridge_ attachListenersForPasswordGenerationFields:form
                                               forFrameId:frame_id_];
    } else if (pending_forms_for_proactive_generation_.size() <
               kMaxPendingFormsForProactiveGeneration) {
      // Push processing the forms eligible for generation for later since it
      // isn't yet known whether the proactive generation can be used. Don't
      // push more than `kMaxPendingFormsForProactiveGeneration` to avoid
      // bloating memory in the case the queue is never cleaned up.
      pending_forms_for_proactive_generation_.push_back(form);
    }
  }
}

void IOSPasswordManagerDriver::GeneratedPasswordAccepted(
    const std::u16string& password) {
  NOTIMPLEMENTED();
}

void IOSPasswordManagerDriver::FillSuggestion(
    const std::u16string& username,
    const std::u16string& password,
    base::OnceCallback<void(bool)> success_callback) {
  NOTIMPLEMENTED();
}

void IOSPasswordManagerDriver::FillSuggestionById(
    autofill::FieldRendererId username_element_id,
    autofill::FieldRendererId password_element_id,
    const std::u16string& username,
    const std::u16string& password,
    autofill::AutofillSuggestionTriggerSource suggestion_source) {
  NOTIMPLEMENTED() << "This function is used for non-iOS manual fallback";
}

void IOSPasswordManagerDriver::PreviewSuggestion(
    const std::u16string& username,
    const std::u16string& password) {
  NOTIMPLEMENTED();
}

void IOSPasswordManagerDriver::PreviewSuggestionById(
    autofill::FieldRendererId username_element_id,
    autofill::FieldRendererId password_element_id,
    const std::u16string& username,
    const std::u16string& password) {
  NOTIMPLEMENTED() << "This function is used for non-iOS manual fallback";
}

void IOSPasswordManagerDriver::PreviewGenerationSuggestion(
    const std::u16string& password) {
  NOTIMPLEMENTED();
}

void IOSPasswordManagerDriver::ClearPreviewedForm() {
  NOTIMPLEMENTED();
}

void IOSPasswordManagerDriver::SetSuggestionAvailability(
    autofill::FieldRendererId generation_element_id,
    autofill::mojom::AutofillSuggestionAvailability suggestion_availability) {
  NOTIMPLEMENTED();
}

password_manager::PasswordGenerationFrameHelper*
IOSPasswordManagerDriver::GetPasswordGenerationHelper() {
  return password_generation_helper_.get();
}

password_manager::PasswordManagerInterface*
IOSPasswordManagerDriver::GetPasswordManager() {
  return password_manager_;
}

PasswordAutofillManager*
IOSPasswordManagerDriver::GetPasswordAutofillManager() {
  // TODO(crbug.com/41088554): Use PasswordAutofillManager to implement password
  // autofill on iOS.
  return nullptr;
}

bool IOSPasswordManagerDriver::IsInPrimaryMainFrame() const {
  return is_in_main_frame_;
}

bool IOSPasswordManagerDriver::CanShowAutofillUi() const {
  return true;
}

int IOSPasswordManagerDriver::GetFrameId() const {
  return cached_frame_id_;
}

const GURL& IOSPasswordManagerDriver::GetLastCommittedURL() const {
  return bridge_.lastCommittedURL;
}

gfx::RectF IOSPasswordManagerDriver::TransformToRootCoordinates(
    const gfx::RectF& bounds_in_frame_coordinates) {
  NOTIMPLEMENTED();
  return bounds_in_frame_coordinates;
}

base::WeakPtr<password_manager::PasswordManagerDriver>
IOSPasswordManagerDriver::AsWeakPtr() {
  return weak_factory_.GetWeakPtr();
}