ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / components / autofill / content / renderer / password_generation_agent.h
blob33aa6cc27bb078d3454d404c47ce45402903d362
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_
8 #include <map>
9 #include <utility>
10 #include <vector>
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "content/public/renderer/render_frame_observer.h"
15 #include "third_party/WebKit/public/web/WebInputElement.h"
16 #include "url/gurl.h"
18 namespace blink {
19 class WebDocument;
22 namespace autofill {
24 struct FormData;
25 struct PasswordForm;
27 // This class is responsible for controlling communication for password
28 // generation between the browser (which shows the popup and generates
29 // passwords) and WebKit (shows the generation icon in the password field).
30 class PasswordGenerationAgent : public content::RenderFrameObserver {
31 public:
32 explicit PasswordGenerationAgent(content::RenderFrame* render_frame);
33 ~PasswordGenerationAgent() override;
35 // Returns true if the field being changed is one where a generated password
36 // is being offered. Updates the state of the popup if necessary.
37 bool TextDidChangeInTextField(const blink::WebInputElement& element);
39 // Returns true if the newly focused node caused the generation UI to show.
40 bool FocusedNodeHasChanged(const blink::WebNode& node);
42 // Called when new form controls are inserted.
43 void OnDynamicFormsSeen();
45 // The length that a password can be before the UI is hidden.
46 static const size_t kMaximumOfferSize = 5;
48 protected:
49 // Returns true if the document for |render_frame()| is one that we should
50 // consider analyzing. Virtual so that it can be overriden during testing.
51 virtual bool ShouldAnalyzeDocument() const;
53 // RenderViewObserver:
54 bool OnMessageReceived(const IPC::Message& message) override;
56 // Use to force enable during testing.
57 void set_enabled(bool enabled) { enabled_ = enabled; }
59 private:
60 struct AccountCreationFormData {
61 linked_ptr<PasswordForm> form;
62 std::vector<blink::WebInputElement> password_elements;
64 AccountCreationFormData(
65 linked_ptr<PasswordForm> form,
66 std::vector<blink::WebInputElement> password_elements);
67 ~AccountCreationFormData();
70 typedef std::vector<AccountCreationFormData> AccountCreationFormDataList;
72 // RenderFrameObserver:
73 void DidFinishDocumentLoad() override;
75 // Message handlers.
76 void OnFormNotBlacklisted(const PasswordForm& form);
77 void OnPasswordAccepted(const base::string16& password);
78 void OnAccountCreationFormsDetected(
79 const std::vector<autofill::FormData>& forms);
81 // Helper function that will try and populate |password_elements_| and
82 // |possible_account_creation_form_|.
83 void FindPossibleGenerationForm();
85 // Helper function to decide if |passwords_| contains password fields for
86 // an account creation form. Sets |generation_element_| to the field that
87 // we want to trigger the generation UI on.
88 void DetermineGenerationElement();
90 // Show password generation UI anchored at |generation_element_|.
91 void ShowGenerationPopup();
93 // Show UI for editing a generated password at |generation_element_|.
94 void ShowEditingPopup();
96 // Hides a password generation popup if one exists.
97 void HidePopup();
99 // Stores forms that are candidates for account creation.
100 AccountCreationFormDataList possible_account_creation_forms_;
102 // Stores the origins of the password forms confirmed not to be blacklisted
103 // by the browser. A form can be blacklisted if a user chooses "never save
104 // passwords for this site".
105 std::vector<GURL> not_blacklisted_password_form_origins_;
107 // Stores each password form for which the Autofill server classifies one of
108 // the form's fields as an ACCOUNT_CREATION_PASSWORD. These forms will
109 // not be sent if the feature is disabled.
110 std::vector<autofill::FormData> generation_enabled_forms_;
112 // Data for form which generation is allowed on.
113 scoped_ptr<AccountCreationFormData> generation_form_data_;
115 // Element where we want to trigger password generation UI.
116 blink::WebInputElement generation_element_;
118 // If the password field at |generation_element_| contains a generated
119 // password.
120 bool password_is_generated_;
122 // True if a password was generated and the user edited it. Used for UMA
123 // stats.
124 bool password_edited_;
126 // True if the generation popup was shown during this navigation. Used to
127 // track UMA stats per page visit rather than per display, since the former
128 // is more interesting.
129 bool generation_popup_shown_;
131 // True if the editing popup was shown during this navigation. Used to track
132 // UMA stats per page rather than per display, since the former is more
133 // interesting.
134 bool editing_popup_shown_;
136 // If this feature is enabled. Controlled by Finch.
137 bool enabled_;
139 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgent);
142 } // namespace autofill
144 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_