File: save_update_address_profile_prompt_controller.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 (110 lines) | stat: -rw-r--r-- 4,854 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
// Copyright 2021 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_AUTOFILL_ANDROID_SAVE_UPDATE_ADDRESS_PROFILE_PROMPT_CONTROLLER_H_
#define CHROME_BROWSER_AUTOFILL_ANDROID_SAVE_UPDATE_ADDRESS_PROFILE_PROMPT_CONTROLLER_H_

#include <jni.h>

#include <memory>
#include <optional>

#include "base/android/scoped_java_ref.h"
#include "base/functional/callback.h"
#include "chrome/browser/autofill/android/save_update_address_profile_prompt_view.h"
#include "components/autofill/core/browser/data_model/addresses/autofill_profile.h"
#include "components/autofill/core/browser/foundations/autofill_client.h"
#include "content/public/browser/web_contents.h"

namespace signin {
class IdentityManager;
}

namespace autofill {

class PersonalDataManager;

// Android implementation of the modal prompt for saving new/updating existing
// address profile. The class is responsible for showing the view and handling
// user interactions. The controller owns its java counterpart and the
// corresponding view.
class SaveUpdateAddressProfilePromptController {
 public:
  SaveUpdateAddressProfilePromptController(
      std::unique_ptr<SaveUpdateAddressProfilePromptView> prompt_view,
      autofill::PersonalDataManager* personal_data,
      const AutofillProfile& profile,
      const AutofillProfile* original_profile,
      bool is_migration_to_account,
      AutofillClient::AddressProfileSavePromptCallback decision_callback,
      base::OnceCallback<void()> dismissal_callback);
  SaveUpdateAddressProfilePromptController(
      const SaveUpdateAddressProfilePromptController&) = delete;
  SaveUpdateAddressProfilePromptController& operator=(
      const SaveUpdateAddressProfilePromptController&) = delete;
  ~SaveUpdateAddressProfilePromptController();

  void DisplayPrompt();

  std::u16string GetTitle();
  std::u16string GetRecordTypeNotice(signin::IdentityManager* profile);
  std::u16string GetPositiveButtonText();
  std::u16string GetNegativeButtonText();
  // For save prompt:
  std::u16string GetAddress();
  std::u16string GetEmail();
  std::u16string GetPhoneNumber();
  // For update prompt:
  std::u16string GetSubtitle();
  // Returns two strings listing formatted profile data that will change when
  // the `original_profile_` is updated to `profile_`. The old values, which
  // will be replaced, are the first value, and the new values, which will be
  // saved, are the second value.
  std::pair<std::u16string, std::u16string> GetDiffFromOldToNewProfile();

  base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
  void OnUserAccepted(JNIEnv* env,
                      const base::android::JavaParamRef<jobject>& obj);
  void OnUserDeclined(JNIEnv* env,
                      const base::android::JavaParamRef<jobject>& obj);
  void OnUserEdited(JNIEnv* env,
                    const base::android::JavaParamRef<jobject>& obj,
                    const base::android::JavaParamRef<jobject>& jprofile);
  // Called whenever the prompt is dismissed (e.g. because the user already
  // accepted/declined/edited the profile (after OnUserAccepted/Declined/Edited
  // is called) or it was closed without interaction).
  void OnPromptDismissed(JNIEnv* env,
                         const base::android::JavaParamRef<jobject>& obj);

 private:
  void RunSaveAddressProfileCallback(
      AutofillClient::AddressPromptUserDecision decision);

  // If the user explicitly accepted/dismissed/edited the profile.
  bool had_user_interaction_ = false;
  // View that displays the prompt.
  std::unique_ptr<SaveUpdateAddressProfilePromptView> prompt_view_;
  // The personal data manager associated with the current web contents of the
  // tab the prompt will be displayed in. The lifetime of this object is
  // constrained with the lifetime of the tab's web content, which owns the
  // corresponding personal data manager.
  raw_ptr<autofill::PersonalDataManager> personal_data_;
  // The profile which is being confirmed by the user.
  AutofillProfile profile_;
  // The profile (if exists) which will be updated if the user confirms.
  std::optional<AutofillProfile> original_profile_;
  // The option which specifies whether the autofill profile is going to be
  // migrated to user's Google Account.
  bool is_migration_to_account_;
  // The callback to run once the user makes a decision.
  AutofillClient::AddressProfileSavePromptCallback decision_callback_;
  // The callback guaranteed to be run once the prompt is dismissed.
  base::OnceCallback<void()> dismissal_callback_;
  // The corresponding Java SaveUpdateAddressProfilePromptController.
  base::android::ScopedJavaGlobalRef<jobject> java_object_;
};

}  // namespace autofill

#endif  // CHROME_BROWSER_AUTOFILL_ANDROID_SAVE_UPDATE_ADDRESS_PROFILE_PROMPT_CONTROLLER_H_