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 #include "chrome/browser/autofill/autofill_manager.h" | 5 #include "chrome/browser/autofill/autofill_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "chrome/browser/autofill/select_control_handler.h" | 36 #include "chrome/browser/autofill/select_control_handler.h" |
37 #include "chrome/browser/infobars/infobar_tab_helper.h" | 37 #include "chrome/browser/infobars/infobar_tab_helper.h" |
38 #include "chrome/browser/password_manager/password_manager.h" | 38 #include "chrome/browser/password_manager/password_manager.h" |
39 #include "chrome/browser/prefs/pref_service.h" | 39 #include "chrome/browser/prefs/pref_service.h" |
40 #include "chrome/browser/profiles/profile.h" | 40 #include "chrome/browser/profiles/profile.h" |
41 #include "chrome/browser/sync/profile_sync_service_factory.h" | 41 #include "chrome/browser/sync/profile_sync_service_factory.h" |
42 #include "chrome/browser/sync/profile_sync_service.h" | 42 #include "chrome/browser/sync/profile_sync_service.h" |
43 #include "chrome/browser/ui/browser.h" | 43 #include "chrome/browser/ui/browser.h" |
44 #include "chrome/browser/ui/browser_finder.h" | 44 #include "chrome/browser/ui/browser_finder.h" |
45 #include "chrome/browser/ui/browser_window.h" | 45 #include "chrome/browser/ui/browser_window.h" |
46 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 46 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
47 #include "chrome/common/autofill_messages.h" | 47 #include "chrome/common/autofill_messages.h" |
48 #include "chrome/common/chrome_notification_types.h" | 48 #include "chrome/common/chrome_notification_types.h" |
49 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
50 #include "chrome/common/guid.h" | 50 #include "chrome/common/guid.h" |
51 #include "chrome/common/pref_names.h" | 51 #include "chrome/common/pref_names.h" |
52 #include "chrome/common/url_constants.h" | 52 #include "chrome/common/url_constants.h" |
53 #include "content/public/browser/browser_thread.h" | 53 #include "content/public/browser/browser_thread.h" |
54 #include "content/public/browser/notification_service.h" | 54 #include "content/public/browser/notification_service.h" |
55 #include "content/public/browser/notification_source.h" | 55 #include "content/public/browser/notification_source.h" |
56 #include "content/public/browser/render_view_host.h" | 56 #include "content/public/browser/render_view_host.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 170 |
171 if (matching_types.empty()) | 171 if (matching_types.empty()) |
172 matching_types.insert(UNKNOWN_TYPE); | 172 matching_types.insert(UNKNOWN_TYPE); |
173 | 173 |
174 field->set_possible_types(matching_types); | 174 field->set_possible_types(matching_types); |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
178 } // namespace | 178 } // namespace |
179 | 179 |
180 AutofillManager::AutofillManager(TabContentsWrapper* tab_contents) | 180 AutofillManager::AutofillManager(TabContents* tab_contents) |
181 : content::WebContentsObserver(tab_contents->web_contents()), | 181 : content::WebContentsObserver(tab_contents->web_contents()), |
182 tab_contents_wrapper_(tab_contents), | 182 tab_contents_(tab_contents), |
183 personal_data_(NULL), | 183 personal_data_(NULL), |
184 download_manager_(tab_contents->profile(), this), | 184 download_manager_(tab_contents->profile(), this), |
185 disable_download_manager_requests_(false), | 185 disable_download_manager_requests_(false), |
186 metric_logger_(new AutofillMetrics), | 186 metric_logger_(new AutofillMetrics), |
187 has_logged_autofill_enabled_(false), | 187 has_logged_autofill_enabled_(false), |
188 has_logged_address_suggestions_count_(false), | 188 has_logged_address_suggestions_count_(false), |
189 did_show_suggestions_(false), | 189 did_show_suggestions_(false), |
190 user_did_type_(false), | 190 user_did_type_(false), |
191 user_did_autofill_(false), | 191 user_did_autofill_(false), |
192 user_did_edit_autofilled_field_(false), | 192 user_did_edit_autofilled_field_(false), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 prefs->RegisterDoublePref(prefs::kAutofillPositiveUploadRate, | 225 prefs->RegisterDoublePref(prefs::kAutofillPositiveUploadRate, |
226 kAutofillPositiveUploadRateDefaultValue, | 226 kAutofillPositiveUploadRateDefaultValue, |
227 PrefService::UNSYNCABLE_PREF); | 227 PrefService::UNSYNCABLE_PREF); |
228 prefs->RegisterDoublePref(prefs::kAutofillNegativeUploadRate, | 228 prefs->RegisterDoublePref(prefs::kAutofillNegativeUploadRate, |
229 kAutofillNegativeUploadRateDefaultValue, | 229 kAutofillNegativeUploadRateDefaultValue, |
230 PrefService::UNSYNCABLE_PREF); | 230 PrefService::UNSYNCABLE_PREF); |
231 } | 231 } |
232 | 232 |
233 void AutofillManager::RegisterWithSyncService() { | 233 void AutofillManager::RegisterWithSyncService() { |
234 ProfileSyncService* temp_sync_service = | 234 ProfileSyncService* temp_sync_service = |
235 ProfileSyncServiceFactory::GetForProfile( | 235 ProfileSyncServiceFactory::GetForProfile(tab_contents_->profile()); |
236 tab_contents_wrapper_->profile()); | |
237 if (temp_sync_service) { | 236 if (temp_sync_service) { |
238 sync_service_ = temp_sync_service->AsWeakPtr(); | 237 sync_service_ = temp_sync_service->AsWeakPtr(); |
239 sync_service_->AddObserver(this); | 238 sync_service_->AddObserver(this); |
240 } | 239 } |
241 } | 240 } |
242 | 241 |
243 void AutofillManager::SendPasswordGenerationStateToRenderer( | 242 void AutofillManager::SendPasswordGenerationStateToRenderer( |
244 content::RenderViewHost* host, bool enabled) { | 243 content::RenderViewHost* host, bool enabled) { |
245 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), | 244 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), |
246 enabled)); | 245 enabled)); |
247 } | 246 } |
248 | 247 |
249 // In order for password generation to be enabled, we need to make sure: | 248 // In order for password generation to be enabled, we need to make sure: |
250 // (1) Password sync is enabled, | 249 // (1) Password sync is enabled, |
251 // (2) Password manager is enabled, and | 250 // (2) Password manager is enabled, and |
252 // (3) Password generation preference check box is checked. | 251 // (3) Password generation preference check box is checked. |
253 void AutofillManager::UpdatePasswordGenerationState( | 252 void AutofillManager::UpdatePasswordGenerationState( |
254 content::RenderViewHost* host, | 253 content::RenderViewHost* host, |
255 bool new_renderer) { | 254 bool new_renderer) { |
256 if (!sync_service_) | 255 if (!sync_service_) |
257 return; | 256 return; |
258 | 257 |
259 syncable::ModelTypeSet sync_set = sync_service_->GetPreferredDataTypes(); | 258 syncable::ModelTypeSet sync_set = sync_service_->GetPreferredDataTypes(); |
260 bool password_sync_enabled = | 259 bool password_sync_enabled = |
261 sync_service_->HasSyncSetupCompleted() && | 260 sync_service_->HasSyncSetupCompleted() && |
262 sync_set.Has(syncable::PASSWORDS); | 261 sync_set.Has(syncable::PASSWORDS); |
263 | 262 |
264 bool password_manager_enabled = | 263 bool password_manager_enabled = |
265 tab_contents_wrapper_->password_manager()->IsSavingEnabled(); | 264 tab_contents_->password_manager()->IsSavingEnabled(); |
266 | 265 |
267 Profile* profile = Profile::FromBrowserContext( | 266 Profile* profile = Profile::FromBrowserContext( |
268 web_contents()->GetBrowserContext()); | 267 web_contents()->GetBrowserContext()); |
269 bool preference_checked = | 268 bool preference_checked = |
270 profile->GetPrefs()->GetBoolean(prefs::kPasswordGenerationEnabled); | 269 profile->GetPrefs()->GetBoolean(prefs::kPasswordGenerationEnabled); |
271 | 270 |
272 bool new_password_generation_enabled = | 271 bool new_password_generation_enabled = |
273 password_sync_enabled && | 272 password_sync_enabled && |
274 password_manager_enabled && | 273 password_manager_enabled && |
275 preference_checked; | 274 preference_checked; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 OnShowPasswordSuggestions) | 345 OnShowPasswordSuggestions) |
347 IPC_MESSAGE_UNHANDLED(handled = false) | 346 IPC_MESSAGE_UNHANDLED(handled = false) |
348 IPC_END_MESSAGE_MAP() | 347 IPC_END_MESSAGE_MAP() |
349 | 348 |
350 return handled; | 349 return handled; |
351 } | 350 } |
352 | 351 |
353 bool AutofillManager::OnFormSubmitted(const FormData& form, | 352 bool AutofillManager::OnFormSubmitted(const FormData& form, |
354 const TimeTicks& timestamp) { | 353 const TimeTicks& timestamp) { |
355 // Let AutoComplete know as well. | 354 // Let AutoComplete know as well. |
356 tab_contents_wrapper_->autocomplete_history_manager()->OnFormSubmitted(form); | 355 tab_contents_->autocomplete_history_manager()->OnFormSubmitted(form); |
357 | 356 |
358 if (!IsAutofillEnabled()) | 357 if (!IsAutofillEnabled()) |
359 return false; | 358 return false; |
360 | 359 |
361 if (web_contents()->GetBrowserContext()->IsOffTheRecord()) | 360 if (web_contents()->GetBrowserContext()->IsOffTheRecord()) |
362 return false; | 361 return false; |
363 | 362 |
364 // Don't save data that was submitted through JavaScript. | 363 // Don't save data that was submitted through JavaScript. |
365 if (!form.user_submitted) | 364 if (!form.user_submitted) |
366 return false; | 365 return false; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 metric_logger_->LogAddressSuggestionsCount(values.size()); | 547 metric_logger_->LogAddressSuggestionsCount(values.size()); |
549 has_logged_address_suggestions_count_ = true; | 548 has_logged_address_suggestions_count_ = true; |
550 } | 549 } |
551 } | 550 } |
552 } | 551 } |
553 } | 552 } |
554 | 553 |
555 // Add the results from AutoComplete. They come back asynchronously, so we | 554 // Add the results from AutoComplete. They come back asynchronously, so we |
556 // hand off what we generated and they will send the results back to the | 555 // hand off what we generated and they will send the results back to the |
557 // renderer. | 556 // renderer. |
558 tab_contents_wrapper_->autocomplete_history_manager()-> | 557 tab_contents_->autocomplete_history_manager()-> |
559 OnGetAutocompleteSuggestions( | 558 OnGetAutocompleteSuggestions( |
560 query_id, field.name, field.value, values, labels, icons, unique_ids); | 559 query_id, field.name, field.value, values, labels, icons, unique_ids); |
561 } | 560 } |
562 | 561 |
563 void AutofillManager::OnFillAutofillFormData(int query_id, | 562 void AutofillManager::OnFillAutofillFormData(int query_id, |
564 const FormData& form, | 563 const FormData& form, |
565 const FormField& field, | 564 const FormField& field, |
566 int unique_id) { | 565 int unique_id) { |
567 const std::vector<AutofillProfile*>& profiles = personal_data_->profiles(); | 566 const std::vector<AutofillProfile*>& profiles = personal_data_->profiles(); |
568 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards(); | 567 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards(); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 | 812 |
814 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { | 813 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { |
815 const CreditCard* imported_credit_card; | 814 const CreditCard* imported_credit_card; |
816 if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card)) | 815 if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card)) |
817 return; | 816 return; |
818 | 817 |
819 // If credit card information was submitted, show an infobar to offer to save | 818 // If credit card information was submitted, show an infobar to offer to save |
820 // it. | 819 // it. |
821 scoped_ptr<const CreditCard> scoped_credit_card(imported_credit_card); | 820 scoped_ptr<const CreditCard> scoped_credit_card(imported_credit_card); |
822 if (imported_credit_card && web_contents()) { | 821 if (imported_credit_card && web_contents()) { |
823 InfoBarTabHelper* infobar_helper = | 822 InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); |
824 tab_contents_wrapper_->infobar_tab_helper(); | |
825 infobar_helper->AddInfoBar( | 823 infobar_helper->AddInfoBar( |
826 new AutofillCCInfoBarDelegate(infobar_helper, | 824 new AutofillCCInfoBarDelegate(infobar_helper, |
827 scoped_credit_card.release(), | 825 scoped_credit_card.release(), |
828 personal_data_, | 826 personal_data_, |
829 metric_logger_.get())); | 827 metric_logger_.get())); |
830 } | 828 } |
831 } | 829 } |
832 | 830 |
833 // Note that |submitted_form| is passed as a pointer rather than as a reference | 831 // Note that |submitted_form| is passed as a pointer rather than as a reference |
834 // so that we can get memory management right across threads. Note also that we | 832 // so that we can get memory management right across threads. Note also that we |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 user_did_type_ = false; | 876 user_did_type_ = false; |
879 user_did_autofill_ = false; | 877 user_did_autofill_ = false; |
880 user_did_edit_autofilled_field_ = false; | 878 user_did_edit_autofilled_field_ = false; |
881 forms_loaded_timestamp_ = TimeTicks(); | 879 forms_loaded_timestamp_ = TimeTicks(); |
882 initial_interaction_timestamp_ = TimeTicks(); | 880 initial_interaction_timestamp_ = TimeTicks(); |
883 | 881 |
884 if (external_delegate_) | 882 if (external_delegate_) |
885 external_delegate_->Reset(); | 883 external_delegate_->Reset(); |
886 } | 884 } |
887 | 885 |
888 AutofillManager::AutofillManager(TabContentsWrapper* tab_contents, | 886 AutofillManager::AutofillManager(TabContents* tab_contents, |
889 PersonalDataManager* personal_data) | 887 PersonalDataManager* personal_data) |
890 : content::WebContentsObserver(tab_contents->web_contents()), | 888 : content::WebContentsObserver(tab_contents->web_contents()), |
891 tab_contents_wrapper_(tab_contents), | 889 tab_contents_(tab_contents), |
892 personal_data_(personal_data), | 890 personal_data_(personal_data), |
893 download_manager_(tab_contents->profile(), this), | 891 download_manager_(tab_contents->profile(), this), |
894 disable_download_manager_requests_(true), | 892 disable_download_manager_requests_(true), |
895 metric_logger_(new AutofillMetrics), | 893 metric_logger_(new AutofillMetrics), |
896 has_logged_autofill_enabled_(false), | 894 has_logged_autofill_enabled_(false), |
897 has_logged_address_suggestions_count_(false), | 895 has_logged_address_suggestions_count_(false), |
898 did_show_suggestions_(false), | 896 did_show_suggestions_(false), |
899 user_did_type_(false), | 897 user_did_type_(false), |
900 user_did_autofill_(false), | 898 user_did_autofill_(false), |
901 user_did_edit_autofilled_field_(false), | 899 user_did_edit_autofilled_field_(false), |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 *profile_guid = IDToGUID(profile_id); | 1386 *profile_guid = IDToGUID(profile_id); |
1389 } | 1387 } |
1390 | 1388 |
1391 void AutofillManager::UpdateInitialInteractionTimestamp( | 1389 void AutofillManager::UpdateInitialInteractionTimestamp( |
1392 const TimeTicks& interaction_timestamp) { | 1390 const TimeTicks& interaction_timestamp) { |
1393 if (initial_interaction_timestamp_.is_null() || | 1391 if (initial_interaction_timestamp_.is_null() || |
1394 interaction_timestamp < initial_interaction_timestamp_) { | 1392 interaction_timestamp < initial_interaction_timestamp_) { |
1395 initial_interaction_timestamp_ = interaction_timestamp; | 1393 initial_interaction_timestamp_ = interaction_timestamp; |
1396 } | 1394 } |
1397 } | 1395 } |
OLD | NEW |