[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 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. |
| 4 | |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 5 | #ifndef EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |
| 6 | #define EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 7 | |
avi | c9cec10 | 2015-12-23 00:39:26 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
| 13 | #include "base/compiler_specific.h" |
| 14 | #include "base/logging.h" |
avi | c9cec10 | 2015-12-23 00:39:26 | [diff] [blame] | 15 | #include "base/macros.h" |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 16 | #include "base/strings/string16.h" |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 17 | #include "extensions/common/stack_frame.h" |
| 18 | #include "url/gurl.h" |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 19 | |
| 20 | namespace extensions { |
| 21 | |
| 22 | class ExtensionError { |
| 23 | public: |
| 24 | enum Type { |
rdevlin.cronin | c799f9f | 2015-03-21 00:56:30 | [diff] [blame] | 25 | MANIFEST_ERROR = 0, |
[email protected] | 7a755d1 | 2014-04-18 18:54:55 | [diff] [blame] | 26 | RUNTIME_ERROR, |
wittman | b3ee048 | 2015-06-24 17:47:40 | [diff] [blame] | 27 | INTERNAL_ERROR, |
rdevlin.cronin | c799f9f | 2015-03-21 00:56:30 | [diff] [blame] | 28 | NUM_ERROR_TYPES, // Put new values above this. |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | virtual ~ExtensionError(); |
| 32 | |
wittman | b3ee048 | 2015-06-24 17:47:40 | [diff] [blame] | 33 | virtual std::string GetDebugString() const; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 34 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 35 | // Return true if this error and |rhs| are considered equal, and should be |
| 36 | // grouped together. |
| 37 | bool IsEqual(const ExtensionError* rhs) const; |
| 38 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 39 | Type type() const { return type_; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 40 | const std::string& extension_id() const { return extension_id_; } |
rdevlin.cronin | c799f9f | 2015-03-21 00:56:30 | [diff] [blame] | 41 | int id() const { return id_; } |
| 42 | void set_id(int id) { id_ = id; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 43 | bool from_incognito() const { return from_incognito_; } |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 44 | logging::LogSeverity level() const { return level_; } |
| 45 | const base::string16& source() const { return source_; } |
| 46 | const base::string16& message() const { return message_; } |
| 47 | size_t occurrences() const { return occurrences_; } |
| 48 | void set_occurrences(size_t occurrences) { occurrences_ = occurrences; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 49 | |
| 50 | protected: |
| 51 | ExtensionError(Type type, |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 52 | const std::string& extension_id, |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 53 | bool from_incognito, |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 54 | logging::LogSeverity level, |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 55 | const base::string16& source, |
| 56 | const base::string16& message); |
| 57 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 58 | virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0; |
| 59 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 60 | // Which type of error this is. |
| 61 | Type type_; |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 62 | // The ID of the extension which caused the error. |
| 63 | std::string extension_id_; |
rdevlin.cronin | c799f9f | 2015-03-21 00:56:30 | [diff] [blame] | 64 | // The id of this particular error. This can be zero if the id is never set. |
| 65 | int id_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 66 | // Whether or not the error was caused while incognito. |
| 67 | bool from_incognito_; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 68 | // The severity level of the error. |
| 69 | logging::LogSeverity level_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 70 | // The source for the error; this can be a script, web page, or manifest file. |
| 71 | // This is stored as a string (rather than a url) since it can be a Chrome |
| 72 | // script file (e.g., event_bindings.js). |
| 73 | base::string16 source_; |
| 74 | // The error message itself. |
| 75 | base::string16 message_; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 76 | // The number of times this error has occurred. |
| 77 | size_t occurrences_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 78 | |
[email protected] | 2919a5e | 2014-04-24 08:34:05 | [diff] [blame] | 79 | private: |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 80 | DISALLOW_COPY_AND_ASSIGN(ExtensionError); |
| 81 | }; |
| 82 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 83 | class ManifestError : public ExtensionError { |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 84 | public: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 85 | ManifestError(const std::string& extension_id, |
[email protected] | b191e2d3 | 2013-09-03 21:08:30 | [diff] [blame] | 86 | const base::string16& message, |
| 87 | const base::string16& manifest_key, |
| 88 | const base::string16& manifest_specific); |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 89 | ~ManifestError() override; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 90 | |
wittman | b3ee048 | 2015-06-24 17:47:40 | [diff] [blame] | 91 | std::string GetDebugString() const override; |
[email protected] | b191e2d3 | 2013-09-03 21:08:30 | [diff] [blame] | 92 | |
| 93 | const base::string16& manifest_key() const { return manifest_key_; } |
| 94 | const base::string16& manifest_specific() const { return manifest_specific_; } |
[email protected] | fa5fed3 | 2013-09-05 21:56:22 | [diff] [blame] | 95 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 96 | private: |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 97 | bool IsEqualImpl(const ExtensionError* rhs) const override; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 98 | |
[email protected] | b191e2d3 | 2013-09-03 21:08:30 | [diff] [blame] | 99 | // If present, this indicates the feature in the manifest which caused the |
| 100 | // error. |
| 101 | base::string16 manifest_key_; |
| 102 | // If present, this is a more-specific location of the error - for instance, |
| 103 | // a specific permission which is incorrect, rather than simply "permissions". |
| 104 | base::string16 manifest_specific_; |
| 105 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 106 | DISALLOW_COPY_AND_ASSIGN(ManifestError); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 107 | }; |
| 108 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 109 | class RuntimeError : public ExtensionError { |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 110 | public: |
[email protected] | a0ed268 | 2013-09-06 08:41:07 | [diff] [blame] | 111 | RuntimeError(const std::string& extension_id, // optional, sometimes unknown. |
| 112 | bool from_incognito, |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 113 | const base::string16& source, |
| 114 | const base::string16& message, |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 115 | const StackTrace& stack_trace, |
| 116 | const GURL& context_url, |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 117 | logging::LogSeverity level, |
| 118 | int render_view_id, |
| 119 | int render_process_id); |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 120 | ~RuntimeError() override; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 121 | |
wittman | b3ee048 | 2015-06-24 17:47:40 | [diff] [blame] | 122 | std::string GetDebugString() const override; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 123 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 124 | const GURL& context_url() const { return context_url_; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 125 | const StackTrace& stack_trace() const { return stack_trace_; } |
rdevlin.cronin | 86f5b70 | 2015-06-24 18:49:17 | [diff] [blame] | 126 | int render_frame_id() const { return render_frame_id_; } |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 127 | int render_process_id() const { return render_process_id_; } |
[email protected] | 2fb9bd2 | 2013-09-07 00:08:08 | [diff] [blame] | 128 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 129 | private: |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 130 | bool IsEqualImpl(const ExtensionError* rhs) const override; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 131 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 132 | // Since we piggy-back onto other error reporting systems (like V8 and |
| 133 | // WebKit), the reported information may need to be cleaned up in order to be |
| 134 | // in a consistent format. |
| 135 | void CleanUpInit(); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 136 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 137 | GURL context_url_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 138 | StackTrace stack_trace_; |
| 139 | |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 140 | // Keep track of the render process which caused the error in order to |
rdevlin.cronin | 86f5b70 | 2015-06-24 18:49:17 | [diff] [blame] | 141 | // inspect the frame later, if possible. |
| 142 | int render_frame_id_; |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 143 | int render_process_id_; |
| 144 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 145 | DISALLOW_COPY_AND_ASSIGN(RuntimeError); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 146 | }; |
| 147 | |
wittman | b3ee048 | 2015-06-24 17:47:40 | [diff] [blame] | 148 | class InternalError : public ExtensionError { |
| 149 | public: |
| 150 | InternalError(const std::string& extension_id, |
| 151 | const base::string16& message, |
| 152 | logging::LogSeverity level); |
| 153 | ~InternalError() override; |
| 154 | |
| 155 | std::string GetDebugString() const override; |
| 156 | |
| 157 | private: |
| 158 | bool IsEqualImpl(const ExtensionError* rhs) const override; |
| 159 | |
| 160 | DISALLOW_COPY_AND_ASSIGN(InternalError); |
| 161 | }; |
| 162 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 163 | } // namespace extensions |
| 164 | |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 165 | #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |