atom_autofill_agent.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright (c) 2017 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_RENDERER_ATOM_AUTOFILL_AGENT_H_
  5. #define ATOM_RENDERER_ATOM_AUTOFILL_AGENT_H_
  6. #include <vector>
  7. #include "base/memory/weak_ptr.h"
  8. #include "content/public/renderer/render_frame_observer.h"
  9. #include "content/public/renderer/render_view_observer.h"
  10. #include "third_party/WebKit/public/web/WebAutofillClient.h"
  11. #include "third_party/WebKit/public/web/WebFormControlElement.h"
  12. #include "third_party/WebKit/public/web/WebInputElement.h"
  13. #include "third_party/WebKit/public/web/WebNode.h"
  14. namespace atom {
  15. class AutofillAgent : public content::RenderFrameObserver,
  16. public blink::WebAutofillClient {
  17. public:
  18. explicit AutofillAgent(content::RenderFrame* frame);
  19. ~AutofillAgent() override;
  20. // content::RenderFrameObserver:
  21. void OnDestruct() override;
  22. void DidChangeScrollOffset() override;
  23. void FocusedNodeChanged(const blink::WebNode&) override;
  24. void DidCompleteFocusChangeInFrame() override;
  25. void DidReceiveLeftMouseDownOrGestureTapInNode(
  26. const blink::WebNode&) override;
  27. private:
  28. struct ShowSuggestionsOptions {
  29. ShowSuggestionsOptions();
  30. bool autofill_on_empty_values;
  31. bool requires_caret_at_end;
  32. };
  33. bool OnMessageReceived(const IPC::Message& message) override;
  34. // blink::WebAutofillClient:
  35. void TextFieldDidEndEditing(const blink::WebInputElement&) override;
  36. void TextFieldDidChange(const blink::WebFormControlElement&) override;
  37. void TextFieldDidChangeImpl(const blink::WebFormControlElement&);
  38. void TextFieldDidReceiveKeyDown(const blink::WebInputElement&,
  39. const blink::WebKeyboardEvent&) override;
  40. void OpenTextDataListChooser(const blink::WebInputElement&) override;
  41. void DataListOptionsChanged(const blink::WebInputElement&) override;
  42. bool IsUserGesture() const;
  43. void HidePopup();
  44. void ShowPopup(const blink::WebFormControlElement&,
  45. const std::vector<base::string16>&,
  46. const std::vector<base::string16>&);
  47. void ShowSuggestions(const blink::WebFormControlElement& element,
  48. const ShowSuggestionsOptions& options);
  49. void OnAcceptSuggestion(base::string16 suggestion);
  50. void DoFocusChangeComplete();
  51. // True when the last click was on the focused node.
  52. bool focused_node_was_last_clicked_ = false;
  53. // This is set to false when the focus changes, then set back to true soon
  54. // afterwards. This helps track whether an event happened after a node was
  55. // already focused, or if it caused the focus to change.
  56. bool was_focused_before_now_ = false;
  57. base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_;
  58. DISALLOW_COPY_AND_ASSIGN(AutofillAgent);
  59. };
  60. } // namespace atom
  61. #endif // ATOM_RENDERER_ATOM_AUTOFILL_AGENT_H_