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/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
23 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 23 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
24 #include "components/autofill/core/browser/autofill_client.h" | 24 #include "components/autofill/core/browser/autofill_client.h" |
25 #include "components/autofill/core/browser/autofill_download_manager.h" | 25 #include "components/autofill/core/browser/autofill_download_manager.h" |
26 #include "components/autofill/core/browser/autofill_driver.h" | 26 #include "components/autofill/core/browser/autofill_driver.h" |
27 #include "components/autofill/core/browser/autofill_metrics.h" | 27 #include "components/autofill/core/browser/autofill_metrics.h" |
28 #include "components/autofill/core/browser/card_unmask_delegate.h" | 28 #include "components/autofill/core/browser/card_unmask_delegate.h" |
29 #include "components/autofill/core/browser/form_structure.h" | 29 #include "components/autofill/core/browser/form_structure.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 // This define protects some debugging code (see DumpAutofillData). This | 35 // This define protects some debugging code (see DumpAutofillData). This |
35 // is here to make it easier to delete this code when the test is complete, | 36 // is here to make it easier to delete this code when the test is complete, |
36 // and to prevent adding the code on mobile where there is no desktop (the | 37 // and to prevent adding the code on mobile where there is no desktop (the |
37 // debug dump file is written to the desktop) or command-line flags to enable. | 38 // debug dump file is written to the desktop) or command-line flags to enable. |
38 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | 39 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
39 #define ENABLE_FORM_DEBUG_DUMP | 40 #define ENABLE_FORM_DEBUG_DUMP |
(...skipping 20 matching lines...) Expand all Loading... |
60 class AutofillType; | 61 class AutofillType; |
61 class CreditCard; | 62 class CreditCard; |
62 class FormStructureBrowserTest; | 63 class FormStructureBrowserTest; |
63 | 64 |
64 struct FormData; | 65 struct FormData; |
65 struct FormFieldData; | 66 struct FormFieldData; |
66 | 67 |
67 // Manages saving and restoring the user's personal information entered into web | 68 // Manages saving and restoring the user's personal information entered into web |
68 // forms. One per frame; owned by the AutofillDriver. | 69 // forms. One per frame; owned by the AutofillDriver. |
69 class AutofillManager : public AutofillDownloadManager::Observer, | 70 class AutofillManager : public AutofillDownloadManager::Observer, |
70 public CardUnmaskDelegate, | 71 public payments::PaymentsClientDelegate, |
71 public payments::PaymentsClientDelegate { | 72 public payments::FullCardRequest::Delegate { |
72 public: | 73 public: |
73 enum AutofillDownloadManagerState { | 74 enum AutofillDownloadManagerState { |
74 ENABLE_AUTOFILL_DOWNLOAD_MANAGER, | 75 ENABLE_AUTOFILL_DOWNLOAD_MANAGER, |
75 DISABLE_AUTOFILL_DOWNLOAD_MANAGER, | 76 DISABLE_AUTOFILL_DOWNLOAD_MANAGER, |
76 }; | 77 }; |
77 | 78 |
78 // Registers our Enable/Disable Autofill pref. | 79 // Registers our Enable/Disable Autofill pref. |
79 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 80 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
80 | 81 |
81 AutofillManager(AutofillDriver* driver, | 82 AutofillManager(AutofillDriver* driver, |
(...skipping 13 matching lines...) Expand all Loading... |
95 | 96 |
96 // Called from our external delegate so they cannot be private. | 97 // Called from our external delegate so they cannot be private. |
97 virtual void FillOrPreviewForm(AutofillDriver::RendererFormDataAction action, | 98 virtual void FillOrPreviewForm(AutofillDriver::RendererFormDataAction action, |
98 int query_id, | 99 int query_id, |
99 const FormData& form, | 100 const FormData& form, |
100 const FormFieldData& field, | 101 const FormFieldData& field, |
101 int unique_id); | 102 int unique_id); |
102 virtual void FillCreditCardForm(int query_id, | 103 virtual void FillCreditCardForm(int query_id, |
103 const FormData& form, | 104 const FormData& form, |
104 const FormFieldData& field, | 105 const FormFieldData& field, |
105 const CreditCard& credit_card); | 106 const CreditCard& credit_card, |
| 107 const base::string16& cvc); |
106 void DidShowSuggestions(bool is_new_popup, | 108 void DidShowSuggestions(bool is_new_popup, |
107 const FormData& form, | 109 const FormData& form, |
108 const FormFieldData& field); | 110 const FormFieldData& field); |
109 void OnFocusNoLongerOnForm(); | 111 void OnFocusNoLongerOnForm(); |
110 void OnDidFillAutofillFormData(const FormData& form, | 112 void OnDidFillAutofillFormData(const FormData& form, |
111 const base::TimeTicks& timestamp); | 113 const base::TimeTicks& timestamp); |
112 void OnDidPreviewAutofillFormData(); | 114 void OnDidPreviewAutofillFormData(); |
113 | 115 |
114 // Returns true if the value/identifier is deletable. Fills out | 116 // Returns true if the value/identifier is deletable. Fills out |
115 // |title| and |body| with relevant user-facing text. | 117 // |title| and |body| with relevant user-facing text. |
(...skipping 18 matching lines...) Expand all Loading... |
134 | 136 |
135 // Happens when the autocomplete dialog runs its callback when being closed. | 137 // Happens when the autocomplete dialog runs its callback when being closed. |
136 void RequestAutocompleteDialogClosed(); | 138 void RequestAutocompleteDialogClosed(); |
137 | 139 |
138 AutofillClient* client() { return client_; } | 140 AutofillClient* client() { return client_; } |
139 | 141 |
140 AutofillDownloadManager* download_manager() { | 142 AutofillDownloadManager* download_manager() { |
141 return download_manager_.get(); | 143 return download_manager_.get(); |
142 } | 144 } |
143 | 145 |
| 146 payments::FullCardRequest* GetOrCreateFullCardRequest(); |
| 147 |
144 const std::string& app_locale() const { return app_locale_; } | 148 const std::string& app_locale() const { return app_locale_; } |
145 | 149 |
146 // Only for testing. | 150 // Only for testing. |
147 void SetTestDelegate(AutofillManagerTestDelegate* delegate); | 151 void SetTestDelegate(AutofillManagerTestDelegate* delegate); |
148 | 152 |
149 void OnFormsSeen(const std::vector<FormData>& forms, | 153 void OnFormsSeen(const std::vector<FormData>& forms, |
150 const base::TimeTicks& timestamp); | 154 const base::TimeTicks& timestamp); |
151 | 155 |
152 void set_app_locale(std::string app_locale) { app_locale_ = app_locale; } | 156 void set_app_locale(std::string app_locale) { app_locale_ = app_locale; } |
153 | 157 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 void set_payments_client(payments::PaymentsClient* payments_client) { | 264 void set_payments_client(payments::PaymentsClient* payments_client) { |
261 payments_client_.reset(payments_client); | 265 payments_client_.reset(payments_client); |
262 } | 266 } |
263 | 267 |
264 private: | 268 private: |
265 // AutofillDownloadManager::Observer: | 269 // AutofillDownloadManager::Observer: |
266 void OnLoadedServerPredictions( | 270 void OnLoadedServerPredictions( |
267 std::string response, | 271 std::string response, |
268 const std::vector<std::string>& form_signatures) override; | 272 const std::vector<std::string>& form_signatures) override; |
269 | 273 |
270 // CardUnmaskDelegate: | |
271 void OnUnmaskResponse(const UnmaskResponse& response) override; | |
272 void OnUnmaskPromptClosed() override; | |
273 | |
274 // payments::PaymentsClientDelegate: | 274 // payments::PaymentsClientDelegate: |
275 IdentityProvider* GetIdentityProvider() override; | 275 IdentityProvider* GetIdentityProvider() override; |
276 void OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, | 276 void OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, |
277 const std::string& real_pan) override; | 277 const std::string& real_pan) override; |
278 void OnDidGetUploadDetails( | 278 void OnDidGetUploadDetails( |
279 AutofillClient::PaymentsRpcResult result, | 279 AutofillClient::PaymentsRpcResult result, |
280 const base::string16& context_token, | 280 const base::string16& context_token, |
281 std::unique_ptr<base::DictionaryValue> legal_message) override; | 281 std::unique_ptr<base::DictionaryValue> legal_message) override; |
282 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result) override; | 282 void OnDidUploadCard(AutofillClient::PaymentsRpcResult result) override; |
283 | 283 |
| 284 // FullCardRequest::Delegate: |
| 285 void OnFullCardDetails(const CreditCard& card, |
| 286 const base::string16& cvc) override; |
| 287 void OnFullCardError() override; |
| 288 |
284 // Saves risk data in |unmasking_risk_data_| and calls UnmaskCard if the user | 289 // Saves risk data in |unmasking_risk_data_| and calls UnmaskCard if the user |
285 // has accepted the prompt. | 290 // has accepted the prompt. |
286 void OnDidGetUnmaskRiskData(const std::string& risk_data); | 291 void OnDidGetUnmaskRiskData(const std::string& risk_data); |
287 | 292 |
288 // Sets |user_did_accept_upload_prompt_| and calls UploadCard if the risk data | 293 // Sets |user_did_accept_upload_prompt_| and calls UploadCard if the risk data |
289 // is available. | 294 // is available. |
290 void OnUserDidAcceptUpload(); | 295 void OnUserDidAcceptUpload(); |
291 | 296 |
292 // Saves risk data in |uploading_risk_data_| and calls UploadCard if the user | 297 // Saves risk data in |uploading_risk_data_| and calls UploadCard if the user |
293 // has accepted the prompt. | 298 // has accepted the prompt. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 const FormData& form, | 335 const FormData& form, |
331 const FormFieldData& field, | 336 const FormFieldData& field, |
332 const AutofillProfile& profile); | 337 const AutofillProfile& profile); |
333 | 338 |
334 // Fills or previews |data_model| in the |form|. | 339 // Fills or previews |data_model| in the |form|. |
335 void FillOrPreviewDataModelForm(AutofillDriver::RendererFormDataAction action, | 340 void FillOrPreviewDataModelForm(AutofillDriver::RendererFormDataAction action, |
336 int query_id, | 341 int query_id, |
337 const FormData& form, | 342 const FormData& form, |
338 const FormFieldData& field, | 343 const FormFieldData& field, |
339 const AutofillDataModel& data_model, | 344 const AutofillDataModel& data_model, |
340 bool is_credit_card); | 345 bool is_credit_card, |
| 346 const base::string16& cvc); |
341 | 347 |
342 // Creates a FormStructure using the FormData received from the renderer. Will | 348 // Creates a FormStructure using the FormData received from the renderer. Will |
343 // return an empty scoped_ptr if the data should not be processed for upload | 349 // return an empty scoped_ptr if the data should not be processed for upload |
344 // or personal data. | 350 // or personal data. |
345 std::unique_ptr<FormStructure> ValidateSubmittedForm(const FormData& form); | 351 std::unique_ptr<FormStructure> ValidateSubmittedForm(const FormData& form); |
346 | 352 |
347 // Fills |form_structure| cached element corresponding to |form|. | 353 // Fills |form_structure| cached element corresponding to |form|. |
348 // Returns false if the cached element was not found. | 354 // Returns false if the cached element was not found. |
349 bool FindCachedForm(const FormData& form, | 355 bool FindCachedForm(const FormData& form, |
350 FormStructure** form_structure) const WARN_UNUSED_RESULT; | 356 FormStructure** form_structure) const WARN_UNUSED_RESULT; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 // When the user first interacted with a potentially fillable form on this | 494 // When the user first interacted with a potentially fillable form on this |
489 // page. | 495 // page. |
490 base::TimeTicks initial_interaction_timestamp_; | 496 base::TimeTicks initial_interaction_timestamp_; |
491 | 497 |
492 // Our copy of the form data. | 498 // Our copy of the form data. |
493 ScopedVector<FormStructure> form_structures_; | 499 ScopedVector<FormStructure> form_structures_; |
494 | 500 |
495 // A copy of the currently interacted form data. | 501 // A copy of the currently interacted form data. |
496 std::unique_ptr<FormData> pending_form_data_; | 502 std::unique_ptr<FormData> pending_form_data_; |
497 | 503 |
498 // Collected information about a pending unmask request, and data about the | 504 // Responsible for getting the full card details, including the PAN and the |
499 // form. | 505 // CVC. |
500 payments::PaymentsClient::UnmaskRequestDetails unmask_request_; | 506 std::unique_ptr<payments::FullCardRequest> full_card_request_; |
| 507 |
| 508 // Collected information about the autofill form where unmasked card will be |
| 509 // filled. |
501 int unmasking_query_id_; | 510 int unmasking_query_id_; |
502 FormData unmasking_form_; | 511 FormData unmasking_form_; |
503 FormFieldData unmasking_field_; | 512 FormFieldData unmasking_field_; |
504 // Time when we requested the last real pan. | 513 CreditCard masked_card_; |
505 base::Time real_pan_request_timestamp_; | |
506 | 514 |
507 // Collected information about a pending upload request. | 515 // Collected information about a pending upload request. |
508 payments::PaymentsClient::UploadRequestDetails upload_request_; | 516 payments::PaymentsClient::UploadRequestDetails upload_request_; |
509 bool user_did_accept_upload_prompt_; | 517 bool user_did_accept_upload_prompt_; |
510 | 518 |
511 #ifdef ENABLE_FORM_DEBUG_DUMP | 519 #ifdef ENABLE_FORM_DEBUG_DUMP |
512 // The last few autofilled forms (key/value pairs) submitted, for debugging. | 520 // The last few autofilled forms (key/value pairs) submitted, for debugging. |
513 // TODO(brettw) this should be removed. See DumpAutofillData. | 521 // TODO(brettw) this should be removed. See DumpAutofillData. |
514 std::vector<std::map<std::string, base::string16>> | 522 std::vector<std::map<std::string, base::string16>> |
515 recently_autofilled_forms_; | 523 recently_autofilled_forms_; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, | 595 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, |
588 DontSaveCvcInAutocompleteHistory); | 596 DontSaveCvcInAutocompleteHistory); |
589 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, DontOfferToSavePaymentsCard); | 597 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, DontOfferToSavePaymentsCard); |
590 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, FillInUpdatedExpirationDate); | 598 FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, FillInUpdatedExpirationDate); |
591 DISALLOW_COPY_AND_ASSIGN(AutofillManager); | 599 DISALLOW_COPY_AND_ASSIGN(AutofillManager); |
592 }; | 600 }; |
593 | 601 |
594 } // namespace autofill | 602 } // namespace autofill |
595 | 603 |
596 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ | 604 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_H_ |
OLD | NEW |