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/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 }, | 287 }, |
288 {net::ERR_BLOCKED_BY_ADMINISTRATOR, | 288 {net::ERR_BLOCKED_BY_ADMINISTRATOR, |
289 IDS_ERRORPAGES_TITLE_BLOCKED, | 289 IDS_ERRORPAGES_TITLE_BLOCKED, |
290 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR, | 290 IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR, |
291 IDS_ERRORPAGES_SUMMARY_BLOCKED_BY_ADMINISTRATOR, | 291 IDS_ERRORPAGES_SUMMARY_BLOCKED_BY_ADMINISTRATOR, |
292 IDS_ERRORPAGES_DETAILS_BLOCKED_BY_ADMINISTRATOR, | 292 IDS_ERRORPAGES_DETAILS_BLOCKED_BY_ADMINISTRATOR, |
293 SUGGEST_VIEW_POLICIES | SUGGEST_CONTACT_ADMINISTRATOR, | 293 SUGGEST_VIEW_POLICIES | SUGGEST_CONTACT_ADMINISTRATOR, |
294 }, | 294 }, |
295 }; | 295 }; |
296 | 296 |
297 // Special error page to be used in the case of navigating back to a page | |
298 // generated by a POST. LocalizedError::HasStrings expects this net error code | |
299 // to also appear in the array above. | |
300 const LocalizedErrorMap repost_error = { | |
301 net::ERR_CACHE_MISS, | |
302 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, | |
303 IDS_HTTP_POST_WARNING_TITLE, | |
304 IDS_ERRORPAGES_HTTP_POST_WARNING, | |
305 IDS_ERRORPAGES_DETAILS_CACHE_MISS, | |
306 SUGGEST_RELOAD, | |
307 }; | |
308 | |
297 const LocalizedErrorMap http_error_options[] = { | 309 const LocalizedErrorMap http_error_options[] = { |
298 {403, | 310 {403, |
299 IDS_ERRORPAGES_TITLE_ACCESS_DENIED, | 311 IDS_ERRORPAGES_TITLE_ACCESS_DENIED, |
300 IDS_ERRORPAGES_HEADING_ACCESS_DENIED, | 312 IDS_ERRORPAGES_HEADING_ACCESS_DENIED, |
301 IDS_ERRORPAGES_SUMMARY_FORBIDDEN, | 313 IDS_ERRORPAGES_SUMMARY_FORBIDDEN, |
302 IDS_ERRORPAGES_DETAILS_FORBIDDEN, | 314 IDS_ERRORPAGES_DETAILS_FORBIDDEN, |
303 SUGGEST_NONE, | 315 SUGGEST_NONE, |
304 }, | 316 }, |
305 {410, | 317 {410, |
306 IDS_ERRORPAGES_TITLE_NOT_FOUND, | 318 IDS_ERRORPAGES_TITLE_NOT_FOUND, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 size_t num_maps, | 370 size_t num_maps, |
359 int error_code) { | 371 int error_code) { |
360 for (size_t i = 0; i < num_maps; ++i) { | 372 for (size_t i = 0; i < num_maps; ++i) { |
361 if (maps[i].error_code == error_code) | 373 if (maps[i].error_code == error_code) |
362 return &maps[i]; | 374 return &maps[i]; |
363 } | 375 } |
364 return NULL; | 376 return NULL; |
365 } | 377 } |
366 | 378 |
367 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain, | 379 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain, |
368 int error_code) { | 380 int error_code, bool is_post) { |
369 if (error_domain == net::kErrorDomain) { | 381 if (error_domain == net::kErrorDomain) { |
382 // Display a different page in the special case of navigating through the | |
383 // history to an uncached page created by a POST. | |
384 if (is_post && error_code == net::ERR_CACHE_MISS) | |
385 return &repost_error; | |
370 return FindErrorMapInArray(net_error_options, | 386 return FindErrorMapInArray(net_error_options, |
371 arraysize(net_error_options), | 387 arraysize(net_error_options), |
372 error_code); | 388 error_code); |
373 } else if (error_domain == LocalizedError::kHttpErrorDomain) { | 389 } else if (error_domain == LocalizedError::kHttpErrorDomain) { |
374 return FindErrorMapInArray(http_error_options, | 390 return FindErrorMapInArray(http_error_options, |
375 arraysize(http_error_options), | 391 arraysize(http_error_options), |
376 error_code); | 392 error_code); |
377 } else { | 393 } else { |
378 NOTREACHED(); | 394 NOTREACHED(); |
379 return NULL; | 395 return NULL; |
(...skipping 19 matching lines...) Expand all Loading... | |
399 standard_menu_items_text->SetString("advancedTitle", | 415 standard_menu_items_text->SetString("advancedTitle", |
400 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS)); | 416 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS)); |
401 return standard_menu_items_text; | 417 return standard_menu_items_text; |
402 } | 418 } |
403 | 419 |
404 } // namespace | 420 } // namespace |
405 | 421 |
406 const char LocalizedError::kHttpErrorDomain[] = "http"; | 422 const char LocalizedError::kHttpErrorDomain[] = "http"; |
407 | 423 |
408 void LocalizedError::GetStrings(const WebKit::WebURLError& error, | 424 void LocalizedError::GetStrings(const WebKit::WebURLError& error, |
409 DictionaryValue* error_strings, | 425 bool is_post, |
410 const std::string& locale) { | 426 const std::string& locale, |
427 DictionaryValue* error_strings) { | |
411 bool rtl = LocaleIsRTL(); | 428 bool rtl = LocaleIsRTL(); |
412 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); | 429 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); |
413 | 430 |
414 // Grab the strings and settings that depend on the error type. Init | 431 // Grab the strings and settings that depend on the error type. Init |
415 // options with default values. | 432 // options with default values. |
416 LocalizedErrorMap options = { | 433 LocalizedErrorMap options = { |
417 0, | 434 0, |
418 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, | 435 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
419 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, | 436 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
420 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE, | 437 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE, |
421 kErrorPagesNoDetails, | 438 kErrorPagesNoDetails, |
422 SUGGEST_NONE, | 439 SUGGEST_NONE, |
423 }; | 440 }; |
424 | 441 |
425 const std::string error_domain = error.domain.utf8(); | 442 const std::string error_domain = error.domain.utf8(); |
426 int error_code = error.reason; | 443 int error_code = error.reason; |
427 const LocalizedErrorMap* error_map = | 444 const LocalizedErrorMap* error_map = LookupErrorMap(error_domain, error_code, |
428 LookupErrorMap(error_domain, error_code); | 445 is_post); |
429 if (error_map) | 446 if (error_map) |
430 options = *error_map; | 447 options = *error_map; |
431 | 448 |
432 const GURL failed_url = error.unreachableURL; | 449 const GURL failed_url = error.unreachableURL; |
433 | 450 |
434 // If we got "access denied" but the url was a file URL, then we say it was a | 451 // If we got "access denied" but the url was a file URL, then we say it was a |
435 // file instead of just using the "not available" default message. Just adding | 452 // file instead of just using the "not available" default message. Just adding |
436 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be | 453 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be |
437 // generated by some OSs when the operation doesn't involve a file URL. | 454 // generated by some OSs when the operation doesn't involve a file URL. |
438 if (error_domain == net::kErrorDomain && | 455 if (error_domain == net::kErrorDomain && |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 // dependent portion of the summary section. | 532 // dependent portion of the summary section. |
516 summary->SetString("msg", | 533 summary->SetString("msg", |
517 l10n_util::GetStringFUTF16( | 534 l10n_util::GetStringFUTF16( |
518 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE, | 535 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE, |
519 l10n_util::GetStringUTF16(options.summary_resource_id), | 536 l10n_util::GetStringUTF16(options.summary_resource_id), |
520 l10n_util::GetStringUTF16(platform_string_id))); | 537 l10n_util::GetStringUTF16(platform_string_id))); |
521 } | 538 } |
522 #endif // defined(OS_MACOSX) || defined(OS_WIN) | 539 #endif // defined(OS_MACOSX) || defined(OS_WIN) |
523 | 540 |
524 if (options.suggestions & SUGGEST_RELOAD) { | 541 if (options.suggestions & SUGGEST_RELOAD) { |
525 DictionaryValue* reload_button = new DictionaryValue; | 542 if (!is_post) { |
526 reload_button->SetString("msg", | 543 DictionaryValue* reload_button = new DictionaryValue; |
527 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); | 544 reload_button->SetString("msg", |
528 reload_button->SetString("reloadUrl", failed_url_string); | 545 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); |
529 error_strings->Set("reload", reload_button); | 546 reload_button->SetString("reloadUrl", failed_url_string); |
547 error_strings->Set("reload", reload_button); | |
548 } else { | |
549 // If the page was created by a post, it can't be reloaded in the same | |
550 // way, so just add a suggestion instead. | |
551 // TODO(mmenke): Fix this. | |
Nico
2013/04/16 21:49:14
nit: Not clear to me what "this" means here.
mmenke
2013/04/16 21:57:04
Fixed ("Make the reload button bring up the repost
| |
552 DictionaryValue* suggest_reload_repost = new DictionaryValue; | |
553 suggest_reload_repost->SetString("header", | |
554 l10n_util::GetStringUTF16( | |
555 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER)); | |
556 suggest_reload_repost->SetString("body", | |
557 l10n_util::GetStringUTF16( | |
558 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY)); | |
559 suggestions->Append(suggest_reload_repost); | |
560 } | |
530 } | 561 } |
531 | 562 |
532 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { | 563 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { |
533 DictionaryValue* suggest_check_connection = new DictionaryValue; | 564 DictionaryValue* suggest_check_connection = new DictionaryValue; |
534 suggest_check_connection->SetString("header", | 565 suggest_check_connection->SetString("header", |
535 l10n_util::GetStringUTF16( | 566 l10n_util::GetStringUTF16( |
536 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)); | 567 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)); |
537 suggest_check_connection->SetString("body", | 568 suggest_check_connection->SetString("body", |
538 l10n_util::GetStringUTF16( | 569 l10n_util::GetStringUTF16( |
539 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY)); | 570 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY)); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 suggest_learn_more->SetString("body", | 677 suggest_learn_more->SetString("body", |
647 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 678 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
648 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 679 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
649 suggestions->Append(suggest_learn_more); | 680 suggestions->Append(suggest_learn_more); |
650 } | 681 } |
651 } | 682 } |
652 | 683 |
653 error_strings->Set("suggestions", suggestions); | 684 error_strings->Set("suggestions", suggestions); |
654 } | 685 } |
655 | 686 |
656 string16 LocalizedError::GetErrorDetails(const WebKit::WebURLError& error) { | 687 string16 LocalizedError::GetErrorDetails(const WebKit::WebURLError& error, |
688 bool is_post) { | |
657 const LocalizedErrorMap* error_map = | 689 const LocalizedErrorMap* error_map = |
658 LookupErrorMap(error.domain.utf8(), error.reason); | 690 LookupErrorMap(error.domain.utf8(), error.reason, is_post); |
659 if (error_map) | 691 if (error_map) |
660 return l10n_util::GetStringUTF16(error_map->details_resource_id); | 692 return l10n_util::GetStringUTF16(error_map->details_resource_id); |
661 else | 693 else |
662 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); | 694 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); |
663 } | 695 } |
664 | 696 |
665 bool LocalizedError::HasStrings(const std::string& error_domain, | 697 bool LocalizedError::HasStrings(const std::string& error_domain, |
666 int error_code) { | 698 int error_code) { |
667 return LookupErrorMap(error_domain, error_code) != NULL; | 699 // Whether or not the there are strings for an error does not depend on |
668 } | 700 // whether or not the page was be generated by a POST, so just claim it was |
669 | 701 // not. |
670 void LocalizedError::GetFormRepostStrings(const GURL& display_url, | 702 return LookupErrorMap(error_domain, error_code, false) != NULL; |
Nico
2013/04/16 21:49:14
nit: /*is_post=*/false
mmenke
2013/04/16 21:57:04
Done.
| |
671 DictionaryValue* error_strings) { | |
672 bool rtl = LocaleIsRTL(); | |
673 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); | |
674 | |
675 string16 failed_url(ASCIIToUTF16(display_url.spec())); | |
676 // URLs are always LTR. | |
677 if (rtl) | |
678 base::i18n::WrapStringWithLTRFormatting(&failed_url); | |
679 error_strings->SetString( | |
680 "title", l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, | |
681 failed_url)); | |
682 error_strings->SetString( | |
683 "heading", l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE)); | |
684 DictionaryValue* summary = new DictionaryValue; | |
685 summary->SetString( | |
686 "msg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_HTTP_POST_WARNING)); | |
687 error_strings->Set("summary", summary); | |
688 } | 703 } |
689 | 704 |
690 void LocalizedError::GetAppErrorStrings( | 705 void LocalizedError::GetAppErrorStrings( |
691 const WebURLError& error, | 706 const WebURLError& error, |
692 const GURL& display_url, | 707 const GURL& display_url, |
693 const extensions::Extension* app, | 708 const extensions::Extension* app, |
694 DictionaryValue* error_strings) { | 709 DictionaryValue* error_strings) { |
695 DCHECK(app); | 710 DCHECK(app); |
696 | 711 |
697 bool rtl = LocaleIsRTL(); | 712 bool rtl = LocaleIsRTL(); |
(...skipping 22 matching lines...) Expand all Loading... | |
720 #if defined(OS_CHROMEOS) | 735 #if defined(OS_CHROMEOS) |
721 GURL learn_more_url(kAppWarningLearnMoreUrl); | 736 GURL learn_more_url(kAppWarningLearnMoreUrl); |
722 DictionaryValue* suggest_learn_more = new DictionaryValue(); | 737 DictionaryValue* suggest_learn_more = new DictionaryValue(); |
723 suggest_learn_more->SetString("msg", | 738 suggest_learn_more->SetString("msg", |
724 l10n_util::GetStringUTF16( | 739 l10n_util::GetStringUTF16( |
725 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 740 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
726 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 741 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
727 error_strings->Set("suggestionsLearnMore", suggest_learn_more); | 742 error_strings->Set("suggestionsLearnMore", suggest_learn_more); |
728 #endif // defined(OS_CHROMEOS) | 743 #endif // defined(OS_CHROMEOS) |
729 } | 744 } |
OLD | NEW |