[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 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/compiler_specific.h" |
| 12 | #include "base/logging.h" |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 13 | #include "base/strings/string16.h" |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 14 | #include "extensions/common/stack_frame.h" |
| 15 | #include "url/gurl.h" |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 16 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 17 | namespace extensions { |
| 18 | |
| 19 | class ExtensionError { |
| 20 | public: |
| 21 | enum Type { |
rdevlin.cronin | c799f9f | 2015-03-21 00:56:30 | [diff] [blame] | 22 | MANIFEST_ERROR = 0, |
[email protected] | 7a755d1 | 2014-04-18 18:54:55 | [diff] [blame] | 23 | RUNTIME_ERROR, |
wittman | b3ee048 | 2015-06-24 17:47:40 | [diff] [blame] | 24 | INTERNAL_ERROR, |
rdevlin.cronin | c799f9f | 2015-03-21 00:56:30 | [diff] [blame] | 25 | NUM_ERROR_TYPES, // Put new values above this. |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | virtual ~ExtensionError(); |
| 29 | |
wittman | b3ee048 | 2015-06-24 17:47:40 | [diff] [blame] | 30 | virtual std::string GetDebugString() const; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 31 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 32 | // Return true if this error and |rhs| are considered equal, and should be |
| 33 | // grouped together. |
| 34 | bool IsEqual(const ExtensionError* rhs) const; |
| 35 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 36 | Type type() const { return type_; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 37 | const std::string& extension_id() const { return extension_id_; } |
rdevlin.cronin | c799f9f | 2015-03-21 00:56:30 | [diff] [blame] | 38 | int id() const { return id_; } |
| 39 | void set_id(int id) { id_ = id; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 40 | bool from_incognito() const { return from_incognito_; } |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 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; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 46 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 47 | protected: |
| 48 | ExtensionError(Type type, |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 49 | const std::string& extension_id, |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 50 | bool from_incognito, |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 51 | logging::LogSeverity level, |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 52 | const base::string16& source, |
| 53 | const base::string16& message); |
| 54 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 55 | virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0; |
| 56 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 57 | // Which type of error this is. |
| 58 | Type type_; |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 59 | // The ID of the extension which caused the error. |
| 60 | std::string extension_id_; |
rdevlin.cronin | c799f9f | 2015-03-21 00:56:30 | [diff] [blame] | 61 | // The id of this particular error. This can be zero if the id is never set. |
| 62 | int id_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 63 | // Whether or not the error was caused while incognito. |
| 64 | bool from_incognito_; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 65 | // The severity level of the error. |
| 66 | logging::LogSeverity level_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 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_; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 73 | // The number of times this error has occurred. |
| 74 | size_t occurrences_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 75 | |
[email protected] | 2919a5e | 2014-04-24 08:34:05 | [diff] [blame] | 76 | private: |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 77 | DISALLOW_COPY_AND_ASSIGN(ExtensionError); |
| 78 | }; |
| 79 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 80 | class ManifestError : public ExtensionError { |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 81 | public: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 82 | ManifestError(const std::string& extension_id, |
[email protected] | b191e2d3 | 2013-09-03 21:08:30 | [diff] [blame] | 83 | const base::string16& message, |
| 84 | const base::string16& manifest_key, |
| 85 | const base::string16& manifest_specific); |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 86 | ~ManifestError() override; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 87 | |
wittman | b3ee048 | 2015-06-24 17:47:40 | [diff] [blame] | 88 | std::string GetDebugString() const override; |
[email protected] | b191e2d3 | 2013-09-03 21:08:30 | [diff] [blame] | 89 | |
| 90 | const base::string16& manifest_key() const { return manifest_key_; } |
| 91 | const base::string16& manifest_specific() const { return manifest_specific_; } |
[email protected] | fa5fed3 | 2013-09-05 21:56:22 | [diff] [blame] | 92 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 93 | private: |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 94 | bool IsEqualImpl(const ExtensionError* rhs) const override; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 95 | |
[email protected] | b191e2d3 | 2013-09-03 21:08:30 | [diff] [blame] | 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_; |
| 102 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 103 | DISALLOW_COPY_AND_ASSIGN(ManifestError); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 104 | }; |
| 105 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 106 | class RuntimeError : public ExtensionError { |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 107 | public: |
[email protected] | a0ed268 | 2013-09-06 08:41:07 | [diff] [blame] | 108 | RuntimeError(const std::string& extension_id, // optional, sometimes unknown. |
| 109 | bool from_incognito, |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 110 | const base::string16& source, |
| 111 | const base::string16& message, |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 112 | const StackTrace& stack_trace, |
| 113 | const GURL& context_url, |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 114 | logging::LogSeverity level, |
| 115 | int render_view_id, |
| 116 | int render_process_id); |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 117 | ~RuntimeError() override; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 118 | |
wittman | b3ee048 | 2015-06-24 17:47:40 | [diff] [blame] | 119 | std::string GetDebugString() const override; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 120 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 121 | const GURL& context_url() const { return context_url_; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 122 | const StackTrace& stack_trace() const { return stack_trace_; } |
rdevlin.cronin | 86f5b70 | 2015-06-24 18:49:17 | [diff] [blame^] | 123 | int render_frame_id() const { return render_frame_id_; } |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 124 | int render_process_id() const { return render_process_id_; } |
[email protected] | 2fb9bd2 | 2013-09-07 00:08:08 | [diff] [blame] | 125 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 126 | private: |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 127 | bool IsEqualImpl(const ExtensionError* rhs) const override; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 128 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 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(); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 133 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame] | 134 | GURL context_url_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 135 | StackTrace stack_trace_; |
| 136 | |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 137 | // Keep track of the render process which caused the error in order to |
rdevlin.cronin | 86f5b70 | 2015-06-24 18:49:17 | [diff] [blame^] | 138 | // inspect the frame later, if possible. |
| 139 | int render_frame_id_; |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 140 | int render_process_id_; |
| 141 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 142 | DISALLOW_COPY_AND_ASSIGN(RuntimeError); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 143 | }; |
| 144 | |
wittman | b3ee048 | 2015-06-24 17:47:40 | [diff] [blame] | 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; |
| 151 | |
| 152 | std::string GetDebugString() const override; |
| 153 | |
| 154 | private: |
| 155 | bool IsEqualImpl(const ExtensionError* rhs) const override; |
| 156 | |
| 157 | DISALLOW_COPY_AND_ASSIGN(InternalError); |
| 158 | }; |
| 159 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 160 | } // namespace extensions |
| 161 | |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 162 | #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |