Index: chrome/browser/autofill/autofill_manager.cc |
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc |
index 2cddabc160f5685523910f698e64bb3845d4b93e..29910e42de5508a89f27de5c5e8eba56de9277c5 100644 |
--- a/chrome/browser/autofill/autofill_manager.cc |
+++ b/chrome/browser/autofill/autofill_manager.cc |
@@ -19,6 +19,8 @@ |
#include "chrome/browser/renderer_host/render_view_host.h" |
#include "chrome/browser/tab_contents/tab_contents.h" |
#include "chrome/common/chrome_switches.h" |
+#include "chrome/common/notification_source.h" |
+#include "chrome/common/notification_service.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/common/url_constants.h" |
#include "webkit/glue/form_data.h" |
@@ -100,6 +102,7 @@ AutoFillManager::AutoFillManager(TabContents* tab_contents) |
: tab_contents_(tab_contents), |
personal_data_(NULL), |
download_manager_(tab_contents_->profile()), |
+ locale_model_(tab_contents_), |
disable_download_manager_requests_(false) { |
DCHECK(tab_contents); |
@@ -107,10 +110,15 @@ AutoFillManager::AutoFillManager(TabContents* tab_contents) |
personal_data_ = |
tab_contents_->profile()->GetOriginalProfile()->GetPersonalDataManager(); |
download_manager_.SetObserver(this); |
+ notification_registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, |
+ Source<TabContents>(tab_contents_)); |
} |
AutoFillManager::~AutoFillManager() { |
download_manager_.SetObserver(NULL); |
+ notification_registrar_.Remove(this, |
+ NotificationType::TAB_LANGUAGE_DETERMINED, |
+ Source<TabContents>(tab_contents_)); |
} |
// static |
@@ -145,6 +153,8 @@ void AutoFillManager::FormSubmitted(const FormData& form) { |
// Grab a copy of the form data. |
upload_form_structure_.reset(new FormStructure(form)); |
+ if (locale_model_.tab_language_determined()) |
+ locale_model_.UpdateLocale(upload_form_structure_.get()); |
if (!upload_form_structure_->IsAutoFillable()) |
return; |
@@ -375,6 +385,7 @@ void AutoFillManager::ShowAutoFillDialog() { |
void AutoFillManager::Reset() { |
upload_form_structure_.reset(); |
form_structures_.reset(); |
+ locale_model_.set_tab_language_determined(false); |
} |
void AutoFillManager::OnLoadedAutoFillHeuristics( |
@@ -396,6 +407,25 @@ void AutoFillManager::OnHeuristicsRequestError( |
int http_error) { |
} |
+void AutoFillManager::Observe(NotificationType type, |
+ const NotificationSource& source, |
+ const NotificationDetails& details) { |
+ if (type != NotificationType::TAB_LANGUAGE_DETERMINED) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ |
+ DCHECK(source == Source<TabContents>(tab_contents_)); |
+ |
+ // Now that the tab language is known, update the locales of the forms we've |
+ // seen. |
+ locale_model_.set_tab_language_determined(true); |
+ for (std::vector<FormStructure*>::iterator it = form_structures_.begin(); |
+ it != form_structures_.end(); ++it) { |
+ locale_model_.UpdateLocale(*it); |
+ } |
+} |
+ |
bool AutoFillManager::IsAutoFillEnabled() const { |
PrefService* prefs = tab_contents_->profile()->GetPrefs(); |
@@ -475,7 +505,10 @@ AutoFillManager::AutoFillManager() |
: tab_contents_(NULL), |
personal_data_(NULL), |
download_manager_(NULL), |
+ locale_model_(NULL), |
disable_download_manager_requests_(false) { |
+ notification_registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, |
+ Source<TabContents>(tab_contents_)); |
} |
AutoFillManager::AutoFillManager(TabContents* tab_contents, |
@@ -483,8 +516,11 @@ AutoFillManager::AutoFillManager(TabContents* tab_contents, |
: tab_contents_(tab_contents), |
personal_data_(personal_data), |
download_manager_(NULL), |
+ locale_model_(tab_contents), |
disable_download_manager_requests_(false) { |
DCHECK(tab_contents); |
+ notification_registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, |
+ Source<TabContents>(tab_contents_)); |
} |
void AutoFillManager::GetProfileSuggestions(FormStructure* form, |
@@ -772,14 +808,16 @@ void AutoFillManager::FillPhoneNumberField(const AutoFillProfile* profile, |
void AutoFillManager::ParseForms( |
const std::vector<webkit_glue::FormData>& forms) { |
- for (std::vector<FormData>::const_iterator iter = |
- forms.begin(); |
+ for (std::vector<FormData>::const_iterator iter = forms.begin(); |
iter != forms.end(); ++iter) { |
scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); |
if (!form_structure->ShouldBeParsed()) |
continue; |
DeterminePossibleFieldTypes(form_structure.get()); |
+ if (locale_model_.tab_language_determined()) |
+ locale_model_.UpdateLocale(form_structure.get()); |
+ |
form_structures_.push_back(form_structure.release()); |
} |