atom_autofill_agent.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "third_party/blink/public/web/web_autofill_client.h"
  10. #include "third_party/blink/public/web/web_element.h"
  11. #include "third_party/blink/public/web/web_form_control_element.h"
  12. #include "third_party/blink/public/web/web_input_element.h"
  13. namespace atom {
  14. class AutofillAgent : public content::RenderFrameObserver,
  15. public blink::WebAutofillClient {
  16. public:
  17. explicit AutofillAgent(content::RenderFrame* frame);
  18. ~AutofillAgent() override;
  19. // content::RenderFrameObserver:
  20. void OnDestruct() override;
  21. void DidChangeScrollOffset() override;
  22. void FocusedElementChanged(const blink::WebElement&) override;
  23. void DidCompleteFocusChangeInFrame() override;
  24. void DidReceiveLeftMouseDownOrGestureTapInNode(
  25. const blink::WebNode&) override;
  26. private:
  27. struct ShowSuggestionsOptions {
  28. ShowSuggestionsOptions();
  29. bool autofill_on_empty_values;
  30. bool requires_caret_at_end;
  31. };
  32. bool OnMessageReceived(const IPC::Message& message) override;
  33. // blink::WebAutofillClient:
  34. void TextFieldDidEndEditing(const blink::WebInputElement&) override;
  35. void TextFieldDidChange(const blink::WebFormControlElement&) override;
  36. void TextFieldDidChangeImpl(const blink::WebFormControlElement&);
  37. void TextFieldDidReceiveKeyDown(const blink::WebInputElement&,
  38. const blink::WebKeyboardEvent&) override;
  39. void OpenTextDataListChooser(const blink::WebInputElement&) override;
  40. void DataListOptionsChanged(const blink::WebInputElement&) override;
  41. bool IsUserGesture() const;
  42. void HidePopup();
  43. void ShowPopup(const blink::WebFormControlElement&,
  44. const std::vector<base::string16>&,
  45. const std::vector<base::string16>&);
  46. void ShowSuggestions(const blink::WebFormControlElement& element,
  47. const ShowSuggestionsOptions& options);
  48. void OnAcceptSuggestion(base::string16 suggestion);
  49. void DoFocusChangeComplete();
  50. // True when the last click was on the focused node.
  51. bool focused_node_was_last_clicked_ = false;
  52. // This is set to false when the focus changes, then set back to true soon
  53. // afterwards. This helps track whether an event happened after a node was
  54. // already focused, or if it caused the focus to change.
  55. bool was_focused_before_now_ = false;
  56. base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_;
  57. DISALLOW_COPY_AND_ASSIGN(AutofillAgent);
  58. };
  59. } // namespace atom
  60. #endif // ATOM_RENDERER_ATOM_AUTOFILL_AGENT_H_