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
|
// 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.
#ifndef COMPONENTS_PASSWORD_MANAGER_IOS_IOS_PASSWORD_MANAGER_DRIVER_H_
#define COMPONENTS_PASSWORD_MANAGER_IOS_IOS_PASSWORD_MANAGER_DRIVER_H_
#import <vector>
#import "base/memory/raw_ptr.h"
#import "base/memory/weak_ptr.h"
#import "components/autofill/core/common/aliases.h"
#import "components/autofill/core/common/field_data_manager.h"
#import "components/password_manager/core/browser/password_generation_frame_helper.h"
#import "components/password_manager/core/browser/password_manager_driver.h"
#import "components/password_manager/ios/password_manager_driver_bridge.h"
#import "url/gurl.h"
#import "url/origin.h"
namespace autofill {
struct PasswordFormFillData;
} // namespace autofill
namespace password_manager {
class PasswordAutofillManager;
class PasswordManager;
} // namespace password_manager
namespace web {
class WebFrame;
class WebState;
} // namespace web
// An iOS implementation of password_manager::PasswordManagerDriver.
class IOSPasswordManagerDriver final
: public password_manager::PasswordManagerDriver,
public base::RefCountedThreadSafe<IOSPasswordManagerDriver> {
public:
IOSPasswordManagerDriver(const IOSPasswordManagerDriver&) = delete;
IOSPasswordManagerDriver& operator=(const IOSPasswordManagerDriver&) = delete;
// password_manager::PasswordManagerDriver implementation.
int GetId() const override;
void PropagateFillDataOnParsingCompletion(
const autofill::PasswordFormFillData& form_data) override;
void InformNoSavedCredentials(
bool should_show_popup_without_passwords) override;
void FormEligibleForGenerationFound(
const autofill::PasswordFormGenerationData& form) override;
void GeneratedPasswordAccepted(const std::u16string& password) override;
void FillSuggestion(const std::u16string& username,
const std::u16string& password,
base::OnceCallback<void(bool)> success_callback) override;
void FillSuggestionById(
autofill::FieldRendererId username_element_id,
autofill::FieldRendererId password_element_id,
const std::u16string& username,
const std::u16string& password,
autofill::AutofillSuggestionTriggerSource suggestion_source) override;
void PreviewSuggestion(const std::u16string& username,
const std::u16string& password) override;
void PreviewSuggestionById(autofill::FieldRendererId username_element_id,
autofill::FieldRendererId password_element_id,
const std::u16string& username,
const std::u16string& password) override;
void PreviewGenerationSuggestion(const std::u16string& password) override;
void ClearPreviewedForm() override;
void SetSuggestionAvailability(
autofill::FieldRendererId generation_element_id,
autofill::mojom::AutofillSuggestionAvailability suggestion_availability)
override;
password_manager::PasswordGenerationFrameHelper* GetPasswordGenerationHelper()
override;
password_manager::PasswordManagerInterface* GetPasswordManager() override;
password_manager::PasswordAutofillManager* GetPasswordAutofillManager()
override;
int GetFrameId() const override;
bool IsInPrimaryMainFrame() const override;
bool CanShowAutofillUi() const override;
const GURL& GetLastCommittedURL() const override;
base::WeakPtr<PasswordManagerDriver> AsWeakPtr() override;
const std::string& web_frame_id() const { return frame_id_; }
const url::Origin& security_origin() const { return security_origin_; }
autofill::FieldDataManager& field_data_manager() {
return *field_data_manager_;
}
const autofill::FieldDataManager& field_data_manager() const {
return *field_data_manager_;
}
private:
// The constructor below is private so that no one uses it while trying to
// create/get a driver. However, IOSPasswordManagerWebFrameDriverHelper needs
// to be able to access it in the driver creation flow.
friend class IOSPasswordManagerWebFrameDriverHelper;
friend class base::RefCountedThreadSafe<IOSPasswordManagerDriver>;
// To create a new driver, use
// IOSPasswordManagerDriverFactory::FromWebStateAndWebFrame.
IOSPasswordManagerDriver(
web::WebState* web_state,
id<PasswordManagerDriverBridge> bridge,
password_manager::PasswordManagerInterface* password_manager,
web::WebFrame* web_frame,
int driver_id);
~IOSPasswordManagerDriver() override;
base::WeakPtr<web::WebState> web_state_;
__weak id<PasswordManagerDriverBridge> bridge_; // (weak)
raw_ptr<password_manager::PasswordManagerInterface> password_manager_;
std::unique_ptr<password_manager::PasswordGenerationFrameHelper>
password_generation_helper_;
int id_;
// The hash of the cached frame ID of `web_frame_`. This is cached because
// `web_frame` might be set to null when the frame is deleted.
int cached_frame_id_;
// The frame ID of `web_frame_`. This is used to get the web frame associated
// to it and determine if it is still a valid web frame. See `web_frame_`
// comment: the driver can outlive the `web_frame()`. This can happen when the
// driver is handling the saving, editing or syncing of the password after a
// form submission.
std::string frame_id_;
// Because `this` can outlast `web_frame_`, we keep a refptr to the associated
// FieldDataManager, to ensure it also outlives the frame.
const scoped_refptr<autofill::FieldDataManager> field_data_manager_;
bool is_in_main_frame_;
// The security origin associated with |web_frame_|.
url::Origin security_origin_;
// True when the conditions are met to display the proactive password
// generation bottom sheet, the sheet that is automatically triggered when you
// tap on a new password field.
bool can_use_proactive_generation_ = false;
// Forms eligible for proactive generation that need listeners attached to if
// the conditions are met.
std::vector<autofill::PasswordFormGenerationData>
pending_forms_for_proactive_generation_;
base::WeakPtrFactory<IOSPasswordManagerDriver> weak_factory_{this};
};
#endif // COMPONENTS_PASSWORD_MANAGER_IOS_IOS_PASSWORD_MANAGER_DRIVER_H_
|