OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 if (alias_name == "US-ASCII") | 403 if (alias_name == "US-ASCII") |
404 return GetCanonicalEncodingNameByCommandId(IDC_ENCODING_ISO88591); | 404 return GetCanonicalEncodingNameByCommandId(IDC_ENCODING_ISO88591); |
405 return canonical_name; | 405 return canonical_name; |
406 } else { | 406 } else { |
407 return std::string(); | 407 return std::string(); |
408 } | 408 } |
409 } | 409 } |
410 | 410 |
411 // Static | 411 // Static |
412 // According to the behavior of user recently selected encoding short list in | 412 // According to the behavior of user recently selected encoding short list in |
413 // FireFox, we always put UTF-8 as toppest position, after then put user | 413 // Firefox, we always put UTF-8 as top position, after then put user |
414 // recently selected encodings, then put local dependent encoding items. | 414 // recent selected encodings, then put local dependent encoding items. |
415 // At last, we put all rest encoding items. | 415 // At last, we put all remaining encoding items. |
416 const std::vector<CharacterEncoding::EncodingInfo>* | 416 const std::vector<CharacterEncoding::EncodingInfo>* |
417 CharacterEncoding::GetCurrentDisplayEncodings( | 417 CharacterEncoding::GetCurrentDisplayEncodings( |
418 const std::string& locale, | 418 const std::string& locale, |
419 const std::string& locale_encodings, | 419 const std::string& locale_encodings, |
420 const std::string& recently_select_encodings) { | 420 const std::string& recently_select_encodings) { |
421 std::vector<int>* const locale_dependent_encoding_list = | 421 std::vector<int>* const locale_dependent_encoding_list = |
422 CanonicalEncodingMapSingleton()->locale_dependent_encoding_ids(); | 422 CanonicalEncodingMapSingleton()->locale_dependent_encoding_ids(); |
423 std::vector<CharacterEncoding::EncodingInfo>* const encoding_list = | 423 std::vector<CharacterEncoding::EncodingInfo>* const encoding_list = |
424 CanonicalEncodingMapSingleton()->current_display_encodings(); | 424 CanonicalEncodingMapSingleton()->current_display_encodings(); |
425 | 425 |
426 // Initialize locale dependent static encoding list. | 426 // Initialize locale dependent static encoding list. |
427 if (locale_dependent_encoding_list->empty() && !locale_encodings.empty()) | 427 if (locale_dependent_encoding_list->empty() && !locale_encodings.empty()) |
428 ParseEncodingListSeparatedWithComma(locale_encodings, | 428 ParseEncodingListSeparatedWithComma(locale_encodings, |
429 locale_dependent_encoding_list, | 429 locale_dependent_encoding_list, |
430 kUserSelectedEncodingsMaxLength); | 430 kUserSelectedEncodingsMaxLength); |
431 | 431 |
432 static std::string cached_user_selected_encodings; | 432 CR_DEFINE_STATIC_LOCAL(std::string, cached_user_selected_encodings, ()); |
433 // Build current display encoding list. | 433 // Build current display encoding list. |
434 if (encoding_list->empty() || | 434 if (encoding_list->empty() || |
435 cached_user_selected_encodings != recently_select_encodings) { | 435 cached_user_selected_encodings != recently_select_encodings) { |
436 // Update user recently selected encodings. | 436 // Update user recently selected encodings. |
437 cached_user_selected_encodings = recently_select_encodings; | 437 cached_user_selected_encodings = recently_select_encodings; |
438 // Clear old encoding list since user recently selected encodings changed. | 438 // Clear old encoding list since user recently selected encodings changed. |
439 encoding_list->clear(); | 439 encoding_list->clear(); |
440 // Always add UTF-8 to first encoding position. | 440 // Always add UTF-8 to first encoding position. |
441 encoding_list->push_back(EncodingInfo(IDC_ENCODING_UTF8)); | 441 encoding_list->push_back(EncodingInfo(IDC_ENCODING_UTF8)); |
442 std::set<int> inserted_encoding; | 442 std::set<int> inserted_encoding; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 // Insert new encoding to head of selected encoding list. | 537 // Insert new encoding to head of selected encoding list. |
538 *selected_encodings = encoding_name; | 538 *selected_encodings = encoding_name; |
539 // Generate the string for rest selected encoding list. | 539 // Generate the string for rest selected encoding list. |
540 for (std::vector<int>::const_iterator it = selected_encoding_list.begin(); | 540 for (std::vector<int>::const_iterator it = selected_encoding_list.begin(); |
541 it != selected_encoding_list.end(); ++it) { | 541 it != selected_encoding_list.end(); ++it) { |
542 selected_encodings->append(1, L','); | 542 selected_encodings->append(1, L','); |
543 selected_encodings->append(GetCanonicalEncodingNameByCommandId(*it)); | 543 selected_encodings->append(GetCanonicalEncodingNameByCommandId(*it)); |
544 } | 544 } |
545 return true; | 545 return true; |
546 } | 546 } |
OLD | NEW |