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 
5 #ifndef COMPONENTS_ERROR_PAGE_COMMON_LOCALIZED_ERROR_H_
6 #define COMPONENTS_ERROR_PAGE_COMMON_LOCALIZED_ERROR_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include "base/macros.h"
12 #include "base/strings/string16.h"
13 #include "base/values.h"
14 #include "url/gurl.h"
15 
16 namespace base {
17 class DictionaryValue;
18 }
19 
20 namespace error_page {
21 
22 class LocalizedError {
23  public:
24   // Information about elements shown on the error page.
25   struct PageState {
26     PageState();
27     ~PageState();
28     PageState(const PageState& other) = delete;
29     PageState(PageState&& other);
30     PageState& operator=(PageState&& other);
31 
32     // Strings used within the error page HTML/JS.
33     base::DictionaryValue strings;
34 
35     bool is_offline_error = false;
36     bool reload_button_shown = false;
37     bool download_button_shown = false;
38     bool offline_content_feature_enabled = false;
39     bool auto_fetch_allowed = false;
40   };
41 
42   // Returns a |PageState| that describes the elements that should be shown on
43   // on HTTP errors, like 404 or connection reset.
44   static PageState GetPageState(
45       int error_code,
46       const std::string& error_domain,
47       const GURL& failed_url,
48       bool is_post,
49       bool is_secure_dns_network_error,
50       bool stale_copy_in_cache,
51       bool can_show_network_diagnostics_dialog,
52       bool is_incognito,
53       bool offline_content_feature_enabled,
54       bool auto_fetch_feature_enabled,
55       bool is_kiosk_mode,  // whether device is currently in single app (kiosk)
56                            // mode
57       const std::string& locale);
58 
59   // Returns a description of the encountered error.
60   static base::string16 GetErrorDetails(const std::string& error_domain,
61                                         int error_code,
62                                         bool is_secure_dns_network_error,
63                                         bool is_post);
64 
65   // Returns true if an error page exists for the specified parameters.
66   static bool HasStrings(const std::string& error_domain, int error_code);
67  private:
68 
69   DISALLOW_IMPLICIT_CONSTRUCTORS(LocalizedError);
70 };
71 
72 }  // namespace error_page
73 
74 #endif  // COMPONENTS_ERROR_PAGE_COMMON_LOCALIZED_ERROR_H_
75