| 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 "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> |
| 10 |
| 9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 10 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/macros.h" | 14 #include "base/macros.h" |
| 13 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 14 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 15 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/values.h" | 20 #include "base/values.h" |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 break; | 643 break; |
| 642 } | 644 } |
| 643 | 645 |
| 644 DCHECK(learn_more_url.is_valid()); | 646 DCHECK(learn_more_url.is_valid()); |
| 645 // Add the language parameter to the URL. | 647 // Add the language parameter to the URL. |
| 646 std::string query = learn_more_url.query() + "&hl=" + locale; | 648 std::string query = learn_more_url.query() + "&hl=" + locale; |
| 647 GURL::Replacements repl; | 649 GURL::Replacements repl; |
| 648 repl.SetQueryStr(query); | 650 repl.SetQueryStr(query); |
| 649 GURL learn_more_url_with_locale = learn_more_url.ReplaceComponents(repl); | 651 GURL learn_more_url_with_locale = learn_more_url.ReplaceComponents(repl); |
| 650 | 652 |
| 651 base::DictionaryValue* suggestion_list_item = new base::DictionaryValue; | 653 std::unique_ptr<base::DictionaryValue> suggestion_list_item( |
| 654 new base::DictionaryValue); |
| 652 suggestion_list_item->SetString("summary", suggestion_string); | 655 suggestion_list_item->SetString("summary", suggestion_string); |
| 653 suggestion_list_item->SetString("learnMoreUrl", | 656 suggestion_list_item->SetString("learnMoreUrl", |
| 654 learn_more_url_with_locale.spec()); | 657 learn_more_url_with_locale.spec()); |
| 655 suggestions_summary_list->Append(suggestion_list_item); | 658 suggestions_summary_list->Append(std::move(suggestion_list_item)); |
| 656 } | 659 } |
| 657 | 660 |
| 658 // Check if a suggestion is in the bitmap of suggestions. | 661 // Check if a suggestion is in the bitmap of suggestions. |
| 659 bool IsSuggested(int suggestions, int suggestion) { | 662 bool IsSuggested(int suggestions, int suggestion) { |
| 660 return !!(suggestions & suggestion); | 663 return !!(suggestions & suggestion); |
| 661 } | 664 } |
| 662 | 665 |
| 663 // Check suggestion is the only item in the suggestions bitmap. | 666 // Check suggestion is the only item in the suggestions bitmap. |
| 664 bool IsOnlySuggestion(int suggestions, int suggestion) { | 667 bool IsOnlySuggestion(int suggestions, int suggestion) { |
| 665 return IsSuggested(suggestions, suggestion) && !(suggestions & ~suggestion); | 668 return IsSuggested(suggestions, suggestion) && !(suggestions & ~suggestion); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 // Detailed suggestion information. | 1043 // Detailed suggestion information. |
| 1041 error_strings->Set("suggestionsDetails", suggestions_details); | 1044 error_strings->Set("suggestionsDetails", suggestions_details); |
| 1042 } else { | 1045 } else { |
| 1043 suggestions_summary_list = params->override_suggestions.release(); | 1046 suggestions_summary_list = params->override_suggestions.release(); |
| 1044 use_default_suggestions = false; | 1047 use_default_suggestions = false; |
| 1045 AddGoogleCachedCopyButton(suggestions_summary_list, error_strings); | 1048 AddGoogleCachedCopyButton(suggestions_summary_list, error_strings); |
| 1046 } | 1049 } |
| 1047 error_strings->Set("suggestionsSummaryList", suggestions_summary_list); | 1050 error_strings->Set("suggestionsSummaryList", suggestions_summary_list); |
| 1048 | 1051 |
| 1049 if (params->search_url.is_valid()) { | 1052 if (params->search_url.is_valid()) { |
| 1050 base::DictionaryValue* search_suggestion = new base::DictionaryValue; | 1053 std::unique_ptr<base::DictionaryValue> search_suggestion( |
| 1054 new base::DictionaryValue); |
| 1051 search_suggestion->SetString("summary",l10n_util::GetStringUTF16( | 1055 search_suggestion->SetString("summary",l10n_util::GetStringUTF16( |
| 1052 IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH_SUMMARY)); | 1056 IDS_ERRORPAGES_SUGGESTION_GOOGLE_SEARCH_SUMMARY)); |
| 1053 search_suggestion->SetString("searchUrl", params->search_url.spec() + | 1057 search_suggestion->SetString("searchUrl", params->search_url.spec() + |
| 1054 params->search_terms); | 1058 params->search_terms); |
| 1055 search_suggestion->SetString("searchTerms", params->search_terms); | 1059 search_suggestion->SetString("searchTerms", params->search_terms); |
| 1056 search_suggestion->SetInteger("trackingId", | 1060 search_suggestion->SetInteger("trackingId", |
| 1057 params->search_tracking_id); | 1061 params->search_tracking_id); |
| 1058 suggestions_summary_list->Append(search_suggestion); | 1062 suggestions_summary_list->Append(std::move(search_suggestion)); |
| 1059 } | 1063 } |
| 1060 | 1064 |
| 1061 // Add the reload suggestion, if needed for pages that didn't come | 1065 // Add the reload suggestion, if needed for pages that didn't come |
| 1062 // from a post. | 1066 // from a post. |
| 1063 if (params->suggest_reload && !is_post) { | 1067 if (params->suggest_reload && !is_post) { |
| 1064 base::DictionaryValue* reload_button = new base::DictionaryValue; | 1068 base::DictionaryValue* reload_button = new base::DictionaryValue; |
| 1065 reload_button->SetString( | 1069 reload_button->SetString( |
| 1066 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); | 1070 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); |
| 1067 reload_button->SetString("reloadUrl", failed_url.spec()); | 1071 reload_button->SetString("reloadUrl", failed_url.spec()); |
| 1068 error_strings->Set("reloadButton", reload_button); | 1072 error_strings->Set("reloadButton", reload_button); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 | 1130 |
| 1127 bool LocalizedError::HasStrings(const std::string& error_domain, | 1131 bool LocalizedError::HasStrings(const std::string& error_domain, |
| 1128 int error_code) { | 1132 int error_code) { |
| 1129 // Whether or not the there are strings for an error does not depend on | 1133 // Whether or not the there are strings for an error does not depend on |
| 1130 // whether or not the page was be generated by a POST, so just claim it was | 1134 // whether or not the page was be generated by a POST, so just claim it was |
| 1131 // not. | 1135 // not. |
| 1132 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != nullptr; | 1136 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != nullptr; |
| 1133 } | 1137 } |
| 1134 | 1138 |
| 1135 } // namespace error_page | 1139 } // namespace error_page |
| OLD | NEW |