OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/string16.h" | 15 #include "base/string16.h" |
16 #include "chrome/browser/autofill/field_types.h" | 16 #include "chrome/browser/autofill/field_types.h" |
17 #include "chrome/browser/autofill/form_structure.h" | 17 #include "chrome/browser/autofill/form_structure.h" |
| 18 #include "chrome/browser/autofill/personal_data_manager.h" |
18 #include "chrome/browser/ui/autofill/autofill_dialog_comboboxes.h" | 19 #include "chrome/browser/ui/autofill/autofill_dialog_comboboxes.h" |
| 20 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
| 21 #include "chrome/browser/ui/autofill/autofill_popup_delegate.h" |
19 #include "content/public/common/ssl_status.h" | 22 #include "content/public/common/ssl_status.h" |
20 #include "ui/base/models/combobox_model.h" | 23 #include "ui/base/models/combobox_model.h" |
| 24 #include "ui/gfx/native_widget_types.h" |
21 | 25 |
| 26 class AutofillPopupControllerImpl; |
22 class FormGroup; | 27 class FormGroup; |
23 class GURL; | 28 class GURL; |
24 class Profile; | 29 class Profile; |
25 | 30 |
26 namespace content { | 31 namespace content { |
27 class WebContents; | 32 class WebContents; |
28 } | 33 } |
29 | 34 |
| 35 namespace gfx { |
| 36 class Rect; |
| 37 } |
| 38 |
30 namespace autofill { | 39 namespace autofill { |
31 | 40 |
32 class AutofillDialogView; | 41 class AutofillDialogView; |
33 | 42 |
34 // This struct describes a single input control for the imperative autocomplete | 43 // This struct describes a single input control for the imperative autocomplete |
35 // dialog. | 44 // dialog. |
36 struct DetailInput { | 45 struct DetailInput { |
37 // Multiple DetailInput structs with the same row_id go on the same row. The | 46 // Multiple DetailInput structs with the same row_id go on the same row. The |
38 // actual order of the rows is determined by their order of appearance in | 47 // actual order of the rows is determined by their order of appearance in |
39 // kBillingInputs. | 48 // kBillingInputs. |
40 int row_id; | 49 int row_id; |
41 AutofillFieldType type; | 50 AutofillFieldType type; |
42 // TODO(estade): remove this, do l10n. | 51 // TODO(estade): remove this, do l10n. |
43 const char* placeholder_text; | 52 const char* placeholder_text; |
44 // The section suffix that the field must have to match up to this input. | 53 // The section suffix that the field must have to match up to this input. |
45 const char* section_suffix; | 54 const char* section_suffix; |
46 // A number between 0 and 1.0 that describes how much of the horizontal space | 55 // A number between 0 and 1.0 that describes how much of the horizontal space |
47 // in the row should be allotted to this input. 0 is equivalent to 1. | 56 // in the row should be allotted to this input. 0 is equivalent to 1. |
48 float expand_weight; | 57 float expand_weight; |
49 // When non-empty, indicates the value that should be pre-filled into the | 58 // When non-empty, indicates the value that should be pre-filled into the |
50 // input. | 59 // input. |
51 string16 starting_value; | 60 string16 autofilled_value; |
52 }; | 61 }; |
53 | 62 |
54 // Sections of the dialog --- all fields that may be shown to the user fit under | 63 // Sections of the dialog --- all fields that may be shown to the user fit under |
55 // one of these sections. TODO(estade): add telephone number. | 64 // one of these sections. TODO(estade): add telephone number. |
56 enum DialogSection { | 65 enum DialogSection { |
57 SECTION_EMAIL, | 66 SECTION_EMAIL, |
58 SECTION_CC, | 67 SECTION_CC, |
59 SECTION_BILLING, | 68 SECTION_BILLING, |
60 SECTION_SHIPPING, | 69 SECTION_SHIPPING, |
61 }; | 70 }; |
62 | 71 |
63 // Termination actions for the dialog. | 72 // Termination actions for the dialog. |
64 enum DialogAction { | 73 enum DialogAction { |
65 ACTION_ABORT, | 74 ACTION_ABORT, |
66 ACTION_SUBMIT, | 75 ACTION_SUBMIT, |
67 }; | 76 }; |
68 | 77 |
69 typedef std::vector<DetailInput> DetailInputs; | 78 typedef std::vector<DetailInput> DetailInputs; |
70 typedef std::map<const DetailInput*, string16> DetailOutputMap; | 79 typedef std::map<const DetailInput*, string16> DetailOutputMap; |
71 | 80 |
72 // This class drives the dialog that appears when a site uses the imperative | 81 // This class drives the dialog that appears when a site uses the imperative |
73 // autocomplete API to fill out a form. | 82 // autocomplete API to fill out a form. |
74 class AutofillDialogController { | 83 class AutofillDialogController : public AutofillPopupDelegate { |
75 public: | 84 public: |
76 AutofillDialogController( | 85 AutofillDialogController( |
77 content::WebContents* contents, | 86 content::WebContents* contents, |
78 const FormData& form_structure, | 87 const FormData& form_structure, |
79 const GURL& source_url, | 88 const GURL& source_url, |
80 const content::SSLStatus& ssl_status, | 89 const content::SSLStatus& ssl_status, |
81 const base::Callback<void(const FormStructure*)>& callback); | 90 const base::Callback<void(const FormStructure*)>& callback); |
82 ~AutofillDialogController(); | 91 ~AutofillDialogController(); |
83 | 92 |
84 void Show(); | 93 void Show(); |
(...skipping 16 matching lines...) Expand all Loading... |
101 // |section|. | 110 // |section|. |
102 const DetailInputs& RequestedFieldsForSection(DialogSection section) const; | 111 const DetailInputs& RequestedFieldsForSection(DialogSection section) const; |
103 ui::ComboboxModel* ComboboxModelForAutofillType(AutofillFieldType type); | 112 ui::ComboboxModel* ComboboxModelForAutofillType(AutofillFieldType type); |
104 // Returns the model for suggestions for fields that fall under |section|. | 113 // Returns the model for suggestions for fields that fall under |section|. |
105 ui::ComboboxModel* ComboboxModelForSection(DialogSection section); | 114 ui::ComboboxModel* ComboboxModelForSection(DialogSection section); |
106 | 115 |
107 // Called when the view has been closed. The value for |action| indicates | 116 // Called when the view has been closed. The value for |action| indicates |
108 // whether the Autofill operation should be aborted. | 117 // whether the Autofill operation should be aborted. |
109 void ViewClosed(DialogAction action); | 118 void ViewClosed(DialogAction action); |
110 | 119 |
| 120 // Called by the view when the user changes the contents of a text field. |
| 121 void UserEditedInput(const DetailInput* input, |
| 122 gfx::NativeView view, |
| 123 const gfx::Rect& content_bounds, |
| 124 const string16& field_contents); |
| 125 |
| 126 // Called when focus has changed position within the view. |
| 127 void FocusMoved(); |
| 128 |
| 129 // AutofillPopupDelegate implementation. |
| 130 virtual void DidSelectSuggestion(int identifier) OVERRIDE; |
| 131 virtual void DidAcceptSuggestion(const string16& value, |
| 132 int identifier) OVERRIDE; |
| 133 virtual void RemoveSuggestion(int identifier) OVERRIDE; |
| 134 virtual void RemoveAutocompleteEntry(const string16& value) OVERRIDE; |
| 135 virtual void ClearPreviewedForm() OVERRIDE; |
| 136 virtual void ControllerDestroyed() OVERRIDE; |
| 137 |
111 content::WebContents* web_contents() { return contents_; } | 138 content::WebContents* web_contents() { return contents_; } |
112 | 139 |
113 private: | 140 private: |
114 // Determines whether |input| and |field| match. | 141 // Determines whether |input| and |field| match. |
115 typedef base::Callback<bool(const DetailInput& input, | 142 typedef base::Callback<bool(const DetailInput& input, |
116 const AutofillField& field)> InputFieldComparator; | 143 const AutofillField& field)> InputFieldComparator; |
117 | 144 |
118 // Whether or not the current request wants credit info back. | 145 // Whether or not the current request wants credit info back. |
119 bool RequestingCreditCardInfo() const; | 146 bool RequestingCreditCardInfo() const; |
120 | 147 |
121 // Whether or not the view should show a security warning. | 148 // Whether or not the view should show a security warning. |
122 bool ShouldShowSecurityWarning() const; | 149 bool ShouldShowSecurityWarning() const; |
123 | 150 |
124 // Initializes |suggested_email_| et al. | 151 // Initializes |suggested_email_| et al. |
125 void GenerateComboboxModels(); | 152 void GenerateComboboxModels(); |
126 | 153 |
127 // Fills in all the DetailInputs structs with guessed values for | |
128 // starting_value. The guesses come from Autofill data, drawing from the most | |
129 // filled out AutofillProfile. | |
130 void PopulateInputsWithGuesses(); | |
131 | |
132 // Fills in |section|-related fields in |output_| according to the state of | 154 // Fills in |section|-related fields in |output_| according to the state of |
133 // |view_|. | 155 // |view_|. |
134 void FillOutputForSection(DialogSection section); | 156 void FillOutputForSection(DialogSection section); |
135 // As above, but uses |compare| to determine whether a DetailInput matches | 157 // As above, but uses |compare| to determine whether a DetailInput matches |
136 // a field. | 158 // a field. |
137 void FillOutputForSectionWithComparator(DialogSection section, | 159 void FillOutputForSectionWithComparator(DialogSection section, |
138 const InputFieldComparator& compare); | 160 const InputFieldComparator& compare); |
139 | 161 |
140 // Fills in |form_structure_| using |form_group|. Utility method for | 162 // Fills in |form_structure_| using |form_group|. Utility method for |
141 // FillOutputForSection. | 163 // FillOutputForSection. |
142 void FillFormStructureForSection(const FormGroup& form_group, | 164 void FillFormStructureForSection(const FormGroup& form_group, |
143 DialogSection section, | 165 DialogSection section, |
144 const InputFieldComparator& compare); | 166 const InputFieldComparator& compare); |
145 | 167 |
146 // Gets the SuggestionsComboboxModel for |section|. | 168 // Gets the SuggestionsComboboxModel for |section|. |
147 SuggestionsComboboxModel* SuggestionsModelForSection(DialogSection section); | 169 SuggestionsComboboxModel* SuggestionsModelForSection(DialogSection section); |
148 | 170 |
| 171 // Loads profiles that can suggest data for |type|. |field_contents| is the |
| 172 // part the user has already typed. |inputs| is the rest of section. |
| 173 // Identifying info is loaded into the last three outparams as well as |
| 174 // |popup_guids_|. |
| 175 void GetProfileSuggestions( |
| 176 AutofillFieldType type, |
| 177 const string16& field_contents, |
| 178 const DetailInputs& inputs, |
| 179 std::vector<string16>* popup_values, |
| 180 std::vector<string16>* popup_labels, |
| 181 std::vector<string16>* popup_icons); |
| 182 |
| 183 // Returns the PersonalDataManager for |profile_|. |
| 184 PersonalDataManager* GetManager(); |
| 185 |
149 // The |profile| for |contents_|. | 186 // The |profile| for |contents_|. |
150 Profile* const profile_; | 187 Profile* const profile_; |
151 | 188 |
152 // The WebContents where the Autofill action originated. | 189 // The WebContents where the Autofill action originated. |
153 content::WebContents* const contents_; | 190 content::WebContents* const contents_; |
154 | 191 |
155 FormStructure form_structure_; | 192 FormStructure form_structure_; |
156 | 193 |
157 // The URL of the invoking site. | 194 // The URL of the invoking site. |
158 GURL source_url_; | 195 GURL source_url_; |
(...skipping 12 matching lines...) Expand all Loading... |
171 // Models for the credit card expiration inputs. | 208 // Models for the credit card expiration inputs. |
172 MonthComboboxModel cc_exp_month_combobox_model_; | 209 MonthComboboxModel cc_exp_month_combobox_model_; |
173 YearComboboxModel cc_exp_year_combobox_model_; | 210 YearComboboxModel cc_exp_year_combobox_model_; |
174 | 211 |
175 // Models for the suggestion views. | 212 // Models for the suggestion views. |
176 SuggestionsComboboxModel suggested_email_; | 213 SuggestionsComboboxModel suggested_email_; |
177 SuggestionsComboboxModel suggested_cc_; | 214 SuggestionsComboboxModel suggested_cc_; |
178 SuggestionsComboboxModel suggested_billing_; | 215 SuggestionsComboboxModel suggested_billing_; |
179 SuggestionsComboboxModel suggested_shipping_; | 216 SuggestionsComboboxModel suggested_shipping_; |
180 | 217 |
| 218 // The GUIDs for the currently showing unverified profiles popup. |
| 219 std::vector<PersonalDataManager::GUIDPair> popup_guids_; |
| 220 |
| 221 AutofillPopupControllerImpl* popup_controller_; |
| 222 |
181 scoped_ptr<AutofillDialogView> view_; | 223 scoped_ptr<AutofillDialogView> view_; |
182 | 224 |
183 DISALLOW_COPY_AND_ASSIGN(AutofillDialogController); | 225 DISALLOW_COPY_AND_ASSIGN(AutofillDialogController); |
184 }; | 226 }; |
185 | 227 |
186 } // namespace autofill | 228 } // namespace autofill |
187 | 229 |
188 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_H_ | 230 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_H_ |
OLD | NEW |