Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3041)

Unified Diff: chrome/browser/autofill/autofill_locale_model.h

Issue 3226001: Detecting form locale (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Unit test for top websites Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_locale_model.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autofill/autofill_locale_model.h
diff --git a/chrome/browser/autofill/autofill_locale_model.h b/chrome/browser/autofill/autofill_locale_model.h
new file mode 100644
index 0000000000000000000000000000000000000000..5501c0d73c9e4edaa64d8b12fbd4a86230ff5ae4
--- /dev/null
+++ b/chrome/browser/autofill/autofill_locale_model.h
@@ -0,0 +1,73 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_LOCALE_MODEL_H_
+#define CHROME_BROWSER_AUTOFILL_AUTOFILL_LOCALE_MODEL_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/hash_tables.h"
+
+class FormStructure;
+class GURL;
+class TabContents;
+
+// This class is responsible for collating and making sense of the various
+// locale indicators for auto-fillable forms.
+class AutoFillLocaleModel {
+ public:
+ explicit AutoFillLocaleModel(const TabContents* tab_contents);
+ virtual ~AutoFillLocaleModel();
+
+ // Updates the |form|'s locale using heuristics that combine three signals:
+ // * the author-specified locale, which we get from the DOM;
+ // * the automatically detected language; and
+ // * the page url's registry (e.g. ".co.uk").
+ void UpdateLocale(FormStructure* form) const;
+
+ // Returns whether |language_tag| is a known language subtag.
+ static bool IsValidLanguageTag(const std::string& language_tag);
+
+ // Returns whether |region_tag| is a known region subtag.
+ static bool IsValidRegionTag(const std::string& region_tag);
+
+ bool tab_language_determined() const {
+ return tab_language_determined_;
+ }
+ void set_tab_language_determined(bool language_determined) {
+ tab_language_determined_ = language_determined;
+ }
+
+ protected:
+ // Region and language data for known domain registries (roughly, top level
+ // domains).
+ struct AutoFillRegistryInfo {
+ std::string region;
+ std::vector<std::string> languages;
+ };
+ typedef base::hash_map<std::string, AutoFillRegistryInfo> AutoFillRegistryMap;
+
+ // For tests.
+ const AutoFillRegistryMap* registries() { return &registries_; }
+
+ private:
+ std::string RegionFromRegistry(const std::string& registry,
+ std::string* guessed_language) const;
+
+ // Hash table mapping registries to their language and region data.
+ AutoFillRegistryMap registries_;
+
+ // The |TabContents| hosting this language model. Weak reference.
+ const TabContents* tab_contents_;
+
+ // Has the tab language been determined?
+ bool tab_language_determined_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutoFillLocaleModel);
+};
+
+#endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_LOCALE_MODEL_H_
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_locale_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698