Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: components/error_page/common/localized_error.cc

Issue 2889163002: Remove raw DictionaryValue::Set in //components (Closed)
Patch Set: Nits Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/error_page/common/localized_error.h" 5 #include "components/error_page/common/localized_error.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 suggestion->GetString("urlCorrection", &cache_url); 499 suggestion->GetString("urlCorrection", &cache_url);
500 int cache_tracking_id = -1; 500 int cache_tracking_id = -1;
501 suggestion->GetInteger("trackingId", &cache_tracking_id); 501 suggestion->GetInteger("trackingId", &cache_tracking_id);
502 std::unique_ptr<base::DictionaryValue> cache_button( 502 std::unique_ptr<base::DictionaryValue> cache_button(
503 new base::DictionaryValue); 503 new base::DictionaryValue);
504 cache_button->SetString( 504 cache_button->SetString(
505 "msg", 505 "msg",
506 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY)); 506 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY));
507 cache_button->SetString("cacheUrl", cache_url); 507 cache_button->SetString("cacheUrl", cache_url);
508 cache_button->SetInteger("trackingId", cache_tracking_id); 508 cache_button->SetInteger("trackingId", cache_tracking_id);
509 error_strings->Set("cacheButton", cache_button.release()); 509 error_strings->Set("cacheButton", std::move(cache_button));
510 510
511 // Remove the item from suggestions dictionary so that it does not get 511 // Remove the item from suggestions dictionary so that it does not get
512 // displayed by the template in the details section. 512 // displayed by the template in the details section.
513 suggestions_summary_list->Remove(0, nullptr); 513 suggestions_summary_list->Remove(0, nullptr);
514 } 514 }
515 } 515 }
516 } 516 }
517 517
518 // Helper function that creates a single entry dictionary and adds it 518 // Helper function that creates a single entry dictionary and adds it
519 // to a ListValue, 519 // to a ListValue,
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 893
894 base::string16 host_name(url_formatter::IDNToUnicode(failed_url.host())); 894 base::string16 host_name(url_formatter::IDNToUnicode(failed_url.host()));
895 if (failed_url.SchemeIsHTTPOrHTTPS()) 895 if (failed_url.SchemeIsHTTPOrHTTPS())
896 error_strings->SetString("title", host_name); 896 error_strings->SetString("title", host_name);
897 else 897 else
898 error_strings->SetString("title", failed_url_string); 898 error_strings->SetString("title", failed_url_string);
899 899
900 std::string icon_class = GetIconClassForError(error_domain, error_code); 900 std::string icon_class = GetIconClassForError(error_domain, error_code);
901 error_strings->SetString("iconClass", icon_class); 901 error_strings->SetString("iconClass", icon_class);
902 902
903 base::DictionaryValue* heading = new base::DictionaryValue; 903 auto heading = base::MakeUnique<base::DictionaryValue>();
904 heading->SetString("msg", 904 heading->SetString("msg",
905 l10n_util::GetStringUTF16(options.heading_resource_id)); 905 l10n_util::GetStringUTF16(options.heading_resource_id));
906 heading->SetString("hostName", host_name); 906 heading->SetString("hostName", host_name);
907 error_strings->Set("heading", heading); 907 error_strings->Set("heading", std::move(heading));
908 908
909 base::DictionaryValue* summary = new base::DictionaryValue; 909 auto summary = base::MakeUnique<base::DictionaryValue>();
910 910
911 // Set summary message under the heading. 911 // Set summary message under the heading.
912 summary->SetString( 912 summary->SetString(
913 "msg", l10n_util::GetStringUTF16(options.summary_resource_id)); 913 "msg", l10n_util::GetStringUTF16(options.summary_resource_id));
914 914
915 // Add a DNS definition string. 915 // Add a DNS definition string.
916 summary->SetString("dnsDefinition", 916 summary->SetString("dnsDefinition",
917 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUMMARY_DNS_DEFINITION)); 917 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUMMARY_DNS_DEFINITION));
918 918
919 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 919 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
920 920
921 // Check if easter egg should be disabled. 921 // Check if easter egg should be disabled.
922 if (command_line->HasSwitch( 922 if (command_line->HasSwitch(
923 error_page::switches::kDisableDinosaurEasterEgg)) { 923 error_page::switches::kDisableDinosaurEasterEgg)) {
924 // The presence of this string disables the easter egg. Acts as a flag. 924 // The presence of this string disables the easter egg. Acts as a flag.
925 error_strings->SetString("disabledEasterEgg", 925 error_strings->SetString("disabledEasterEgg",
926 l10n_util::GetStringUTF16(IDS_ERRORPAGE_FUN_DISABLED)); 926 l10n_util::GetStringUTF16(IDS_ERRORPAGE_FUN_DISABLED));
927 } 927 }
928 928
929 summary->SetString("failedUrl", failed_url_string); 929 summary->SetString("failedUrl", failed_url_string);
930 summary->SetString("hostName", host_name); 930 summary->SetString("hostName", host_name);
931 931
932 error_strings->SetString( 932 error_strings->SetString(
933 "details", l10n_util::GetStringUTF16(IDS_ERRORPAGE_NET_BUTTON_DETAILS)); 933 "details", l10n_util::GetStringUTF16(IDS_ERRORPAGE_NET_BUTTON_DETAILS));
934 error_strings->SetString( 934 error_strings->SetString(
935 "hideDetails", l10n_util::GetStringUTF16( 935 "hideDetails", l10n_util::GetStringUTF16(
936 IDS_ERRORPAGE_NET_BUTTON_HIDE_DETAILS)); 936 IDS_ERRORPAGE_NET_BUTTON_HIDE_DETAILS));
937 error_strings->Set("summary", summary); 937 error_strings->Set("summary", std::move(summary));
938 938
939 base::string16 error_string; 939 base::string16 error_string;
940 if (error_domain == net::kErrorDomain) { 940 if (error_domain == net::kErrorDomain) {
941 // Non-internationalized error string, for debugging Chrome itself. 941 // Non-internationalized error string, for debugging Chrome itself.
942 error_string = base::ASCIIToUTF16(net::ErrorToShortString(error_code)); 942 error_string = base::ASCIIToUTF16(net::ErrorToShortString(error_code));
943 } else if (error_domain == error_page::kDnsProbeErrorDomain) { 943 } else if (error_domain == error_page::kDnsProbeErrorDomain) {
944 std::string ascii_error_string = 944 std::string ascii_error_string =
945 error_page::DnsProbeStatusToString(error_code); 945 error_page::DnsProbeStatusToString(error_code);
946 error_string = base::ASCIIToUTF16(ascii_error_string); 946 error_string = base::ASCIIToUTF16(ascii_error_string);
947 } else { 947 } else {
948 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain); 948 DCHECK_EQ(LocalizedError::kHttpErrorDomain, error_domain);
949 error_string = base::ASCIIToUTF16(HttpErrorCodeToString(error_code)); 949 error_string = base::ASCIIToUTF16(HttpErrorCodeToString(error_code));
950 } 950 }
951 error_strings->SetString("errorCode", error_string); 951 error_strings->SetString("errorCode", error_string);
952 952
953 // If no parameters were provided, use the defaults. 953 // If no parameters were provided, use the defaults.
954 if (!params) { 954 if (!params) {
955 params.reset(new error_page::ErrorPageParams()); 955 params.reset(new error_page::ErrorPageParams());
956 params->suggest_reload = !!(options.buttons && SHOW_BUTTON_RELOAD); 956 params->suggest_reload = !!(options.buttons && SHOW_BUTTON_RELOAD);
957 } 957 }
958 958
959 base::ListValue* suggestions_details = nullptr; 959 base::ListValue* suggestions_details = nullptr;
960 base::ListValue* suggestions_summary_list = nullptr; 960 base::ListValue* suggestions_summary_list = nullptr;
961 961
962 bool use_default_suggestions = true; 962 bool use_default_suggestions = true;
963 if (!params->override_suggestions) { 963 if (!params->override_suggestions) {
964 suggestions_details = new base::ListValue();
965 suggestions_summary_list = new base::ListValue();
966 // Detailed suggestion information. 964 // Detailed suggestion information.
967 error_strings->Set("suggestionsDetails", suggestions_details); 965 suggestions_details = error_strings->SetList(
966 "suggestionsDetails", base::MakeUnique<base::ListValue>());
967 suggestions_summary_list = error_strings->SetList(
968 "suggestionsSummaryList", base::MakeUnique<base::ListValue>());
968 } else { 969 } else {
969 suggestions_summary_list = params->override_suggestions.release(); 970 suggestions_summary_list = error_strings->SetList(
971 "suggestionsSummaryList", std::move(params->override_suggestions));
970 use_default_suggestions = false; 972 use_default_suggestions = false;
971 AddGoogleCachedCopyButton(suggestions_summary_list, error_strings); 973 AddGoogleCachedCopyButton(suggestions_summary_list, error_strings);
972 } 974 }
973 error_strings->Set("suggestionsSummaryList", suggestions_summary_list);
974 975
975 if (params->search_url.is_valid()) { 976 if (params->search_url.is_valid()) {
976 std::unique_ptr<base::DictionaryValue> search_suggestion( 977 std::unique_ptr<base::DictionaryValue> search_suggestion(
977 new base::DictionaryValue); 978 new base::DictionaryValue);
978 search_suggestion->SetString("summary",l10n_util::GetStringUTF16( 979 search_suggestion->SetString("summary",l10n_util::GetStringUTF16(
979 IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH_SUMMARY)); 980 IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH_SUMMARY));
980 search_suggestion->SetString("searchUrl", params->search_url.spec() + 981 search_suggestion->SetString("searchUrl", params->search_url.spec() +
981 params->search_terms); 982 params->search_terms);
982 search_suggestion->SetString("searchTerms", params->search_terms); 983 search_suggestion->SetString("searchTerms", params->search_terms);
983 search_suggestion->SetInteger("trackingId", 984 search_suggestion->SetInteger("trackingId",
984 params->search_tracking_id); 985 params->search_tracking_id);
985 suggestions_summary_list->Append(std::move(search_suggestion)); 986 suggestions_summary_list->Append(std::move(search_suggestion));
986 } 987 }
987 988
988 // Add the reload suggestion, if needed for pages that didn't come 989 // Add the reload suggestion, if needed for pages that didn't come
989 // from a post. 990 // from a post.
990 #if defined(OS_ANDROID) 991 #if defined(OS_ANDROID)
991 bool reload_visible = false; 992 bool reload_visible = false;
992 #endif // defined(OS_ANDROID) 993 #endif // defined(OS_ANDROID)
993 if (params->suggest_reload && !is_post) { 994 if (params->suggest_reload && !is_post) {
994 #if defined(OS_ANDROID) 995 #if defined(OS_ANDROID)
995 reload_visible = true; 996 reload_visible = true;
996 #endif // defined(OS_ANDROID) 997 #endif // defined(OS_ANDROID)
997 base::DictionaryValue* reload_button = new base::DictionaryValue; 998 auto reload_button = base::MakeUnique<base::DictionaryValue>();
998 reload_button->SetString( 999 reload_button->SetString(
999 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); 1000 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD));
1000 reload_button->SetString("reloadUrl", failed_url.spec()); 1001 reload_button->SetString("reloadUrl", failed_url.spec());
1001 error_strings->Set("reloadButton", reload_button);
1002 reload_button->SetInteger("reloadTrackingId", params->reload_tracking_id); 1002 reload_button->SetInteger("reloadTrackingId", params->reload_tracking_id);
1003 error_strings->Set("reloadButton", std::move(reload_button));
1003 } 1004 }
1004 1005
1005 // If not using the default suggestions, nothing else to do. 1006 // If not using the default suggestions, nothing else to do.
1006 if (!use_default_suggestions) 1007 if (!use_default_suggestions)
1007 return; 1008 return;
1008 1009
1009 #if defined(OS_CHROMEOS) 1010 #if defined(OS_CHROMEOS)
1010 // ChromeOS has its own diagnostics extension, which doesn't rely on a 1011 // ChromeOS has its own diagnostics extension, which doesn't rely on a
1011 // browser-initiated dialog. 1012 // browser-initiated dialog.
1012 can_show_network_diagnostics_dialog = true; 1013 can_show_network_diagnostics_dialog = true;
(...skipping 13 matching lines...) Expand all
1026 (show_saved_copy_value == 1027 (show_saved_copy_value ==
1027 error_page::switches::kEnableShowSavedCopyPrimary); 1028 error_page::switches::kEnableShowSavedCopyPrimary);
1028 bool show_saved_copy_secondary = 1029 bool show_saved_copy_secondary =
1029 (show_saved_copy_value == 1030 (show_saved_copy_value ==
1030 error_page::switches::kEnableShowSavedCopySecondary); 1031 error_page::switches::kEnableShowSavedCopySecondary);
1031 bool show_saved_copy_visible = 1032 bool show_saved_copy_visible =
1032 (stale_copy_in_cache && !is_post && 1033 (stale_copy_in_cache && !is_post &&
1033 (show_saved_copy_primary || show_saved_copy_secondary)); 1034 (show_saved_copy_primary || show_saved_copy_secondary));
1034 1035
1035 if (show_saved_copy_visible) { 1036 if (show_saved_copy_visible) {
1036 base::DictionaryValue* show_saved_copy_button = new base::DictionaryValue; 1037 auto show_saved_copy_button = base::MakeUnique<base::DictionaryValue>();
1037 show_saved_copy_button->SetString( 1038 show_saved_copy_button->SetString(
1038 "msg", l10n_util::GetStringUTF16( 1039 "msg", l10n_util::GetStringUTF16(
1039 IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY)); 1040 IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY));
1040 show_saved_copy_button->SetString( 1041 show_saved_copy_button->SetString(
1041 "title", 1042 "title",
1042 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY_HELP)); 1043 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_SHOW_SAVED_COPY_HELP));
1043 if (show_saved_copy_primary) 1044 if (show_saved_copy_primary)
1044 show_saved_copy_button->SetString("primary", "true"); 1045 show_saved_copy_button->SetString("primary", "true");
1045 error_strings->Set("showSavedCopyButton", show_saved_copy_button); 1046 error_strings->Set("showSavedCopyButton",
1047 std::move(show_saved_copy_button));
1046 } 1048 }
1047 1049
1048 #if defined(OS_ANDROID) 1050 #if defined(OS_ANDROID)
1049 if (!is_post && !reload_visible && !show_saved_copy_visible && 1051 if (!is_post && !reload_visible && !show_saved_copy_visible &&
1050 !is_incognito && failed_url.is_valid() && 1052 !is_incognito && failed_url.is_valid() &&
1051 failed_url.SchemeIsHTTPOrHTTPS() && 1053 failed_url.SchemeIsHTTPOrHTTPS() &&
1052 IsSuggested(options.suggestions, SUGGEST_OFFLINE_CHECKS) && 1054 IsSuggested(options.suggestions, SUGGEST_OFFLINE_CHECKS) &&
1053 offline_pages::IsOfflinePagesAsyncDownloadEnabled()) { 1055 offline_pages::IsOfflinePagesAsyncDownloadEnabled()) {
1054 std::unique_ptr<base::DictionaryValue> download_button = 1056 std::unique_ptr<base::DictionaryValue> download_button =
1055 base::MakeUnique<base::DictionaryValue>(); 1057 base::MakeUnique<base::DictionaryValue>();
(...skipping 21 matching lines...) Expand all
1077 1079
1078 bool LocalizedError::HasStrings(const std::string& error_domain, 1080 bool LocalizedError::HasStrings(const std::string& error_domain,
1079 int error_code) { 1081 int error_code) {
1080 // Whether or not the there are strings for an error does not depend on 1082 // Whether or not the there are strings for an error does not depend on
1081 // whether or not the page was be generated by a POST, so just claim it was 1083 // whether or not the page was be generated by a POST, so just claim it was
1082 // not. 1084 // not.
1083 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != nullptr; 1085 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != nullptr;
1084 } 1086 }
1085 1087
1086 } // namespace error_page 1088 } // namespace error_page
OLDNEW
« no previous file with comments | « components/domain_reliability/context.cc ('k') | components/error_page/renderer/net_error_helper_core.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698