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/common/localized_error.h" | 5 #include "chrome/common/localized_error.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 arraysize(dns_probe_error_options), | 470 arraysize(dns_probe_error_options), |
471 error_code); | 471 error_code); |
472 DCHECK(map); | 472 DCHECK(map); |
473 return map; | 473 return map; |
474 } else { | 474 } else { |
475 NOTREACHED(); | 475 NOTREACHED(); |
476 return NULL; | 476 return NULL; |
477 } | 477 } |
478 } | 478 } |
479 | 479 |
480 bool LocaleIsRTL() { | |
481 return base::i18n::IsRTL(); | |
482 } | |
483 | |
484 // Returns a dictionary containing the strings for the settings menu under the | 480 // Returns a dictionary containing the strings for the settings menu under the |
485 // wrench, and the advanced settings button. | 481 // wrench, and the advanced settings button. |
486 base::DictionaryValue* GetStandardMenuItemsText() { | 482 base::DictionaryValue* GetStandardMenuItemsText() { |
487 base::DictionaryValue* standard_menu_items_text = new base::DictionaryValue(); | 483 base::DictionaryValue* standard_menu_items_text = new base::DictionaryValue(); |
488 standard_menu_items_text->SetString("settingsTitle", | 484 standard_menu_items_text->SetString("settingsTitle", |
489 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); | 485 l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE)); |
490 standard_menu_items_text->SetString("advancedTitle", | 486 standard_menu_items_text->SetString("advancedTitle", |
491 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS)); | 487 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS)); |
492 return standard_menu_items_text; | 488 return standard_menu_items_text; |
493 } | 489 } |
(...skipping 16 matching lines...) Expand all Loading... |
510 | 506 |
511 void LocalizedError::GetStrings(int error_code, | 507 void LocalizedError::GetStrings(int error_code, |
512 const std::string& error_domain, | 508 const std::string& error_domain, |
513 const GURL& failed_url, | 509 const GURL& failed_url, |
514 bool is_post, | 510 bool is_post, |
515 bool show_stale_load_button, | 511 bool show_stale_load_button, |
516 const std::string& locale, | 512 const std::string& locale, |
517 const std::string& accept_languages, | 513 const std::string& accept_languages, |
518 scoped_ptr<error_page::ErrorPageParams> params, | 514 scoped_ptr<error_page::ErrorPageParams> params, |
519 base::DictionaryValue* error_strings) { | 515 base::DictionaryValue* error_strings) { |
520 bool rtl = LocaleIsRTL(); | 516 webui::SetLoadTimeDataDefaults(locale, error_strings); |
521 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); | |
522 webui::SetFontAndTextDirection(error_strings); | |
523 | 517 |
524 // Grab the strings and settings that depend on the error type. Init | 518 // Grab the strings and settings that depend on the error type. Init |
525 // options with default values. | 519 // options with default values. |
526 LocalizedErrorMap options = { | 520 LocalizedErrorMap options = { |
527 0, | 521 0, |
528 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, | 522 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
529 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, | 523 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
530 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE, | 524 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE, |
531 kErrorPagesNoDetails, | 525 kErrorPagesNoDetails, |
532 SUGGEST_NONE, | 526 SUGGEST_NONE, |
(...skipping 15 matching lines...) Expand all Loading... |
548 options.heading_resource_id = IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED; | 542 options.heading_resource_id = IDS_ERRORPAGES_HEADING_FILE_ACCESS_DENIED; |
549 options.summary_resource_id = IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED; | 543 options.summary_resource_id = IDS_ERRORPAGES_SUMMARY_FILE_ACCESS_DENIED; |
550 options.details_resource_id = IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED; | 544 options.details_resource_id = IDS_ERRORPAGES_DETAILS_FILE_ACCESS_DENIED; |
551 options.suggestions = SUGGEST_NONE; | 545 options.suggestions = SUGGEST_NONE; |
552 } | 546 } |
553 | 547 |
554 base::string16 failed_url_string(net::FormatUrl( | 548 base::string16 failed_url_string(net::FormatUrl( |
555 failed_url, accept_languages, net::kFormatUrlOmitNothing, | 549 failed_url, accept_languages, net::kFormatUrlOmitNothing, |
556 net::UnescapeRule::NORMAL, NULL, NULL, NULL)); | 550 net::UnescapeRule::NORMAL, NULL, NULL, NULL)); |
557 // URLs are always LTR. | 551 // URLs are always LTR. |
558 if (rtl) | 552 if (base::i18n::IsRTL()) |
559 base::i18n::WrapStringWithLTRFormatting(&failed_url_string); | 553 base::i18n::WrapStringWithLTRFormatting(&failed_url_string); |
560 error_strings->SetString("title", | 554 error_strings->SetString("title", |
561 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url_string)); | 555 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url_string)); |
562 error_strings->SetString("heading", | 556 error_strings->SetString("heading", |
563 l10n_util::GetStringUTF16(options.heading_resource_id)); | 557 l10n_util::GetStringUTF16(options.heading_resource_id)); |
564 | 558 |
565 std::string icon_class = GetIconClassForError(error_domain, error_code); | 559 std::string icon_class = GetIconClassForError(error_domain, error_code); |
566 error_strings->SetString("iconClass", icon_class); | 560 error_strings->SetString("iconClass", icon_class); |
567 | 561 |
568 base::DictionaryValue* summary = new base::DictionaryValue; | 562 base::DictionaryValue* summary = new base::DictionaryValue; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 // Whether or not the there are strings for an error does not depend on | 843 // Whether or not the there are strings for an error does not depend on |
850 // whether or not the page was be generated by a POST, so just claim it was | 844 // whether or not the page was be generated by a POST, so just claim it was |
851 // not. | 845 // not. |
852 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL; | 846 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL; |
853 } | 847 } |
854 | 848 |
855 #if defined(ENABLE_EXTENSIONS) | 849 #if defined(ENABLE_EXTENSIONS) |
856 void LocalizedError::GetAppErrorStrings( | 850 void LocalizedError::GetAppErrorStrings( |
857 const GURL& display_url, | 851 const GURL& display_url, |
858 const extensions::Extension* app, | 852 const extensions::Extension* app, |
| 853 const std::string& locale, |
859 base::DictionaryValue* error_strings) { | 854 base::DictionaryValue* error_strings) { |
860 DCHECK(app); | 855 DCHECK(app); |
861 | 856 |
862 bool rtl = LocaleIsRTL(); | 857 webui::SetLoadTimeDataDefaults(locale, error_strings); |
863 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); | |
864 | 858 |
865 base::string16 failed_url(base::ASCIIToUTF16(display_url.spec())); | 859 base::string16 failed_url(base::ASCIIToUTF16(display_url.spec())); |
866 // URLs are always LTR. | 860 // URLs are always LTR. |
867 if (rtl) | 861 if (base::i18n::IsRTL()) |
868 base::i18n::WrapStringWithLTRFormatting(&failed_url); | 862 base::i18n::WrapStringWithLTRFormatting(&failed_url); |
869 error_strings->SetString( | 863 error_strings->SetString( |
870 "url", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, | 864 "url", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
871 failed_url.c_str())); | 865 failed_url.c_str())); |
872 | 866 |
873 error_strings->SetString("title", app->name()); | 867 error_strings->SetString("title", app->name()); |
874 error_strings->SetString( | 868 error_strings->SetString( |
875 "icon", | 869 "icon", |
876 extensions::IconsInfo::GetIconURL( | 870 extensions::IconsInfo::GetIconURL( |
877 app, | 871 app, |
878 extension_misc::EXTENSION_ICON_GIGANTOR, | 872 extension_misc::EXTENSION_ICON_GIGANTOR, |
879 ExtensionIconSet::MATCH_SMALLER).spec()); | 873 ExtensionIconSet::MATCH_SMALLER).spec()); |
880 error_strings->SetString("name", app->name()); | 874 error_strings->SetString("name", app->name()); |
881 error_strings->SetString( | 875 error_strings->SetString( |
882 "msg", | 876 "msg", |
883 l10n_util::GetStringUTF16(IDS_ERRORPAGES_APP_WARNING)); | 877 l10n_util::GetStringUTF16(IDS_ERRORPAGES_APP_WARNING)); |
884 | 878 |
885 #if defined(OS_CHROMEOS) | 879 #if defined(OS_CHROMEOS) |
886 GURL learn_more_url(kAppWarningLearnMoreUrl); | 880 GURL learn_more_url(kAppWarningLearnMoreUrl); |
887 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); | 881 base::DictionaryValue* suggest_learn_more = new base::DictionaryValue(); |
888 suggest_learn_more->SetString("msg", | 882 suggest_learn_more->SetString("msg", |
889 l10n_util::GetStringUTF16( | 883 l10n_util::GetStringUTF16( |
890 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 884 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
891 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 885 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
892 error_strings->Set("suggestionsLearnMore", suggest_learn_more); | 886 error_strings->Set("suggestionsLearnMore", suggest_learn_more); |
893 #endif // defined(OS_CHROMEOS) | 887 #endif // defined(OS_CHROMEOS) |
894 } | 888 } |
895 #endif | 889 #endif |
OLD | NEW |