| 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/string16.h" | 9 #include "base/string16.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/common/extensions/api/icons/icons_handler.h" | 13 #include "chrome/common/extensions/api/icons/icons_handler.h" |
| 14 #include "chrome/common/extensions/extension_constants.h" | 14 #include "chrome/common/extensions/extension_constants.h" |
| 15 #include "chrome/common/extensions/extension_icon_set.h" | 15 #include "chrome/common/extensions/extension_icon_set.h" |
| 16 #include "chrome/common/extensions/extension_set.h" | 16 #include "chrome/common/extensions/extension_set.h" |
| 17 #include "chrome/common/net/net_error_info.h" |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
| 19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 20 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
| 21 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h" | 23 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "webkit/glue/webkit_glue.h" | 25 #include "webkit/glue/webkit_glue.h" |
| 25 | 26 |
| 26 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 }, | 344 }, |
| 344 {505, | 345 {505, |
| 345 IDS_ERRORPAGES_TITLE_LOAD_FAILED, | 346 IDS_ERRORPAGES_TITLE_LOAD_FAILED, |
| 346 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR, | 347 IDS_ERRORPAGES_HEADING_HTTP_SERVER_ERROR, |
| 347 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE, | 348 IDS_ERRORPAGES_SUMMARY_WEBSITE_CANNOT_HANDLE, |
| 348 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED, | 349 IDS_ERRORPAGES_DETAILS_HTTP_VERSION_NOT_SUPPORTED, |
| 349 SUGGEST_NONE, | 350 SUGGEST_NONE, |
| 350 }, | 351 }, |
| 351 }; | 352 }; |
| 352 | 353 |
| 354 const LocalizedErrorMap dns_probe_error_options[] = { |
| 355 {chrome_common_net::DNS_PROBE_ERR_POSSIBLE, |
| 356 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 357 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 358 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING, |
| 359 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING, |
| 360 SUGGEST_NONE, |
| 361 }, |
| 362 {chrome_common_net::DNS_PROBE_ERR_RUNNING, |
| 363 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 364 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 365 IDS_ERRORPAGES_SUMMARY_DNS_PROBE_RUNNING, |
| 366 IDS_ERRORPAGES_DETAILS_DNS_PROBE_RUNNING, |
| 367 SUGGEST_NONE, |
| 368 }, |
| 369 {chrome_common_net::DNS_PROBE_ERR_FINISHED + |
| 370 chrome_common_net::DNS_PROBE_UNKNOWN, |
| 371 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 372 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 373 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED, |
| 374 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED, |
| 375 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_DNS_CONFIG | |
| 376 SUGGEST_FIREWALL_CONFIG | SUGGEST_PROXY_CONFIG, |
| 377 }, |
| 378 {chrome_common_net::DNS_PROBE_ERR_FINISHED + |
| 379 chrome_common_net::DNS_PROBE_NO_INTERNET, |
| 380 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 381 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 382 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED, |
| 383 IDS_ERRORPAGES_DETAILS_INTERNET_DISCONNECTED, |
| 384 SUGGEST_RELOAD | SUGGEST_CHECK_CONNECTION | SUGGEST_FIREWALL_CONFIG, |
| 385 }, |
| 386 {chrome_common_net::DNS_PROBE_ERR_FINISHED + |
| 387 chrome_common_net::DNS_PROBE_BAD_CONFIG, |
| 388 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 389 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 390 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED, |
| 391 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED, |
| 392 SUGGEST_RELOAD | SUGGEST_DNS_CONFIG | SUGGEST_FIREWALL_CONFIG, |
| 393 }, |
| 394 {chrome_common_net::DNS_PROBE_ERR_FINISHED + |
| 395 chrome_common_net::DNS_PROBE_NXDOMAIN, |
| 396 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 397 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 398 IDS_ERRORPAGES_SUMMARY_NAME_NOT_RESOLVED, |
| 399 IDS_ERRORPAGES_DETAILS_NAME_NOT_RESOLVED, |
| 400 SUGGEST_RELOAD | SUGGEST_HOSTNAME, |
| 401 }, |
| 402 }; |
| 403 |
| 353 const char* HttpErrorToString(int status_code) { | 404 const char* HttpErrorToString(int status_code) { |
| 354 switch (status_code) { | 405 switch (status_code) { |
| 355 case 403: | 406 case 403: |
| 356 return "Forbidden"; | 407 return "Forbidden"; |
| 357 case 410: | 408 case 410: |
| 358 return "Gone"; | 409 return "Gone"; |
| 359 case 500: | 410 case 500: |
| 360 return "Internal Server Error"; | 411 return "Internal Server Error"; |
| 361 case 501: | 412 case 501: |
| 362 return "Not Implemented"; | 413 return "Not Implemented"; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 379 int error_page_template; | 430 int error_page_template; |
| 380 const char* error_string; | 431 const char* error_string; |
| 381 if (error_domain == net::kErrorDomain) { | 432 if (error_domain == net::kErrorDomain) { |
| 382 error_page_template = IDS_ERRORPAGES_DETAILS_TEMPLATE; | 433 error_page_template = IDS_ERRORPAGES_DETAILS_TEMPLATE; |
| 383 error_string = net::ErrorToString(error_code); | 434 error_string = net::ErrorToString(error_code); |
| 384 DCHECK(error_code < 0); // Net error codes are negative. | 435 DCHECK(error_code < 0); // Net error codes are negative. |
| 385 error_code = -error_code; | 436 error_code = -error_code; |
| 386 } else if (error_domain == LocalizedError::kHttpErrorDomain) { | 437 } else if (error_domain == LocalizedError::kHttpErrorDomain) { |
| 387 error_page_template = IDS_ERRORPAGES_HTTP_DETAILS_TEMPLATE; | 438 error_page_template = IDS_ERRORPAGES_HTTP_DETAILS_TEMPLATE; |
| 388 error_string = HttpErrorToString(error_code); | 439 error_string = HttpErrorToString(error_code); |
| 440 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) { |
| 441 error_page_template = IDS_ERRORPAGES_DETAILS_TEMPLATE; |
| 442 error_string = chrome_common_net::DnsProbeErrorToString(error_code); |
| 389 } else { | 443 } else { |
| 390 NOTREACHED(); | 444 NOTREACHED(); |
| 391 return string16(); | 445 return string16(); |
| 392 } | 446 } |
| 393 return l10n_util::GetStringFUTF16( | 447 return l10n_util::GetStringFUTF16( |
| 394 error_page_template, | 448 error_page_template, |
| 395 base::IntToString16(error_code), | 449 base::IntToString16(error_code), |
| 396 ASCIIToUTF16(error_string), | 450 ASCIIToUTF16(error_string), |
| 397 details); | 451 details); |
| 398 } | 452 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 410 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain, | 464 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain, |
| 411 int error_code) { | 465 int error_code) { |
| 412 if (error_domain == net::kErrorDomain) { | 466 if (error_domain == net::kErrorDomain) { |
| 413 return FindErrorMapInArray(net_error_options, | 467 return FindErrorMapInArray(net_error_options, |
| 414 arraysize(net_error_options), | 468 arraysize(net_error_options), |
| 415 error_code); | 469 error_code); |
| 416 } else if (error_domain == LocalizedError::kHttpErrorDomain) { | 470 } else if (error_domain == LocalizedError::kHttpErrorDomain) { |
| 417 return FindErrorMapInArray(http_error_options, | 471 return FindErrorMapInArray(http_error_options, |
| 418 arraysize(http_error_options), | 472 arraysize(http_error_options), |
| 419 error_code); | 473 error_code); |
| 474 } else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) { |
| 475 return FindErrorMapInArray(dns_probe_error_options, |
| 476 arraysize(dns_probe_error_options), |
| 477 error_code); |
| 420 } else { | 478 } else { |
| 421 NOTREACHED(); | 479 NOTREACHED(); |
| 422 return NULL; | 480 return NULL; |
| 423 } | 481 } |
| 424 } | 482 } |
| 425 | 483 |
| 426 bool LocaleIsRTL() { | 484 bool LocaleIsRTL() { |
| 427 #if defined(TOOLKIT_GTK) | 485 #if defined(TOOLKIT_GTK) |
| 428 // base::i18n::IsRTL() uses the GTK text direction, which doesn't work within | 486 // base::i18n::IsRTL() uses the GTK text direction, which doesn't work within |
| 429 // the renderer sandbox. | 487 // the renderer sandbox. |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 #if defined(OS_CHROMEOS) | 814 #if defined(OS_CHROMEOS) |
| 757 GURL learn_more_url(kAppWarningLearnMoreUrl); | 815 GURL learn_more_url(kAppWarningLearnMoreUrl); |
| 758 DictionaryValue* suggest_learn_more = new DictionaryValue(); | 816 DictionaryValue* suggest_learn_more = new DictionaryValue(); |
| 759 suggest_learn_more->SetString("msg", | 817 suggest_learn_more->SetString("msg", |
| 760 l10n_util::GetStringUTF16( | 818 l10n_util::GetStringUTF16( |
| 761 IDS_ERRORPAGES_SUGGESTION_LEARNMORE)); | 819 IDS_ERRORPAGES_SUGGESTION_LEARNMORE)); |
| 762 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 820 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
| 763 error_strings->Set("suggestionsLearnMore", suggest_learn_more); | 821 error_strings->Set("suggestionsLearnMore", suggest_learn_more); |
| 764 #endif // defined(OS_CHROMEOS) | 822 #endif // defined(OS_CHROMEOS) |
| 765 } | 823 } |
| OLD | NEW |