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

Side by Side Diff: chrome/common/localized_error.cc

Issue 13811022: New network error page: Fix resubmit warning page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync prior to commit Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/localized_error.h ('k') | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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
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
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
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): Make the reload button bring up the repost confirmation
552 // dialog for pages resulting from posts.
553 DictionaryValue* suggest_reload_repost = new DictionaryValue;
554 suggest_reload_repost->SetString("header",
555 l10n_util::GetStringUTF16(
556 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_HEADER));
557 suggest_reload_repost->SetString("body",
558 l10n_util::GetStringUTF16(
559 IDS_ERRORPAGES_SUGGESTION_RELOAD_REPOST_BODY));
560 suggestions->Append(suggest_reload_repost);
561 }
530 } 562 }
531 563
532 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { 564 if (options.suggestions & SUGGEST_CHECK_CONNECTION) {
533 DictionaryValue* suggest_check_connection = new DictionaryValue; 565 DictionaryValue* suggest_check_connection = new DictionaryValue;
534 suggest_check_connection->SetString("header", 566 suggest_check_connection->SetString("header",
535 l10n_util::GetStringUTF16( 567 l10n_util::GetStringUTF16(
536 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)); 568 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER));
537 suggest_check_connection->SetString("body", 569 suggest_check_connection->SetString("body",
538 l10n_util::GetStringUTF16( 570 l10n_util::GetStringUTF16(
539 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY)); 571 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 suggest_learn_more->SetString("body", 678 suggest_learn_more->SetString("body",
647 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); 679 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
648 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); 680 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
649 suggestions->Append(suggest_learn_more); 681 suggestions->Append(suggest_learn_more);
650 } 682 }
651 } 683 }
652 684
653 error_strings->Set("suggestions", suggestions); 685 error_strings->Set("suggestions", suggestions);
654 } 686 }
655 687
656 string16 LocalizedError::GetErrorDetails(const WebKit::WebURLError& error) { 688 string16 LocalizedError::GetErrorDetails(const WebKit::WebURLError& error,
689 bool is_post) {
657 const LocalizedErrorMap* error_map = 690 const LocalizedErrorMap* error_map =
658 LookupErrorMap(error.domain.utf8(), error.reason); 691 LookupErrorMap(error.domain.utf8(), error.reason, is_post);
659 if (error_map) 692 if (error_map)
660 return l10n_util::GetStringUTF16(error_map->details_resource_id); 693 return l10n_util::GetStringUTF16(error_map->details_resource_id);
661 else 694 else
662 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); 695 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN);
663 } 696 }
664 697
665 bool LocalizedError::HasStrings(const std::string& error_domain, 698 bool LocalizedError::HasStrings(const std::string& error_domain,
666 int error_code) { 699 int error_code) {
667 return LookupErrorMap(error_domain, error_code) != NULL; 700 // Whether or not the there are strings for an error does not depend on
668 } 701 // whether or not the page was be generated by a POST, so just claim it was
669 702 // not.
670 void LocalizedError::GetFormRepostStrings(const GURL& display_url, 703 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL;
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 } 704 }
689 705
690 void LocalizedError::GetAppErrorStrings( 706 void LocalizedError::GetAppErrorStrings(
691 const WebURLError& error, 707 const WebURLError& error,
692 const GURL& display_url, 708 const GURL& display_url,
693 const extensions::Extension* app, 709 const extensions::Extension* app,
694 DictionaryValue* error_strings) { 710 DictionaryValue* error_strings) {
695 DCHECK(app); 711 DCHECK(app);
696 712
697 bool rtl = LocaleIsRTL(); 713 bool rtl = LocaleIsRTL();
(...skipping 22 matching lines...) Expand all
720 #if defined(OS_CHROMEOS) 736 #if defined(OS_CHROMEOS)
721 GURL learn_more_url(kAppWarningLearnMoreUrl); 737 GURL learn_more_url(kAppWarningLearnMoreUrl);
722 DictionaryValue* suggest_learn_more = new DictionaryValue(); 738 DictionaryValue* suggest_learn_more = new DictionaryValue();
723 suggest_learn_more->SetString("msg", 739 suggest_learn_more->SetString("msg",
724 l10n_util::GetStringUTF16( 740 l10n_util::GetStringUTF16(
725 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); 741 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY));
726 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); 742 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec());
727 error_strings->Set("suggestionsLearnMore", suggest_learn_more); 743 error_strings->Set("suggestionsLearnMore", suggest_learn_more);
728 #endif // defined(OS_CHROMEOS) 744 #endif // defined(OS_CHROMEOS)
729 } 745 }
OLDNEW
« no previous file with comments | « chrome/common/localized_error.h ('k') | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698