| Index: extensions/browser/extension_error.cc
|
| diff --git a/extensions/browser/extension_error.cc b/extensions/browser/extension_error.cc
|
| index 8b6196c4200967605b3eb51f0653035bd4e88744..8a88a067954b45d6e990078b4329e9bd73de5909 100644
|
| --- a/extensions/browser/extension_error.cc
|
| +++ b/extensions/browser/extension_error.cc
|
| @@ -12,11 +12,20 @@
|
| #include "url/gurl.h"
|
|
|
| using base::string16;
|
| +using base::DictionaryValue;
|
|
|
| namespace extensions {
|
|
|
| namespace {
|
|
|
| +const char kTypeKey[] = "type";
|
| +const char kSourceKey[] = "source";
|
| +const char kMessageKey[] = "message";
|
| +const char kExtensionIdKey[] = "extensionId";
|
| +const char kFromIncognitoKey[] = "fromIncognito";
|
| +const char kManifestKeyKey[] = "manifestKey";
|
| +const char kManifestSpecificKey[] = "manifestSpecific";
|
| +const char kLevelKey[] = "level";
|
| const char kLineNumberKey[] = "lineNumber";
|
| const char kColumnNumberKey[] = "columnNumber";
|
| const char kURLKey[] = "url";
|
| @@ -27,7 +36,7 @@ const char kStackTraceKey[] = "stackTrace";
|
| // Try to retrieve an extension ID from a |url|. On success, returns true and
|
| // populates |extension_id| with the ID. On failure, returns false and leaves
|
| // extension_id untouched.
|
| -bool GetExtensionIDFromGURL(const GURL& url, std::string* extension_id) {
|
| +bool GetExtensionIdFromGURL(const GURL& url, std::string* extension_id) {
|
| if (url.SchemeIs(kExtensionScheme)) {
|
| *extension_id = url.host();
|
| return true;
|
| @@ -52,6 +61,17 @@ ExtensionError::ExtensionError(Type type,
|
| ExtensionError::~ExtensionError() {
|
| }
|
|
|
| +scoped_ptr<DictionaryValue> ExtensionError::ToValue() const {
|
| + scoped_ptr<DictionaryValue> value(new DictionaryValue);
|
| + value->SetInteger(kTypeKey, static_cast<int>(type_));
|
| + value->SetString(kExtensionIdKey, extension_id_);
|
| + value->SetBoolean(kFromIncognitoKey, from_incognito_);
|
| + value->SetString(kSourceKey, source_);
|
| + value->SetString(kMessageKey, message_);
|
| +
|
| + return value.Pass();
|
| +}
|
| +
|
| std::string ExtensionError::PrintForTest() const {
|
| return std::string("Extension Error:") +
|
| "\n OTR: " + std::string(from_incognito_ ? "true" : "false") +
|
| @@ -60,28 +80,58 @@ std::string ExtensionError::PrintForTest() const {
|
| "\n ID: " + extension_id_;
|
| }
|
|
|
| -ManifestParsingError::ManifestParsingError(const std::string& extension_id,
|
| - const string16& message)
|
| - : ExtensionError(ExtensionError::MANIFEST_PARSING_ERROR,
|
| +bool ExtensionError::IsEqual(const ExtensionError* rhs) const {
|
| + return type_ == rhs->type_ &&
|
| + extension_id_ == rhs->extension_id_ &&
|
| + source_ == rhs->source_ &&
|
| + message_ == rhs->message_ &&
|
| + IsEqualImpl(rhs);
|
| +}
|
| +
|
| +ManifestError::ManifestError(const std::string& extension_id,
|
| + const string16& message,
|
| + const string16& manifest_key,
|
| + const string16& manifest_specific)
|
| + : ExtensionError(ExtensionError::MANIFEST_ERROR,
|
| extension_id,
|
| false, // extensions can't be installed while incognito.
|
| base::FilePath(kManifestFilename).AsUTF16Unsafe(),
|
| - message) {
|
| + message),
|
| + manifest_key_(manifest_key),
|
| + manifest_specific_(manifest_specific) {
|
| +}
|
| +
|
| +ManifestError::~ManifestError() {
|
| }
|
|
|
| -ManifestParsingError::~ManifestParsingError() {
|
| +scoped_ptr<DictionaryValue> ManifestError::ToValue() const {
|
| + scoped_ptr<DictionaryValue> value = ExtensionError::ToValue();
|
| + // All manifest errors are warnings - if it was a fatal error, we wouldn't
|
| + // get far enough to add an error for the extension.
|
| + value->SetInteger(kLevelKey, logging::LOG_WARNING);
|
| + if (!manifest_key_.empty())
|
| + value->SetString(kManifestKeyKey, manifest_key_);
|
| + if (!manifest_specific_.empty())
|
| + value->SetString(kManifestSpecificKey, manifest_specific_);
|
| + return value.Pass();
|
| }
|
|
|
| -std::string ManifestParsingError::PrintForTest() const {
|
| +std::string ManifestError::PrintForTest() const {
|
| return ExtensionError::PrintForTest() +
|
| - "\n Type: ManifestParsingError";
|
| + "\n Type: ManifestError";
|
| +}
|
| +
|
| +bool ManifestError::IsEqualImpl(const ExtensionError* rhs) const {
|
| + // If two manifest errors have the same extension id and message (which are
|
| + // both checked in ExtensionError::IsEqual), then they are equal.
|
| + return true;
|
| }
|
|
|
| -JavascriptRuntimeError::StackFrame::StackFrame() : line_number(-1),
|
| - column_number(-1) {
|
| +RuntimeError::StackFrame::StackFrame() : line_number(-1),
|
| + column_number(-1) {
|
| }
|
|
|
| -JavascriptRuntimeError::StackFrame::StackFrame(size_t frame_line,
|
| +RuntimeError::StackFrame::StackFrame(size_t frame_line,
|
| size_t frame_column,
|
| const string16& frame_url,
|
| const string16& frame_function)
|
| @@ -91,30 +141,37 @@ JavascriptRuntimeError::StackFrame::StackFrame(size_t frame_line,
|
| function(frame_function) {
|
| }
|
|
|
| -JavascriptRuntimeError::StackFrame::~StackFrame() {
|
| +RuntimeError::StackFrame::~StackFrame() {
|
| }
|
|
|
| -JavascriptRuntimeError::JavascriptRuntimeError(bool from_incognito,
|
| - const string16& source,
|
| - const string16& message,
|
| - logging::LogSeverity level,
|
| - const string16& details)
|
| - : ExtensionError(ExtensionError::JAVASCRIPT_RUNTIME_ERROR,
|
| +bool RuntimeError::StackFrame::operator==(
|
| + const RuntimeError::StackFrame& rhs) const {
|
| + return line_number == rhs.line_number &&
|
| + column_number == rhs.column_number &&
|
| + url == rhs.url &&
|
| + function == rhs.function;
|
| +}
|
| +RuntimeError::RuntimeError(bool from_incognito,
|
| + const string16& source,
|
| + const string16& message,
|
| + logging::LogSeverity level,
|
| + const string16& details)
|
| + : ExtensionError(ExtensionError::JAVASCRIPT_ERROR,
|
| std::string(), // We don't know the id yet.
|
| from_incognito,
|
| source,
|
| message),
|
| level_(level) {
|
| ParseDetails(details);
|
| - DetermineExtensionID();
|
| + DetermineExtensionId();
|
| }
|
|
|
| -JavascriptRuntimeError::~JavascriptRuntimeError() {
|
| +RuntimeError::~RuntimeError() {
|
| }
|
|
|
| -std::string JavascriptRuntimeError::PrintForTest() const {
|
| +std::string RuntimeError::PrintForTest() const {
|
| std::string result = ExtensionError::PrintForTest() +
|
| - "\n Type: JavascriptRuntimeError"
|
| + "\n Type: RuntimeError"
|
| "\n Context: " + base::UTF16ToUTF8(execution_context_url_) +
|
| "\n Stack Trace: ";
|
| for (StackTrace::const_iterator iter = stack_trace_.begin();
|
| @@ -129,10 +186,22 @@ std::string JavascriptRuntimeError::PrintForTest() const {
|
| return result;
|
| }
|
|
|
| -void JavascriptRuntimeError::ParseDetails(const string16& details) {
|
| +bool RuntimeError::IsEqualImpl(const ExtensionError* rhs) const {
|
| + const RuntimeError* error = static_cast<const RuntimeError*>(rhs);
|
| +
|
| + // We don't look at the full stack trace, because if the first frame is
|
| + // the same, it's close enough to heuristically count as a duplicate (after
|
| + // all, the same line caused the error).
|
| + // If the stack trace is empty, just compare the context.
|
| + return execution_context_url_ == error->execution_context_url_ &&
|
| + stack_trace_.size() == error->stack_trace_.size() &&
|
| + (stack_trace_.empty() || stack_trace_[0] == error->stack_trace_[0]);
|
| +}
|
| +
|
| +void RuntimeError::ParseDetails(const string16& details) {
|
| scoped_ptr<base::Value> value(
|
| base::JSONReader::Read(base::UTF16ToUTF8(details)));
|
| - const base::DictionaryValue* details_value;
|
| + const DictionaryValue* details_value;
|
| const base::ListValue* trace_value = NULL;
|
|
|
| // The |details| value should contain an execution context url and a stack
|
| @@ -151,7 +220,7 @@ void JavascriptRuntimeError::ParseDetails(const string16& details) {
|
| string16 url;
|
|
|
| for (size_t i = 0; i < trace_value->GetSize(); ++i) {
|
| - const base::DictionaryValue* frame_value = NULL;
|
| + const DictionaryValue* frame_value = NULL;
|
| CHECK(trace_value->GetDictionary(i, &frame_value));
|
|
|
| frame_value->GetInteger(kLineNumberKey, &line);
|
| @@ -164,9 +233,9 @@ void JavascriptRuntimeError::ParseDetails(const string16& details) {
|
| }
|
| }
|
|
|
| -void JavascriptRuntimeError::DetermineExtensionID() {
|
| - if (!GetExtensionIDFromGURL(GURL(source_), &extension_id_))
|
| - GetExtensionIDFromGURL(GURL(execution_context_url_), &extension_id_);
|
| +void RuntimeError::DetermineExtensionId() {
|
| + if (!GetExtensionIdFromGURL(GURL(source_), &extension_id_))
|
| + GetExtensionIdFromGURL(GURL(execution_context_url_), &extension_id_);
|
| }
|
|
|
| } // namespace extensions
|
|
|