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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_locale_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_LOCALE_MODEL_H_
6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_LOCALE_MODEL_H_
7 #pragma once
8
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/hash_tables.h"
14
15 class FormStructure;
16 class GURL;
17 class TabContents;
18
19 // This class is responsible for collating and making sense of the various
20 // locale indicators for auto-fillable forms.
21 class AutoFillLocaleModel {
22 public:
23 explicit AutoFillLocaleModel(const TabContents* tab_contents);
24 virtual ~AutoFillLocaleModel();
25
26 // Updates the |form|'s locale using heuristics that combine three signals:
27 // * the author-specified locale, which we get from the DOM;
28 // * the automatically detected language; and
29 // * the page url's registry (e.g. ".co.uk").
30 void UpdateLocale(FormStructure* form) const;
31
32 // Returns whether |language_tag| is a known language subtag.
33 static bool IsValidLanguageTag(const std::string& language_tag);
34
35 // Returns whether |region_tag| is a known region subtag.
36 static bool IsValidRegionTag(const std::string& region_tag);
37
38 bool tab_language_determined() const {
39 return tab_language_determined_;
40 }
41 void set_tab_language_determined(bool language_determined) {
42 tab_language_determined_ = language_determined;
43 }
44
45 protected:
46 // Region and language data for known domain registries (roughly, top level
47 // domains).
48 struct AutoFillRegistryInfo {
49 std::string region;
50 std::vector<std::string> languages;
51 };
52 typedef base::hash_map<std::string, AutoFillRegistryInfo> AutoFillRegistryMap;
53
54 // For tests.
55 const AutoFillRegistryMap* registries() { return &registries_; }
56
57 private:
58 std::string RegionFromRegistry(const std::string& registry,
59 std::string* guessed_language) const;
60
61 // Hash table mapping registries to their language and region data.
62 AutoFillRegistryMap registries_;
63
64 // The |TabContents| hosting this language model. Weak reference.
65 const TabContents* tab_contents_;
66
67 // Has the tab language been determined?
68 bool tab_language_determined_;
69
70 DISALLOW_COPY_AND_ASSIGN(AutoFillLocaleModel);
71 };
72
73 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_LOCALE_MODEL_H_
OLDNEW
« 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