Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: extensions/browser/extension_error.cc

Issue 23624002: Add UI for RuntimeErrors in the ErrorConsole (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dc_ec_merge
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "extensions/browser/extension_error.h" 5 #include "extensions/browser/extension_error.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "extensions/common/constants.h" 10 #include "extensions/common/constants.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 return ExtensionError::PrintForTest() + 113 return ExtensionError::PrintForTest() +
114 "\n Type: ManifestError"; 114 "\n Type: ManifestError";
115 } 115 }
116 116
117 bool ManifestError::IsEqualImpl(const ExtensionError* rhs) const { 117 bool ManifestError::IsEqualImpl(const ExtensionError* rhs) const {
118 // If two manifest errors have the same extension id and message (which are 118 // If two manifest errors have the same extension id and message (which are
119 // both checked in ExtensionError::IsEqual), then they are equal. 119 // both checked in ExtensionError::IsEqual), then they are equal.
120 return true; 120 return true;
121 } 121 }
122 122
123 ////////////////////////////////////////////////////////////////////////////////
124 // RuntimeError
125
126 // Static JSON keys.
127 const char RuntimeError::kColumnNumberKey[] = "columnNumber";
128 const char RuntimeError::kContextUrlKey[] = "contextUrl";
129 const char RuntimeError::kFunctionNameKey[] = "functionName";
130 const char RuntimeError::kLineNumberKey[] = "lineNumber";
131 const char RuntimeError::kStackTraceKey[] = "stackTrace";
132 const char RuntimeError::kUrlKey[] = "url";
133
123 RuntimeError::RuntimeError(bool from_incognito, 134 RuntimeError::RuntimeError(bool from_incognito,
124 const string16& source, 135 const string16& source,
125 const string16& message, 136 const string16& message,
126 const StackTrace& stack_trace, 137 const StackTrace& stack_trace,
127 const GURL& context_url, 138 const GURL& context_url,
128 logging::LogSeverity level) 139 logging::LogSeverity level)
129 : ExtensionError(ExtensionError::RUNTIME_ERROR, 140 : ExtensionError(ExtensionError::RUNTIME_ERROR,
130 GURL(source).host(), 141 GURL(source).host(),
131 from_incognito, 142 from_incognito,
132 level, 143 level,
133 source, 144 source,
134 message), 145 message),
135 context_url_(context_url), 146 context_url_(context_url),
136 stack_trace_(stack_trace) { 147 stack_trace_(stack_trace) {
137 CleanUpInit(); 148 CleanUpInit();
138 } 149 }
139 150
140 RuntimeError::~RuntimeError() { 151 RuntimeError::~RuntimeError() {
141 } 152 }
142 153
154 scoped_ptr<DictionaryValue> RuntimeError::ToValue() const {
155 scoped_ptr<DictionaryValue> value = ExtensionError::ToValue();
156 value->SetString(kContextUrlKey, context_url_.spec());
157
158 ListValue* trace_value = new ListValue;
159 for (StackTrace::const_iterator iter = stack_trace_.begin();
160 iter != stack_trace_.end(); ++iter) {
161 DictionaryValue* frame_value = new DictionaryValue;
162 frame_value->SetInteger(kLineNumberKey, iter->line_number);
163 frame_value->SetInteger(kColumnNumberKey, iter->column_number);
164 frame_value->SetString(kUrlKey, iter->source);
165 frame_value->SetString(kFunctionNameKey, iter->function);
166 trace_value->Append(frame_value);
167 }
168
169 value->Set(kStackTraceKey, trace_value);
170
171 return value.Pass();
172 }
173
143 std::string RuntimeError::PrintForTest() const { 174 std::string RuntimeError::PrintForTest() const {
144 std::string result = ExtensionError::PrintForTest() + 175 std::string result = ExtensionError::PrintForTest() +
145 "\n Type: RuntimeError" 176 "\n Type: RuntimeError"
146 "\n Context: " + context_url_.spec() + 177 "\n Context: " + context_url_.spec() +
147 "\n Stack Trace: "; 178 "\n Stack Trace: ";
148 for (StackTrace::const_iterator iter = stack_trace_.begin(); 179 for (StackTrace::const_iterator iter = stack_trace_.begin();
149 iter != stack_trace_.end(); ++iter) { 180 iter != stack_trace_.end(); ++iter) {
150 result += "\n {" 181 result += "\n {"
151 "\n Line: " + base::IntToString(iter->line_number) + 182 "\n Line: " + base::IntToString(iter->line_number) +
152 "\n Column: " + base::IntToString(iter->column_number) + 183 "\n Column: " + base::IntToString(iter->column_number) +
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // other systems), the source won't match up with the final entry in the stack 216 // other systems), the source won't match up with the final entry in the stack
186 // trace. (For instance, in a browser action error, the source is the page - 217 // trace. (For instance, in a browser action error, the source is the page -
187 // sometimes the background page - but the error is thrown from the script.) 218 // sometimes the background page - but the error is thrown from the script.)
188 // Make the source match the stack trace, since that is more likely the cause 219 // Make the source match the stack trace, since that is more likely the cause
189 // of the error. 220 // of the error.
190 if (!stack_trace_.empty() && source_ != stack_trace_[0].source) 221 if (!stack_trace_.empty() && source_ != stack_trace_[0].source)
191 source_ = stack_trace_[0].source; 222 source_ = stack_trace_[0].source;
192 } 223 }
193 224
194 } // namespace extensions 225 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698