| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
| 17 #include "components/autofill/content/public/interfaces/autofill_agent.mojom.h" |
| 18 #include "components/autofill/content/public/interfaces/autofill_driver.mojom.h" |
| 17 #include "content/public/renderer/render_frame_observer.h" | 19 #include "content/public/renderer/render_frame_observer.h" |
| 20 #include "mojo/public/cpp/bindings/binding.h" |
| 18 #include "third_party/WebKit/public/web/WebInputElement.h" | 21 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 19 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 20 | 23 |
| 21 namespace blink { | 24 namespace blink { |
| 22 class WebDocument; | 25 class WebDocument; |
| 23 } | 26 } |
| 24 | 27 |
| 25 namespace autofill { | 28 namespace autofill { |
| 26 | 29 |
| 27 struct FormData; | 30 struct FormData; |
| 28 struct PasswordForm; | 31 struct PasswordForm; |
| 29 struct PasswordFormGenerationData; | 32 struct PasswordFormGenerationData; |
| 30 class PasswordAutofillAgent; | 33 class PasswordAutofillAgent; |
| 31 | 34 |
| 32 // This class is responsible for controlling communication for password | 35 // This class is responsible for controlling communication for password |
| 33 // generation between the browser (which shows the popup and generates | 36 // generation between the browser (which shows the popup and generates |
| 34 // passwords) and WebKit (shows the generation icon in the password field). | 37 // passwords) and WebKit (shows the generation icon in the password field). |
| 35 class PasswordGenerationAgent : public content::RenderFrameObserver { | 38 class PasswordGenerationAgent : public content::RenderFrameObserver, |
| 39 public mojom::PasswordGenerationAgent { |
| 36 public: | 40 public: |
| 37 PasswordGenerationAgent(content::RenderFrame* render_frame, | 41 PasswordGenerationAgent(content::RenderFrame* render_frame, |
| 38 PasswordAutofillAgent* password_agent); | 42 PasswordAutofillAgent* password_agent); |
| 39 ~PasswordGenerationAgent() override; | 43 ~PasswordGenerationAgent() override; |
| 40 | 44 |
| 45 void BindRequest(mojom::PasswordGenerationAgentRequest request); |
| 46 |
| 47 // mojom::PasswordGenerationAgent: |
| 48 void FormNotBlacklisted(const PasswordForm& form) override; |
| 49 void GeneratedPasswordAccepted(const base::string16& password) override; |
| 50 void FoundFormsEligibleForGeneration( |
| 51 const std::vector<PasswordFormGenerationData>& forms) override; |
| 52 // Sets |generation_element_| to the focused password field and shows a |
| 53 // generation popup at this field. |
| 54 void UserTriggeredGeneratePassword() override; |
| 55 // Enables the form classifier. |
| 56 void AllowToRunFormClassifier() override; |
| 57 |
| 41 // Returns true if the field being changed is one where a generated password | 58 // Returns true if the field being changed is one where a generated password |
| 42 // is being offered. Updates the state of the popup if necessary. | 59 // is being offered. Updates the state of the popup if necessary. |
| 43 bool TextDidChangeInTextField(const blink::WebInputElement& element); | 60 bool TextDidChangeInTextField(const blink::WebInputElement& element); |
| 44 | 61 |
| 45 // Returns true if the newly focused node caused the generation UI to show. | 62 // Returns true if the newly focused node caused the generation UI to show. |
| 46 bool FocusedNodeHasChanged(const blink::WebNode& node); | 63 bool FocusedNodeHasChanged(const blink::WebNode& node); |
| 47 | 64 |
| 48 // Called when new form controls are inserted. | 65 // Called when new form controls are inserted. |
| 49 void OnDynamicFormsSeen(); | 66 void OnDynamicFormsSeen(); |
| 50 | 67 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 67 AccountCreationFormData( | 84 AccountCreationFormData( |
| 68 linked_ptr<PasswordForm> form, | 85 linked_ptr<PasswordForm> form, |
| 69 std::vector<blink::WebInputElement> password_elements); | 86 std::vector<blink::WebInputElement> password_elements); |
| 70 AccountCreationFormData(const AccountCreationFormData& other); | 87 AccountCreationFormData(const AccountCreationFormData& other); |
| 71 ~AccountCreationFormData(); | 88 ~AccountCreationFormData(); |
| 72 }; | 89 }; |
| 73 | 90 |
| 74 typedef std::vector<AccountCreationFormData> AccountCreationFormDataList; | 91 typedef std::vector<AccountCreationFormData> AccountCreationFormDataList; |
| 75 | 92 |
| 76 // RenderFrameObserver: | 93 // RenderFrameObserver: |
| 77 bool OnMessageReceived(const IPC::Message& message) override; | |
| 78 void DidFinishDocumentLoad() override; | 94 void DidFinishDocumentLoad() override; |
| 79 void DidFinishLoad() override; | 95 void DidFinishLoad() override; |
| 80 void OnDestruct() override; | 96 void OnDestruct() override; |
| 81 | 97 |
| 82 // Message handlers. | 98 const mojom::PasswordManagerDriverPtr& GetPasswordManagerDriver(); |
| 83 void OnFormNotBlacklisted(const PasswordForm& form); | |
| 84 void OnPasswordAccepted(const base::string16& password); | |
| 85 void OnFormsEligibleForGenerationFound( | |
| 86 const std::vector<autofill::PasswordFormGenerationData>& forms); | |
| 87 | 99 |
| 88 // Helper function that will try and populate |password_elements_| and | 100 // Helper function that will try and populate |password_elements_| and |
| 89 // |possible_account_creation_form_|. | 101 // |possible_account_creation_form_|. |
| 90 void FindPossibleGenerationForm(); | 102 void FindPossibleGenerationForm(); |
| 91 | 103 |
| 92 // Helper function to decide if |passwords_| contains password fields for | 104 // Helper function to decide if |passwords_| contains password fields for |
| 93 // an account creation form. Sets |generation_element_| to the field that | 105 // an account creation form. Sets |generation_element_| to the field that |
| 94 // we want to trigger the generation UI on. | 106 // we want to trigger the generation UI on. |
| 95 void DetermineGenerationElement(); | 107 void DetermineGenerationElement(); |
| 96 | 108 |
| 97 // Show password generation UI anchored at |generation_element_|. | 109 // Show password generation UI anchored at |generation_element_|. |
| 98 void ShowGenerationPopup(); | 110 void ShowGenerationPopup(); |
| 99 | 111 |
| 100 // Show UI for editing a generated password at |generation_element_|. | 112 // Show UI for editing a generated password at |generation_element_|. |
| 101 void ShowEditingPopup(); | 113 void ShowEditingPopup(); |
| 102 | 114 |
| 103 // Hides a password generation popup if one exists. | 115 // Hides a password generation popup if one exists. |
| 104 void HidePopup(); | 116 void HidePopup(); |
| 105 | 117 |
| 106 // Sets |generation_element_| to the focused password field and shows a | |
| 107 // generation popup at this field. | |
| 108 void OnUserTriggeredGeneratePassword(); | |
| 109 | |
| 110 // Enables the form classifier. | |
| 111 void OnAllowToRunFormClassifier(); | |
| 112 | |
| 113 // Runs HTML parsing based classifier and saves its outcome to proto. | 118 // Runs HTML parsing based classifier and saves its outcome to proto. |
| 114 // TODO(crbug.com/621442): Remove client-side form classifier when server-side | 119 // TODO(crbug.com/621442): Remove client-side form classifier when server-side |
| 115 // classifier is ready. | 120 // classifier is ready. |
| 116 void RunFormClassifierAndSaveVote(const blink::WebFormElement& web_form, | 121 void RunFormClassifierAndSaveVote(const blink::WebFormElement& web_form, |
| 117 const PasswordForm& form); | 122 const PasswordForm& form); |
| 118 | 123 |
| 119 // Creates a password form to presave a generated password. It copies behavior | 124 // Creates a password form to presave a generated password. It copies behavior |
| 120 // of CreatePasswordFormFromWebForm/FromUnownedInputElements, but takes | 125 // of CreatePasswordFormFromWebForm/FromUnownedInputElements, but takes |
| 121 // |password_value| from |generation_element_| and empties |username_value|. | 126 // |password_value| from |generation_element_| and empties |username_value|. |
| 122 // If a form creating is failed, returns an empty unique_ptr. | 127 // If a form creating is failed, returns an empty unique_ptr. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // If this feature is enabled. Controlled by Finch. | 175 // If this feature is enabled. Controlled by Finch. |
| 171 bool enabled_; | 176 bool enabled_; |
| 172 | 177 |
| 173 // If the form classifier should run. | 178 // If the form classifier should run. |
| 174 bool form_classifier_enabled_; | 179 bool form_classifier_enabled_; |
| 175 | 180 |
| 176 // Unowned pointer. Used to notify PassowrdAutofillAgent when values | 181 // Unowned pointer. Used to notify PassowrdAutofillAgent when values |
| 177 // in password fields are updated. | 182 // in password fields are updated. |
| 178 PasswordAutofillAgent* password_agent_; | 183 PasswordAutofillAgent* password_agent_; |
| 179 | 184 |
| 185 mojo::Binding<mojom::PasswordGenerationAgent> binding_; |
| 186 |
| 180 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgent); | 187 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationAgent); |
| 181 }; | 188 }; |
| 182 | 189 |
| 183 } // namespace autofill | 190 } // namespace autofill |
| 184 | 191 |
| 185 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_ | 192 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PASSWORD_GENERATION_AGENT_H_ |
| OLD | NEW |