localized_error.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_ERROR_PAGE_COMMON_LOCALIZED_ERROR_H_
  5. #define COMPONENTS_ERROR_PAGE_COMMON_LOCALIZED_ERROR_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/values.h"
  9. #include "url/gurl.h"
  10. namespace error_page {
  11. class LocalizedError {
  12. public:
  13. // Information about elements shown on the error page.
  14. struct PageState {
  15. PageState();
  16. ~PageState();
  17. PageState(const PageState& other) = delete;
  18. PageState(PageState&& other);
  19. PageState& operator=(PageState&& other);
  20. // Strings used within the error page HTML/JS.
  21. base::Value::Dict strings;
  22. bool is_offline_error = false;
  23. bool reload_button_shown = false;
  24. bool download_button_shown = false;
  25. bool offline_content_feature_enabled = false;
  26. bool auto_fetch_allowed = false;
  27. };
  28. LocalizedError() = delete;
  29. LocalizedError(const LocalizedError&) = delete;
  30. LocalizedError& operator=(const LocalizedError&) = delete;
  31. // Returns a |PageState| that describes the elements that should be shown on
  32. // on HTTP errors, like 404 or connection reset.
  33. // |is_kiosk_mode| whether device is currently in the Kiosk session mode.
  34. static PageState GetPageState(int error_code,
  35. const std::string& error_domain,
  36. const GURL& failed_url,
  37. bool is_post,
  38. bool is_secure_dns_network_error,
  39. bool stale_copy_in_cache,
  40. bool can_show_network_diagnostics_dialog,
  41. bool is_incognito,
  42. bool offline_content_feature_enabled,
  43. bool auto_fetch_feature_enabled,
  44. bool is_kiosk_mode,
  45. const std::string& locale,
  46. bool is_blocked_by_extension);
  47. // Returns a |PageState| that describes the elements that should be shown on
  48. // when default offline page is shown.
  49. static PageState GetPageStateForOverriddenErrorPage(
  50. base::Value::Dict string_dict,
  51. int error_code,
  52. const std::string& error_domain,
  53. const GURL& failed_url,
  54. const std::string& locale);
  55. // Returns a description of the encountered error.
  56. static std::u16string GetErrorDetails(const std::string& error_domain,
  57. int error_code,
  58. bool is_secure_dns_network_error,
  59. bool is_post);
  60. // Returns true if an error page exists for the specified parameters.
  61. static bool HasStrings(const std::string& error_domain, int error_code);
  62. static bool IsOfflineError(const std::string& error_domain, int error_code);
  63. };
  64. } // namespace error_page
  65. #endif // COMPONENTS_ERROR_PAGE_COMMON_LOCALIZED_ERROR_H_