Durable Storage: Refactor browser test and test the basic "deny" flow.
[chromium-blink-merge.git] / extensions / browser / extension_error.h
blob9f331681136a759910527d551291c0e0034d746b
1 // Copyright 2013 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.
5 #ifndef EXTENSIONS_BROWSER_EXTENSION_ERROR_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_ERROR_H_
8 #include <string>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/logging.h"
13 #include "base/strings/string16.h"
14 #include "extensions/common/stack_frame.h"
15 #include "url/gurl.h"
17 namespace extensions {
19 class ExtensionError {
20 public:
21 enum Type {
22 MANIFEST_ERROR = 0,
23 RUNTIME_ERROR,
24 INTERNAL_ERROR,
25 NUM_ERROR_TYPES, // Put new values above this.
28 virtual ~ExtensionError();
30 virtual std::string GetDebugString() const;
32 // Return true if this error and |rhs| are considered equal, and should be
33 // grouped together.
34 bool IsEqual(const ExtensionError* rhs) const;
36 Type type() const { return type_; }
37 const std::string& extension_id() const { return extension_id_; }
38 int id() const { return id_; }
39 void set_id(int id) { id_ = id; }
40 bool from_incognito() const { return from_incognito_; }
41 logging::LogSeverity level() const { return level_; }
42 const base::string16& source() const { return source_; }
43 const base::string16& message() const { return message_; }
44 size_t occurrences() const { return occurrences_; }
45 void set_occurrences(size_t occurrences) { occurrences_ = occurrences; }
47 protected:
48 ExtensionError(Type type,
49 const std::string& extension_id,
50 bool from_incognito,
51 logging::LogSeverity level,
52 const base::string16& source,
53 const base::string16& message);
55 virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0;
57 // Which type of error this is.
58 Type type_;
59 // The ID of the extension which caused the error.
60 std::string extension_id_;
61 // The id of this particular error. This can be zero if the id is never set.
62 int id_;
63 // Whether or not the error was caused while incognito.
64 bool from_incognito_;
65 // The severity level of the error.
66 logging::LogSeverity level_;
67 // The source for the error; this can be a script, web page, or manifest file.
68 // This is stored as a string (rather than a url) since it can be a Chrome
69 // script file (e.g., event_bindings.js).
70 base::string16 source_;
71 // The error message itself.
72 base::string16 message_;
73 // The number of times this error has occurred.
74 size_t occurrences_;
76 private:
77 DISALLOW_COPY_AND_ASSIGN(ExtensionError);
80 class ManifestError : public ExtensionError {
81 public:
82 ManifestError(const std::string& extension_id,
83 const base::string16& message,
84 const base::string16& manifest_key,
85 const base::string16& manifest_specific);
86 ~ManifestError() override;
88 std::string GetDebugString() const override;
90 const base::string16& manifest_key() const { return manifest_key_; }
91 const base::string16& manifest_specific() const { return manifest_specific_; }
93 private:
94 bool IsEqualImpl(const ExtensionError* rhs) const override;
96 // If present, this indicates the feature in the manifest which caused the
97 // error.
98 base::string16 manifest_key_;
99 // If present, this is a more-specific location of the error - for instance,
100 // a specific permission which is incorrect, rather than simply "permissions".
101 base::string16 manifest_specific_;
103 DISALLOW_COPY_AND_ASSIGN(ManifestError);
106 class RuntimeError : public ExtensionError {
107 public:
108 RuntimeError(const std::string& extension_id, // optional, sometimes unknown.
109 bool from_incognito,
110 const base::string16& source,
111 const base::string16& message,
112 const StackTrace& stack_trace,
113 const GURL& context_url,
114 logging::LogSeverity level,
115 int render_view_id,
116 int render_process_id);
117 ~RuntimeError() override;
119 std::string GetDebugString() const override;
121 const GURL& context_url() const { return context_url_; }
122 const StackTrace& stack_trace() const { return stack_trace_; }
123 int render_frame_id() const { return render_frame_id_; }
124 int render_process_id() const { return render_process_id_; }
126 private:
127 bool IsEqualImpl(const ExtensionError* rhs) const override;
129 // Since we piggy-back onto other error reporting systems (like V8 and
130 // WebKit), the reported information may need to be cleaned up in order to be
131 // in a consistent format.
132 void CleanUpInit();
134 GURL context_url_;
135 StackTrace stack_trace_;
137 // Keep track of the render process which caused the error in order to
138 // inspect the frame later, if possible.
139 int render_frame_id_;
140 int render_process_id_;
142 DISALLOW_COPY_AND_ASSIGN(RuntimeError);
145 class InternalError : public ExtensionError {
146 public:
147 InternalError(const std::string& extension_id,
148 const base::string16& message,
149 logging::LogSeverity level);
150 ~InternalError() override;
152 std::string GetDebugString() const override;
154 private:
155 bool IsEqualImpl(const ExtensionError* rhs) const override;
157 DISALLOW_COPY_AND_ASSIGN(InternalError);
160 } // namespace extensions
162 #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_