Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / extensions / browser / extension_error.h
blob7628f7e353995bc0d0eba74f78eb320ba56fc44d
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/memory/scoped_ptr.h"
14 #include "base/strings/string16.h"
15 #include "extensions/common/stack_frame.h"
16 #include "url/gurl.h"
18 namespace base {
19 class DictionaryValue;
22 namespace extensions {
24 class ExtensionError {
25 public:
26 enum Type {
27 MANIFEST_ERROR = 0,
28 RUNTIME_ERROR,
29 NUM_ERROR_TYPES, // Put new values above this.
32 virtual ~ExtensionError();
34 // Serializes the ExtensionError into JSON format.
35 virtual scoped_ptr<base::DictionaryValue> ToValue() const;
37 virtual std::string PrintForTest() const;
39 // Return true if this error and |rhs| are considered equal, and should be
40 // grouped together.
41 bool IsEqual(const ExtensionError* rhs) const;
43 Type type() const { return type_; }
44 const std::string& extension_id() const { return extension_id_; }
45 int id() const { return id_; }
46 void set_id(int id) { id_ = id; }
47 bool from_incognito() const { return from_incognito_; }
48 logging::LogSeverity level() const { return level_; }
49 const base::string16& source() const { return source_; }
50 const base::string16& message() const { return message_; }
51 size_t occurrences() const { return occurrences_; }
52 void set_occurrences(size_t occurrences) { occurrences_ = occurrences; }
54 // Keys used for retrieving JSON values.
55 static const char kExtensionIdKey[];
56 static const char kFromIncognitoKey[];
57 static const char kLevelKey[];
58 static const char kMessageKey[];
59 static const char kSourceKey[];
60 static const char kTypeKey[];
62 protected:
63 ExtensionError(Type type,
64 const std::string& extension_id,
65 bool from_incognito,
66 logging::LogSeverity level,
67 const base::string16& source,
68 const base::string16& message);
70 virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0;
72 // Which type of error this is.
73 Type type_;
74 // The ID of the extension which caused the error.
75 std::string extension_id_;
76 // The id of this particular error. This can be zero if the id is never set.
77 int id_;
78 // Whether or not the error was caused while incognito.
79 bool from_incognito_;
80 // The severity level of the error.
81 logging::LogSeverity level_;
82 // The source for the error; this can be a script, web page, or manifest file.
83 // This is stored as a string (rather than a url) since it can be a Chrome
84 // script file (e.g., event_bindings.js).
85 base::string16 source_;
86 // The error message itself.
87 base::string16 message_;
88 // The number of times this error has occurred.
89 size_t occurrences_;
91 private:
92 DISALLOW_COPY_AND_ASSIGN(ExtensionError);
95 class ManifestError : public ExtensionError {
96 public:
97 ManifestError(const std::string& extension_id,
98 const base::string16& message,
99 const base::string16& manifest_key,
100 const base::string16& manifest_specific);
101 ~ManifestError() override;
103 scoped_ptr<base::DictionaryValue> ToValue() const override;
105 std::string PrintForTest() const override;
107 const base::string16& manifest_key() const { return manifest_key_; }
108 const base::string16& manifest_specific() const { return manifest_specific_; }
110 // Keys used for retrieving JSON values.
111 static const char kManifestKeyKey[];
112 static const char kManifestSpecificKey[];
114 private:
115 bool IsEqualImpl(const ExtensionError* rhs) const override;
117 // If present, this indicates the feature in the manifest which caused the
118 // error.
119 base::string16 manifest_key_;
120 // If present, this is a more-specific location of the error - for instance,
121 // a specific permission which is incorrect, rather than simply "permissions".
122 base::string16 manifest_specific_;
124 DISALLOW_COPY_AND_ASSIGN(ManifestError);
127 class RuntimeError : public ExtensionError {
128 public:
129 RuntimeError(const std::string& extension_id, // optional, sometimes unknown.
130 bool from_incognito,
131 const base::string16& source,
132 const base::string16& message,
133 const StackTrace& stack_trace,
134 const GURL& context_url,
135 logging::LogSeverity level,
136 int render_view_id,
137 int render_process_id);
138 ~RuntimeError() override;
140 scoped_ptr<base::DictionaryValue> ToValue() const override;
142 std::string PrintForTest() const override;
144 const GURL& context_url() const { return context_url_; }
145 const StackTrace& stack_trace() const { return stack_trace_; }
146 int render_view_id() const { return render_view_id_; }
147 int render_process_id() const { return render_process_id_; }
149 // Keys used for retrieving JSON values.
150 static const char kColumnNumberKey[];
151 static const char kContextUrlKey[];
152 static const char kFunctionNameKey[];
153 static const char kLineNumberKey[];
154 static const char kStackTraceKey[];
155 static const char kUrlKey[];
156 static const char kRenderProcessIdKey[];
157 static const char kRenderViewIdKey[];
159 private:
160 bool IsEqualImpl(const ExtensionError* rhs) const override;
162 // Since we piggy-back onto other error reporting systems (like V8 and
163 // WebKit), the reported information may need to be cleaned up in order to be
164 // in a consistent format.
165 void CleanUpInit();
167 GURL context_url_;
168 StackTrace stack_trace_;
170 // Keep track of the render process which caused the error in order to
171 // inspect the view later, if possible.
172 int render_view_id_;
173 int render_process_id_;
175 DISALLOW_COPY_AND_ASSIGN(RuntimeError);
178 } // namespace extensions
180 #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_