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