blob: ceb1504b3c6acfdfe58db05527f013e861469c7a [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"
13#include "base/strings/string16.h"
[email protected]88b50b62013-09-01 23:05:0614#include "extensions/common/stack_frame.h"
15#include "url/gurl.h"
[email protected]1b66fdb2013-07-26 09:57:2816
17namespace extensions {
18
19class ExtensionError {
20 public:
21 enum Type {
[email protected]d466f782013-08-28 21:59:2322 MANIFEST_ERROR,
23 RUNTIME_ERROR
[email protected]1b66fdb2013-07-26 09:57:2824 };
25
26 virtual ~ExtensionError();
27
28 virtual std::string PrintForTest() const;
29
[email protected]d466f782013-08-28 21:59:2330 // 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]1b66fdb2013-07-26 09:57:2834 Type type() const { return type_; }
[email protected]1b66fdb2013-07-26 09:57:2835 const std::string& extension_id() const { return extension_id_; }
36 bool from_incognito() const { return from_incognito_; }
[email protected]d466f782013-08-28 21:59:2337 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]1b66fdb2013-07-26 09:57:2842
43 protected:
44 ExtensionError(Type type,
[email protected]921237d062013-08-10 15:30:4945 const std::string& extension_id,
[email protected]1b66fdb2013-07-26 09:57:2846 bool from_incognito,
[email protected]d466f782013-08-28 21:59:2347 logging::LogSeverity level,
[email protected]1b66fdb2013-07-26 09:57:2848 const base::string16& source,
49 const base::string16& message);
50
[email protected]d466f782013-08-28 21:59:2351 virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0;
52
[email protected]1b66fdb2013-07-26 09:57:2853 // Which type of error this is.
54 Type type_;
[email protected]921237d062013-08-10 15:30:4955 // The ID of the extension which caused the error.
56 std::string extension_id_;
[email protected]1b66fdb2013-07-26 09:57:2857 // Whether or not the error was caused while incognito.
58 bool from_incognito_;
[email protected]d466f782013-08-28 21:59:2359 // The severity level of the error.
60 logging::LogSeverity level_;
[email protected]1b66fdb2013-07-26 09:57:2861 // 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]d466f782013-08-28 21:59:2367 // The number of times this error has occurred.
68 size_t occurrences_;
[email protected]1b66fdb2013-07-26 09:57:2869
70 DISALLOW_COPY_AND_ASSIGN(ExtensionError);
71};
72
[email protected]d466f782013-08-28 21:59:2373class ManifestError : public ExtensionError {
[email protected]1b66fdb2013-07-26 09:57:2874 public:
[email protected]d466f782013-08-28 21:59:2375 ManifestError(const std::string& extension_id,
[email protected]b191e2d32013-09-03 21:08:3076 const base::string16& message,
77 const base::string16& manifest_key,
78 const base::string16& manifest_specific);
[email protected]d466f782013-08-28 21:59:2379 virtual ~ManifestError();
[email protected]1b66fdb2013-07-26 09:57:2880
81 virtual std::string PrintForTest() const OVERRIDE;
[email protected]b191e2d32013-09-03 21:08:3082
83 const base::string16& manifest_key() const { return manifest_key_; }
84 const base::string16& manifest_specific() const { return manifest_specific_; }
[email protected]1b66fdb2013-07-26 09:57:2885 private:
[email protected]d466f782013-08-28 21:59:2386 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE;
87
[email protected]b191e2d32013-09-03 21:08:3088 // If present, this indicates the feature in the manifest which caused the
89 // error.
90 base::string16 manifest_key_;
91 // If present, this is a more-specific location of the error - for instance,
92 // a specific permission which is incorrect, rather than simply "permissions".
93 base::string16 manifest_specific_;
94
[email protected]d466f782013-08-28 21:59:2395 DISALLOW_COPY_AND_ASSIGN(ManifestError);
[email protected]1b66fdb2013-07-26 09:57:2896};
97
[email protected]d466f782013-08-28 21:59:2398class RuntimeError : public ExtensionError {
[email protected]1b66fdb2013-07-26 09:57:2899 public:
[email protected]d466f782013-08-28 21:59:23100 RuntimeError(bool from_incognito,
101 const base::string16& source,
102 const base::string16& message,
[email protected]88b50b62013-09-01 23:05:06103 const StackTrace& stack_trace,
104 const GURL& context_url,
105 logging::LogSeverity level);
[email protected]d466f782013-08-28 21:59:23106 virtual ~RuntimeError();
[email protected]1b66fdb2013-07-26 09:57:28107
108 virtual std::string PrintForTest() const OVERRIDE;
109
[email protected]88b50b62013-09-01 23:05:06110 const GURL& context_url() const { return context_url_; }
[email protected]1b66fdb2013-07-26 09:57:28111 const StackTrace& stack_trace() const { return stack_trace_; }
112 private:
[email protected]d466f782013-08-28 21:59:23113 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE;
114
[email protected]88b50b62013-09-01 23:05:06115 // Since we piggy-back onto other error reporting systems (like V8 and
116 // WebKit), the reported information may need to be cleaned up in order to be
117 // in a consistent format.
118 void CleanUpInit();
[email protected]1b66fdb2013-07-26 09:57:28119
[email protected]88b50b62013-09-01 23:05:06120 GURL context_url_;
[email protected]1b66fdb2013-07-26 09:57:28121 StackTrace stack_trace_;
122
[email protected]d466f782013-08-28 21:59:23123 DISALLOW_COPY_AND_ASSIGN(RuntimeError);
[email protected]1b66fdb2013-07-26 09:57:28124};
125
126} // namespace extensions
127
[email protected]921237d062013-08-10 15:30:49128#endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_