Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / autofill / content / renderer / password_generation_agent.h
blob2d75af0376d36170c0bbedf8abe908de4089f279
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/scoped_ptr.h"
13 #include "content/public/renderer/render_view_observer.h"
14 #include "third_party/WebKit/public/web/WebInputElement.h"
15 #include "url/gurl.h"
17 namespace blink {
18 class WebCString;
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::RenderViewObserver {
31 public:
32 explicit PasswordGenerationAgent(content::RenderView* render_view);
33 virtual ~PasswordGenerationAgent();
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 // The length that a password can be before the UI is hidden.
43 static const size_t kMaximumOfferSize = 5;
45 protected:
46 // Returns true if this document is one that we should consider analyzing.
47 // Virtual so that it can be overriden during testing.
48 virtual bool ShouldAnalyzeDocument(const blink::WebDocument& document) const;
50 // RenderViewObserver:
51 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
53 // Use to force enable during testing.
54 void set_enabled(bool enabled) { enabled_ = enabled; }
56 private:
57 // RenderViewObserver:
58 virtual void DidFinishDocumentLoad(blink::WebLocalFrame* frame) OVERRIDE;
59 virtual void DidFinishLoad(blink::WebLocalFrame* frame) OVERRIDE;
61 // Message handlers.
62 void OnFormNotBlacklisted(const PasswordForm& form);
63 void OnPasswordAccepted(const base::string16& password);
64 void OnAccountCreationFormsDetected(
65 const std::vector<autofill::FormData>& forms);
67 // Helper function to decide if |passwords_| contains password fields for
68 // an account creation form. Sets |generation_element_| to the field that
69 // we want to trigger the generation UI on.
70 void DetermineGenerationElement();
72 // Show password generation UI anchored at |generation_element_|.
73 void ShowGenerationPopup();
75 // Show UI for editing a generated password at |generation_element_|.
76 void ShowEditingPopup();
78 // Hides a password generation popup if one exists.
79 void HidePopup();
81 content::RenderView* render_view_;
83 // Stores the origin of the account creation form we detected.
84 scoped_ptr<PasswordForm> possible_account_creation_form_;
86 // Stores the origins of the password forms confirmed not to be blacklisted
87 // by the browser. A form can be blacklisted if a user chooses "never save
88 // passwords for this site".
89 std::vector<GURL> not_blacklisted_password_form_origins_;
91 // Stores each password form for which the Autofill server classifies one of
92 // the form's fields as an ACCOUNT_CREATION_PASSWORD. These forms will
93 // not be sent if the feature is disabled.
94 std::vector<autofill::FormData> generation_enabled_forms_;
96 // Password elements that may be part of an account creation form.
97 std::vector<blink::WebInputElement> password_elements_;
99 // Element where we want to trigger password generation UI.
100 blink::WebInputElement generation_element_;
102 // If the password field at |generation_element_| contains a generated
103 // password.
104 bool password_is_generated_;
106 // True if a password was generated and the user edited it. Used for UMA
107 // stats.
108 bool password_edited_;
110 // If this feature is enabled. Controlled by Finch.
111 bool enabled_;
113 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgent);
116 } // namespace autofill
118 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_