| 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 COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_MANAGER_H_ | 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_MANAGER_H_ |
| 6 #define COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_MANAGER_H_ | 6 #define COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_MANAGER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 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/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.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/supports_user_data.h" | |
| 22 #include "base/time.h" | 21 #include "base/time.h" |
| 23 #include "components/autofill/browser/autocomplete_history_manager.h" | 22 #include "components/autofill/browser/autocomplete_history_manager.h" |
| 24 #include "components/autofill/browser/autofill_download.h" | 23 #include "components/autofill/browser/autofill_download.h" |
| 25 #include "components/autofill/browser/autofill_manager_delegate.h" | 24 #include "components/autofill/browser/autofill_manager_delegate.h" |
| 26 #include "components/autofill/browser/field_types.h" | 25 #include "components/autofill/browser/field_types.h" |
| 27 #include "components/autofill/browser/form_structure.h" | 26 #include "components/autofill/browser/form_structure.h" |
| 28 #include "components/autofill/browser/personal_data_manager.h" | 27 #include "components/autofill/browser/personal_data_manager.h" |
| 29 #include "components/autofill/common/autocheckout_status.h" | 28 #include "components/autofill/common/autocheckout_status.h" |
| 30 #include "components/autofill/common/form_data.h" | 29 #include "components/autofill/common/form_data.h" |
| 31 #include "components/autofill/common/forms_seen_state.h" | 30 #include "components/autofill/common/forms_seen_state.h" |
| 32 #include "components/autofill/content/browser/autocheckout_manager.h" | 31 #include "components/autofill/content/browser/autocheckout_manager.h" |
| 33 #include "content/public/browser/web_contents_observer.h" | |
| 34 #include "content/public/common/ssl_status.h" | 32 #include "content/public/common/ssl_status.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 36 | 34 |
| 37 class GURL; | 35 class GURL; |
| 38 | 36 |
| 39 struct ViewHostMsg_FrameNavigate_Params; | |
| 40 | |
| 41 namespace content { | 37 namespace content { |
| 42 class RenderViewHost; | 38 class RenderViewHost; |
| 43 class WebContents; | 39 class WebContents; |
| 40 struct FrameNavigateParams; |
| 41 struct LoadCommittedDetails; |
| 44 } | 42 } |
| 45 | 43 |
| 46 namespace gfx { | 44 namespace gfx { |
| 47 class Rect; | 45 class Rect; |
| 48 class RectF; | 46 class RectF; |
| 49 } | 47 } |
| 50 | 48 |
| 51 namespace IPC { | 49 namespace IPC { |
| 52 class Message; | 50 class Message; |
| 53 } | 51 } |
| 54 | 52 |
| 55 namespace user_prefs { | 53 namespace user_prefs { |
| 56 class PrefRegistrySyncable; | 54 class PrefRegistrySyncable; |
| 57 } | 55 } |
| 58 | 56 |
| 59 namespace autofill { | 57 namespace autofill { |
| 60 | 58 |
| 59 class AutofillDriver; |
| 61 class AutofillDataModel; | 60 class AutofillDataModel; |
| 62 class AutofillDownloadManager; | 61 class AutofillDownloadManager; |
| 63 class AutofillExternalDelegate; | 62 class AutofillExternalDelegate; |
| 64 class AutofillField; | 63 class AutofillField; |
| 65 class AutofillProfile; | 64 class AutofillProfile; |
| 66 class AutofillManagerDelegate; | 65 class AutofillManagerDelegate; |
| 67 class AutofillManagerTestDelegate; | 66 class AutofillManagerTestDelegate; |
| 68 class AutofillMetrics; | 67 class AutofillMetrics; |
| 69 class CreditCard; | 68 class CreditCard; |
| 70 class FormStructureBrowserTest; | 69 class FormStructureBrowserTest; |
| 71 | 70 |
| 72 struct FormData; | 71 struct FormData; |
| 73 struct FormFieldData; | 72 struct FormFieldData; |
| 74 struct PasswordFormFillData; | 73 struct PasswordFormFillData; |
| 75 | 74 |
| 76 // Manages saving and restoring the user's personal information entered into web | 75 // Manages saving and restoring the user's personal information entered into web |
| 77 // forms. | 76 // forms. |
| 78 class AutofillManager : public content::WebContentsObserver, | 77 class AutofillManager : public AutofillDownloadManager::Observer { |
| 79 public AutofillDownloadManager::Observer, | |
| 80 public base::SupportsUserData::Data { | |
| 81 public: | 78 public: |
| 82 enum AutofillDownloadManagerState { | 79 enum AutofillDownloadManagerState { |
| 83 ENABLE_AUTOFILL_DOWNLOAD_MANAGER, | 80 ENABLE_AUTOFILL_DOWNLOAD_MANAGER, |
| 84 DISABLE_AUTOFILL_DOWNLOAD_MANAGER, | 81 DISABLE_AUTOFILL_DOWNLOAD_MANAGER, |
| 85 }; | 82 }; |
| 86 | 83 |
| 87 static void CreateForWebContentsAndDelegate( | |
| 88 content::WebContents* contents, | |
| 89 autofill::AutofillManagerDelegate* delegate, | |
| 90 const std::string& app_locale, | |
| 91 AutofillDownloadManagerState enable_download_manager); | |
| 92 static AutofillManager* FromWebContents(content::WebContents* contents); | |
| 93 | |
| 94 // Registers our Enable/Disable Autofill pref. | 84 // Registers our Enable/Disable Autofill pref. |
| 95 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); | 85 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); |
| 96 | 86 |
| 87 AutofillManager(AutofillDriver* driver, |
| 88 autofill::AutofillManagerDelegate* delegate, |
| 89 const std::string& app_locale, |
| 90 AutofillDownloadManagerState enable_download_manager); |
| 91 virtual ~AutofillManager(); |
| 92 |
| 97 // Set an external delegate. | 93 // Set an external delegate. |
| 98 void SetExternalDelegate(AutofillExternalDelegate* delegate); | 94 void SetExternalDelegate(AutofillExternalDelegate* delegate); |
| 99 | 95 |
| 100 // Whether browser process will create and own the Autofill popup UI. | 96 // Whether browser process will create and own the Autofill popup UI. |
| 101 bool IsNativeUiEnabled(); | 97 bool IsNativeUiEnabled(); |
| 102 | 98 |
| 103 // Called from our external delegate so they cannot be private. | 99 // Called from our external delegate so they cannot be private. |
| 104 virtual void OnFillAutofillFormData(int query_id, | 100 virtual void OnFillAutofillFormData(int query_id, |
| 105 const FormData& form, | 101 const FormData& form, |
| 106 const FormFieldData& field, | 102 const FormFieldData& field, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 137 | 133 |
| 138 autofill::AutofillManagerDelegate* delegate() const { | 134 autofill::AutofillManagerDelegate* delegate() const { |
| 139 return manager_delegate_; | 135 return manager_delegate_; |
| 140 } | 136 } |
| 141 | 137 |
| 142 const std::string& app_locale() const { return app_locale_; } | 138 const std::string& app_locale() const { return app_locale_; } |
| 143 | 139 |
| 144 // Only for testing. | 140 // Only for testing. |
| 145 void SetTestDelegate(autofill::AutofillManagerTestDelegate* delegate); | 141 void SetTestDelegate(autofill::AutofillManagerTestDelegate* delegate); |
| 146 | 142 |
| 143 // TODO(blundell): Move the logic in these methods into AutofillDriver and |
| 144 // eliminate these methods. |
| 145 virtual void DidNavigateMainFrame( |
| 146 const content::LoadCommittedDetails& details, |
| 147 const content::FrameNavigateParams& params); |
| 148 virtual bool OnMessageReceived(const IPC::Message& message); |
| 149 |
| 147 protected: | 150 protected: |
| 148 // Only test code should subclass AutofillManager. | |
| 149 AutofillManager(content::WebContents* web_contents, | |
| 150 autofill::AutofillManagerDelegate* delegate, | |
| 151 const std::string& app_locale, | |
| 152 AutofillDownloadManagerState enable_download_manager); | |
| 153 virtual ~AutofillManager(); | |
| 154 | |
| 155 // Test code should prefer to use this constructor. | 151 // Test code should prefer to use this constructor. |
| 156 AutofillManager(content::WebContents* web_contents, | 152 AutofillManager(AutofillDriver* driver, |
| 157 autofill::AutofillManagerDelegate* delegate, | 153 autofill::AutofillManagerDelegate* delegate, |
| 158 PersonalDataManager* personal_data); | 154 PersonalDataManager* personal_data); |
| 159 | 155 |
| 160 // Returns the value of the AutofillEnabled pref. | 156 // Returns the value of the AutofillEnabled pref. |
| 161 virtual bool IsAutofillEnabled() const; | 157 virtual bool IsAutofillEnabled() const; |
| 162 | 158 |
| 163 // Uploads the form data to the Autofill server. | 159 // Uploads the form data to the Autofill server. |
| 164 virtual void UploadFormData(const FormStructure& submitted_form); | 160 virtual void UploadFormData(const FormStructure& submitted_form); |
| 165 | 161 |
| 166 // Reset cache. | 162 // Reset cache. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // server. Returns false if this form is not relevant for Autofill. | 210 // server. Returns false if this form is not relevant for Autofill. |
| 215 bool OnFormSubmitted(const FormData& form, | 211 bool OnFormSubmitted(const FormData& form, |
| 216 const base::TimeTicks& timestamp); | 212 const base::TimeTicks& timestamp); |
| 217 | 213 |
| 218 // Tell the renderer the current interactive autocomplete finished. | 214 // Tell the renderer the current interactive autocomplete finished. |
| 219 virtual void ReturnAutocompleteResult( | 215 virtual void ReturnAutocompleteResult( |
| 220 WebKit::WebFormElement::AutocompleteResult result, | 216 WebKit::WebFormElement::AutocompleteResult result, |
| 221 const FormData& form_data); | 217 const FormData& form_data); |
| 222 | 218 |
| 223 private: | 219 private: |
| 224 // content::WebContentsObserver: | |
| 225 virtual void DidNavigateMainFrame( | |
| 226 const content::LoadCommittedDetails& details, | |
| 227 const content::FrameNavigateParams& params) OVERRIDE; | |
| 228 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 229 | 220 |
| 230 // AutofillDownloadManager::Observer: | 221 // AutofillDownloadManager::Observer: |
| 231 virtual void OnLoadedServerPredictions( | 222 virtual void OnLoadedServerPredictions( |
| 232 const std::string& response_xml) OVERRIDE; | 223 const std::string& response_xml) OVERRIDE; |
| 233 | 224 |
| 234 void OnFormsSeen(const std::vector<FormData>& forms, | 225 void OnFormsSeen(const std::vector<FormData>& forms, |
| 235 const base::TimeTicks& timestamp, | 226 const base::TimeTicks& timestamp, |
| 236 autofill::FormsSeenState state); | 227 autofill::FormsSeenState state); |
| 237 void OnTextFieldDidChange(const FormData& form, | 228 void OnTextFieldDidChange(const FormData& form, |
| 238 const FormFieldData& field, | 229 const FormFieldData& field, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 // |interaction_timestamp|, updates the cached timestamp. The latter check is | 327 // |interaction_timestamp|, updates the cached timestamp. The latter check is |
| 337 // needed because IPC messages can arrive out of order. | 328 // needed because IPC messages can arrive out of order. |
| 338 void UpdateInitialInteractionTimestamp( | 329 void UpdateInitialInteractionTimestamp( |
| 339 const base::TimeTicks& interaction_timestamp); | 330 const base::TimeTicks& interaction_timestamp); |
| 340 | 331 |
| 341 // Send our current field type predictions to the renderer. This is a no-op if | 332 // Send our current field type predictions to the renderer. This is a no-op if |
| 342 // the appropriate command-line flag is not set. | 333 // the appropriate command-line flag is not set. |
| 343 void SendAutofillTypePredictions( | 334 void SendAutofillTypePredictions( |
| 344 const std::vector<FormStructure*>& forms) const; | 335 const std::vector<FormStructure*>& forms) const; |
| 345 | 336 |
| 337 // Provides driver-level context to the shared code of the component. Must |
| 338 // outlive this object. |
| 339 AutofillDriver* driver_; |
| 340 |
| 346 autofill::AutofillManagerDelegate* const manager_delegate_; | 341 autofill::AutofillManagerDelegate* const manager_delegate_; |
| 347 | 342 |
| 348 std::string app_locale_; | 343 std::string app_locale_; |
| 349 | 344 |
| 350 // The personal data manager, used to save and load personal data to/from the | 345 // The personal data manager, used to save and load personal data to/from the |
| 351 // web database. This is overridden by the AutofillManagerTest. | 346 // web database. This is overridden by the AutofillManagerTest. |
| 352 // Weak reference. | 347 // Weak reference. |
| 353 // May be NULL. NULL indicates OTR. | 348 // May be NULL. NULL indicates OTR. |
| 354 PersonalDataManager* personal_data_; | 349 PersonalDataManager* personal_data_; |
| 355 | 350 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, | 421 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, |
| 427 UserHappinessFormLoadAndSubmission); | 422 UserHappinessFormLoadAndSubmission); |
| 428 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); | 423 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); |
| 429 | 424 |
| 430 DISALLOW_COPY_AND_ASSIGN(AutofillManager); | 425 DISALLOW_COPY_AND_ASSIGN(AutofillManager); |
| 431 }; | 426 }; |
| 432 | 427 |
| 433 } // namespace autofill | 428 } // namespace autofill |
| 434 | 429 |
| 435 #endif // COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_MANAGER_H_ | 430 #endif // COMPONENTS_AUTOFILL_BROWSER_AUTOFILL_MANAGER_H_ |
| OLD | NEW |