OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/encoding_menu_controller.h" | 5 #include "chrome/browser/encoding_menu_controller.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/character_encoding.h" | 10 #include "chrome/browser/character_encoding.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 const int* EncodingMenuController::ValidGUIEncodingIDs() { | 70 const int* EncodingMenuController::ValidGUIEncodingIDs() { |
71 return kValidEncodingIds; | 71 return kValidEncodingIds; |
72 } | 72 } |
73 | 73 |
74 int EncodingMenuController::NumValidGUIEncodingIDs() { | 74 int EncodingMenuController::NumValidGUIEncodingIDs() { |
75 return arraysize(kValidEncodingIds); | 75 return arraysize(kValidEncodingIds); |
76 } | 76 } |
77 | 77 |
78 bool EncodingMenuController::IsItemChecked( | 78 bool EncodingMenuController::IsItemChecked( |
79 Profile* browser_profile, | 79 Profile* browser_profile, |
80 const std::wstring& current_tab_encoding, | 80 const std::string& current_tab_encoding, |
81 int item_id) { | 81 int item_id) { |
82 if (!DoesCommandBelongToEncodingMenu(item_id)) { | 82 if (!DoesCommandBelongToEncodingMenu(item_id)) { |
83 return false; | 83 return false; |
84 } | 84 } |
85 | 85 |
86 std::wstring encoding = current_tab_encoding; | 86 std::string encoding = current_tab_encoding; |
87 if (encoding.empty()) { | 87 if (encoding.empty()) { |
88 encoding = browser_profile->GetPrefs()->GetString(prefs::kDefaultCharset); | 88 encoding = WideToASCII(browser_profile->GetPrefs()->GetString( |
| 89 prefs::kDefaultCharset)); |
89 } | 90 } |
90 | 91 |
91 if (item_id == IDC_ENCODING_AUTO_DETECT) { | 92 if (item_id == IDC_ENCODING_AUTO_DETECT) { |
92 return browser_profile->GetPrefs()->GetBoolean( | 93 return browser_profile->GetPrefs()->GetBoolean( |
93 prefs::kWebKitUsesUniversalDetector); | 94 prefs::kWebKitUsesUniversalDetector); |
94 } | 95 } |
95 | 96 |
96 if (!encoding.empty()) { | 97 if (!encoding.empty()) { |
97 return encoding == | 98 return encoding == |
98 CharacterEncoding::GetCanonicalEncodingNameByCommandId(item_id); | 99 CharacterEncoding::GetCanonicalEncodingNameByCommandId(item_id); |
99 } | 100 } |
100 | 101 |
101 return false; | 102 return false; |
102 } | 103 } |
103 | 104 |
104 void EncodingMenuController::GetEncodingMenuItems(Profile* profile, | 105 void EncodingMenuController::GetEncodingMenuItems(Profile* profile, |
105 EncodingMenuItemList* menuItems) { | 106 EncodingMenuItemList* menuItems) { |
106 | 107 |
107 DCHECK(menuItems); | 108 DCHECK(menuItems); |
108 EncodingMenuItem separator(0, L""); | 109 EncodingMenuItem separator(0, string16()); |
109 | 110 |
110 menuItems->clear(); | 111 menuItems->clear(); |
111 menuItems->push_back( | 112 menuItems->push_back( |
112 EncodingMenuItem(IDC_ENCODING_AUTO_DETECT, | 113 EncodingMenuItem(IDC_ENCODING_AUTO_DETECT, |
113 l10n_util::GetString(IDS_ENCODING_AUTO_DETECT))); | 114 l10n_util::GetStringUTF16(IDS_ENCODING_AUTO_DETECT))); |
114 menuItems->push_back(separator); | 115 menuItems->push_back(separator); |
115 | 116 |
116 // Create current display encoding list. | 117 // Create current display encoding list. |
117 const std::vector<CharacterEncoding::EncodingInfo>* encodings; | 118 const std::vector<CharacterEncoding::EncodingInfo>* encodings; |
118 | 119 |
119 // Build the list of encoding ids : It is made of the | 120 // Build the list of encoding ids : It is made of the |
120 // locale-dependent short list, the cache of recently selected | 121 // locale-dependent short list, the cache of recently selected |
121 // encodings and other encodings. | 122 // encodings and other encodings. |
122 encodings = CharacterEncoding::GetCurrentDisplayEncodings( | 123 encodings = CharacterEncoding::GetCurrentDisplayEncodings( |
123 g_browser_process->GetApplicationLocale(), | 124 g_browser_process->GetApplicationLocale(), |
124 profile->GetPrefs()->GetString(prefs::kStaticEncodings), | 125 WideToASCII(profile->GetPrefs()->GetString(prefs::kStaticEncodings)), |
125 profile->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding)); | 126 WideToASCII(profile->GetPrefs()->GetString( |
| 127 prefs::kRecentlySelectedEncoding))); |
126 DCHECK(encodings); | 128 DCHECK(encodings); |
127 DCHECK(!encodings->empty()); | 129 DCHECK(!encodings->empty()); |
128 | 130 |
129 // Build up output list for menu. | 131 // Build up output list for menu. |
130 std::vector<CharacterEncoding::EncodingInfo>::const_iterator it; | 132 std::vector<CharacterEncoding::EncodingInfo>::const_iterator it; |
131 for (it = encodings->begin(); it != encodings->end(); ++it) { | 133 for (it = encodings->begin(); it != encodings->end(); ++it) { |
132 if (it->encoding_id) { | 134 if (it->encoding_id) { |
133 std::wstring encoding = it->encoding_display_name; | 135 std::wstring encoding = it->encoding_display_name; |
134 std::wstring bidi_safe_encoding; | 136 std::wstring bidi_safe_encoding; |
135 if (l10n_util::AdjustStringForLocaleDirection(encoding, | 137 if (l10n_util::AdjustStringForLocaleDirection(encoding, |
136 &bidi_safe_encoding)) | 138 &bidi_safe_encoding)) |
137 encoding.swap(bidi_safe_encoding); | 139 encoding.swap(bidi_safe_encoding); |
138 menuItems->push_back(EncodingMenuItem(it->encoding_id, encoding)); | 140 menuItems->push_back(EncodingMenuItem(it->encoding_id, |
| 141 WideToUTF16(encoding))); |
139 } else { | 142 } else { |
140 menuItems->push_back(separator); | 143 menuItems->push_back(separator); |
141 } | 144 } |
142 } | 145 } |
143 | |
144 } | 146 } |
OLD | NEW |