File: password_ui_view_android.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (178 lines) | stat: -rw-r--r-- 7,354 bytes parent folder | download | duplicates (5)
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
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PASSWORD_MANAGER_ANDROID_PASSWORD_UI_VIEW_ANDROID_H_
#define CHROME_BROWSER_PASSWORD_MANAGER_ANDROID_PASSWORD_UI_VIEW_ANDROID_H_

#include <stddef.h>

#include <memory>
#include <string>
#include <vector>

#include "base/android/jni_weak_ref.h"
#include "base/android/scoped_java_ref.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/affiliations/affiliation_service_factory.h"
#include "chrome/browser/password_entry_edit/android/credential_edit_bridge.h"
#include "chrome/browser/password_manager/account_password_store_factory.h"
#include "chrome/browser/password_manager/profile_password_store_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "components/password_manager/core/browser/password_store/password_store_consumer.h"
#include "components/password_manager/core/browser/ui/saved_passwords_presenter.h"

class Profile;

namespace password_manager {
class CredentialProviderInterface;
}

// PasswordUIView for Android, contains jni hooks that allows Android UI to
// display passwords and route UI commands back to SavedPasswordsPresenter.
class PasswordUiViewAndroid
    : public password_manager::SavedPasswordsPresenter::Observer {
 public:
  // Result of transforming a vector of PasswordForms into their CSV
  // description and writing that to disk.
  struct SerializationResult {
    // The number of password entries written. 0 if error encountered.
    int entries_count;

    // The path to the temporary file containing the serialized passwords. Empty
    // if error encountered.
    std::string exported_file_path;

    // The error description recorded after the last write operation. Empty if
    // no error encountered.
    std::string error;
  };

  PasswordUiViewAndroid(JNIEnv* env,
                        const jni_zero::JavaRef<jobject>& obj,
                        Profile* profile);

  PasswordUiViewAndroid(const PasswordUiViewAndroid&) = delete;
  PasswordUiViewAndroid& operator=(const PasswordUiViewAndroid&) = delete;

  ~PasswordUiViewAndroid() override;

  // Calls from Java.
  base::android::ScopedJavaLocalRef<jobject> GetSavedPasswordEntry(
      JNIEnv* env,
      const base::android::JavaRef<jobject>&,
      int index);
  std::string GetSavedPasswordException(JNIEnv* env,
                                        const base::android::JavaRef<jobject>&,
                                        int index);
  void InsertPasswordEntryForTesting(JNIEnv* env,
                                     const std::u16string& origin,
                                     const std::u16string& username,
                                     const std::u16string& password);
  void UpdatePasswordLists(JNIEnv* env, const base::android::JavaRef<jobject>&);
  void HandleRemoveSavedPasswordEntry(JNIEnv* env,
                                      const base::android::JavaRef<jobject>&,
                                      int index);
  void HandleRemoveSavedPasswordException(
      JNIEnv* env,
      const base::android::JavaRef<jobject>&,
      int index);
  void HandleSerializePasswords(
      JNIEnv* env,
      const base::android::JavaRef<jobject>&,
      const std::string& java_target_directory,
      const base::android::JavaRef<jobject>& success_callback,
      const base::android::JavaRef<jobject>& error_callback);
  void HandleShowPasswordEntryEditingView(
      JNIEnv* env,
      const base::android::JavaRef<jobject>& context,
      int index,
      const base::android::JavaParamRef<jobject>& obj);
  void HandleShowBlockedCredentialView(
      JNIEnv* env,
      const base::android::JavaRef<jobject>& context,
      int index,
      const base::android::JavaParamRef<jobject>& obj);
  jboolean IsWaitingForPasswordStore(JNIEnv* env,
                                     const base::android::JavaRef<jobject>&);
  // Destroy the native implementation.
  void Destroy(JNIEnv*, const base::android::JavaRef<jobject>&);

  void OnEditUIDismissed();

  void set_export_target_for_testing(
      SerializationResult* export_target_for_testing) {
    export_target_for_testing_ = export_target_for_testing;
  }

  void set_credential_provider_for_testing(
      password_manager::CredentialProviderInterface* provider) {
    credential_provider_for_testing_ = provider;
  }

 private:
  // Possible states in the life of PasswordUiViewAndroid.
  // ALIVE:
  //   * Destroy was not called and no background tasks are pending.
  //   * All data members can be used on the main task runner.
  // ALIVE_SERIALIZATION_PENDING:
  //   * Destroy was not called, password serialization task on another task
  //     runner is running.
  //   * All data members can be used on the main task runner, except for
  //     |saved_passwords_presenter_| which can only be used inside
  //     ObtainAndSerializePasswords, which is being run on a backend task
  //     runner.
  // DELETION_PENDING:
  //   * Destroy() was called, a background task is pending and |this| should
  //     be deleted once the tasks complete.
  //   * This state should not be reached anywhere but in the completion call
  //     of the pending task.
  enum class State { ALIVE, ALIVE_SERIALIZATION_PENDING, DELETION_PENDING };

  // password_manager::SavedPasswordsPresenter::Observer implementation.
  void OnSavedPasswordsChanged(
      const password_manager::PasswordStoreChangeList& changes) override;

  void UpdatePasswordLists();

  // Sends |serialization_result| to Java via |success_callback| or
  // |error_callback|, depending on whether the result is a success or an error.
  void PostSerializedPasswords(
      const base::android::JavaRef<jobject>& success_callback,
      const base::android::JavaRef<jobject>& error_callback,
      SerializationResult serialization_result);

  // The |state_| must only be accessed on the main task runner.
  State state_ = State::ALIVE;

  // If not null, PostSerializedPasswords will write the serialized passwords to
  // |*export_target_for_testing_| instead of passing them to Java. This must
  // remain null in production code.
  raw_ptr<SerializationResult> export_target_for_testing_ = nullptr;

  raw_ptr<Profile> profile_;

  // Pointer to the password store, powering |saved_passwords_presenter_|.
  scoped_refptr<password_manager::PasswordStoreInterface> profile_store_;

  // Manages the list of saved passwords, including updates.
  password_manager::SavedPasswordsPresenter saved_passwords_presenter_;

  // Cached passwords and blocked sites.
  std::vector<password_manager::CredentialUIEntry> passwords_;
  std::vector<password_manager::CredentialUIEntry> blocked_sites_;

  // If not null, passwords for exporting will be obtained from
  // |*credential_provider_for_testing_|, otherwise from
  // |saved_passwords_presenter_|. This must remain null in production code.
  raw_ptr<password_manager::CredentialProviderInterface>
      credential_provider_for_testing_ = nullptr;

  // Java side of UI controller.
  JavaObjectWeakGlobalRef weak_java_ui_controller_;

  // Used to open the view/edit/delete UI.
  std::unique_ptr<CredentialEditBridge> credential_edit_bridge_;
};

#endif  // CHROME_BROWSER_PASSWORD_MANAGER_ANDROID_PASSWORD_UI_VIEW_ANDROID_H_