| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/renderer/localized_error.h" | 5 #include "chrome/renderer/localized_error.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string16.h" |
| 10 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 13 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 14 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" |
| 17 #include "webkit/glue/webkit_glue.h" | 18 #include "webkit/glue/webkit_glue.h" |
| 18 | 19 |
| 19 using WebKit::WebURLError; | 20 using WebKit::WebURLError; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 #else | 121 #else |
| 121 return base::i18n::IsRTL(); | 122 return base::i18n::IsRTL(); |
| 122 #endif | 123 #endif |
| 123 } | 124 } |
| 124 | 125 |
| 125 } // namespace | 126 } // namespace |
| 126 | 127 |
| 127 void GetLocalizedErrorValues(const WebURLError& error, | 128 void GetLocalizedErrorValues(const WebURLError& error, |
| 128 DictionaryValue* error_strings) { | 129 DictionaryValue* error_strings) { |
| 129 bool rtl = LocaleIsRTL(); | 130 bool rtl = LocaleIsRTL(); |
| 130 error_strings->SetString(L"textdirection", rtl ? L"rtl" : L"ltr"); | 131 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); |
| 131 | 132 |
| 132 // Grab strings that are applicable to all error pages | 133 // Grab strings that are applicable to all error pages |
| 133 error_strings->SetString(L"detailsLink", | 134 error_strings->SetStringFromUTF16("detailsLink", |
| 134 l10n_util::GetString(IDS_ERRORPAGES_DETAILS_LINK)); | 135 l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_LINK)); |
| 135 error_strings->SetString(L"detailsHeading", | 136 error_strings->SetStringFromUTF16("detailsHeading", |
| 136 l10n_util::GetString(IDS_ERRORPAGES_DETAILS_HEADING)); | 137 l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_HEADING)); |
| 137 | 138 |
| 138 // Grab the strings and settings that depend on the error type. Init | 139 // Grab the strings and settings that depend on the error type. Init |
| 139 // options with default values. | 140 // options with default values. |
| 140 WebErrorNetErrorMap options = { | 141 WebErrorNetErrorMap options = { |
| 141 0, | 142 0, |
| 142 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, | 143 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 143 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, | 144 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 144 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE, | 145 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE, |
| 145 IDS_ERRORPAGES_DETAILS_UNKNOWN, | 146 IDS_ERRORPAGES_DETAILS_UNKNOWN, |
| 146 SUGGEST_NONE, | 147 SUGGEST_NONE, |
| 147 }; | 148 }; |
| 148 int error_code = error.reason; | 149 int error_code = error.reason; |
| 149 for (size_t i = 0; i < arraysize(net_error_options); ++i) { | 150 for (size_t i = 0; i < arraysize(net_error_options); ++i) { |
| 150 if (net_error_options[i].error_code == error_code) { | 151 if (net_error_options[i].error_code == error_code) { |
| 151 memcpy(&options, &net_error_options[i], sizeof(WebErrorNetErrorMap)); | 152 memcpy(&options, &net_error_options[i], sizeof(WebErrorNetErrorMap)); |
| 152 break; | 153 break; |
| 153 } | 154 } |
| 154 } | 155 } |
| 155 | 156 |
| 156 std::wstring suggestions_heading; | 157 string16 suggestions_heading; |
| 157 if (options.suggestions != SUGGEST_NONE) { | 158 if (options.suggestions != SUGGEST_NONE) { |
| 158 suggestions_heading = | 159 suggestions_heading = |
| 159 l10n_util::GetString(IDS_ERRORPAGES_SUGGESTION_HEADING); | 160 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_HEADING); |
| 160 } | 161 } |
| 161 error_strings->SetString(L"suggestionsHeading", suggestions_heading); | 162 error_strings->SetStringFromUTF16("suggestionsHeading", suggestions_heading); |
| 162 | 163 |
| 163 std::wstring failed_url( | 164 string16 failed_url(ASCIIToUTF16(error.unreachableURL.spec())); |
| 164 ASCIIToWide(std::string(error.unreachableURL.spec()))); | |
| 165 // URLs are always LTR. | 165 // URLs are always LTR. |
| 166 if (rtl) | 166 if (rtl) |
| 167 base::i18n::WrapStringWithLTRFormatting(&failed_url); | 167 base::i18n::WrapStringWithLTRFormatting(&failed_url); |
| 168 error_strings->SetString(L"title", | 168 error_strings->SetStringFromUTF16("title", |
| 169 l10n_util::GetStringF(options.title_resource_id, | 169 l10n_util::GetStringFUTF16(options.title_resource_id, failed_url)); |
| 170 failed_url)); | 170 error_strings->SetStringFromUTF16("heading", |
| 171 error_strings->SetString(L"heading", | 171 l10n_util::GetStringUTF16(options.heading_resource_id)); |
| 172 l10n_util::GetString(options.heading_resource_id)); | |
| 173 | 172 |
| 174 DictionaryValue* summary = new DictionaryValue; | 173 DictionaryValue* summary = new DictionaryValue; |
| 175 summary->SetString(L"msg", | 174 summary->SetStringFromUTF16("msg", |
| 176 l10n_util::GetString(options.summary_resource_id)); | 175 l10n_util::GetStringUTF16(options.summary_resource_id)); |
| 177 // TODO(tc): we want the unicode url here since it's being displayed | 176 // TODO(tc): we want the unicode url here since it's being displayed |
| 178 summary->SetString(L"failedUrl", failed_url); | 177 summary->SetStringFromUTF16("failedUrl", failed_url); |
| 179 error_strings->Set(L"summary", summary); | 178 error_strings->Set("summary", summary); |
| 180 | 179 |
| 181 // Error codes are expected to be negative | 180 // Error codes are expected to be negative |
| 182 DCHECK(error_code < 0); | 181 DCHECK(error_code < 0); |
| 183 std::wstring details = l10n_util::GetString(options.details_resource_id); | 182 string16 details = l10n_util::GetStringUTF16(options.details_resource_id); |
| 184 error_strings->SetString(L"details", | 183 error_strings->SetStringFromUTF16("details", |
| 185 l10n_util::GetStringF(IDS_ERRORPAGES_DETAILS_TEMPLATE, | 184 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_DETAILS_TEMPLATE, |
| 186 ASCIIToWide(base::IntToString(-error_code)), | 185 base::IntToString16(-error_code), |
| 187 ASCIIToWide(net::ErrorToString(error_code)), | 186 ASCIIToUTF16(net::ErrorToString(error_code)), |
| 188 details)); | 187 details)); |
| 189 | 188 |
| 190 if (options.suggestions & SUGGEST_RELOAD) { | 189 if (options.suggestions & SUGGEST_RELOAD) { |
| 191 DictionaryValue* suggest_reload = new DictionaryValue; | 190 DictionaryValue* suggest_reload = new DictionaryValue; |
| 192 suggest_reload->SetString(L"msg", | 191 suggest_reload->SetStringFromUTF16("msg", |
| 193 l10n_util::GetString(IDS_ERRORPAGES_SUGGESTION_RELOAD)); | 192 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_RELOAD)); |
| 194 suggest_reload->SetString(L"reloadUrl", failed_url); | 193 suggest_reload->SetStringFromUTF16("reloadUrl", failed_url); |
| 195 error_strings->Set(L"suggestionsReload", suggest_reload); | 194 error_strings->Set("suggestionsReload", suggest_reload); |
| 196 } | 195 } |
| 197 | 196 |
| 198 if (options.suggestions & SUGGEST_HOSTNAME) { | 197 if (options.suggestions & SUGGEST_HOSTNAME) { |
| 199 // Only show the "Go to hostname" suggestion if the failed_url has a path. | 198 // Only show the "Go to hostname" suggestion if the failed_url has a path. |
| 200 const GURL& failed_url = error.unreachableURL; | 199 const GURL& failed_url = error.unreachableURL; |
| 201 if (std::string() == failed_url.path()) { | 200 if (std::string() == failed_url.path()) { |
| 202 DictionaryValue* suggest_home_page = new DictionaryValue; | 201 DictionaryValue* suggest_home_page = new DictionaryValue; |
| 203 suggest_home_page->SetString(L"suggestionsHomepageMsg", | 202 suggest_home_page->SetStringFromUTF16("suggestionsHomepageMsg", |
| 204 l10n_util::GetString(IDS_ERRORPAGES_SUGGESTION_HOMEPAGE)); | 203 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_HOMEPAGE)); |
| 205 std::wstring homepage(ASCIIToWide(failed_url.GetWithEmptyPath().spec())); | 204 string16 homepage(ASCIIToUTF16(failed_url.GetWithEmptyPath().spec())); |
| 206 // URLs are always LTR. | 205 // URLs are always LTR. |
| 207 if (rtl) | 206 if (rtl) |
| 208 base::i18n::WrapStringWithLTRFormatting(&homepage); | 207 base::i18n::WrapStringWithLTRFormatting(&homepage); |
| 209 suggest_home_page->SetString(L"homePage", homepage); | 208 suggest_home_page->SetStringFromUTF16("homePage", homepage); |
| 210 // TODO(tc): we actually want the unicode hostname | 209 // TODO(tc): we actually want the unicode hostname |
| 211 suggest_home_page->SetString(L"hostName", | 210 suggest_home_page->SetString("hostName", failed_url.host()); |
| 212 ASCIIToWide(failed_url.host())); | 211 error_strings->Set("suggestionsHomepage", suggest_home_page); |
| 213 error_strings->Set(L"suggestionsHomepage", suggest_home_page); | |
| 214 } | 212 } |
| 215 } | 213 } |
| 216 | 214 |
| 217 if (options.suggestions & SUGGEST_LEARNMORE) { | 215 if (options.suggestions & SUGGEST_LEARNMORE) { |
| 218 GURL learn_more_url; | 216 GURL learn_more_url; |
| 219 switch (options.error_code) { | 217 switch (options.error_code) { |
| 220 case net::ERR_TOO_MANY_REDIRECTS: | 218 case net::ERR_TOO_MANY_REDIRECTS: |
| 221 learn_more_url = GURL(kRedirectLoopLearnMoreUrl); | 219 learn_more_url = GURL(kRedirectLoopLearnMoreUrl); |
| 222 break; | 220 break; |
| 223 default: | 221 default: |
| 224 break; | 222 break; |
| 225 } | 223 } |
| 226 | 224 |
| 227 if (learn_more_url.is_valid()) { | 225 if (learn_more_url.is_valid()) { |
| 228 // Add the language parameter to the URL. | 226 // Add the language parameter to the URL. |
| 229 std::string query = learn_more_url.query() + "&hl=" + | 227 std::string query = learn_more_url.query() + "&hl=" + |
| 230 WideToASCII(webkit_glue::GetWebKitLocale()); | 228 WideToASCII(webkit_glue::GetWebKitLocale()); |
| 231 GURL::Replacements repl; | 229 GURL::Replacements repl; |
| 232 repl.SetQueryStr(query); | 230 repl.SetQueryStr(query); |
| 233 learn_more_url = learn_more_url.ReplaceComponents(repl); | 231 learn_more_url = learn_more_url.ReplaceComponents(repl); |
| 234 | 232 |
| 235 DictionaryValue* suggest_learn_more = new DictionaryValue; | 233 DictionaryValue* suggest_learn_more = new DictionaryValue; |
| 236 suggest_learn_more->SetString(L"msg", | 234 suggest_learn_more->SetStringFromUTF16("msg", |
| 237 l10n_util::GetString(IDS_ERRORPAGES_SUGGESTION_LEARNMORE)); | 235 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE)); |
| 238 suggest_learn_more->SetString(L"learnMoreUrl", | 236 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
| 239 ASCIIToWide(learn_more_url.spec())); | 237 error_strings->Set("suggestionsLearnMore", suggest_learn_more); |
| 240 error_strings->Set(L"suggestionsLearnMore", suggest_learn_more); | |
| 241 } | 238 } |
| 242 } | 239 } |
| 243 } | 240 } |
| 244 | 241 |
| 245 void GetFormRepostErrorValues(const GURL& display_url, | 242 void GetFormRepostErrorValues(const GURL& display_url, |
| 246 DictionaryValue* error_strings) { | 243 DictionaryValue* error_strings) { |
| 247 bool rtl = LocaleIsRTL(); | 244 bool rtl = LocaleIsRTL(); |
| 248 error_strings->SetString(L"textdirection", rtl ? L"rtl" : L"ltr"); | 245 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); |
| 249 | 246 |
| 250 std::wstring failed_url(ASCIIToWide(display_url.spec())); | 247 string16 failed_url(ASCIIToUTF16(display_url.spec())); |
| 251 // URLs are always LTR. | 248 // URLs are always LTR. |
| 252 if (rtl) | 249 if (rtl) |
| 253 base::i18n::WrapStringWithLTRFormatting(&failed_url); | 250 base::i18n::WrapStringWithLTRFormatting(&failed_url); |
| 254 error_strings->SetString( | 251 error_strings->SetStringFromUTF16( |
| 255 L"title", l10n_util::GetStringF(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, | 252 "title", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 256 failed_url.c_str())); | 253 failed_url)); |
| 257 error_strings->SetString(L"heading", | 254 error_strings->SetStringFromUTF16( |
| 258 l10n_util::GetString(IDS_HTTP_POST_WARNING_TITLE)); | 255 "heading", l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE)); |
| 259 error_strings->SetString(L"suggestionsHeading", L""); | 256 error_strings->SetString("suggestionsHeading", ""); |
| 260 DictionaryValue* summary = new DictionaryValue; | 257 DictionaryValue* summary = new DictionaryValue; |
| 261 summary->SetString(L"msg", | 258 summary->SetStringFromUTF16( |
| 262 l10n_util::GetString(IDS_ERRORPAGES_HTTP_POST_WARNING)); | 259 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_HTTP_POST_WARNING)); |
| 263 error_strings->Set(L"summary", summary); | 260 error_strings->Set("summary", summary); |
| 264 } | 261 } |
| OLD | NEW |