| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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_BROWSER_AUTOFILL_EXTERNAL_DELEGATE_H_ | |
| 6 #define COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_EXTERNAL_DELEGATE_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/strings/string16.h" | |
| 13 #include "components/autofill/browser/autofill_popup_delegate.h" | |
| 14 #include "components/autofill/browser/password_autofill_manager.h" | |
| 15 #include "components/autofill/core/common/form_data.h" | |
| 16 #include "components/autofill/core/common/form_field_data.h" | |
| 17 #include "components/autofill/core/common/password_form_fill_data.h" | |
| 18 #include "content/public/browser/notification_observer.h" | |
| 19 #include "content/public/browser/notification_registrar.h" | |
| 20 #include "ui/gfx/rect.h" | |
| 21 | |
| 22 namespace gfx { | |
| 23 class Rect; | |
| 24 } | |
| 25 | |
| 26 namespace content { | |
| 27 class RenderViewHost; | |
| 28 class WebContents; | |
| 29 } | |
| 30 | |
| 31 namespace autofill { | |
| 32 | |
| 33 class AutofillManager; | |
| 34 | |
| 35 // TODO(csharp): A lot of the logic in this class is copied from autofillagent. | |
| 36 // Once Autofill is moved out of WebKit this class should be the only home for | |
| 37 // this logic. See http://crbug.com/51644 | |
| 38 | |
| 39 // Delegate for in-browser Autocomplete and Autofill display and selection. | |
| 40 class AutofillExternalDelegate | |
| 41 : public content::NotificationObserver, | |
| 42 public AutofillPopupDelegate { | |
| 43 public: | |
| 44 // Creates an AutofillExternalDelegate for the specified contents; the second | |
| 45 // argument is an AutofillManager managing Autofill for that WebContents. | |
| 46 AutofillExternalDelegate(content::WebContents* web_contents, | |
| 47 AutofillManager* autofill_manager); | |
| 48 virtual ~AutofillExternalDelegate(); | |
| 49 | |
| 50 // AutofillPopupDelegate implementation. | |
| 51 virtual void OnPopupShown(content::KeyboardListener* listener) OVERRIDE; | |
| 52 virtual void OnPopupHidden(content::KeyboardListener* listener) OVERRIDE; | |
| 53 virtual void DidSelectSuggestion(int identifier) OVERRIDE; | |
| 54 virtual void DidAcceptSuggestion(const base::string16& value, | |
| 55 int identifier) OVERRIDE; | |
| 56 virtual void RemoveSuggestion(const base::string16& value, | |
| 57 int identifier) OVERRIDE; | |
| 58 virtual void ClearPreviewedForm() OVERRIDE; | |
| 59 | |
| 60 // Records and associates a query_id with web form data. Called | |
| 61 // when the renderer posts an Autofill query to the browser. |bounds| | |
| 62 // is window relative. |display_warning_if_disabled| tells us if we should | |
| 63 // display warnings (such as autofill is disabled, but had suggestions). | |
| 64 // We might not want to display the warning if a website has disabled | |
| 65 // Autocomplete because they have their own popup, and showing our popup | |
| 66 // on to of theirs would be a poor user experience. | |
| 67 virtual void OnQuery(int query_id, | |
| 68 const FormData& form, | |
| 69 const FormFieldData& field, | |
| 70 const gfx::RectF& element_bounds, | |
| 71 bool display_warning_if_disabled); | |
| 72 | |
| 73 // Records query results and correctly formats them before sending them off | |
| 74 // to be displayed. Called when an Autofill query result is available. | |
| 75 virtual void OnSuggestionsReturned( | |
| 76 int query_id, | |
| 77 const std::vector<base::string16>& autofill_values, | |
| 78 const std::vector<base::string16>& autofill_labels, | |
| 79 const std::vector<base::string16>& autofill_icons, | |
| 80 const std::vector<int>& autofill_unique_ids); | |
| 81 | |
| 82 // Show password suggestions in the popup. | |
| 83 void OnShowPasswordSuggestions(const std::vector<base::string16>& suggestions, | |
| 84 const FormFieldData& field, | |
| 85 const gfx::RectF& bounds); | |
| 86 | |
| 87 // Set the data list value associated with the current field. | |
| 88 void SetCurrentDataListValues( | |
| 89 const std::vector<base::string16>& autofill_values, | |
| 90 const std::vector<base::string16>& autofill_labels, | |
| 91 const std::vector<base::string16>& autofill_icons, | |
| 92 const std::vector<int>& autofill_unique_ids); | |
| 93 | |
| 94 // Inform the delegate that the text field editing has ended. This is | |
| 95 // used to help record the metrics of when a new popup is shown. | |
| 96 void DidEndTextFieldEditing(); | |
| 97 | |
| 98 // Returns the delegate to its starting state by removing any page specific | |
| 99 // values or settings. | |
| 100 void Reset(); | |
| 101 | |
| 102 // Inform the Password Manager of a filled form. | |
| 103 void AddPasswordFormMapping( | |
| 104 const FormFieldData& form, | |
| 105 const PasswordFormFillData& fill_data); | |
| 106 | |
| 107 protected: | |
| 108 content::WebContents* web_contents() { return web_contents_; } | |
| 109 | |
| 110 base::WeakPtr<AutofillExternalDelegate> GetWeakPtr(); | |
| 111 | |
| 112 private: | |
| 113 // Fills the form with the Autofill data corresponding to |unique_id|. | |
| 114 // If |is_preview| is true then this is just a preview to show the user what | |
| 115 // would be selected and if |is_preview| is false then the user has selected | |
| 116 // this data. | |
| 117 void FillAutofillFormData(int unique_id, bool is_preview); | |
| 118 | |
| 119 // Handle applying any Autofill warnings to the Autofill popup. | |
| 120 void ApplyAutofillWarnings(std::vector<base::string16>* autofill_values, | |
| 121 std::vector<base::string16>* autofill_labels, | |
| 122 std::vector<base::string16>* autofill_icons, | |
| 123 std::vector<int>* autofill_unique_ids); | |
| 124 | |
| 125 // Handle applying any Autofill option listings to the Autofill popup. | |
| 126 // This function should only get called when there is at least one | |
| 127 // multi-field suggestion in the list of suggestions. | |
| 128 void ApplyAutofillOptions(std::vector<base::string16>* autofill_values, | |
| 129 std::vector<base::string16>* autofill_labels, | |
| 130 std::vector<base::string16>* autofill_icons, | |
| 131 std::vector<int>* autofill_unique_ids); | |
| 132 | |
| 133 // Insert the data list values at the start of the given list, including | |
| 134 // any required separators. | |
| 135 void InsertDataListValues(std::vector<base::string16>* autofill_values, | |
| 136 std::vector<base::string16>* autofill_labels, | |
| 137 std::vector<base::string16>* autofill_icons, | |
| 138 std::vector<int>* autofill_unique_ids); | |
| 139 | |
| 140 // content::NotificationObserver method override. | |
| 141 virtual void Observe(int type, | |
| 142 const content::NotificationSource& source, | |
| 143 const content::NotificationDetails& details) OVERRIDE; | |
| 144 | |
| 145 // The web_contents associated with this delegate. | |
| 146 content::WebContents* web_contents_; // weak; owns me. | |
| 147 AutofillManager* autofill_manager_; // weak. | |
| 148 | |
| 149 // Password Autofill manager, handles all password-related Autofilling. | |
| 150 PasswordAutofillManager password_autofill_manager_; | |
| 151 | |
| 152 // The ID of the last request sent for form field Autofill. Used to ignore | |
| 153 // out of date responses. | |
| 154 int autofill_query_id_; | |
| 155 | |
| 156 // A scoped container for notification registries. | |
| 157 content::NotificationRegistrar registrar_; | |
| 158 | |
| 159 // The current form and field selected by Autofill. | |
| 160 FormData autofill_query_form_; | |
| 161 FormFieldData autofill_query_field_; | |
| 162 | |
| 163 // The bounds of the form field that user is interacting with. | |
| 164 gfx::RectF element_bounds_; | |
| 165 | |
| 166 // Should we display a warning if Autofill is disabled? | |
| 167 bool display_warning_if_disabled_; | |
| 168 | |
| 169 // Does the popup include any Autofill profile or credit card suggestions? | |
| 170 bool has_autofill_suggestion_; | |
| 171 | |
| 172 // Have we already shown Autofill suggestions for the field the user is | |
| 173 // currently editing? Used to keep track of state for metrics logging. | |
| 174 bool has_shown_autofill_popup_for_current_edit_; | |
| 175 | |
| 176 // The RenderViewHost that this object has been registered with as a | |
| 177 // keyboard listener. | |
| 178 content::RenderViewHost* registered_keyboard_listener_with_; | |
| 179 | |
| 180 // The current data list values. | |
| 181 std::vector<base::string16> data_list_values_; | |
| 182 std::vector<base::string16> data_list_labels_; | |
| 183 std::vector<base::string16> data_list_icons_; | |
| 184 std::vector<int> data_list_unique_ids_; | |
| 185 | |
| 186 base::WeakPtrFactory<AutofillExternalDelegate> weak_ptr_factory_; | |
| 187 | |
| 188 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegate); | |
| 189 }; | |
| 190 | |
| 191 } // namespace autofill | |
| 192 | |
| 193 #endif // COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_EXTERNAL_DELEGATE_H_ | |
| OLD | NEW |