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
|
// Copyright 2024 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_PASSWORD_CHANGE_DELEGATE_IMPL_H_
#define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_CHANGE_DELEGATE_IMPL_H_
#include <string>
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/scoped_observation.h"
#include "base/time/time.h"
#include "chrome/browser/password_manager/password_change_delegate.h"
#include "components/password_manager/core/browser/one_time_passwords/otp_manager.h"
#include "components/tabs/public/tab_interface.h"
#include "content/public/browser/web_contents_observer.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "ui/accessibility/ax_tree_update.h"
#include "url/gurl.h"
namespace content {
class WebContents;
}
namespace password_manager {
class PasswordFormManager;
} // namespace password_manager
class ChangePasswordFormFillingSubmissionHelper;
class ChangePasswordFormFinder;
class CrossOriginNavigationObserver;
class ModelQualityLogsUploader;
class PasswordChangeUIController;
class PasswordChangeHats;
class Profile;
class OtpDetectionHelper;
// This class controls password change process including acceptance of privacy
// notice, opening of a new tab, navigation to the change password url, password
// generation and form submission.
class PasswordChangeDelegateImpl : public PasswordChangeDelegate,
password_manager::OtpManager::Observer {
public:
static constexpr char kFinalPasswordChangeStatusHistogram[] =
"PasswordManager.FinalPasswordChangeStatus";
static constexpr char kCoarseFinalPasswordChangeStatusHistogram[] =
"PasswordManager.CoarseFinalPasswordChangeStatus";
PasswordChangeDelegateImpl(GURL change_password_url,
std::u16string username,
std::u16string password,
tabs::TabInterface* tab_interface);
~PasswordChangeDelegateImpl() override;
PasswordChangeDelegateImpl(const PasswordChangeDelegateImpl&) = delete;
PasswordChangeDelegateImpl& operator=(const PasswordChangeDelegateImpl&) =
delete;
base::WeakPtr<PasswordChangeDelegate> AsWeakPtr() override;
#if defined(UNIT_TEST)
ModelQualityLogsUploader* logs_uploader() { return logs_uploader_.get(); }
OtpDetectionHelper* otp_helper() { return otp_detection_.get(); }
ChangePasswordFormFinder* form_finder() { return form_finder_.get(); }
content::WebContents* executor() { return executor_.get(); }
PasswordChangeUIController* ui_controller() { return ui_controller_.get(); }
std::u16string generated_password() { return generated_password_; }
void SetCustomUIController(
std::unique_ptr<PasswordChangeUIController> controller) {
ui_controller_ = std::move(controller);
}
#endif
// password_manager::OtpManager::Observer
void OnOtpFieldDetected(
password_manager::OtpFormManager* form_manager) override;
private:
// PasswordChangeDelegate Impl
void StartPasswordChangeFlow() override;
void CancelPasswordChangeFlow() override;
bool IsPasswordChangeOngoing(content::WebContents* web_contents) override;
State GetCurrentState() const override;
void Stop() override;
void OpenPasswordChangeTab() override;
void OpenPasswordDetails() override;
void OnPasswordFormSubmission(content::WebContents* web_contents) override;
void OnPrivacyNoticeAccepted() override;
void OnPasswordChangeDeclined() override;
void AddObserver(PasswordChangeDelegate::Observer* observer) override;
void RemoveObserver(PasswordChangeDelegate::Observer* observer) override;
void OnOtpNotFound();
void OnTabWillDetach(tabs::TabInterface* tab_interface,
tabs::TabInterface::DetachReason reason);
// Updates `current_state_` and notifies `observers_`.
void UpdateState(State new_state);
void OnPasswordChangeFormFound(
password_manager::PasswordFormManager* form_manager);
void OnChangeFormSubmissionVerified(bool result);
bool IsPrivacyNoticeAcknowledged() const;
std::u16string GetDisplayOrigin() const;
void OnCrossOriginNavigationDetected();
const GURL change_password_url_;
const std::u16string username_;
const std::u16string original_password_;
std::u16string generated_password_;
raw_ptr<content::WebContents> originator_ = nullptr;
std::unique_ptr<content::WebContents> executor_;
const raw_ptr<Profile> profile_ = nullptr;
// Helper class which uploads model quality logs.
std::unique_ptr<ModelQualityLogsUploader> logs_uploader_;
State current_state_ = State::kNoState;
std::unique_ptr<OtpDetectionHelper> otp_detection_;
// Helper class which looks for a change password form.
std::unique_ptr<ChangePasswordFormFinder> form_finder_;
// Helper class which submits a form and verifies submission.
std::unique_ptr<ChangePasswordFormFillingSubmissionHelper>
submission_verifier_;
base::ObserverList<PasswordChangeDelegate::Observer, /*check_empty=*/true>
observers_;
// The time when the initial dialog was displayed to the user.
base::Time leak_dialog_display_time_;
// The time when the user started the password change flow.
base::Time flow_start_time_;
// The time when the password change form was found.
base::Time change_password_form_found_time_;
// The controller for password change views.
std::unique_ptr<PasswordChangeUIController> ui_controller_;
// Helper class for handling happiness tracking surveys.
std::unique_ptr<PasswordChangeHats> password_change_hats_;
std::unique_ptr<CrossOriginNavigationObserver> navigation_observer_;
base::CallbackListSubscription tab_will_detach_subscription_;
base::ScopedObservation<password_manager::OtpManager,
password_manager::OtpManager::Observer>
otp_observation_{this};
ukm::SourceId ukm_source_id_ = ukm::kInvalidSourceId;
base::WeakPtrFactory<PasswordChangeDelegateImpl> weak_ptr_factory_{this};
};
#endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_CHANGE_DELEGATE_IMPL_H_
|