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_
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"
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
{
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
);
43 // Returns true if this document is one that we should consider analyzing.
44 // Virtual so that it can be overriden during testing.
45 virtual bool ShouldAnalyzeDocument(const blink::WebDocument
& document
) const;
47 // RenderViewObserver:
48 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
50 // Use to force enable during testing.
51 void set_enabled(bool enabled
) { enabled_
= enabled
; }
54 // RenderViewObserver:
55 virtual void DidFinishDocumentLoad(blink::WebLocalFrame
* frame
) OVERRIDE
;
56 virtual void DidFinishLoad(blink::WebLocalFrame
* frame
) OVERRIDE
;
59 void OnFormNotBlacklisted(const PasswordForm
& form
);
60 void OnPasswordAccepted(const base::string16
& password
);
61 void OnAccountCreationFormsDetected(
62 const std::vector
<autofill::FormData
>& forms
);
64 // Helper function to decide if |passwords_| contains password fields for
65 // an account creation form. Sets |generation_element_| to the field that
66 // we want to trigger the generation UI on.
67 void DetermineGenerationElement();
69 // Show password generation UI anchored at |generation_element_|.
70 void ShowGenerationPopup();
72 // Show UI for editing a generated password at |generation_element_|.
73 void ShowEditingPopup();
75 // Hides a password generation popup if one exists.
78 content::RenderView
* render_view_
;
80 // Stores the origin of the account creation form we detected.
81 scoped_ptr
<PasswordForm
> possible_account_creation_form_
;
83 // Stores the origins of the password forms confirmed not to be blacklisted
84 // by the browser. A form can be blacklisted if a user chooses "never save
85 // passwords for this site".
86 std::vector
<GURL
> not_blacklisted_password_form_origins_
;
88 // Stores each password form for which the Autofill server classifies one of
89 // the form's fields as an ACCOUNT_CREATION_PASSWORD. These forms will
90 // not be sent if the feature is disabled.
91 std::vector
<autofill::FormData
> generation_enabled_forms_
;
93 // Password elements that may be part of an account creation form.
94 std::vector
<blink::WebInputElement
> password_elements_
;
96 // Element where we want to trigger password generation UI.
97 blink::WebInputElement generation_element_
;
99 // If the password field at |generation_element_| contains a generated
101 bool password_is_generated_
;
103 // True if a password was generated and the user edited it. Used for UMA
105 bool password_edited_
;
107 // If this feature is enabled. Controlled by Finch.
110 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgent
);
113 } // namespace autofill
115 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_