blob: ea3c0827fefe17181b8f245eda1789902e51adb9 [file] [log] [blame]
[email protected]1b66fdb2013-07-26 09:57:281// 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.
4
[email protected]921237d062013-08-10 15:30:495#ifndef EXTENSIONS_BROWSER_EXTENSION_ERROR_H_
6#define EXTENSIONS_BROWSER_EXTENSION_ERROR_H_
[email protected]1b66fdb2013-07-26 09:57:287
8#include <string>
9#include <vector>
10
11#include "base/compiler_specific.h"
12#include "base/logging.h"
[email protected]fa5fed32013-09-05 21:56:2213#include "base/memory/scoped_ptr.h"
[email protected]1b66fdb2013-07-26 09:57:2814#include "base/strings/string16.h"
[email protected]88b50b62013-09-01 23:05:0615#include "extensions/common/stack_frame.h"
16#include "url/gurl.h"
[email protected]1b66fdb2013-07-26 09:57:2817
[email protected]fa5fed32013-09-05 21:56:2218namespace base {
19class DictionaryValue;
20}
21
[email protected]1b66fdb2013-07-26 09:57:2822namespace extensions {
23
24class ExtensionError {
25 public:
26 enum Type {
[email protected]d466f782013-08-28 21:59:2327 MANIFEST_ERROR,
[email protected]7a755d12014-04-18 18:54:5528 RUNTIME_ERROR,
29 NUM_ERROR_TYPES // Put new values above this.
[email protected]1b66fdb2013-07-26 09:57:2830 };
31
32 virtual ~ExtensionError();
33
[email protected]fa5fed32013-09-05 21:56:2234 // Serializes the ExtensionError into JSON format.
35 virtual scoped_ptr<base::DictionaryValue> ToValue() const;
36
[email protected]1b66fdb2013-07-26 09:57:2837 virtual std::string PrintForTest() const;
38
[email protected]d466f782013-08-28 21:59:2339 // Return true if this error and |rhs| are considered equal, and should be
40 // grouped together.
41 bool IsEqual(const ExtensionError* rhs) const;
42
[email protected]1b66fdb2013-07-26 09:57:2843 Type type() const { return type_; }
[email protected]1b66fdb2013-07-26 09:57:2844 const std::string& extension_id() const { return extension_id_; }
45 bool from_incognito() const { return from_incognito_; }
[email protected]d466f782013-08-28 21:59:2346 logging::LogSeverity level() const { return level_; }
47 const base::string16& source() const { return source_; }
48 const base::string16& message() const { return message_; }
49 size_t occurrences() const { return occurrences_; }
50 void set_occurrences(size_t occurrences) { occurrences_ = occurrences; }
[email protected]1b66fdb2013-07-26 09:57:2851
[email protected]fa5fed32013-09-05 21:56:2252 // Keys used for retrieving JSON values.
53 static const char kExtensionIdKey[];
54 static const char kFromIncognitoKey[];
55 static const char kLevelKey[];
56 static const char kMessageKey[];
57 static const char kSourceKey[];
58 static const char kTypeKey[];
59
[email protected]1b66fdb2013-07-26 09:57:2860 protected:
61 ExtensionError(Type type,
[email protected]921237d062013-08-10 15:30:4962 const std::string& extension_id,
[email protected]1b66fdb2013-07-26 09:57:2863 bool from_incognito,
[email protected]d466f782013-08-28 21:59:2364 logging::LogSeverity level,
[email protected]1b66fdb2013-07-26 09:57:2865 const base::string16& source,
66 const base::string16& message);
67
[email protected]d466f782013-08-28 21:59:2368 virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0;
69
[email protected]1b66fdb2013-07-26 09:57:2870 // Which type of error this is.
71 Type type_;
[email protected]921237d062013-08-10 15:30:4972 // The ID of the extension which caused the error.
73 std::string extension_id_;
[email protected]1b66fdb2013-07-26 09:57:2874 // Whether or not the error was caused while incognito.
75 bool from_incognito_;
[email protected]d466f782013-08-28 21:59:2376 // The severity level of the error.
77 logging::LogSeverity level_;
[email protected]1b66fdb2013-07-26 09:57:2878 // The source for the error; this can be a script, web page, or manifest file.
79 // This is stored as a string (rather than a url) since it can be a Chrome
80 // script file (e.g., event_bindings.js).
81 base::string16 source_;
82 // The error message itself.
83 base::string16 message_;
[email protected]d466f782013-08-28 21:59:2384 // The number of times this error has occurred.
85 size_t occurrences_;
[email protected]1b66fdb2013-07-26 09:57:2886
[email protected]2919a5e2014-04-24 08:34:0587 private:
[email protected]1b66fdb2013-07-26 09:57:2888 DISALLOW_COPY_AND_ASSIGN(ExtensionError);
89};
90
[email protected]d466f782013-08-28 21:59:2391class ManifestError : public ExtensionError {
[email protected]1b66fdb2013-07-26 09:57:2892 public:
[email protected]d466f782013-08-28 21:59:2393 ManifestError(const std::string& extension_id,
[email protected]b191e2d32013-09-03 21:08:3094 const base::string16& message,
95 const base::string16& manifest_key,
96 const base::string16& manifest_specific);
[email protected]d466f782013-08-28 21:59:2397 virtual ~ManifestError();
[email protected]1b66fdb2013-07-26 09:57:2898
[email protected]fa5fed32013-09-05 21:56:2299 virtual scoped_ptr<base::DictionaryValue> ToValue() const OVERRIDE;
100
[email protected]1b66fdb2013-07-26 09:57:28101 virtual std::string PrintForTest() const OVERRIDE;
[email protected]b191e2d32013-09-03 21:08:30102
103 const base::string16& manifest_key() const { return manifest_key_; }
104 const base::string16& manifest_specific() const { return manifest_specific_; }
[email protected]fa5fed32013-09-05 21:56:22105
106 // Keys used for retrieving JSON values.
107 static const char kManifestKeyKey[];
108 static const char kManifestSpecificKey[];
109
[email protected]1b66fdb2013-07-26 09:57:28110 private:
[email protected]d466f782013-08-28 21:59:23111 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE;
112
[email protected]b191e2d32013-09-03 21:08:30113 // If present, this indicates the feature in the manifest which caused the
114 // error.
115 base::string16 manifest_key_;
116 // If present, this is a more-specific location of the error - for instance,
117 // a specific permission which is incorrect, rather than simply "permissions".
118 base::string16 manifest_specific_;
119
[email protected]d466f782013-08-28 21:59:23120 DISALLOW_COPY_AND_ASSIGN(ManifestError);
[email protected]1b66fdb2013-07-26 09:57:28121};
122
[email protected]d466f782013-08-28 21:59:23123class RuntimeError : public ExtensionError {
[email protected]1b66fdb2013-07-26 09:57:28124 public:
[email protected]a0ed2682013-09-06 08:41:07125 RuntimeError(const std::string& extension_id, // optional, sometimes unknown.
126 bool from_incognito,
[email protected]d466f782013-08-28 21:59:23127 const base::string16& source,
128 const base::string16& message,
[email protected]88b50b62013-09-01 23:05:06129 const StackTrace& stack_trace,
130 const GURL& context_url,
[email protected]c934c382013-11-01 00:36:01131 logging::LogSeverity level,
132 int render_view_id,
133 int render_process_id);
[email protected]d466f782013-08-28 21:59:23134 virtual ~RuntimeError();
[email protected]1b66fdb2013-07-26 09:57:28135
[email protected]2fb9bd22013-09-07 00:08:08136 virtual scoped_ptr<base::DictionaryValue> ToValue() const OVERRIDE;
137
[email protected]1b66fdb2013-07-26 09:57:28138 virtual std::string PrintForTest() const OVERRIDE;
139
[email protected]88b50b62013-09-01 23:05:06140 const GURL& context_url() const { return context_url_; }
[email protected]1b66fdb2013-07-26 09:57:28141 const StackTrace& stack_trace() const { return stack_trace_; }
[email protected]c934c382013-11-01 00:36:01142 int render_view_id() const { return render_view_id_; }
143 int render_process_id() const { return render_process_id_; }
[email protected]2fb9bd22013-09-07 00:08:08144
145 // Keys used for retrieving JSON values.
146 static const char kColumnNumberKey[];
147 static const char kContextUrlKey[];
148 static const char kFunctionNameKey[];
149 static const char kLineNumberKey[];
150 static const char kStackTraceKey[];
151 static const char kUrlKey[];
[email protected]c934c382013-11-01 00:36:01152 static const char kRenderProcessIdKey[];
153 static const char kRenderViewIdKey[];
[email protected]2fb9bd22013-09-07 00:08:08154
[email protected]1b66fdb2013-07-26 09:57:28155 private:
[email protected]d466f782013-08-28 21:59:23156 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE;
157
[email protected]88b50b62013-09-01 23:05:06158 // Since we piggy-back onto other error reporting systems (like V8 and
159 // WebKit), the reported information may need to be cleaned up in order to be
160 // in a consistent format.
161 void CleanUpInit();
[email protected]1b66fdb2013-07-26 09:57:28162
[email protected]88b50b62013-09-01 23:05:06163 GURL context_url_;
[email protected]1b66fdb2013-07-26 09:57:28164 StackTrace stack_trace_;
165
[email protected]c934c382013-11-01 00:36:01166 // Keep track of the render process which caused the error in order to
167 // inspect the view later, if possible.
168 int render_view_id_;
169 int render_process_id_;
170
[email protected]d466f782013-08-28 21:59:23171 DISALLOW_COPY_AND_ASSIGN(RuntimeError);
[email protected]1b66fdb2013-07-26 09:57:28172};
173
174} // namespace extensions
175
[email protected]921237d062013-08-10 15:30:49176#endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_