refactor: mojofy autofill (#18723)
This commit is contained in:
parent
ec10fd3044
commit
ba96cdb7dc
26 changed files with 76 additions and 160 deletions
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "atom/common/api/api_messages.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "atom/common/node_bindings.h"
|
||||
#include "atom/common/node_includes.h"
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include <vector>
|
||||
|
||||
#include "atom/common/api/api.mojom.h"
|
||||
#include "atom/common/api/api_messages.h"
|
||||
#include "atom/common/api/event_emitter_caller.h"
|
||||
#include "atom/common/native_mate_converters/blink_converter.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
|
|
|
@ -4,11 +4,12 @@
|
|||
|
||||
#include "atom/renderer/atom_autofill_agent.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/api/api_messages.h"
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "content/public/renderer/render_view.h"
|
||||
#include "services/service_manager/public/cpp/interface_provider.h"
|
||||
#include "third_party/blink/public/platform/web_keyboard_event.h"
|
||||
#include "third_party/blink/public/platform/web_string.h"
|
||||
#include "third_party/blink/public/web/web_document.h"
|
||||
|
@ -49,13 +50,23 @@ void TrimStringVectorForIPC(std::vector<base::string16>* strings) {
|
|||
}
|
||||
} // namespace
|
||||
|
||||
AutofillAgent::AutofillAgent(content::RenderFrame* frame)
|
||||
: content::RenderFrameObserver(frame), weak_ptr_factory_(this) {
|
||||
AutofillAgent::AutofillAgent(content::RenderFrame* frame,
|
||||
blink::AssociatedInterfaceRegistry* registry)
|
||||
: content::RenderFrameObserver(frame),
|
||||
binding_(this),
|
||||
weak_ptr_factory_(this) {
|
||||
render_frame()->GetWebFrame()->SetAutofillClient(this);
|
||||
registry->AddInterface(
|
||||
base::Bind(&AutofillAgent::BindRequest, base::Unretained(this)));
|
||||
}
|
||||
|
||||
AutofillAgent::~AutofillAgent() = default;
|
||||
|
||||
void AutofillAgent::BindRequest(
|
||||
mojom::ElectronAutofillAgentAssociatedRequest request) {
|
||||
binding_.Bind(std::move(request));
|
||||
}
|
||||
|
||||
void AutofillAgent::OnDestruct() {
|
||||
delete this;
|
||||
}
|
||||
|
@ -165,24 +176,13 @@ void AutofillAgent::DidCompleteFocusChangeInFrame() {
|
|||
DoFocusChangeComplete();
|
||||
}
|
||||
|
||||
bool AutofillAgent::OnMessageReceived(const IPC::Message& message) {
|
||||
bool handled = true;
|
||||
IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message)
|
||||
IPC_MESSAGE_HANDLER(AtomAutofillFrameMsg_AcceptSuggestion,
|
||||
OnAcceptSuggestion)
|
||||
IPC_MESSAGE_UNHANDLED(handled = false)
|
||||
IPC_END_MESSAGE_MAP()
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
bool AutofillAgent::IsUserGesture() const {
|
||||
return blink::WebUserGestureIndicator::IsProcessingUserGesture(
|
||||
render_frame()->GetWebFrame());
|
||||
}
|
||||
|
||||
void AutofillAgent::HidePopup() {
|
||||
Send(new AtomAutofillFrameHostMsg_HidePopup(render_frame()->GetRoutingID()));
|
||||
GetElectronBrowser()->HideAutofillPopup();
|
||||
}
|
||||
|
||||
void AutofillAgent::ShowPopup(const blink::WebFormControlElement& element,
|
||||
|
@ -190,11 +190,10 @@ void AutofillAgent::ShowPopup(const blink::WebFormControlElement& element,
|
|||
const std::vector<base::string16>& labels) {
|
||||
gfx::RectF bounds =
|
||||
render_frame()->GetRenderView()->ElementBoundsInWindow(element);
|
||||
Send(new AtomAutofillFrameHostMsg_ShowPopup(render_frame()->GetRoutingID(),
|
||||
bounds, values, labels));
|
||||
GetElectronBrowser()->ShowAutofillPopup(bounds, values, labels);
|
||||
}
|
||||
|
||||
void AutofillAgent::OnAcceptSuggestion(base::string16 suggestion) {
|
||||
void AutofillAgent::AcceptDataListSuggestion(const base::string16& suggestion) {
|
||||
auto element = render_frame()->GetWebFrame()->GetDocument().FocusedElement();
|
||||
if (element.IsFormControlElement()) {
|
||||
ToWebInputElement(&element)->SetAutofillValue(
|
||||
|
@ -219,4 +218,13 @@ void AutofillAgent::DoFocusChangeComplete() {
|
|||
focused_node_was_last_clicked_ = false;
|
||||
}
|
||||
|
||||
const mojom::ElectronBrowserPtr& AutofillAgent::GetElectronBrowser() {
|
||||
if (!browser_ptr_) {
|
||||
render_frame()->GetRemoteInterfaces()->GetInterface(
|
||||
mojo::MakeRequest(&browser_ptr_));
|
||||
}
|
||||
|
||||
return browser_ptr_;
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/api/api_messages.h"
|
||||
#include "atom/common/api/event_emitter_caller.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "atom/common/node_includes.h"
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "atom/renderer/atom_sandboxed_renderer_client.h"
|
||||
|
||||
#include "atom/common/api/api_messages.h"
|
||||
#include "atom/common/api/electron_bindings.h"
|
||||
#include "atom/common/application_info.h"
|
||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||
|
|
|
@ -200,7 +200,8 @@ void RendererClientBase::RenderThreadStarted() {
|
|||
void RendererClientBase::RenderFrameCreated(
|
||||
content::RenderFrame* render_frame) {
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
new AutofillAgent(render_frame);
|
||||
new AutofillAgent(render_frame,
|
||||
render_frame->GetAssociatedInterfaceRegistry());
|
||||
#endif
|
||||
#if BUILDFLAG(ENABLE_PEPPER_FLASH)
|
||||
new PepperHelper(render_frame);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue