| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/character_encoding.h" | 5 #include "chrome/browser/character_encoding.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 if (!id) | 245 if (!id) |
| 246 continue; | 246 continue; |
| 247 available_list->push_back(id); | 247 available_list->push_back(id); |
| 248 if (available_list->size() == maximum_size) | 248 if (available_list->size() == maximum_size) |
| 249 return; | 249 return; |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 | 252 |
| 253 string16 GetEncodingDisplayName(const std::string& encoding_name, | 253 string16 GetEncodingDisplayName(const std::string& encoding_name, |
| 254 int category_string_id) { | 254 int category_string_id) { |
| 255 string16 category_name = l10n_util::GetStringUTF16(category_string_id); | 255 base::string16 category_name = l10n_util::GetStringUTF16(category_string_id); |
| 256 if (category_string_id != IDS_ENCODING_KOREAN && | 256 if (category_string_id != IDS_ENCODING_KOREAN && |
| 257 category_string_id != IDS_ENCODING_THAI && | 257 category_string_id != IDS_ENCODING_THAI && |
| 258 category_string_id != IDS_ENCODING_TURKISH) { | 258 category_string_id != IDS_ENCODING_TURKISH) { |
| 259 const CanonicalNameDisplayNameMapType* map = | 259 const CanonicalNameDisplayNameMapType* map = |
| 260 CanonicalEncodingMapSingleton()->GetCanonicalNameDisplayNameMapData(); | 260 CanonicalEncodingMapSingleton()->GetCanonicalNameDisplayNameMapData(); |
| 261 DCHECK(map); | 261 DCHECK(map); |
| 262 | 262 |
| 263 CanonicalNameDisplayNameMapType::const_iterator found_name = | 263 CanonicalNameDisplayNameMapType::const_iterator found_name = |
| 264 map->find(encoding_name); | 264 map->find(encoding_name); |
| 265 DCHECK(found_name != map->end()); | 265 DCHECK(found_name != map->end()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 string16 CharacterEncoding::GetCanonicalEncodingDisplayNameByCommandId( | 327 string16 CharacterEncoding::GetCanonicalEncodingDisplayNameByCommandId( |
| 328 int id) { | 328 int id) { |
| 329 const IdToCanonicalEncodingNameMapType* map = | 329 const IdToCanonicalEncodingNameMapType* map = |
| 330 CanonicalEncodingMapSingleton()->GetIdToCanonicalEncodingNameMapData(); | 330 CanonicalEncodingMapSingleton()->GetIdToCanonicalEncodingNameMapData(); |
| 331 DCHECK(map); | 331 DCHECK(map); |
| 332 | 332 |
| 333 IdToCanonicalEncodingNameMapType::const_iterator found_name = map->find(id); | 333 IdToCanonicalEncodingNameMapType::const_iterator found_name = map->find(id); |
| 334 if (found_name != map->end()) | 334 if (found_name != map->end()) |
| 335 return GetEncodingDisplayName(found_name->second.first, | 335 return GetEncodingDisplayName(found_name->second.first, |
| 336 found_name->second.second); | 336 found_name->second.second); |
| 337 return string16(); | 337 return base::string16(); |
| 338 } | 338 } |
| 339 | 339 |
| 340 // Static. | 340 // Static. |
| 341 // Return count number of all supported canonical encoding. | 341 // Return count number of all supported canonical encoding. |
| 342 int CharacterEncoding::GetSupportCanonicalEncodingCount() { | 342 int CharacterEncoding::GetSupportCanonicalEncodingCount() { |
| 343 return kCanonicalEncodingNamesLength; | 343 return kCanonicalEncodingNamesLength; |
| 344 } | 344 } |
| 345 | 345 |
| 346 // Static. | 346 // Static. |
| 347 std::string CharacterEncoding::GetCanonicalEncodingNameByIndex(int index) { | 347 std::string CharacterEncoding::GetCanonicalEncodingNameByIndex(int index) { |
| 348 if (index < kCanonicalEncodingNamesLength) | 348 if (index < kCanonicalEncodingNamesLength) |
| 349 return kCanonicalEncodingNames[index].name; | 349 return kCanonicalEncodingNames[index].name; |
| 350 return std::string(); | 350 return std::string(); |
| 351 } | 351 } |
| 352 | 352 |
| 353 // Static. | 353 // Static. |
| 354 string16 CharacterEncoding::GetCanonicalEncodingDisplayNameByIndex( | 354 string16 CharacterEncoding::GetCanonicalEncodingDisplayNameByIndex( |
| 355 int index) { | 355 int index) { |
| 356 if (index < kCanonicalEncodingNamesLength) | 356 if (index < kCanonicalEncodingNamesLength) |
| 357 return GetEncodingDisplayName(kCanonicalEncodingNames[index].name, | 357 return GetEncodingDisplayName(kCanonicalEncodingNames[index].name, |
| 358 kCanonicalEncodingNames[index].category_string_id); | 358 kCanonicalEncodingNames[index].category_string_id); |
| 359 return string16(); | 359 return base::string16(); |
| 360 } | 360 } |
| 361 | 361 |
| 362 // Static. | 362 // Static. |
| 363 int CharacterEncoding::GetEncodingCommandIdByIndex(int index) { | 363 int CharacterEncoding::GetEncodingCommandIdByIndex(int index) { |
| 364 if (index < kCanonicalEncodingNamesLength) | 364 if (index < kCanonicalEncodingNamesLength) |
| 365 return kCanonicalEncodingNames[index].resource_id; | 365 return kCanonicalEncodingNames[index].resource_id; |
| 366 return 0; | 366 return 0; |
| 367 } | 367 } |
| 368 | 368 |
| 369 // Static. | 369 // Static. |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 // Insert new encoding to head of selected encoding list. | 533 // Insert new encoding to head of selected encoding list. |
| 534 *selected_encodings = encoding_name; | 534 *selected_encodings = encoding_name; |
| 535 // Generate the string for rest selected encoding list. | 535 // Generate the string for rest selected encoding list. |
| 536 for (std::vector<int>::const_iterator it = selected_encoding_list.begin(); | 536 for (std::vector<int>::const_iterator it = selected_encoding_list.begin(); |
| 537 it != selected_encoding_list.end(); ++it) { | 537 it != selected_encoding_list.end(); ++it) { |
| 538 selected_encodings->append(1, L','); | 538 selected_encodings->append(1, L','); |
| 539 selected_encodings->append(GetCanonicalEncodingNameByCommandId(*it)); | 539 selected_encodings->append(GetCanonicalEncodingNameByCommandId(*it)); |
| 540 } | 540 } |
| 541 return true; | 541 return true; |
| 542 } | 542 } |
| OLD | NEW |