OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_ |
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_ | 6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "content/public/renderer/render_view_observer.h" | 13 #include "content/public/renderer/render_frame_observer.h" |
14 #include "third_party/WebKit/public/web/WebInputElement.h" | 14 #include "third_party/WebKit/public/web/WebInputElement.h" |
15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 class WebDocument; | 18 class WebDocument; |
19 } | 19 } |
20 | 20 |
21 namespace autofill { | 21 namespace autofill { |
22 | 22 |
23 struct FormData; | 23 struct FormData; |
24 struct PasswordForm; | 24 struct PasswordForm; |
25 | 25 |
26 // This class is responsible for controlling communication for password | 26 // This class is responsible for controlling communication for password |
27 // generation between the browser (which shows the popup and generates | 27 // generation between the browser (which shows the popup and generates |
28 // passwords) and WebKit (shows the generation icon in the password field). | 28 // passwords) and WebKit (shows the generation icon in the password field). |
29 class PasswordGenerationAgent : public content::RenderViewObserver { | 29 class PasswordGenerationAgent : public content::RenderFrameObserver { |
30 public: | 30 public: |
31 explicit PasswordGenerationAgent(content::RenderView* render_view); | 31 explicit PasswordGenerationAgent(content::RenderFrame* render_frame); |
32 ~PasswordGenerationAgent() override; | 32 ~PasswordGenerationAgent() override; |
33 | 33 |
34 // Returns true if the field being changed is one where a generated password | 34 // Returns true if the field being changed is one where a generated password |
35 // is being offered. Updates the state of the popup if necessary. | 35 // is being offered. Updates the state of the popup if necessary. |
36 bool TextDidChangeInTextField(const blink::WebInputElement& element); | 36 bool TextDidChangeInTextField(const blink::WebInputElement& element); |
37 | 37 |
38 // Returns true if the newly focused node caused the generation UI to show. | 38 // Returns true if the newly focused node caused the generation UI to show. |
39 bool FocusedNodeHasChanged(const blink::WebNode& node); | 39 bool FocusedNodeHasChanged(const blink::WebNode& node); |
40 | 40 |
41 // Called when new form controls are inserted. | 41 // Called when new form controls are inserted. |
42 void OnDynamicFormsSeen(blink::WebLocalFrame* frame); | 42 void OnDynamicFormsSeen(); |
43 | 43 |
44 // The length that a password can be before the UI is hidden. | 44 // The length that a password can be before the UI is hidden. |
45 static const size_t kMaximumOfferSize = 5; | 45 static const size_t kMaximumOfferSize = 5; |
46 | 46 |
47 protected: | 47 protected: |
48 // Returns true if this document is one that we should consider analyzing. | 48 // Returns true if the document for |render_frame()| is one that we should |
49 // Virtual so that it can be overriden during testing. | 49 // consider analyzing. Virtual so that it can be overriden during testing. |
50 virtual bool ShouldAnalyzeDocument(const blink::WebDocument& document) const; | 50 virtual bool ShouldAnalyzeDocument() const; |
51 | 51 |
52 // RenderViewObserver: | 52 // RenderViewObserver: |
53 bool OnMessageReceived(const IPC::Message& message) override; | 53 bool OnMessageReceived(const IPC::Message& message) override; |
54 | 54 |
55 // Use to force enable during testing. | 55 // Use to force enable during testing. |
56 void set_enabled(bool enabled) { enabled_ = enabled; } | 56 void set_enabled(bool enabled) { enabled_ = enabled; } |
57 | 57 |
58 private: | 58 private: |
59 // RenderViewObserver: | 59 // RenderFrameObserver: |
60 void DidFinishDocumentLoad(blink::WebLocalFrame* frame) override; | 60 void DidFinishDocumentLoad() override; |
61 void DidFinishLoad(blink::WebLocalFrame* frame) override; | 61 void DidFinishLoad() override; |
62 | 62 |
63 // Message handlers. | 63 // Message handlers. |
64 void OnFormNotBlacklisted(const PasswordForm& form); | 64 void OnFormNotBlacklisted(const PasswordForm& form); |
65 void OnPasswordAccepted(const base::string16& password); | 65 void OnPasswordAccepted(const base::string16& password); |
66 void OnAccountCreationFormsDetected( | 66 void OnAccountCreationFormsDetected( |
67 const std::vector<autofill::FormData>& forms); | 67 const std::vector<autofill::FormData>& forms); |
68 | 68 |
69 // Helper function that will try and populate |password_elements_| and | 69 // Helper function that will try and populate |password_elements_| and |
70 // |possible_account_creation_form_|. | 70 // |possible_account_creation_form_|. |
71 void FindPossibleGenerationForm(blink::WebLocalFrame* frame); | 71 void FindPossibleGenerationForm(); |
72 | 72 |
73 // Helper function to decide if |passwords_| contains password fields for | 73 // Helper function to decide if |passwords_| contains password fields for |
74 // an account creation form. Sets |generation_element_| to the field that | 74 // an account creation form. Sets |generation_element_| to the field that |
75 // we want to trigger the generation UI on. | 75 // we want to trigger the generation UI on. |
76 void DetermineGenerationElement(); | 76 void DetermineGenerationElement(); |
77 | 77 |
78 // Show password generation UI anchored at |generation_element_|. | 78 // Show password generation UI anchored at |generation_element_|. |
79 void ShowGenerationPopup(); | 79 void ShowGenerationPopup(); |
80 | 80 |
81 // Show UI for editing a generated password at |generation_element_|. | 81 // Show UI for editing a generated password at |generation_element_|. |
82 void ShowEditingPopup(); | 82 void ShowEditingPopup(); |
83 | 83 |
84 // Hides a password generation popup if one exists. | 84 // Hides a password generation popup if one exists. |
85 void HidePopup(); | 85 void HidePopup(); |
86 | 86 |
87 content::RenderView* render_view_; | |
88 | |
89 // Stores the origin of the account creation form we detected. | 87 // Stores the origin of the account creation form we detected. |
90 scoped_ptr<PasswordForm> possible_account_creation_form_; | 88 scoped_ptr<PasswordForm> possible_account_creation_form_; |
91 | 89 |
92 // Stores the origins of the password forms confirmed not to be blacklisted | 90 // Stores the origins of the password forms confirmed not to be blacklisted |
93 // by the browser. A form can be blacklisted if a user chooses "never save | 91 // by the browser. A form can be blacklisted if a user chooses "never save |
94 // passwords for this site". | 92 // passwords for this site". |
95 std::vector<GURL> not_blacklisted_password_form_origins_; | 93 std::vector<GURL> not_blacklisted_password_form_origins_; |
96 | 94 |
97 // Stores each password form for which the Autofill server classifies one of | 95 // Stores each password form for which the Autofill server classifies one of |
98 // the form's fields as an ACCOUNT_CREATION_PASSWORD. These forms will | 96 // the form's fields as an ACCOUNT_CREATION_PASSWORD. These forms will |
(...skipping 26 matching lines...) Expand all Loading... |
125 | 123 |
126 // If this feature is enabled. Controlled by Finch. | 124 // If this feature is enabled. Controlled by Finch. |
127 bool enabled_; | 125 bool enabled_; |
128 | 126 |
129 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgent); | 127 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgent); |
130 }; | 128 }; |
131 | 129 |
132 } // namespace autofill | 130 } // namespace autofill |
133 | 131 |
134 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_ | 132 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_ |
OLD | NEW |