OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |
6 #define EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | |
13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
14 | 15 |
16 namespace base { | |
17 class DictionaryValue; | |
18 } | |
19 | |
15 namespace extensions { | 20 namespace extensions { |
16 | 21 |
17 class ExtensionError { | 22 class ExtensionError { |
18 public: | 23 public: |
19 enum Type { | 24 enum Type { |
20 MANIFEST_PARSING_ERROR, | 25 MANIFEST_PARSING_ERROR, |
21 JAVASCRIPT_RUNTIME_ERROR | 26 JAVASCRIPT_RUNTIME_ERROR |
22 }; | 27 }; |
23 | 28 |
24 virtual ~ExtensionError(); | 29 virtual ~ExtensionError(); |
25 | 30 |
31 // Serializes the ExtensionError into JSON format. | |
32 virtual scoped_ptr<base::DictionaryValue> ToValue() const; | |
33 | |
26 virtual std::string PrintForTest() const; | 34 virtual std::string PrintForTest() const; |
27 | 35 |
36 bool IsEqual(const ExtensionError* rhs) const; | |
37 | |
28 Type type() const { return type_; } | 38 Type type() const { return type_; } |
29 const base::string16& source() const { return source_; } | 39 const base::string16& source() const { return source_; } |
30 const base::string16& message() const { return message_; } | 40 const base::string16& message() const { return message_; } |
31 const std::string& extension_id() const { return extension_id_; } | 41 const std::string& extension_id() const { return extension_id_; } |
32 bool from_incognito() const { return from_incognito_; } | 42 bool from_incognito() const { return from_incognito_; } |
33 | 43 |
34 protected: | 44 protected: |
35 ExtensionError(Type type, | 45 ExtensionError(Type type, |
36 const std::string& extension_id, | 46 const std::string& extension_id, |
37 bool from_incognito, | 47 bool from_incognito, |
38 const base::string16& source, | 48 const base::string16& source, |
39 const base::string16& message); | 49 const base::string16& message); |
40 | 50 |
51 virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0; | |
52 | |
41 // Which type of error this is. | 53 // Which type of error this is. |
42 Type type_; | 54 Type type_; |
43 // The ID of the extension which caused the error. | 55 // The ID of the extension which caused the error. |
44 std::string extension_id_; | 56 std::string extension_id_; |
45 // Whether or not the error was caused while incognito. | 57 // Whether or not the error was caused while incognito. |
46 bool from_incognito_; | 58 bool from_incognito_; |
47 // The source for the error; this can be a script, web page, or manifest file. | 59 // The source for the error; this can be a script, web page, or manifest file. |
48 // This is stored as a string (rather than a url) since it can be a Chrome | 60 // This is stored as a string (rather than a url) since it can be a Chrome |
49 // script file (e.g., event_bindings.js). | 61 // script file (e.g., event_bindings.js). |
50 base::string16 source_; | 62 base::string16 source_; |
51 // The error message itself. | 63 // The error message itself. |
52 base::string16 message_; | 64 base::string16 message_; |
53 | 65 |
54 DISALLOW_COPY_AND_ASSIGN(ExtensionError); | 66 DISALLOW_COPY_AND_ASSIGN(ExtensionError); |
55 }; | 67 }; |
56 | 68 |
57 class ManifestParsingError : public ExtensionError { | 69 class ManifestParsingError : public ExtensionError { |
58 public: | 70 public: |
59 ManifestParsingError(const std::string& extension_id, | 71 ManifestParsingError(const std::string& extension_id, |
60 const base::string16& message); | 72 const base::string16& message, |
73 const base::string16& manifest_key, | |
74 const base::string16& manifest_specific); | |
61 virtual ~ManifestParsingError(); | 75 virtual ~ManifestParsingError(); |
62 | 76 |
77 virtual scoped_ptr<base::DictionaryValue> ToValue() const OVERRIDE; | |
78 | |
63 virtual std::string PrintForTest() const OVERRIDE; | 79 virtual std::string PrintForTest() const OVERRIDE; |
80 | |
81 const base::string16& manifest_key() const { return manifest_key_; } | |
82 const base::string16& manifest_specific() const { return manifest_specific_; } | |
64 private: | 83 private: |
84 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE; | |
85 | |
86 // If present, this indicates the feature in the manifest which caused the | |
87 // error. | |
88 base::string16 manifest_key_; | |
89 // If present, this is a more-specific location of the error - for instance, | |
90 // a specific permission which is incorrect, rather than simply "permissions". | |
91 base::string16 manifest_specific_; | |
92 | |
65 DISALLOW_COPY_AND_ASSIGN(ManifestParsingError); | 93 DISALLOW_COPY_AND_ASSIGN(ManifestParsingError); |
66 }; | 94 }; |
67 | 95 |
68 class JavascriptRuntimeError : public ExtensionError { | 96 class JavascriptRuntimeError : public ExtensionError { |
69 public: | 97 public: |
70 struct StackFrame { | 98 struct StackFrame { |
71 size_t line_number; | 99 size_t line_number; |
72 size_t column_number; | 100 size_t column_number; |
73 // This is stored as a string (rather than a url) since it can be a | 101 // This is stored as a string (rather than a url) since it can be a |
74 // Chrome script file (e.g., event_bindings.js). | 102 // Chrome script file (e.g., event_bindings.js). |
75 base::string16 url; | 103 base::string16 url; |
76 base::string16 function; // optional | 104 base::string16 function; // optional |
77 | 105 |
78 // STL-Required constructor | 106 // STL-Required constructor |
79 StackFrame(); | 107 StackFrame(); |
80 | 108 |
81 StackFrame(size_t frame_line, | 109 StackFrame(size_t frame_line, |
82 size_t frame_column, | 110 size_t frame_column, |
83 const base::string16& frame_url, | 111 const base::string16& frame_url, |
84 const base::string16& frame_function /* can be empty */); | 112 const base::string16& frame_function /* can be empty */); |
85 | 113 |
86 ~StackFrame(); | 114 ~StackFrame(); |
115 | |
116 bool operator==(const StackFrame& rhs) const; | |
87 }; | 117 }; |
88 typedef std::vector<StackFrame> StackTrace; | 118 typedef std::vector<StackFrame> StackTrace; |
89 | 119 |
90 JavascriptRuntimeError(bool from_incognito, | 120 JavascriptRuntimeError(bool from_incognito, |
91 const base::string16& source, | 121 const base::string16& source, |
92 const base::string16& message, | 122 const base::string16& message, |
93 logging::LogSeverity level, | 123 logging::LogSeverity level, |
94 const base::string16& details); | 124 const base::string16& details); |
95 virtual ~JavascriptRuntimeError(); | 125 virtual ~JavascriptRuntimeError(); |
96 | 126 |
97 virtual std::string PrintForTest() const OVERRIDE; | 127 virtual std::string PrintForTest() const OVERRIDE; |
98 | 128 |
99 logging::LogSeverity level() const { return level_; } | 129 logging::LogSeverity level() const { return level_; } |
100 const base::string16& execution_context_url() const { | 130 const base::string16& execution_context_url() const { |
101 return execution_context_url_; | 131 return execution_context_url_; |
102 } | 132 } |
103 const StackTrace& stack_trace() const { return stack_trace_; } | 133 const StackTrace& stack_trace() const { return stack_trace_; } |
104 private: | 134 private: |
135 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE; | |
136 | |
105 // Parse the JSON |details| passed to the error. This includes a stack trace | 137 // Parse the JSON |details| passed to the error. This includes a stack trace |
106 // and an execution context url. | 138 // and an execution context url. |
107 void ParseDetails(const base::string16& details); | 139 void ParseDetails(const base::string16& details); |
108 // Try to determine the ID of the extension. This may be obtained through the | 140 // Try to determine the ID of the extension. This may be obtained through the |
109 // reported source, or through the execution context url. | 141 // reported source, or through the execution context url. |
110 void DetermineExtensionID(); | 142 void DetermineExtensionId(); |
Yoyo Zhou
2013/08/16 00:17:25
We (aa and I) had a debate about this a long time
Devlin
2013/08/16 23:56:54
My reasoning was:
$ git grep "xtensionId" | wc
| |
111 | 143 |
112 logging::LogSeverity level_; | 144 logging::LogSeverity level_; |
113 base::string16 execution_context_url_; | 145 base::string16 execution_context_url_; |
114 StackTrace stack_trace_; | 146 StackTrace stack_trace_; |
115 | 147 |
116 DISALLOW_COPY_AND_ASSIGN(JavascriptRuntimeError); | 148 DISALLOW_COPY_AND_ASSIGN(JavascriptRuntimeError); |
117 }; | 149 }; |
118 | 150 |
119 } // namespace extensions | 151 } // namespace extensions |
120 | 152 |
121 #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ | 153 #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_ |
OLD | NEW |