| 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 | |
| 309 const LocalizedErrorMap http_error_options[] = { | 297 const LocalizedErrorMap http_error_options[] = { |
| 310 {403, | 298 {403, |
| 311 IDS_ERRORPAGES_TITLE_ACCESS_DENIED, | 299 IDS_ERRORPAGES_TITLE_ACCESS_DENIED, |
| 312 IDS_ERRORPAGES_HEADING_ACCESS_DENIED, | 300 IDS_ERRORPAGES_HEADING_ACCESS_DENIED, |
| 313 IDS_ERRORPAGES_SUMMARY_FORBIDDEN, | 301 IDS_ERRORPAGES_SUMMARY_FORBIDDEN, |
| 314 IDS_ERRORPAGES_DETAILS_FORBIDDEN, | 302 IDS_ERRORPAGES_DETAILS_FORBIDDEN, |
| 315 SUGGEST_NONE, | 303 SUGGEST_NONE, |
| 316 }, | 304 }, |
| 317 {410, | 305 {410, |
| 318 IDS_ERRORPAGES_TITLE_NOT_FOUND, | 306 IDS_ERRORPAGES_TITLE_NOT_FOUND, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 size_t num_maps, | 358 size_t num_maps, |
| 371 int error_code) { | 359 int error_code) { |
| 372 for (size_t i = 0; i < num_maps; ++i) { | 360 for (size_t i = 0; i < num_maps; ++i) { |
| 373 if (maps[i].error_code == error_code) | 361 if (maps[i].error_code == error_code) |
| 374 return &maps[i]; | 362 return &maps[i]; |
| 375 } | 363 } |
| 376 return NULL; | 364 return NULL; |
| 377 } | 365 } |
| 378 | 366 |
| 379 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain, | 367 const LocalizedErrorMap* LookupErrorMap(const std::string& error_domain, |
| 380 int error_code, bool is_post) { | 368 int error_code) { |
| 381 if (error_domain == net::kErrorDomain) { | 369 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; | |
| 386 return FindErrorMapInArray(net_error_options, | 370 return FindErrorMapInArray(net_error_options, |
| 387 arraysize(net_error_options), | 371 arraysize(net_error_options), |
| 388 error_code); | 372 error_code); |
| 389 } else if (error_domain == LocalizedError::kHttpErrorDomain) { | 373 } else if (error_domain == LocalizedError::kHttpErrorDomain) { |
| 390 return FindErrorMapInArray(http_error_options, | 374 return FindErrorMapInArray(http_error_options, |
| 391 arraysize(http_error_options), | 375 arraysize(http_error_options), |
| 392 error_code); | 376 error_code); |
| 393 } else { | 377 } else { |
| 394 NOTREACHED(); | 378 NOTREACHED(); |
| 395 return NULL; | 379 return NULL; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 415 standard_menu_items_text->SetString("advancedTitle", | 399 standard_menu_items_text->SetString("advancedTitle", |
| 416 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS)); | 400 l10n_util::GetStringUTF16(IDS_SETTINGS_SHOW_ADVANCED_SETTINGS)); |
| 417 return standard_menu_items_text; | 401 return standard_menu_items_text; |
| 418 } | 402 } |
| 419 | 403 |
| 420 } // namespace | 404 } // namespace |
| 421 | 405 |
| 422 const char LocalizedError::kHttpErrorDomain[] = "http"; | 406 const char LocalizedError::kHttpErrorDomain[] = "http"; |
| 423 | 407 |
| 424 void LocalizedError::GetStrings(const WebKit::WebURLError& error, | 408 void LocalizedError::GetStrings(const WebKit::WebURLError& error, |
| 425 bool is_post, | 409 DictionaryValue* error_strings, |
| 426 const std::string& locale, | 410 const std::string& locale) { |
| 427 DictionaryValue* error_strings) { | |
| 428 bool rtl = LocaleIsRTL(); | 411 bool rtl = LocaleIsRTL(); |
| 429 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); | 412 error_strings->SetString("textdirection", rtl ? "rtl" : "ltr"); |
| 430 | 413 |
| 431 // Grab the strings and settings that depend on the error type. Init | 414 // Grab the strings and settings that depend on the error type. Init |
| 432 // options with default values. | 415 // options with default values. |
| 433 LocalizedErrorMap options = { | 416 LocalizedErrorMap options = { |
| 434 0, | 417 0, |
| 435 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, | 418 IDS_ERRORPAGES_TITLE_NOT_AVAILABLE, |
| 436 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, | 419 IDS_ERRORPAGES_HEADING_NOT_AVAILABLE, |
| 437 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE, | 420 IDS_ERRORPAGES_SUMMARY_NOT_AVAILABLE, |
| 438 kErrorPagesNoDetails, | 421 kErrorPagesNoDetails, |
| 439 SUGGEST_NONE, | 422 SUGGEST_NONE, |
| 440 }; | 423 }; |
| 441 | 424 |
| 442 const std::string error_domain = error.domain.utf8(); | 425 const std::string error_domain = error.domain.utf8(); |
| 443 int error_code = error.reason; | 426 int error_code = error.reason; |
| 444 const LocalizedErrorMap* error_map = LookupErrorMap(error_domain, error_code, | 427 const LocalizedErrorMap* error_map = |
| 445 is_post); | 428 LookupErrorMap(error_domain, error_code); |
| 446 if (error_map) | 429 if (error_map) |
| 447 options = *error_map; | 430 options = *error_map; |
| 448 | 431 |
| 449 const GURL failed_url = error.unreachableURL; | 432 const GURL failed_url = error.unreachableURL; |
| 450 | 433 |
| 451 // If we got "access denied" but the url was a file URL, then we say it was a | 434 // If we got "access denied" but the url was a file URL, then we say it was a |
| 452 // file instead of just using the "not available" default message. Just adding | 435 // file instead of just using the "not available" default message. Just adding |
| 453 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be | 436 // ERR_ACCESS_DENIED to the map isn't sufficient, since that message may be |
| 454 // generated by some OSs when the operation doesn't involve a file URL. | 437 // generated by some OSs when the operation doesn't involve a file URL. |
| 455 if (error_domain == net::kErrorDomain && | 438 if (error_domain == net::kErrorDomain && |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 // dependent portion of the summary section. | 515 // dependent portion of the summary section. |
| 533 summary->SetString("msg", | 516 summary->SetString("msg", |
| 534 l10n_util::GetStringFUTF16( | 517 l10n_util::GetStringFUTF16( |
| 535 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE, | 518 IDS_ERRORPAGES_SUMMARY_INTERNET_DISCONNECTED_INSTRUCTIONS_TEMPLATE, |
| 536 l10n_util::GetStringUTF16(options.summary_resource_id), | 519 l10n_util::GetStringUTF16(options.summary_resource_id), |
| 537 l10n_util::GetStringUTF16(platform_string_id))); | 520 l10n_util::GetStringUTF16(platform_string_id))); |
| 538 } | 521 } |
| 539 #endif // defined(OS_MACOSX) || defined(OS_WIN) | 522 #endif // defined(OS_MACOSX) || defined(OS_WIN) |
| 540 | 523 |
| 541 if (options.suggestions & SUGGEST_RELOAD) { | 524 if (options.suggestions & SUGGEST_RELOAD) { |
| 542 if (!is_post) { | 525 DictionaryValue* reload_button = new DictionaryValue; |
| 543 DictionaryValue* reload_button = new DictionaryValue; | 526 reload_button->SetString("msg", |
| 544 reload_button->SetString("msg", | 527 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); |
| 545 l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); | 528 reload_button->SetString("reloadUrl", failed_url_string); |
| 546 reload_button->SetString("reloadUrl", failed_url_string); | 529 error_strings->Set("reload", reload_button); |
| 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 } | |
| 562 } | 530 } |
| 563 | 531 |
| 564 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { | 532 if (options.suggestions & SUGGEST_CHECK_CONNECTION) { |
| 565 DictionaryValue* suggest_check_connection = new DictionaryValue; | 533 DictionaryValue* suggest_check_connection = new DictionaryValue; |
| 566 suggest_check_connection->SetString("header", | 534 suggest_check_connection->SetString("header", |
| 567 l10n_util::GetStringUTF16( | 535 l10n_util::GetStringUTF16( |
| 568 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)); | 536 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_HEADER)); |
| 569 suggest_check_connection->SetString("body", | 537 suggest_check_connection->SetString("body", |
| 570 l10n_util::GetStringUTF16( | 538 l10n_util::GetStringUTF16( |
| 571 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY)); | 539 IDS_ERRORPAGES_SUGGESTION_CHECK_CONNECTION_BODY)); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 suggest_learn_more->SetString("body", | 646 suggest_learn_more->SetString("body", |
| 679 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 647 l10n_util::GetStringUTF16(IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
| 680 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 648 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
| 681 suggestions->Append(suggest_learn_more); | 649 suggestions->Append(suggest_learn_more); |
| 682 } | 650 } |
| 683 } | 651 } |
| 684 | 652 |
| 685 error_strings->Set("suggestions", suggestions); | 653 error_strings->Set("suggestions", suggestions); |
| 686 } | 654 } |
| 687 | 655 |
| 688 string16 LocalizedError::GetErrorDetails(const WebKit::WebURLError& error, | 656 string16 LocalizedError::GetErrorDetails(const WebKit::WebURLError& error) { |
| 689 bool is_post) { | |
| 690 const LocalizedErrorMap* error_map = | 657 const LocalizedErrorMap* error_map = |
| 691 LookupErrorMap(error.domain.utf8(), error.reason, is_post); | 658 LookupErrorMap(error.domain.utf8(), error.reason); |
| 692 if (error_map) | 659 if (error_map) |
| 693 return l10n_util::GetStringUTF16(error_map->details_resource_id); | 660 return l10n_util::GetStringUTF16(error_map->details_resource_id); |
| 694 else | 661 else |
| 695 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); | 662 return l10n_util::GetStringUTF16(IDS_ERRORPAGES_DETAILS_UNKNOWN); |
| 696 } | 663 } |
| 697 | 664 |
| 698 bool LocalizedError::HasStrings(const std::string& error_domain, | 665 bool LocalizedError::HasStrings(const std::string& error_domain, |
| 699 int error_code) { | 666 int error_code) { |
| 700 // Whether or not the there are strings for an error does not depend on | 667 return LookupErrorMap(error_domain, error_code) != NULL; |
| 701 // whether or not the page was be generated by a POST, so just claim it was | 668 } |
| 702 // not. | 669 |
| 703 return LookupErrorMap(error_domain, error_code, /*is_post=*/false) != NULL; | 670 void LocalizedError::GetFormRepostStrings(const GURL& display_url, |
| 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); |
| 704 } | 688 } |
| 705 | 689 |
| 706 void LocalizedError::GetAppErrorStrings( | 690 void LocalizedError::GetAppErrorStrings( |
| 707 const WebURLError& error, | 691 const WebURLError& error, |
| 708 const GURL& display_url, | 692 const GURL& display_url, |
| 709 const extensions::Extension* app, | 693 const extensions::Extension* app, |
| 710 DictionaryValue* error_strings) { | 694 DictionaryValue* error_strings) { |
| 711 DCHECK(app); | 695 DCHECK(app); |
| 712 | 696 |
| 713 bool rtl = LocaleIsRTL(); | 697 bool rtl = LocaleIsRTL(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 736 #if defined(OS_CHROMEOS) | 720 #if defined(OS_CHROMEOS) |
| 737 GURL learn_more_url(kAppWarningLearnMoreUrl); | 721 GURL learn_more_url(kAppWarningLearnMoreUrl); |
| 738 DictionaryValue* suggest_learn_more = new DictionaryValue(); | 722 DictionaryValue* suggest_learn_more = new DictionaryValue(); |
| 739 suggest_learn_more->SetString("msg", | 723 suggest_learn_more->SetString("msg", |
| 740 l10n_util::GetStringUTF16( | 724 l10n_util::GetStringUTF16( |
| 741 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); | 725 IDS_ERRORPAGES_SUGGESTION_LEARNMORE_BODY)); |
| 742 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); | 726 suggest_learn_more->SetString("learnMoreUrl", learn_more_url.spec()); |
| 743 error_strings->Set("suggestionsLearnMore", suggest_learn_more); | 727 error_strings->Set("suggestionsLearnMore", suggest_learn_more); |
| 744 #endif // defined(OS_CHROMEOS) | 728 #endif // defined(OS_CHROMEOS) |
| 745 } | 729 } |
| OLD | NEW |