blob: 6ee7791f66c603497fe6be5697c4cdcc8db2a59d [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,
76 const base::string16& message);
77 virtual ~ManifestError();
[email protected]1b66fdb2013-07-26 09:57:2878
79 virtual std::string PrintForTest() const OVERRIDE;
[email protected]1b66fdb2013-07-26 09:57:2880 private:
[email protected]d466f782013-08-28 21:59:2381 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE;
82
83 DISALLOW_COPY_AND_ASSIGN(ManifestError);
[email protected]1b66fdb2013-07-26 09:57:2884};
85
[email protected]d466f782013-08-28 21:59:2386class RuntimeError : public ExtensionError {
[email protected]1b66fdb2013-07-26 09:57:2887 public:
[email protected]d466f782013-08-28 21:59:2388 RuntimeError(bool from_incognito,
89 const base::string16& source,
90 const base::string16& message,
[email protected]88b50b62013-09-01 23:05:0691 const StackTrace& stack_trace,
92 const GURL& context_url,
93 logging::LogSeverity level);
[email protected]d466f782013-08-28 21:59:2394 virtual ~RuntimeError();
[email protected]1b66fdb2013-07-26 09:57:2895
96 virtual std::string PrintForTest() const OVERRIDE;
97
[email protected]88b50b62013-09-01 23:05:0698 const GURL& context_url() const { return context_url_; }
[email protected]1b66fdb2013-07-26 09:57:2899 const StackTrace& stack_trace() const { return stack_trace_; }
100 private:
[email protected]d466f782013-08-28 21:59:23101 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE;
102
[email protected]88b50b62013-09-01 23:05:06103 // 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]1b66fdb2013-07-26 09:57:28107
[email protected]88b50b62013-09-01 23:05:06108 GURL context_url_;
[email protected]1b66fdb2013-07-26 09:57:28109 StackTrace stack_trace_;
110
[email protected]d466f782013-08-28 21:59:23111 DISALLOW_COPY_AND_ASSIGN(RuntimeError);
[email protected]1b66fdb2013-07-26 09:57:28112};
113
114} // namespace extensions
115
[email protected]921237d062013-08-10 15:30:49116#endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_