| Index: components/autofill/content/renderer/password_generation_agent.cc
|
| diff --git a/components/autofill/content/renderer/password_generation_agent.cc b/components/autofill/content/renderer/password_generation_agent.cc
|
| index 1264b0ce1cf270e3f43d8bc48bf4707fc9cb2dd4..71d45b6756910c9ef6b048542a112159fd3901de 100644
|
| --- a/components/autofill/content/renderer/password_generation_agent.cc
|
| +++ b/components/autofill/content/renderer/password_generation_agent.cc
|
| @@ -21,6 +21,7 @@
|
| #include "content/public/renderer/render_frame.h"
|
| #include "content/public/renderer/render_view.h"
|
| #include "google_apis/gaia/gaia_urls.h"
|
| +#include "services/shell/public/cpp/interface_registry.h"
|
| #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
|
| #include "third_party/WebKit/public/platform/WebVector.h"
|
| #include "third_party/WebKit/public/web/WebDocument.h"
|
| @@ -127,11 +128,20 @@ PasswordGenerationAgent::PasswordGenerationAgent(
|
| editing_popup_shown_(false),
|
| enabled_(password_generation::IsPasswordGenerationEnabled()),
|
| form_classifier_enabled_(false),
|
| - password_agent_(password_agent) {
|
| + password_agent_(password_agent),
|
| + binding_(this) {
|
| VLOG(2) << "Password Generation is " << (enabled_ ? "Enabled" : "Disabled");
|
| + // PasswordGenerationAgent is guaranteed to outlive |render_frame|.
|
| + render_frame->GetInterfaceRegistry()->AddInterface(base::Bind(
|
| + &PasswordGenerationAgent::BindRequest, base::Unretained(this)));
|
| }
|
| PasswordGenerationAgent::~PasswordGenerationAgent() {}
|
|
|
| +void PasswordGenerationAgent::BindRequest(
|
| + mojom::PasswordGenerationAgentRequest request) {
|
| + binding_.Bind(std::move(request));
|
| +}
|
| +
|
| void PasswordGenerationAgent::DidFinishDocumentLoad() {
|
| // Update stats for main frame navigation.
|
| if (!render_frame()->GetWebFrame()->parent()) {
|
| @@ -196,7 +206,7 @@ void PasswordGenerationAgent::OnDynamicFormsSeen() {
|
| FindPossibleGenerationForm();
|
| }
|
|
|
| -void PasswordGenerationAgent::OnAllowToRunFormClassifier() {
|
| +void PasswordGenerationAgent::AllowToRunFormClassifier() {
|
| form_classifier_enabled_ = true;
|
| }
|
|
|
| @@ -207,8 +217,8 @@ void PasswordGenerationAgent::RunFormClassifierAndSaveVote(
|
|
|
| base::string16 generation_field;
|
| ClassifyFormAndFindGenerationField(web_form, &generation_field);
|
| - Send(new AutofillHostMsg_SaveGenerationFieldDetectedByClassifier(
|
| - routing_id(), form, generation_field));
|
| + GetPasswordManagerDriver()->SaveGenerationFieldDetectedByClassifier(
|
| + form, generation_field);
|
| }
|
|
|
| void PasswordGenerationAgent::FindPossibleGenerationForm() {
|
| @@ -280,30 +290,12 @@ bool PasswordGenerationAgent::ShouldAnalyzeDocument() const {
|
| return true;
|
| }
|
|
|
| -bool PasswordGenerationAgent::OnMessageReceived(const IPC::Message& message) {
|
| - bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP(PasswordGenerationAgent, message)
|
| - IPC_MESSAGE_HANDLER(AutofillMsg_FormNotBlacklisted,
|
| - OnFormNotBlacklisted)
|
| - IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted,
|
| - OnPasswordAccepted)
|
| - IPC_MESSAGE_HANDLER(AutofillMsg_FoundFormsEligibleForGeneration,
|
| - OnFormsEligibleForGenerationFound);
|
| - IPC_MESSAGE_HANDLER(AutofillMsg_UserTriggeredGeneratePassword,
|
| - OnUserTriggeredGeneratePassword);
|
| - IPC_MESSAGE_HANDLER(AutofillMsg_AllowToRunFormClassifier,
|
| - OnAllowToRunFormClassifier);
|
| - IPC_MESSAGE_UNHANDLED(handled = false)
|
| - IPC_END_MESSAGE_MAP()
|
| - return handled;
|
| -}
|
| -
|
| -void PasswordGenerationAgent::OnFormNotBlacklisted(const PasswordForm& form) {
|
| +void PasswordGenerationAgent::FormNotBlacklisted(const PasswordForm& form) {
|
| not_blacklisted_password_form_origins_.push_back(form.origin);
|
| DetermineGenerationElement();
|
| }
|
|
|
| -void PasswordGenerationAgent::OnPasswordAccepted(
|
| +void PasswordGenerationAgent::GeneratedPasswordAccepted(
|
| const base::string16& password) {
|
| password_is_generated_ = true;
|
| password_generation::LogPasswordGenerationEvent(
|
| @@ -325,8 +317,7 @@ void PasswordGenerationAgent::OnPasswordAccepted(
|
| }
|
| std::unique_ptr<PasswordForm> presaved_form(CreatePasswordFormToPresave());
|
| if (presaved_form) {
|
| - Send(new AutofillHostMsg_PresaveGeneratedPassword(routing_id(),
|
| - *presaved_form));
|
| + GetPasswordManagerDriver()->PresaveGeneratedPassword(*presaved_form);
|
| }
|
| }
|
|
|
| @@ -354,8 +345,8 @@ PasswordGenerationAgent::CreatePasswordFormToPresave() {
|
| return password_form;
|
| }
|
|
|
| -void PasswordGenerationAgent::OnFormsEligibleForGenerationFound(
|
| - const std::vector<autofill::PasswordFormGenerationData>& forms) {
|
| +void PasswordGenerationAgent::FoundFormsEligibleForGeneration(
|
| + const std::vector<PasswordFormGenerationData>& forms) {
|
| generation_enabled_forms_.insert(generation_enabled_forms_.end(),
|
| forms.begin(), forms.end());
|
| DetermineGenerationElement();
|
| @@ -483,8 +474,7 @@ bool PasswordGenerationAgent::TextDidChangeInTextField(
|
| std::unique_ptr<PasswordForm> presaved_form(
|
| CreatePasswordFormToPresave());
|
| if (presaved_form) {
|
| - Send(new AutofillHostMsg_PasswordNoLongerGenerated(routing_id(),
|
| - *presaved_form));
|
| + GetPasswordManagerDriver()->PasswordNoLongerGenerated(*presaved_form);
|
| }
|
| }
|
|
|
| @@ -501,8 +491,7 @@ bool PasswordGenerationAgent::TextDidChangeInTextField(
|
| &generation_form_data_->password_elements);
|
| std::unique_ptr<PasswordForm> presaved_form(CreatePasswordFormToPresave());
|
| if (presaved_form) {
|
| - Send(new AutofillHostMsg_PresaveGeneratedPassword(routing_id(),
|
| - *presaved_form));
|
| + GetPasswordManagerDriver()->PresaveGeneratedPassword(*presaved_form);
|
| }
|
| } else if (element.value().length() > kMaximumOfferSize) {
|
| // User has rejected the feature and has started typing a password.
|
| @@ -546,7 +535,7 @@ void PasswordGenerationAgent::HidePopup() {
|
| Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id()));
|
| }
|
|
|
| -void PasswordGenerationAgent::OnUserTriggeredGeneratePassword() {
|
| +void PasswordGenerationAgent::UserTriggeredGeneratePassword() {
|
| if (last_focused_password_element_.isNull() || !render_frame())
|
| return;
|
|
|
| @@ -581,4 +570,10 @@ void PasswordGenerationAgent::OnUserTriggeredGeneratePassword() {
|
| ShowGenerationPopup();
|
| }
|
|
|
| +const mojom::PasswordManagerDriverPtr&
|
| +PasswordGenerationAgent::GetPasswordManagerDriver() {
|
| + DCHECK(password_agent_);
|
| + return password_agent_->GetPasswordManagerDriver();
|
| +}
|
| +
|
| } // namespace autofill
|
|
|