• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2006-2008 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_CHARACTER_ENCODING_H_
6 #define CHROME_BROWSER_CHARACTER_ENCODING_H_
7 #pragma once
8 
9 #include <string>
10 #include <vector>
11 
12 #include "base/basictypes.h"
13 #include "base/string16.h"
14 
15 class CharacterEncoding {
16  public:
17   // Enumeration of the types of Browser encoding name we
18   // currently support. This is defined outside of Browser
19   // to avoid cyclical dependencies.
20 
21   // Structure to save encoding information.
22   struct EncodingInfo {
23     explicit EncodingInfo(int id);
24     // Gets string key of EncodingInfo. With this method, we can use
25     // l10n_util::SortVectorWithStringKey to sort the encoding menu items
26     // by current locale character sequence. We need to keep the order within
27     // encoding category name, that's why we use category name as key.
GetStringKeyEncodingInfo28     const string16& GetStringKey() const { return encoding_category_name; }
29 
30     // Encoding command id.
31     int encoding_id;
32     // Encoding display name.
33     string16 encoding_display_name;
34     // Encoding category name.
35     string16 encoding_category_name;
36   };
37 
38   // Return canonical encoding name according to the command ID.
39   // THIS FUNCTION IS NOT THREADSAFE. You must run this function
40   // only in UI thread.
41   static std::string GetCanonicalEncodingNameByCommandId(int id);
42 
43   // Return display name of canonical encoding according to the command
44   // ID. THIS FUNCTION IS NOT THREADSAFE. You must run this function
45   // only in UI thread.
46   static string16 GetCanonicalEncodingDisplayNameByCommandId(int id);
47 
48   // Return count number of all supported canonical encoding.
49   static int GetSupportCanonicalEncodingCount();
50 
51   // Return canonical encoding name according to the index, which starts
52   // from zero to GetSupportCanonicalEncodingCount() - 1. THIS FUNCTION
53   // IS NOT THREADSAFE. You must run this function only in UI thread.
54   static std::string GetCanonicalEncodingNameByIndex(int index);
55 
56   // Return display name of canonical encoding according to the index,
57   // which starts from zero to GetSupportCanonicalEncodingCount() - 1.
58   // THIS FUNCTION IS NOT THREADSAFE. You must run this function
59   // only in UI thread.
60   static string16 GetCanonicalEncodingDisplayNameByIndex(int index);
61 
62   // Return encoding command id according to the index, which starts from
63   // zero to GetSupportCanonicalEncodingCount() - 1. Otherwise returns 0.
64   static int GetEncodingCommandIdByIndex(int index);
65 
66   // Return canonical encoding name according to the encoding alias name. THIS
67   // FUNCTION IS NOT THREADSAFE. You must run this function only in UI thread.
68   static std::string GetCanonicalEncodingNameByAliasName(
69       const std::string& alias_name);
70 
71   // Returns the pointer of a vector of EncodingInfos corresponding to
72   // encodings to display in the encoding menu. The locale-dependent static
73   // encodings come at the top of the list and recently selected encodings
74   // come next. Finally, the rest of encodings are listed.
75   // The vector will be created and destroyed by CharacterEncoding.
76   // The returned std::vector is maintained by this class. The parameter
77   // |locale| points to the current application (UI) locale. The parameter
78   // |locale_encodings| is string of static encodings list which is from the
79   // corresponding string resource that is stored in the resource bundle.
80   // The parameter |recently_select_encodings| is string of encoding list which
81   // is from user recently selected. THIS FUNCTION IS NOT THREADSAFE. You must
82   // run this function only in UI thread.
83   static const std::vector<EncodingInfo>* GetCurrentDisplayEncodings(
84       const std::string& locale,
85       const std::string& locale_encodings,
86       const std::string& recently_select_encodings);
87 
88   // This function is for updating |original_selected_encoding_list| with a
89   // |new_selected_encoding_id|. If the encoding is already in the original
90   // list, then returns false. Otherwise |selected_encoding_list| will return a
91   // new string for user selected encoding short list and function returns true.
92   static bool UpdateRecentlySelectedEncoding(
93       const std::string& original_selected_encodings,
94       int new_selected_encoding_id,
95       std::string* selected_encodings);
96 
97   // Get encoding command id according to input encoding name. If the name is
98   // valid, return corresponding encoding command id. Otherwise return 0;
99   static int GetCommandIdByCanonicalEncodingName(
100       const std::string& encoding_name);
101 
102  private:
103   // Disallow instantiating it since this class only contains static methods.
104   DISALLOW_IMPLICIT_CONSTRUCTORS(CharacterEncoding);
105 };
106 
107 #endif  // CHROME_BROWSER_CHARACTER_ENCODING_H_
108