Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / common / localized_error.h
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 CHROME_COMMON_LOCALIZED_ERROR_H_
6 #define CHROME_COMMON_LOCALIZED_ERROR_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h"
13 #include "url/gurl.h"
14
15 namespace base {
16 class DictionaryValue;
17 class ListValue;
18 }
19
20 namespace extensions {
21 class Extension;
22 }
23
24 namespace blink {
25 struct WebURLError;
26 }
27
28 class LocalizedError {
29  public:
30   // Optional parameters that affect the display of an error page.
31   struct ErrorPageParams {
32     ErrorPageParams();
33     ~ErrorPageParams();
34
35     // Overrides whether reloading is suggested.
36     bool suggest_reload;
37     int reload_tracking_id;
38
39     // Overrides default suggestions.  Each entry must contain a header and may
40     // optionally contain a body as well.  Must not be NULL.
41     scoped_ptr<base::ListValue> override_suggestions;
42
43     // Prefix to prepend to search terms.  Search box is only shown if this is
44     // a valid url.  The search terms will be appended to the end of this URL to
45     // conduct a search.
46     GURL search_url;
47     // Default search terms.  Ignored if |search_url| is invalid.
48     std::string search_terms;
49     int search_tracking_id;
50   };
51
52   // Fills |error_strings| with values to be used to build an error page used
53   // on HTTP errors, like 404 or connection reset.
54   static void GetStrings(int error_code,
55                          const std::string& error_domain,
56                          const GURL& failed_url,
57                          bool is_post,
58                          bool show_stale_load_button,
59                          const std::string& locale,
60                          const std::string& accept_languages,
61                          scoped_ptr<ErrorPageParams> params,
62                          base::DictionaryValue* strings);
63
64   // Returns a description of the encountered error.
65   static base::string16 GetErrorDetails(const blink::WebURLError& error,
66                                         bool is_post);
67
68   // Returns true if an error page exists for the specified parameters.
69   static bool HasStrings(const std::string& error_domain, int error_code);
70
71   // Fills |error_strings| with values to be used to build an error page used
72   // on HTTP errors, like 404 or connection reset, but using information from
73   // the associated |app| in order to make the error page look like it's more
74   // part of the app.
75   static void GetAppErrorStrings(const GURL& display_url,
76                                  const extensions::Extension* app,
77                                  base::DictionaryValue* error_strings);
78
79   static const char kHttpErrorDomain[];
80
81  private:
82   DISALLOW_IMPLICIT_CONSTRUCTORS(LocalizedError);
83 };
84
85 #endif  // CHROME_COMMON_LOCALIZED_ERROR_H_