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. 4 5 #ifndef COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_GENERATION_UTIL_H_ 6 #define COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_GENERATION_UTIL_H_ 7 8 #include "base/i18n/rtl.h" 9 #include "base/strings/string16.h" 10 #include "components/autofill/core/common/form_data.h" 11 #include "components/autofill/core/common/renderer_id.h" 12 #include "ui/gfx/geometry/rect_f.h" 13 14 namespace autofill { 15 16 namespace password_generation { 17 18 // Enumerates various events related to the password generation process. 19 // Do not remove items from this enum as they are used for UMA stats logging. 20 enum PasswordGenerationEvent { 21 // No Account creation form is detected. 22 NO_SIGN_UP_DETECTED, 23 24 // Account creation form is detected. 25 SIGN_UP_DETECTED, 26 27 // DEPRECATED: Password generation icon shown (old UI). 28 DEPRECATED_ICON_SHOWN, 29 30 // DEPRECATED: Password generation bubble shown (old UI). 31 DEPRECATED_BUBBLE_SHOWN, 32 33 // Password generation could be triggered if the user selects the appropriate 34 // element. 35 GENERATION_AVAILABLE, 36 37 // Password generation popup is shown after user focuses the appropriate 38 // password field. 39 // DEPRECATED: These reports were triggered when the popup could have shown 40 // not when it did show so they paint an unreliable picture. Newer stats 41 // are only incremented per page, which is more useful to judge the 42 // effectiveness of the UI. 43 DEPRECATED_GENERATION_POPUP_SHOWN, 44 45 // Generated password was accepted by the user. 46 PASSWORD_ACCEPTED, 47 48 // User focused the password field containing the generated password. 49 // DEPRECATED: These reports were triggered when the popup could have shown 50 // not when it did show so they paint an unreliable picture. Newer stats 51 // are only incremented per page, which is more useful to judge the 52 // effectiveness of the UI. 53 DEPRECATED_EDITING_POPUP_SHOWN, 54 55 // Password was changed after generation. 56 PASSWORD_EDITED, 57 58 // Generated password was deleted by the user 59 PASSWORD_DELETED, 60 61 // Password generation popup is shown after user focuses the appropriate 62 // password field. 63 GENERATION_POPUP_SHOWN, 64 65 // User focused the password field containing the generated password. 66 EDITING_POPUP_SHOWN, 67 68 // Generation enabled because autocomplete attributes for new-password is set. 69 AUTOCOMPLETE_ATTRIBUTES_ENABLED_GENERATION, 70 71 // Generation is triggered by the user from the context menu. 72 PASSWORD_GENERATION_CONTEXT_MENU_PRESSED, 73 74 // Context menu with generation item was shown. 75 PASSWORD_GENERATION_CONTEXT_MENU_SHOWN, 76 77 // The generated password was removed from the field because a credential 78 // was autofilled. 79 PASSWORD_DELETED_BY_AUTOFILLING, 80 81 // Number of enum entries, used for UMA histogram reporting macros. 82 EVENT_ENUM_COUNT 83 }; 84 85 enum class PasswordGenerationType { 86 // The user was automatically shown the possibility to generate a password. 87 kAutomatic, 88 // The user had to manually request password generation. 89 kManual 90 }; 91 92 // Wrapper to store the user interactions with the password generation bubble. 93 struct PasswordGenerationActions { 94 // Whether the user has clicked on the learn more link. 95 bool learn_more_visited; 96 97 // Whether the user has accepted the generated password. 98 bool password_accepted; 99 100 // Whether the user has manually edited password entry. 101 bool password_edited; 102 103 // Whether the user has clicked on the regenerate button. 104 bool password_regenerated; 105 106 PasswordGenerationActions(); 107 ~PasswordGenerationActions(); 108 }; 109 110 struct PasswordGenerationUIData { 111 PasswordGenerationUIData(const gfx::RectF& bounds, 112 int max_length, 113 const base::string16& generation_element, 114 FieldRendererId generation_element_id, 115 bool is_generation_element_password_type, 116 base::i18n::TextDirection text_direction, 117 const autofill::FormData& form_data); 118 PasswordGenerationUIData(); 119 PasswordGenerationUIData(const PasswordGenerationUIData& rhs); 120 PasswordGenerationUIData(PasswordGenerationUIData&& rhs); 121 PasswordGenerationUIData& operator=(const PasswordGenerationUIData& rhs); 122 PasswordGenerationUIData& operator=(PasswordGenerationUIData&& rhs); 123 ~PasswordGenerationUIData(); 124 125 // Location at which to display a popup if needed. This location is specified 126 // in the renderer's coordinate system. The popup will be anchored at 127 // |bounds|. 128 gfx::RectF bounds; 129 130 // Maximum length of the generated password. 131 int max_length; 132 133 // Name of the password field to which the generation popup is attached. 134 base::string16 generation_element; 135 136 // Renderer ID of the generation element. 137 FieldRendererId generation_element_id; 138 139 // Is the generation element |type=password|. 140 bool is_generation_element_password_type; 141 142 // Direction of the text for |generation_element|. 143 base::i18n::TextDirection text_direction; 144 145 // The form associated with the password field. 146 autofill::FormData form_data; 147 }; 148 149 void LogPasswordGenerationEvent(PasswordGenerationEvent event); 150 151 } // namespace password_generation 152 } // namespace autofill 153 154 #endif // COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_GENERATION_UTIL_H_ 155