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