refactor: mojofy autofill (#18723)

This commit is contained in:
Jeremy Apthorp 2019-06-12 15:08:22 -07:00 committed by GitHub
parent ec10fd3044
commit ba96cdb7dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 76 additions and 160 deletions

View file

@ -7,8 +7,11 @@
#include <vector>
#include "atom/common/api/api.mojom.h"
#include "base/memory/weak_ptr.h"
#include "content/public/renderer/render_frame_observer.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/blink/public/web/web_autofill_client.h"
#include "third_party/blink/public/web/web_element.h"
#include "third_party/blink/public/web/web_form_control_element.h"
@ -17,11 +20,15 @@
namespace atom {
class AutofillAgent : public content::RenderFrameObserver,
public blink::WebAutofillClient {
public blink::WebAutofillClient,
public mojom::ElectronAutofillAgent {
public:
explicit AutofillAgent(content::RenderFrame* frame);
explicit AutofillAgent(content::RenderFrame* frame,
blink::AssociatedInterfaceRegistry* registry);
~AutofillAgent() override;
void BindRequest(mojom::ElectronAutofillAgentAssociatedRequest request);
// content::RenderFrameObserver:
void OnDestruct() override;
@ -38,8 +45,6 @@ class AutofillAgent : public content::RenderFrameObserver,
bool requires_caret_at_end;
};
bool OnMessageReceived(const IPC::Message& message) override;
// blink::WebAutofillClient:
void TextFieldDidEndEditing(const blink::WebInputElement&) override;
void TextFieldDidChange(const blink::WebFormControlElement&) override;
@ -49,6 +54,9 @@ class AutofillAgent : public content::RenderFrameObserver,
void OpenTextDataListChooser(const blink::WebInputElement&) override;
void DataListOptionsChanged(const blink::WebInputElement&) override;
// mojom::ElectronAutofillAgent
void AcceptDataListSuggestion(const base::string16& suggestion) override;
bool IsUserGesture() const;
void HidePopup();
void ShowPopup(const blink::WebFormControlElement&,
@ -56,10 +64,12 @@ class AutofillAgent : public content::RenderFrameObserver,
const std::vector<base::string16>&);
void ShowSuggestions(const blink::WebFormControlElement& element,
const ShowSuggestionsOptions& options);
void OnAcceptSuggestion(base::string16 suggestion);
void DoFocusChangeComplete();
const mojom::ElectronBrowserPtr& GetElectronBrowser();
mojom::ElectronBrowserPtr browser_ptr_;
// True when the last click was on the focused node.
bool focused_node_was_last_clicked_ = false;
@ -68,6 +78,8 @@ class AutofillAgent : public content::RenderFrameObserver,
// already focused, or if it caused the focus to change.
bool was_focused_before_now_ = false;
mojo::AssociatedBinding<mojom::ElectronAutofillAgent> binding_;
base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(AutofillAgent);