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_CORE_BROWSER_AUTOFILL_MANAGER_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ |
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "components/autofill/core/common/form_data.h" | 30 #include "components/autofill/core/common/form_data.h" |
31 #include "components/autofill/core/common/forms_seen_state.h" | 31 #include "components/autofill/core/common/forms_seen_state.h" |
32 #include "content/public/common/ssl_status.h" | 32 #include "content/public/common/ssl_status.h" |
33 #include "third_party/WebKit/public/web/WebFormElement.h" | 33 #include "third_party/WebKit/public/web/WebFormElement.h" |
34 | 34 |
35 class GURL; | 35 class GURL; |
36 | 36 |
37 namespace content { | 37 namespace content { |
38 class RenderViewHost; | 38 class RenderViewHost; |
39 class WebContents; | 39 class WebContents; |
40 struct FrameNavigateParams; | |
41 struct LoadCommittedDetails; | |
42 } | 40 } |
43 | 41 |
44 namespace gfx { | 42 namespace gfx { |
45 class Rect; | 43 class Rect; |
46 class RectF; | 44 class RectF; |
47 } | 45 } |
48 | 46 |
49 namespace IPC { | |
50 class Message; | |
51 } | |
52 | |
53 namespace user_prefs { | 47 namespace user_prefs { |
54 class PrefRegistrySyncable; | 48 class PrefRegistrySyncable; |
55 } | 49 } |
56 | 50 |
57 namespace autofill { | 51 namespace autofill { |
58 | 52 |
59 class AutofillDriver; | 53 class AutofillDriver; |
60 class AutofillDataModel; | 54 class AutofillDataModel; |
61 class AutofillDownloadManager; | 55 class AutofillDownloadManager; |
62 class AutofillExternalDelegate; | 56 class AutofillExternalDelegate; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 127 |
134 autofill::AutofillManagerDelegate* delegate() const { | 128 autofill::AutofillManagerDelegate* delegate() const { |
135 return manager_delegate_; | 129 return manager_delegate_; |
136 } | 130 } |
137 | 131 |
138 const std::string& app_locale() const { return app_locale_; } | 132 const std::string& app_locale() const { return app_locale_; } |
139 | 133 |
140 // Only for testing. | 134 // Only for testing. |
141 void SetTestDelegate(autofill::AutofillManagerTestDelegate* delegate); | 135 void SetTestDelegate(autofill::AutofillManagerTestDelegate* delegate); |
142 | 136 |
143 // TODO(blundell): Move the logic in these methods into AutofillDriver and | 137 void OnFormsSeen(const std::vector<FormData>& forms, |
144 // eliminate these methods. | 138 const base::TimeTicks& timestamp, |
145 virtual void DidNavigateMainFrame( | 139 autofill::FormsSeenState state); |
146 const content::LoadCommittedDetails& details, | 140 |
147 const content::FrameNavigateParams& params); | 141 // Processes the submitted |form|, saving any new Autofill data and uploading |
148 virtual bool OnMessageReceived(const IPC::Message& message); | 142 // the possible field types for the submitted fields to the crowdsouring |
| 143 // server. Returns false if this form is not relevant for Autofill. |
| 144 bool OnFormSubmitted(const FormData& form, |
| 145 const base::TimeTicks& timestamp); |
| 146 |
| 147 void OnTextFieldDidChange(const FormData& form, |
| 148 const FormFieldData& field, |
| 149 const base::TimeTicks& timestamp); |
| 150 |
| 151 // The |bounding_box| is a window relative value. |
| 152 void OnQueryFormFieldAutofill(int query_id, |
| 153 const FormData& form, |
| 154 const FormFieldData& field, |
| 155 const gfx::RectF& bounding_box, |
| 156 bool display_warning); |
| 157 void OnDidEndTextFieldEditing(); |
| 158 void OnHideAutofillUi(); |
| 159 void OnAddPasswordFormMapping( |
| 160 const FormFieldData& form, |
| 161 const PasswordFormFillData& fill_data); |
| 162 void OnShowPasswordSuggestions( |
| 163 const FormFieldData& field, |
| 164 const gfx::RectF& bounds, |
| 165 const std::vector<base::string16>& suggestions); |
| 166 void OnSetDataList(const std::vector<base::string16>& values, |
| 167 const std::vector<base::string16>& labels, |
| 168 const std::vector<base::string16>& icons, |
| 169 const std::vector<int>& unique_ids); |
| 170 |
| 171 // Requests an interactive autocomplete UI be shown. |
| 172 void OnRequestAutocomplete(const FormData& form, |
| 173 const GURL& frame_url); |
| 174 |
| 175 // Called to signal clicking an element failed in some way during an |
| 176 // Autocheckout flow. |
| 177 void OnClickFailed(autofill::AutocheckoutStatus status); |
| 178 |
| 179 // Shows the Autocheckout bubble if conditions are right. See comments for |
| 180 // AutocheckoutManager::MaybeShowAutocheckoutBubble. Input element requesting |
| 181 // bubble belongs to |form|. |bounding_box| is the bounding box of the input |
| 182 // field in focus. |
| 183 virtual void OnMaybeShowAutocheckoutBubble(const FormData& form, |
| 184 const gfx::RectF& bounding_box); |
| 185 |
| 186 // Resets cache. |
| 187 void Reset(); |
149 | 188 |
150 protected: | 189 protected: |
151 // Test code should prefer to use this constructor. | 190 // Test code should prefer to use this constructor. |
152 AutofillManager(AutofillDriver* driver, | 191 AutofillManager(AutofillDriver* driver, |
153 autofill::AutofillManagerDelegate* delegate, | 192 autofill::AutofillManagerDelegate* delegate, |
154 PersonalDataManager* personal_data); | 193 PersonalDataManager* personal_data); |
155 | 194 |
156 // Returns the value of the AutofillEnabled pref. | 195 // Returns the value of the AutofillEnabled pref. |
157 virtual bool IsAutofillEnabled() const; | 196 virtual bool IsAutofillEnabled() const; |
158 | 197 |
159 // Uploads the form data to the Autofill server. | 198 // Uploads the form data to the Autofill server. |
160 virtual void UploadFormData(const FormStructure& submitted_form); | 199 virtual void UploadFormData(const FormStructure& submitted_form); |
161 | 200 |
162 // Reset cache. | |
163 void Reset(); | |
164 | |
165 // Logs quality metrics for the |submitted_form| and uploads the form data | 201 // Logs quality metrics for the |submitted_form| and uploads the form data |
166 // to the crowdsourcing server, if appropriate. | 202 // to the crowdsourcing server, if appropriate. |
167 virtual void UploadFormDataAsyncCallback( | 203 virtual void UploadFormDataAsyncCallback( |
168 const FormStructure* submitted_form, | 204 const FormStructure* submitted_form, |
169 const base::TimeTicks& load_time, | 205 const base::TimeTicks& load_time, |
170 const base::TimeTicks& interaction_time, | 206 const base::TimeTicks& interaction_time, |
171 const base::TimeTicks& submission_time); | 207 const base::TimeTicks& submission_time); |
172 | 208 |
173 // Shows the Autocheckout bubble if conditions are right. See comments for | |
174 // AutocheckoutManager::MaybeShowAutocheckoutBubble. Input element requesting | |
175 // bubble belongs to |form|. |bounding_box| is the bounding box of the input | |
176 // field in focus. | |
177 virtual void OnMaybeShowAutocheckoutBubble(const FormData& form, | |
178 const gfx::RectF& bounding_box); | |
179 | |
180 // Maps GUIDs to and from IDs that are used to identify profiles and credit | 209 // Maps GUIDs to and from IDs that are used to identify profiles and credit |
181 // cards sent to and from the renderer process. | 210 // cards sent to and from the renderer process. |
182 virtual int GUIDToID(const PersonalDataManager::GUIDPair& guid) const; | 211 virtual int GUIDToID(const PersonalDataManager::GUIDPair& guid) const; |
183 virtual const PersonalDataManager::GUIDPair IDToGUID(int id) const; | 212 virtual const PersonalDataManager::GUIDPair IDToGUID(int id) const; |
184 | 213 |
185 // Methods for packing and unpacking credit card and profile IDs for sending | 214 // Methods for packing and unpacking credit card and profile IDs for sending |
186 // and receiving to and from the renderer process. | 215 // and receiving to and from the renderer process. |
187 int PackGUIDs(const PersonalDataManager::GUIDPair& cc_guid, | 216 int PackGUIDs(const PersonalDataManager::GUIDPair& cc_guid, |
188 const PersonalDataManager::GUIDPair& profile_guid) const; | 217 const PersonalDataManager::GUIDPair& profile_guid) const; |
189 void UnpackGUIDs(int id, | 218 void UnpackGUIDs(int id, |
190 PersonalDataManager::GUIDPair* cc_guid, | 219 PersonalDataManager::GUIDPair* cc_guid, |
191 PersonalDataManager::GUIDPair* profile_guid) const; | 220 PersonalDataManager::GUIDPair* profile_guid) const; |
192 | 221 |
193 const AutofillMetrics* metric_logger() const { return metric_logger_.get(); } | 222 const AutofillMetrics* metric_logger() const { return metric_logger_.get(); } |
194 void set_metric_logger(const AutofillMetrics* metric_logger); | 223 void set_metric_logger(const AutofillMetrics* metric_logger); |
195 | 224 |
196 ScopedVector<FormStructure>* form_structures() { return &form_structures_; } | 225 ScopedVector<FormStructure>* form_structures() { return &form_structures_; } |
197 | 226 |
198 // Exposed for testing. | 227 // Exposed for testing. |
199 AutofillExternalDelegate* external_delegate() { | 228 AutofillExternalDelegate* external_delegate() { |
200 return external_delegate_; | 229 return external_delegate_; |
201 } | 230 } |
202 | 231 |
203 // Exposed for testing. | 232 // Exposed for testing. |
204 autofill::AutocheckoutManager* autocheckout_manager() { | 233 autofill::AutocheckoutManager* autocheckout_manager() { |
205 return &autocheckout_manager_; | 234 return &autocheckout_manager_; |
206 } | 235 } |
207 | 236 |
208 // Processes the submitted |form|, saving any new Autofill data and uploading | |
209 // the possible field types for the submitted fields to the crowdsouring | |
210 // server. Returns false if this form is not relevant for Autofill. | |
211 bool OnFormSubmitted(const FormData& form, | |
212 const base::TimeTicks& timestamp); | |
213 | |
214 // Tell the renderer the current interactive autocomplete finished. | 237 // Tell the renderer the current interactive autocomplete finished. |
215 virtual void ReturnAutocompleteResult( | 238 virtual void ReturnAutocompleteResult( |
216 WebKit::WebFormElement::AutocompleteResult result, | 239 WebKit::WebFormElement::AutocompleteResult result, |
217 const FormData& form_data); | 240 const FormData& form_data); |
218 | 241 |
219 private: | 242 private: |
220 | 243 |
221 // AutofillDownloadManager::Observer: | 244 // AutofillDownloadManager::Observer: |
222 virtual void OnLoadedServerPredictions( | 245 virtual void OnLoadedServerPredictions( |
223 const std::string& response_xml) OVERRIDE; | 246 const std::string& response_xml) OVERRIDE; |
224 | 247 |
225 void OnFormsSeen(const std::vector<FormData>& forms, | |
226 const base::TimeTicks& timestamp, | |
227 autofill::FormsSeenState state); | |
228 void OnTextFieldDidChange(const FormData& form, | |
229 const FormFieldData& field, | |
230 const base::TimeTicks& timestamp); | |
231 | |
232 // The |bounding_box| is a window relative value. | |
233 void OnQueryFormFieldAutofill(int query_id, | |
234 const FormData& form, | |
235 const FormFieldData& field, | |
236 const gfx::RectF& bounding_box, | |
237 bool display_warning); | |
238 void OnDidEndTextFieldEditing(); | |
239 void OnHideAutofillUi(); | |
240 void OnAddPasswordFormMapping( | |
241 const FormFieldData& form, | |
242 const PasswordFormFillData& fill_data); | |
243 void OnShowPasswordSuggestions( | |
244 const FormFieldData& field, | |
245 const gfx::RectF& bounds, | |
246 const std::vector<base::string16>& suggestions); | |
247 void OnSetDataList(const std::vector<base::string16>& values, | |
248 const std::vector<base::string16>& labels, | |
249 const std::vector<base::string16>& icons, | |
250 const std::vector<int>& unique_ids); | |
251 | |
252 // Requests an interactive autocomplete UI be shown. | |
253 void OnRequestAutocomplete(const FormData& form, | |
254 const GURL& frame_url); | |
255 | |
256 // Passes return data for an OnRequestAutocomplete call back to the page. | 248 // Passes return data for an OnRequestAutocomplete call back to the page. |
257 void ReturnAutocompleteData(const FormStructure* result, | 249 void ReturnAutocompleteData(const FormStructure* result, |
258 const std::string& unused_transaction_id); | 250 const std::string& unused_transaction_id); |
259 | 251 |
260 // Called to signal clicking an element failed in some way during an | |
261 // Autocheckout flow. | |
262 void OnClickFailed(autofill::AutocheckoutStatus status); | |
263 | |
264 // Returns the matched whitelist URL prefix for the current tab's url. | 252 // Returns the matched whitelist URL prefix for the current tab's url. |
265 virtual std::string GetAutocheckoutURLPrefix() const; | 253 virtual std::string GetAutocheckoutURLPrefix() const; |
266 | 254 |
267 // Fills |host| with the RenderViewHost for this tab. | 255 // Fills |host| with the RenderViewHost for this tab. |
268 // Returns false if Autofill is disabled or if the host is unavailable. | 256 // Returns false if Autofill is disabled or if the host is unavailable. |
269 bool GetHost(content::RenderViewHost** host) const WARN_UNUSED_RESULT; | 257 bool GetHost(content::RenderViewHost** host) const WARN_UNUSED_RESULT; |
270 | 258 |
271 // Unpacks |unique_id| and fills |form_group| and |variant| with the | 259 // Unpacks |unique_id| and fills |form_group| and |variant| with the |
272 // appropriate data source and variant index. Returns false if the unpacked | 260 // appropriate data source and variant index. Returns false if the unpacked |
273 // id cannot be found. | 261 // id cannot be found. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, | 409 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, |
422 UserHappinessFormLoadAndSubmission); | 410 UserHappinessFormLoadAndSubmission); |
423 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); | 411 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); |
424 | 412 |
425 DISALLOW_COPY_AND_ASSIGN(AutofillManager); | 413 DISALLOW_COPY_AND_ASSIGN(AutofillManager); |
426 }; | 414 }; |
427 | 415 |
428 } // namespace autofill | 416 } // namespace autofill |
429 | 417 |
430 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ | 418 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ |
OLD | NEW |