Chromium Code Reviews| Index: extensions/browser/extension_error.cc |
| diff --git a/extensions/browser/extension_error.cc b/extensions/browser/extension_error.cc |
| index b372885e2dd67676ac773b1093cae143460d8f04..891e7913f5a61233b3b222ed61d22374e7782602 100644 |
| --- a/extensions/browser/extension_error.cc |
| +++ b/extensions/browser/extension_error.cc |
| @@ -11,18 +11,12 @@ |
| #include "url/gurl.h" |
| using base::string16; |
| +using base::DictionaryValue; |
| namespace extensions { |
| namespace { |
| -const char kLineNumberKey[] = "lineNumber"; |
| -const char kColumnNumberKey[] = "columnNumber"; |
| -const char kURLKey[] = "url"; |
| -const char kFunctionNameKey[] = "functionName"; |
| -const char kExecutionContextURLKey[] = "executionContextURL"; |
| -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. |
| @@ -36,6 +30,17 @@ bool GetExtensionIDFromGURL(const GURL& url, std::string* extension_id) { |
| } // namespace |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// ExtensionError |
| + |
| +// Static JSON keys. |
| +const char ExtensionError::kExtensionIdKey[] = "extensionId"; |
| +const char ExtensionError::kFromIncognitoKey[] = "fromIncognito"; |
| +const char ExtensionError::kLevelKey[] = "level"; |
| +const char ExtensionError::kMessageKey[] = "message"; |
| +const char ExtensionError::kSourceKey[] = "source"; |
| +const char ExtensionError::kTypeKey[] = "type"; |
| + |
| ExtensionError::ExtensionError(Type type, |
| const std::string& extension_id, |
| bool from_incognito, |
| @@ -54,6 +59,18 @@ 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->SetInteger(kLevelKey, static_cast<int>(level_)); |
| + value->SetString(kSourceKey, source_); |
| + value->SetString(kMessageKey, message_); |
| + |
| + return value.Pass(); |
|
not at google - send to devlin
2013/09/03 22:51:46
consider using DictionaryBuilder here.
Devlin
2013/09/03 23:54:22
Will do once we have value builder in extensions/.
|
| +} |
| + |
| std::string ExtensionError::PrintForTest() const { |
| return std::string("Extension Error:") + |
| "\n OTR: " + std::string(from_incognito_ ? "true" : "false") + |
| @@ -72,6 +89,13 @@ bool ExtensionError::IsEqual(const ExtensionError* rhs) const { |
| IsEqualImpl(rhs); |
| } |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// ManifestError |
| + |
| +// Static JSON keys. |
| +const char ManifestError::kManifestKeyKey[] = "manifestKey"; |
| +const char ManifestError::kManifestSpecificKey[] = "manifestSpecific"; |
| + |
| ManifestError::ManifestError(const std::string& extension_id, |
| const string16& message, |
| const string16& manifest_key, |
| @@ -89,6 +113,15 @@ ManifestError::ManifestError(const std::string& extension_id, |
| ManifestError::~ManifestError() { |
| } |
| +scoped_ptr<DictionaryValue> ManifestError::ToValue() const { |
| + scoped_ptr<DictionaryValue> value = ExtensionError::ToValue(); |
| + if (!manifest_key_.empty()) |
| + value->SetString(kManifestKeyKey, manifest_key_); |
| + if (!manifest_specific_.empty()) |
| + value->SetString(kManifestSpecificKey, manifest_specific_); |
| + return value.Pass(); |
| +} |
| + |
| std::string ManifestError::PrintForTest() const { |
| return ExtensionError::PrintForTest() + |
| "\n Type: ManifestError"; |