blob: 7caa95cddd558fcddf88d0c05ebff311fc3de0b8 [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
avic9cec102015-12-23 00:39:268#include <stddef.h>
9
[email protected]1b66fdb2013-07-26 09:57:2810#include <string>
11#include <vector>
12
13#include "base/compiler_specific.h"
14#include "base/logging.h"
avic9cec102015-12-23 00:39:2615#include "base/macros.h"
[email protected]1b66fdb2013-07-26 09:57:2816#include "base/strings/string16.h"
[email protected]88b50b62013-09-01 23:05:0617#include "extensions/common/stack_frame.h"
18#include "url/gurl.h"
[email protected]1b66fdb2013-07-26 09:57:2819
20namespace extensions {
21
22class ExtensionError {
23 public:
24 enum Type {
rdevlin.croninc799f9f2015-03-21 00:56:3025 MANIFEST_ERROR = 0,
[email protected]7a755d12014-04-18 18:54:5526 RUNTIME_ERROR,
wittmanb3ee0482015-06-24 17:47:4027 INTERNAL_ERROR,
rdevlin.croninc799f9f2015-03-21 00:56:3028 NUM_ERROR_TYPES, // Put new values above this.
[email protected]1b66fdb2013-07-26 09:57:2829 };
30
31 virtual ~ExtensionError();
32
wittmanb3ee0482015-06-24 17:47:4033 virtual std::string GetDebugString() const;
[email protected]1b66fdb2013-07-26 09:57:2834
[email protected]d466f782013-08-28 21:59:2335 // 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]1b66fdb2013-07-26 09:57:2839 Type type() const { return type_; }
[email protected]1b66fdb2013-07-26 09:57:2840 const std::string& extension_id() const { return extension_id_; }
rdevlin.croninc799f9f2015-03-21 00:56:3041 int id() const { return id_; }
42 void set_id(int id) { id_ = id; }
[email protected]1b66fdb2013-07-26 09:57:2843 bool from_incognito() const { return from_incognito_; }
[email protected]d466f782013-08-28 21:59:2344 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]1b66fdb2013-07-26 09:57:2849
50 protected:
51 ExtensionError(Type type,
[email protected]921237d062013-08-10 15:30:4952 const std::string& extension_id,
[email protected]1b66fdb2013-07-26 09:57:2853 bool from_incognito,
[email protected]d466f782013-08-28 21:59:2354 logging::LogSeverity level,
[email protected]1b66fdb2013-07-26 09:57:2855 const base::string16& source,
56 const base::string16& message);
57
[email protected]d466f782013-08-28 21:59:2358 virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0;
59
[email protected]1b66fdb2013-07-26 09:57:2860 // Which type of error this is.
61 Type type_;
[email protected]921237d062013-08-10 15:30:4962 // The ID of the extension which caused the error.
63 std::string extension_id_;
rdevlin.croninc799f9f2015-03-21 00:56:3064 // The id of this particular error. This can be zero if the id is never set.
65 int id_;
[email protected]1b66fdb2013-07-26 09:57:2866 // Whether or not the error was caused while incognito.
67 bool from_incognito_;
[email protected]d466f782013-08-28 21:59:2368 // The severity level of the error.
69 logging::LogSeverity level_;
[email protected]1b66fdb2013-07-26 09:57:2870 // 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]d466f782013-08-28 21:59:2376 // The number of times this error has occurred.
77 size_t occurrences_;
[email protected]1b66fdb2013-07-26 09:57:2878
[email protected]2919a5e2014-04-24 08:34:0579 private:
[email protected]1b66fdb2013-07-26 09:57:2880 DISALLOW_COPY_AND_ASSIGN(ExtensionError);
81};
82
[email protected]d466f782013-08-28 21:59:2383class ManifestError : public ExtensionError {
[email protected]1b66fdb2013-07-26 09:57:2884 public:
[email protected]d466f782013-08-28 21:59:2385 ManifestError(const std::string& extension_id,
[email protected]b191e2d32013-09-03 21:08:3086 const base::string16& message,
87 const base::string16& manifest_key,
88 const base::string16& manifest_specific);
dcheng9168b2f2014-10-21 12:38:2489 ~ManifestError() override;
[email protected]1b66fdb2013-07-26 09:57:2890
wittmanb3ee0482015-06-24 17:47:4091 std::string GetDebugString() const override;
[email protected]b191e2d32013-09-03 21:08:3092
93 const base::string16& manifest_key() const { return manifest_key_; }
94 const base::string16& manifest_specific() const { return manifest_specific_; }
[email protected]fa5fed32013-09-05 21:56:2295
[email protected]1b66fdb2013-07-26 09:57:2896 private:
dcheng9168b2f2014-10-21 12:38:2497 bool IsEqualImpl(const ExtensionError* rhs) const override;
[email protected]d466f782013-08-28 21:59:2398
[email protected]b191e2d32013-09-03 21:08:3099 // 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]d466f782013-08-28 21:59:23106 DISALLOW_COPY_AND_ASSIGN(ManifestError);
[email protected]1b66fdb2013-07-26 09:57:28107};
108
[email protected]d466f782013-08-28 21:59:23109class RuntimeError : public ExtensionError {
[email protected]1b66fdb2013-07-26 09:57:28110 public:
[email protected]a0ed2682013-09-06 08:41:07111 RuntimeError(const std::string& extension_id, // optional, sometimes unknown.
112 bool from_incognito,
[email protected]d466f782013-08-28 21:59:23113 const base::string16& source,
114 const base::string16& message,
[email protected]88b50b62013-09-01 23:05:06115 const StackTrace& stack_trace,
116 const GURL& context_url,
[email protected]c934c382013-11-01 00:36:01117 logging::LogSeverity level,
118 int render_view_id,
119 int render_process_id);
dcheng9168b2f2014-10-21 12:38:24120 ~RuntimeError() override;
[email protected]1b66fdb2013-07-26 09:57:28121
wittmanb3ee0482015-06-24 17:47:40122 std::string GetDebugString() const override;
[email protected]1b66fdb2013-07-26 09:57:28123
[email protected]88b50b62013-09-01 23:05:06124 const GURL& context_url() const { return context_url_; }
[email protected]1b66fdb2013-07-26 09:57:28125 const StackTrace& stack_trace() const { return stack_trace_; }
rdevlin.cronin86f5b702015-06-24 18:49:17126 int render_frame_id() const { return render_frame_id_; }
[email protected]c934c382013-11-01 00:36:01127 int render_process_id() const { return render_process_id_; }
[email protected]2fb9bd22013-09-07 00:08:08128
[email protected]1b66fdb2013-07-26 09:57:28129 private:
dcheng9168b2f2014-10-21 12:38:24130 bool IsEqualImpl(const ExtensionError* rhs) const override;
[email protected]d466f782013-08-28 21:59:23131
[email protected]88b50b62013-09-01 23:05:06132 // 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]1b66fdb2013-07-26 09:57:28136
[email protected]88b50b62013-09-01 23:05:06137 GURL context_url_;
[email protected]1b66fdb2013-07-26 09:57:28138 StackTrace stack_trace_;
139
[email protected]c934c382013-11-01 00:36:01140 // Keep track of the render process which caused the error in order to
rdevlin.cronin86f5b702015-06-24 18:49:17141 // inspect the frame later, if possible.
142 int render_frame_id_;
[email protected]c934c382013-11-01 00:36:01143 int render_process_id_;
144
[email protected]d466f782013-08-28 21:59:23145 DISALLOW_COPY_AND_ASSIGN(RuntimeError);
[email protected]1b66fdb2013-07-26 09:57:28146};
147
wittmanb3ee0482015-06-24 17:47:40148class 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]1b66fdb2013-07-26 09:57:28163} // namespace extensions
164
[email protected]921237d062013-08-10 15:30:49165#endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_