| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <limits> | 7 #include <limits> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/autocomplete_history_manager.h" | 16 #include "chrome/browser/autocomplete_history_manager.h" |
| 17 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 17 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
| 18 #include "chrome/browser/autofill/autofill_dialog.h" | 18 #include "chrome/browser/autofill/autofill_dialog.h" |
| 19 #include "chrome/browser/autofill/autofill_metrics.h" | 19 #include "chrome/browser/autofill/autofill_metrics.h" |
| 20 #include "chrome/browser/autofill/form_structure.h" | 20 #include "chrome/browser/autofill/form_structure.h" |
| 21 #include "chrome/browser/autofill/phone_number.h" | 21 #include "chrome/browser/autofill/phone_number.h" |
| 22 #include "chrome/browser/autofill/select_control_handler.h" | 22 #include "chrome/browser/autofill/select_control_handler.h" |
| 23 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/renderer_host/render_view_host.h" | 25 #include "chrome/browser/renderer_host/render_view_host.h" |
| 26 #include "chrome/browser/tab_contents/tab_contents.h" | 26 #include "chrome/browser/tab_contents/tab_contents.h" |
| 27 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
| 28 #include "chrome/common/autofill_messages.h" |
| 28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/guid.h" | 30 #include "chrome/common/guid.h" |
| 30 #include "chrome/common/notification_details.h" | 31 #include "chrome/common/notification_details.h" |
| 31 #include "chrome/common/notification_service.h" | 32 #include "chrome/common/notification_service.h" |
| 32 #include "chrome/common/notification_type.h" | 33 #include "chrome/common/notification_type.h" |
| 33 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
| 34 #include "chrome/common/render_messages.h" | |
| 35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
| 36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 37 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 38 #include "webkit/glue/form_data.h" | 38 #include "webkit/glue/form_data.h" |
| 39 #include "webkit/glue/form_field.h" | 39 #include "webkit/glue/form_field.h" |
| 40 | 40 |
| 41 using webkit_glue::FormData; | 41 using webkit_glue::FormData; |
| 42 using webkit_glue::FormField; | 42 using webkit_glue::FormField; |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 173 |
| 174 void AutoFillManager::DidNavigateMainFramePostCommit( | 174 void AutoFillManager::DidNavigateMainFramePostCommit( |
| 175 const NavigationController::LoadCommittedDetails& details, | 175 const NavigationController::LoadCommittedDetails& details, |
| 176 const ViewHostMsg_FrameNavigate_Params& params) { | 176 const ViewHostMsg_FrameNavigate_Params& params) { |
| 177 Reset(); | 177 Reset(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 bool AutoFillManager::OnMessageReceived(const IPC::Message& message) { | 180 bool AutoFillManager::OnMessageReceived(const IPC::Message& message) { |
| 181 bool handled = true; | 181 bool handled = true; |
| 182 IPC_BEGIN_MESSAGE_MAP(AutoFillManager, message) | 182 IPC_BEGIN_MESSAGE_MAP(AutoFillManager, message) |
| 183 IPC_MESSAGE_HANDLER(ViewHostMsg_FormsSeen, OnFormsSeen) | 183 IPC_MESSAGE_HANDLER(AutoFillHostMsg_FormsSeen, OnFormsSeen) |
| 184 IPC_MESSAGE_HANDLER(ViewHostMsg_FormSubmitted, OnFormSubmitted) | 184 IPC_MESSAGE_HANDLER(AutoFillHostMsg_FormSubmitted, OnFormSubmitted) |
| 185 IPC_MESSAGE_HANDLER(ViewHostMsg_QueryFormFieldAutoFill, | 185 IPC_MESSAGE_HANDLER(AutoFillHostMsg_QueryFormFieldAutoFill, |
| 186 OnQueryFormFieldAutoFill) | 186 OnQueryFormFieldAutoFill) |
| 187 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowAutoFillDialog, OnShowAutoFillDialog) | 187 IPC_MESSAGE_HANDLER(AutoFillHostMsg_ShowAutoFillDialog, |
| 188 IPC_MESSAGE_HANDLER(ViewHostMsg_FillAutoFillFormData, | 188 OnShowAutoFillDialog) |
| 189 IPC_MESSAGE_HANDLER(AutoFillHostMsg_FillAutoFillFormData, |
| 189 OnFillAutoFillFormData) | 190 OnFillAutoFillFormData) |
| 190 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFillAutoFillFormData, | 191 IPC_MESSAGE_HANDLER(AutoFillHostMsg_DidFillAutoFillFormData, |
| 191 OnDidFillAutoFillFormData) | 192 OnDidFillAutoFillFormData) |
| 192 IPC_MESSAGE_HANDLER(ViewHostMsg_DidShowAutoFillSuggestions, | 193 IPC_MESSAGE_HANDLER(AutoFillHostMsg_DidShowAutoFillSuggestions, |
| 193 OnDidShowAutoFillSuggestions) | 194 OnDidShowAutoFillSuggestions) |
| 194 IPC_MESSAGE_UNHANDLED(handled = false) | 195 IPC_MESSAGE_UNHANDLED(handled = false) |
| 195 IPC_END_MESSAGE_MAP() | 196 IPC_END_MESSAGE_MAP() |
| 196 | 197 |
| 197 return handled; | 198 return handled; |
| 198 } | 199 } |
| 199 | 200 |
| 200 void AutoFillManager::OnFormSubmitted(const FormData& form) { | 201 void AutoFillManager::OnFormSubmitted(const FormData& form) { |
| 201 // Let AutoComplete know as well. | 202 // Let AutoComplete know as well. |
| 202 tab_contents_->autocomplete_history_manager()->OnFormSubmitted(form); | 203 tab_contents_->autocomplete_history_manager()->OnFormSubmitted(form); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 autofill_type.group() == AutoFillType::CREDIT_CARD) { | 369 autofill_type.group() == AutoFillType::CREDIT_CARD) { |
| 369 FillCreditCardFormField(credit_card, autofill_type, &(*iter)); | 370 FillCreditCardFormField(credit_card, autofill_type, &(*iter)); |
| 370 } else if (profile && | 371 } else if (profile && |
| 371 autofill_type.group() != AutoFillType::CREDIT_CARD) { | 372 autofill_type.group() != AutoFillType::CREDIT_CARD) { |
| 372 FillFormField(profile, autofill_type, &(*iter)); | 373 FillFormField(profile, autofill_type, &(*iter)); |
| 373 } | 374 } |
| 374 break; | 375 break; |
| 375 } | 376 } |
| 376 } | 377 } |
| 377 | 378 |
| 378 host->Send(new ViewMsg_AutoFillFormDataFilled( | 379 host->Send(new AutoFillMsg_FormDataFilled( |
| 379 host->routing_id(), query_id, result)); | 380 host->routing_id(), query_id, result)); |
| 380 return; | 381 return; |
| 381 } | 382 } |
| 382 | 383 |
| 383 // The list of fields in |form_structure| and |result.fields| often match | 384 // The list of fields in |form_structure| and |result.fields| often match |
| 384 // directly and we can fill these corresponding fields; however, when the | 385 // directly and we can fill these corresponding fields; however, when the |
| 385 // |form_structure| and |result.fields| do not match directly we search | 386 // |form_structure| and |result.fields| do not match directly we search |
| 386 // ahead in the |form_structure| for the matching field. | 387 // ahead in the |form_structure| for the matching field. |
| 387 // See unit tests: AutoFillManagerTest.FormChangesRemoveField and | 388 // See unit tests: AutoFillManagerTest.FormChangesRemoveField and |
| 388 // AutoFillManagerTest.FormChangesAddField for usage. | 389 // AutoFillManagerTest.FormChangesAddField for usage. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 411 autofill_type.group() != AutoFillType::CREDIT_CARD) { | 412 autofill_type.group() != AutoFillType::CREDIT_CARD) { |
| 412 FillFormField(profile, autofill_type, &result.fields[j]); | 413 FillFormField(profile, autofill_type, &result.fields[j]); |
| 413 } | 414 } |
| 414 | 415 |
| 415 // We found a matching field in the |form_structure| so we | 416 // We found a matching field in the |form_structure| so we |
| 416 // proceed to the next |result| field, and the next |form_structure|. | 417 // proceed to the next |result| field, and the next |form_structure|. |
| 417 ++i; | 418 ++i; |
| 418 } | 419 } |
| 419 autofilled_forms_signatures_.push_front(form_structure->FormSignature()); | 420 autofilled_forms_signatures_.push_front(form_structure->FormSignature()); |
| 420 | 421 |
| 421 host->Send(new ViewMsg_AutoFillFormDataFilled( | 422 host->Send(new AutoFillMsg_FormDataFilled( |
| 422 host->routing_id(), query_id, result)); | 423 host->routing_id(), query_id, result)); |
| 423 } | 424 } |
| 424 | 425 |
| 425 void AutoFillManager::OnShowAutoFillDialog() { | 426 void AutoFillManager::OnShowAutoFillDialog() { |
| 426 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 427 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 427 switches::kDisableTabbedOptions)) { | 428 switches::kDisableTabbedOptions)) { |
| 428 Browser* browser = BrowserList::GetLastActive(); | 429 Browser* browser = BrowserList::GetLastActive(); |
| 429 if (browser) | 430 if (browser) |
| 430 browser->ShowOptionsTab(chrome::kAutoFillSubPage); | 431 browser->ShowOptionsTab(chrome::kAutoFillSubPage); |
| 431 return; | 432 return; |
| 432 } | 433 } |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 return std::string(); | 911 return std::string(); |
| 911 | 912 |
| 912 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id); | 913 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id); |
| 913 if (iter == id_guid_map_.end()) { | 914 if (iter == id_guid_map_.end()) { |
| 914 NOTREACHED(); | 915 NOTREACHED(); |
| 915 return std::string(); | 916 return std::string(); |
| 916 } | 917 } |
| 917 | 918 |
| 918 return iter->second; | 919 return iter->second; |
| 919 } | 920 } |
| OLD | NEW |