[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" |
| 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 | |
| 17 | namespace extensions { |
| 18 | |
| 19 | class ExtensionError { |
| 20 | public: |
| 21 | enum Type { |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 22 | MANIFEST_ERROR, |
| 23 | RUNTIME_ERROR |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | virtual ~ExtensionError(); |
| 27 | |
| 28 | virtual std::string PrintForTest() const; |
| 29 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 30 | // Return true if this error and |rhs| are considered equal, and should be |
| 31 | // grouped together. |
| 32 | bool IsEqual(const ExtensionError* rhs) const; |
| 33 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 34 | Type type() const { return type_; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 35 | const std::string& extension_id() const { return extension_id_; } |
| 36 | bool from_incognito() const { return from_incognito_; } |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 37 | logging::LogSeverity level() const { return level_; } |
| 38 | const base::string16& source() const { return source_; } |
| 39 | const base::string16& message() const { return message_; } |
| 40 | size_t occurrences() const { return occurrences_; } |
| 41 | void set_occurrences(size_t occurrences) { occurrences_ = occurrences; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 42 | |
| 43 | protected: |
| 44 | ExtensionError(Type type, |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 45 | const std::string& extension_id, |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 46 | bool from_incognito, |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 47 | logging::LogSeverity level, |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 48 | const base::string16& source, |
| 49 | const base::string16& message); |
| 50 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 51 | virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0; |
| 52 | |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 53 | // Which type of error this is. |
| 54 | Type type_; |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 55 | // The ID of the extension which caused the error. |
| 56 | std::string extension_id_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 57 | // Whether or not the error was caused while incognito. |
| 58 | bool from_incognito_; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 59 | // The severity level of the error. |
| 60 | logging::LogSeverity level_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 61 | // The source for the error; this can be a script, web page, or manifest file. |
| 62 | // This is stored as a string (rather than a url) since it can be a Chrome |
| 63 | // script file (e.g., event_bindings.js). |
| 64 | base::string16 source_; |
| 65 | // The error message itself. |
| 66 | base::string16 message_; |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 67 | // The number of times this error has occurred. |
| 68 | size_t occurrences_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 69 | |
| 70 | DISALLOW_COPY_AND_ASSIGN(ExtensionError); |
| 71 | }; |
| 72 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 73 | class ManifestError : public ExtensionError { |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 74 | public: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 75 | ManifestError(const std::string& extension_id, |
| 76 | const base::string16& message); |
| 77 | virtual ~ManifestError(); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 78 | |
| 79 | virtual std::string PrintForTest() const OVERRIDE; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 80 | private: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 81 | virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE; |
| 82 | |
| 83 | DISALLOW_COPY_AND_ASSIGN(ManifestError); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 84 | }; |
| 85 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 86 | class RuntimeError : public ExtensionError { |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 87 | public: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 88 | RuntimeError(bool from_incognito, |
| 89 | const base::string16& source, |
| 90 | const base::string16& message, |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame^] | 91 | const StackTrace& stack_trace, |
| 92 | const GURL& context_url, |
| 93 | logging::LogSeverity level); |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 94 | virtual ~RuntimeError(); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 95 | |
| 96 | virtual std::string PrintForTest() const OVERRIDE; |
| 97 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame^] | 98 | const GURL& context_url() const { return context_url_; } |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 99 | const StackTrace& stack_trace() const { return stack_trace_; } |
| 100 | private: |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 101 | virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE; |
| 102 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame^] | 103 | // Since we piggy-back onto other error reporting systems (like V8 and |
| 104 | // WebKit), the reported information may need to be cleaned up in order to be |
| 105 | // in a consistent format. |
| 106 | void CleanUpInit(); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 107 | |
[email protected] | 88b50b6 | 2013-09-01 23:05:06 | [diff] [blame^] | 108 | GURL context_url_; |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 109 | StackTrace stack_trace_; |
| 110 | |
[email protected] | d466f78 | 2013-08-28 21:59:23 | [diff] [blame] | 111 | DISALLOW_COPY_AND_ASSIGN(RuntimeError); |
[email protected] | 1b66fdb | 2013-07-26 09:57:28 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } // namespace extensions |
| 115 | |
[email protected] | 921237d06 | 2013-08-10 15:30:49 | [diff] [blame] | 116 | #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |