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 <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
22 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 22 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
23 #include "components/autofill/core/browser/autofill_client.h" | 23 #include "components/autofill/core/browser/autofill_client.h" |
24 #include "components/autofill/core/browser/autofill_download_manager.h" | 24 #include "components/autofill/core/browser/autofill_download_manager.h" |
25 #include "components/autofill/core/browser/autofill_driver.h" | 25 #include "components/autofill/core/browser/autofill_driver.h" |
| 26 #include "components/autofill/core/browser/autofill_handler.h" |
26 #include "components/autofill/core/browser/autofill_metrics.h" | 27 #include "components/autofill/core/browser/autofill_metrics.h" |
27 #include "components/autofill/core/browser/card_unmask_delegate.h" | 28 #include "components/autofill/core/browser/card_unmask_delegate.h" |
28 #include "components/autofill/core/browser/form_structure.h" | 29 #include "components/autofill/core/browser/form_structure.h" |
29 #include "components/autofill/core/browser/payments/full_card_request.h" | 30 #include "components/autofill/core/browser/payments/full_card_request.h" |
30 #include "components/autofill/core/browser/payments/payments_client.h" | 31 #include "components/autofill/core/browser/payments/payments_client.h" |
31 #include "components/autofill/core/browser/personal_data_manager.h" | 32 #include "components/autofill/core/browser/personal_data_manager.h" |
32 #include "components/autofill/core/common/form_data.h" | 33 #include "components/autofill/core/common/form_data.h" |
33 | 34 |
34 #if defined(OS_ANDROID) || defined(OS_IOS) | 35 #if defined(OS_ANDROID) || defined(OS_IOS) |
35 #include "components/autofill/core/browser/autofill_assistant.h" | 36 #include "components/autofill/core/browser/autofill_assistant.h" |
(...skipping 29 matching lines...) Expand all Loading... |
65 class FormStructureBrowserTest; | 66 class FormStructureBrowserTest; |
66 | 67 |
67 struct FormData; | 68 struct FormData; |
68 struct FormFieldData; | 69 struct FormFieldData; |
69 | 70 |
70 // We show the credit card signin promo only a certain number of times. | 71 // We show the credit card signin promo only a certain number of times. |
71 extern const int kCreditCardSigninPromoImpressionLimit; | 72 extern const int kCreditCardSigninPromoImpressionLimit; |
72 | 73 |
73 // Manages saving and restoring the user's personal information entered into web | 74 // Manages saving and restoring the user's personal information entered into web |
74 // forms. One per frame; owned by the AutofillDriver. | 75 // forms. One per frame; owned by the AutofillDriver. |
75 class AutofillManager : public AutofillDownloadManager::Observer, | 76 class AutofillManager : public AutofillHandler, |
| 77 public AutofillDownloadManager::Observer, |
76 public payments::PaymentsClientDelegate, | 78 public payments::PaymentsClientDelegate, |
77 public payments::FullCardRequest::ResultDelegate, | 79 public payments::FullCardRequest::ResultDelegate, |
78 public payments::FullCardRequest::UIDelegate { | 80 public payments::FullCardRequest::UIDelegate { |
79 public: | 81 public: |
80 enum AutofillDownloadManagerState { | |
81 ENABLE_AUTOFILL_DOWNLOAD_MANAGER, | |
82 DISABLE_AUTOFILL_DOWNLOAD_MANAGER, | |
83 }; | |
84 | |
85 // Registers our Enable/Disable Autofill pref. | 82 // Registers our Enable/Disable Autofill pref. |
86 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 83 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
87 | 84 |
88 AutofillManager(AutofillDriver* driver, | 85 AutofillManager(AutofillDriver* driver, |
89 AutofillClient* client, | 86 AutofillClient* client, |
90 const std::string& app_locale, | 87 const std::string& app_locale, |
91 AutofillDownloadManagerState enable_download_manager); | 88 AutofillDownloadManagerState enable_download_manager); |
92 ~AutofillManager() override; | 89 ~AutofillManager() override; |
93 | 90 |
94 // Sets an external delegate. | 91 // Sets an external delegate. |
(...skipping 21 matching lines...) Expand all Loading... |
116 const FormFieldData& field, | 113 const FormFieldData& field, |
117 int unique_id); | 114 int unique_id); |
118 virtual void FillCreditCardForm(int query_id, | 115 virtual void FillCreditCardForm(int query_id, |
119 const FormData& form, | 116 const FormData& form, |
120 const FormFieldData& field, | 117 const FormFieldData& field, |
121 const CreditCard& credit_card, | 118 const CreditCard& credit_card, |
122 const base::string16& cvc); | 119 const base::string16& cvc); |
123 void DidShowSuggestions(bool is_new_popup, | 120 void DidShowSuggestions(bool is_new_popup, |
124 const FormData& form, | 121 const FormData& form, |
125 const FormFieldData& field); | 122 const FormFieldData& field); |
126 void OnFocusNoLongerOnForm(); | |
127 void OnDidFillAutofillFormData(const FormData& form, | |
128 const base::TimeTicks& timestamp); | |
129 void OnDidPreviewAutofillFormData(); | |
130 | 123 |
131 // Returns true if the value/identifier is deletable. Fills out | 124 // Returns true if the value/identifier is deletable. Fills out |
132 // |title| and |body| with relevant user-facing text. | 125 // |title| and |body| with relevant user-facing text. |
133 bool GetDeletionConfirmationText(const base::string16& value, | 126 bool GetDeletionConfirmationText(const base::string16& value, |
134 int identifier, | 127 int identifier, |
135 base::string16* title, | 128 base::string16* title, |
136 base::string16* body); | 129 base::string16* body); |
137 | 130 |
138 // Remove the credit card or Autofill profile that matches |unique_id| | 131 // Remove the credit card or Autofill profile that matches |unique_id| |
139 // from the database. Returns true if deletion is allowed. | 132 // from the database. Returns true if deletion is allowed. |
(...skipping 20 matching lines...) Expand all Loading... |
160 base::WeakPtr<payments::FullCardRequest::UIDelegate> | 153 base::WeakPtr<payments::FullCardRequest::UIDelegate> |
161 GetAsFullCardRequestUIDelegate() { | 154 GetAsFullCardRequestUIDelegate() { |
162 return weak_ptr_factory_.GetWeakPtr(); | 155 return weak_ptr_factory_.GetWeakPtr(); |
163 } | 156 } |
164 | 157 |
165 const std::string& app_locale() const { return app_locale_; } | 158 const std::string& app_locale() const { return app_locale_; } |
166 | 159 |
167 // Only for testing. | 160 // Only for testing. |
168 void SetTestDelegate(AutofillManagerTestDelegate* delegate); | 161 void SetTestDelegate(AutofillManagerTestDelegate* delegate); |
169 | 162 |
170 void OnFormsSeen(const std::vector<FormData>& forms, | |
171 const base::TimeTicks& timestamp); | |
172 | |
173 void set_app_locale(std::string app_locale) { app_locale_ = app_locale; } | 163 void set_app_locale(std::string app_locale) { app_locale_ = app_locale; } |
174 | 164 |
175 // IMPORTANT: On iOS, this method is called when the form is submitted, | |
176 // immediately before OnFormSubmitted() is called. Do not assume that | |
177 // OnWillSubmitForm() will run before the form submits. | |
178 // TODO(mathp): Revisit this and use a single method to track form submission. | |
179 // | |
180 // Processes the about-to-be-submitted |form|, uploading the possible field | |
181 // types for the submitted fields to the crowdsourcing server. Returns false | |
182 // if this form is not relevant for Autofill. | |
183 bool OnWillSubmitForm(const FormData& form, const base::TimeTicks& timestamp); | |
184 | |
185 // Processes the submitted |form|, saving any new Autofill data to the user's | |
186 // personal profile. Returns false if this form is not relevant for Autofill. | |
187 bool OnFormSubmitted(const FormData& form); | |
188 | |
189 // Will send an upload based on the |form_structure| data and the local | 165 // Will send an upload based on the |form_structure| data and the local |
190 // Autofill profile data. |observed_submission| is specified if the upload | 166 // Autofill profile data. |observed_submission| is specified if the upload |
191 // follows an observed submission event. | 167 // follows an observed submission event. |
192 virtual void StartUploadProcess(std::unique_ptr<FormStructure> form_structure, | 168 virtual void StartUploadProcess(std::unique_ptr<FormStructure> form_structure, |
193 const base::TimeTicks& timestamp, | 169 const base::TimeTicks& timestamp, |
194 bool observed_submission); | 170 bool observed_submission); |
195 | 171 |
196 // Update the pending form with |form|, possibly processing the current | 172 // Update the pending form with |form|, possibly processing the current |
197 // pending form for upload. | 173 // pending form for upload. |
198 void UpdatePendingForm(const FormData& form); | 174 void UpdatePendingForm(const FormData& form); |
199 | 175 |
200 // Upload the current pending form. | 176 // Upload the current pending form. |
201 void ProcessPendingFormForUpload(); | 177 void ProcessPendingFormForUpload(); |
202 | 178 |
203 void OnTextFieldDidChange(const FormData& form, | 179 // AutofillHandler: |
204 const FormFieldData& field, | 180 void OnFocusNoLongerOnForm() override; |
205 const base::TimeTicks& timestamp); | 181 void OnDidFillAutofillFormData(const FormData& form, |
206 | 182 const base::TimeTicks timestamp) override; |
207 // The |bounding_box| is a window relative value. | 183 void OnDidPreviewAutofillFormData() override; |
208 void OnQueryFormFieldAutofill(int query_id, | 184 void OnFormsSeen(const std::vector<FormData>& forms, |
209 const FormData& form, | 185 const base::TimeTicks timestamp) override; |
210 const FormFieldData& field, | 186 bool OnFormSubmitted(const FormData& form) override; |
211 const gfx::RectF& bounding_box); | 187 void OnDidEndTextFieldEditing() override; |
212 void OnDidEndTextFieldEditing(); | 188 void OnHidePopup() override; |
213 void OnHidePopup(); | |
214 void OnSetDataList(const std::vector<base::string16>& values, | 189 void OnSetDataList(const std::vector<base::string16>& values, |
215 const std::vector<base::string16>& labels); | 190 const std::vector<base::string16>& labels) override; |
216 | 191 void Reset() override; |
217 // Resets cache. | |
218 virtual void Reset(); | |
219 | 192 |
220 // Returns the value of the AutofillEnabled pref. | 193 // Returns the value of the AutofillEnabled pref. |
221 virtual bool IsAutofillEnabled() const; | 194 virtual bool IsAutofillEnabled() const; |
222 | 195 |
223 // Returns true if all the conditions for enabling the upload of credit card | 196 // Returns true if all the conditions for enabling the upload of credit card |
224 // are satisfied. | 197 // are satisfied. |
225 virtual bool IsCreditCardUploadEnabled(); | 198 virtual bool IsCreditCardUploadEnabled(); |
226 | 199 |
227 // Shared code to determine if |form| should be uploaded to the Autofill | 200 // Shared code to determine if |form| should be uploaded to the Autofill |
228 // server. It verifies that uploading is allowed and |form| meets conditions | 201 // server. It verifies that uploading is allowed and |form| meets conditions |
(...skipping 28 matching lines...) Expand all Loading... |
257 virtual std::string IntToBackendID(int int_id) const; | 230 virtual std::string IntToBackendID(int int_id) const; |
258 | 231 |
259 // Methods for packing and unpacking credit card and profile IDs for sending | 232 // Methods for packing and unpacking credit card and profile IDs for sending |
260 // and receiving to and from the renderer process. | 233 // and receiving to and from the renderer process. |
261 int MakeFrontendID(const std::string& cc_backend_id, | 234 int MakeFrontendID(const std::string& cc_backend_id, |
262 const std::string& profile_backend_id) const; | 235 const std::string& profile_backend_id) const; |
263 void SplitFrontendID(int frontend_id, | 236 void SplitFrontendID(int frontend_id, |
264 std::string* cc_backend_id, | 237 std::string* cc_backend_id, |
265 std::string* profile_backend_id) const; | 238 std::string* profile_backend_id) const; |
266 | 239 |
| 240 // AutofillHandler: |
| 241 bool OnWillSubmitFormImpl(const FormData& form, |
| 242 const base::TimeTicks timestamp) override; |
| 243 void OnTextFieldDidChangeImpl(const FormData& form, |
| 244 const FormFieldData& field, |
| 245 const base::TimeTicks timestamp) override; |
| 246 void OnQueryFormFieldAutofillImpl(int query_id, |
| 247 const FormData& form, |
| 248 const FormFieldData& field, |
| 249 const gfx::RectF& transformed_box) override; |
| 250 |
267 std::vector<std::unique_ptr<FormStructure>>* form_structures() { | 251 std::vector<std::unique_ptr<FormStructure>>* form_structures() { |
268 return &form_structures_; | 252 return &form_structures_; |
269 } | 253 } |
270 | 254 |
271 AutofillMetrics::FormInteractionsUkmLogger* form_interactions_ukm_logger() { | 255 AutofillMetrics::FormInteractionsUkmLogger* form_interactions_ukm_logger() { |
272 return form_interactions_ukm_logger_.get(); | 256 return form_interactions_ukm_logger_.get(); |
273 } | 257 } |
274 | 258 |
275 // payments::PaymentsClientDelegate: | 259 // payments::PaymentsClientDelegate: |
276 // Exposed for testing. | 260 // Exposed for testing. |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 #ifdef ENABLE_FORM_DEBUG_DUMP | 472 #ifdef ENABLE_FORM_DEBUG_DUMP |
489 // Dumps the cached forms to a file on disk. | 473 // Dumps the cached forms to a file on disk. |
490 void DumpAutofillData(bool imported_cc) const; | 474 void DumpAutofillData(bool imported_cc) const; |
491 #endif | 475 #endif |
492 | 476 |
493 // Logs the card upload decisions in UKM and UMA. | 477 // Logs the card upload decisions in UKM and UMA. |
494 // |upload_decision_metrics| is a bitmask of | 478 // |upload_decision_metrics| is a bitmask of |
495 // |AutofillMetrics::CardUploadDecisionMetric|. | 479 // |AutofillMetrics::CardUploadDecisionMetric|. |
496 void LogCardUploadDecisions(int upload_decision_metrics); | 480 void LogCardUploadDecisions(int upload_decision_metrics); |
497 | 481 |
498 // Provides driver-level context to the shared code of the component. Must | |
499 // outlive this object. | |
500 AutofillDriver* driver_; | |
501 | |
502 AutofillClient* const client_; | 482 AutofillClient* const client_; |
503 | 483 |
504 // Handles Payments service requests. | 484 // Handles Payments service requests. |
505 std::unique_ptr<payments::PaymentsClient> payments_client_; | 485 std::unique_ptr<payments::PaymentsClient> payments_client_; |
506 | 486 |
507 std::string app_locale_; | 487 std::string app_locale_; |
508 | 488 |
509 // The personal data manager, used to save and load personal data to/from the | 489 // The personal data manager, used to save and load personal data to/from the |
510 // web database. This is overridden by the AutofillManagerTest. | 490 // web database. This is overridden by the AutofillManagerTest. |
511 // Weak reference. | 491 // Weak reference. |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, | 634 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, |
655 OnLoadedServerPredictions_ResetManager); | 635 OnLoadedServerPredictions_ResetManager); |
656 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, DontOfferToSavePaymentsCard); | 636 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, DontOfferToSavePaymentsCard); |
657 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, FillInUpdatedExpirationDate); | 637 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, FillInUpdatedExpirationDate); |
658 DISALLOW_COPY_AND_ASSIGN(AutofillManager); | 638 DISALLOW_COPY_AND_ASSIGN(AutofillManager); |
659 }; | 639 }; |
660 | 640 |
661 } // namespace autofill | 641 } // namespace autofill |
662 | 642 |
663 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ | 643 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ |
OLD | NEW |