| 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 #include "chrome/browser/extensions/error_console/extension_error.h" | 5 #include "extensions/browser/extension_error.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/common/extensions/extension.h" | |
| 12 #include "extensions/common/constants.h" | 11 #include "extensions/common/constants.h" |
| 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 using base::string16; | 14 using base::string16; |
| 15 | 15 |
| 16 namespace extensions { | 16 namespace extensions { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 const char kLineNumberKey[] = "lineNumber"; | 20 const char kLineNumberKey[] = "lineNumber"; |
| 21 const char kColumnNumberKey[] = "columnNumber"; | 21 const char kColumnNumberKey[] = "columnNumber"; |
| 22 const char kURLKey[] = "url"; | 22 const char kURLKey[] = "url"; |
| 23 const char kFunctionNameKey[] = "functionName"; | 23 const char kFunctionNameKey[] = "functionName"; |
| 24 const char kExecutionContextURLKey[] = "executionContextURL"; | 24 const char kExecutionContextURLKey[] = "executionContextURL"; |
| 25 const char kStackTraceKey[] = "stackTrace"; | 25 const char kStackTraceKey[] = "stackTrace"; |
| 26 | 26 |
| 27 // Try to retrieve an extension ID from a |url|. On success, returns true and | 27 // Try to retrieve an extension ID from a |url|. On success, returns true and |
| 28 // populates |extension_id| with the ID. On failure, returns false and leaves | 28 // populates |extension_id| with the ID. On failure, returns false and leaves |
| 29 // extension_id untouched. | 29 // extension_id untouched. |
| 30 bool GetExtensionIDFromGURL(const GURL& url, std::string* extension_id) { | 30 bool GetExtensionIDFromGURL(const GURL& url, std::string* extension_id) { |
| 31 if (url.SchemeIs(extensions::kExtensionScheme)) { | 31 if (url.SchemeIs(kExtensionScheme)) { |
| 32 *extension_id = url.host(); | 32 *extension_id = url.host(); |
| 33 return true; | 33 return true; |
| 34 } | 34 } |
| 35 return false; | 35 return false; |
| 36 } | 36 } |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 ExtensionError::ExtensionError(Type type, | 40 ExtensionError::ExtensionError(Type type, |
| 41 const std::string& extension_id, |
| 41 bool from_incognito, | 42 bool from_incognito, |
| 42 const string16& source, | 43 const string16& source, |
| 43 const string16& message) | 44 const string16& message) |
| 44 : type_(type), | 45 : type_(type), |
| 46 extension_id_(extension_id), |
| 45 from_incognito_(from_incognito), | 47 from_incognito_(from_incognito), |
| 46 source_(source), | 48 source_(source), |
| 47 message_(message) { | 49 message_(message) { |
| 48 } | 50 } |
| 49 | 51 |
| 50 ExtensionError::~ExtensionError() { | 52 ExtensionError::~ExtensionError() { |
| 51 } | 53 } |
| 52 | 54 |
| 53 std::string ExtensionError::PrintForTest() const { | 55 std::string ExtensionError::PrintForTest() const { |
| 54 return std::string("Extension Error:") + | 56 return std::string("Extension Error:") + |
| 55 "\n OTR: " + std::string(from_incognito_ ? "true" : "false") + | 57 "\n OTR: " + std::string(from_incognito_ ? "true" : "false") + |
| 56 "\n Source: " + base::UTF16ToUTF8(source_) + | 58 "\n Source: " + base::UTF16ToUTF8(source_) + |
| 57 "\n Message: " + base::UTF16ToUTF8(message_) + | 59 "\n Message: " + base::UTF16ToUTF8(message_) + |
| 58 "\n ID: " + extension_id_; | 60 "\n ID: " + extension_id_; |
| 59 } | 61 } |
| 60 | 62 |
| 61 ManifestParsingError::ManifestParsingError(bool from_incognito, | 63 ManifestParsingError::ManifestParsingError(const std::string& extension_id, |
| 62 const string16& source, | 64 const string16& message) |
| 63 const string16& message, | |
| 64 size_t line_number) | |
| 65 : ExtensionError(ExtensionError::MANIFEST_PARSING_ERROR, | 65 : ExtensionError(ExtensionError::MANIFEST_PARSING_ERROR, |
| 66 from_incognito, | 66 extension_id, |
| 67 source, | 67 false, // extensions can't be installed while incognito. |
| 68 message), | 68 base::FilePath(kManifestFilename).AsUTF16Unsafe(), |
| 69 line_number_(line_number) { | 69 message) { |
| 70 } | 70 } |
| 71 | 71 |
| 72 ManifestParsingError::~ManifestParsingError() { | 72 ManifestParsingError::~ManifestParsingError() { |
| 73 } | 73 } |
| 74 | 74 |
| 75 std::string ManifestParsingError::PrintForTest() const { | 75 std::string ManifestParsingError::PrintForTest() const { |
| 76 return ExtensionError::PrintForTest() + | 76 return ExtensionError::PrintForTest() + |
| 77 "\n Type: ManifestParsingError" + | 77 "\n Type: ManifestParsingError"; |
| 78 "\n Line: " + base::IntToString(line_number_); | |
| 79 } | 78 } |
| 80 | 79 |
| 81 JavascriptRuntimeError::StackFrame::StackFrame() : line_number(-1), | 80 JavascriptRuntimeError::StackFrame::StackFrame() : line_number(-1), |
| 82 column_number(-1) { | 81 column_number(-1) { |
| 83 } | 82 } |
| 84 | 83 |
| 85 JavascriptRuntimeError::StackFrame::StackFrame(size_t frame_line, | 84 JavascriptRuntimeError::StackFrame::StackFrame(size_t frame_line, |
| 86 size_t frame_column, | 85 size_t frame_column, |
| 87 const string16& frame_url, | 86 const string16& frame_url, |
| 88 const string16& frame_function) | 87 const string16& frame_function) |
| 89 : line_number(frame_line), | 88 : line_number(frame_line), |
| 90 column_number(frame_column), | 89 column_number(frame_column), |
| 91 url(frame_url), | 90 url(frame_url), |
| 92 function(frame_function) { | 91 function(frame_function) { |
| 93 } | 92 } |
| 94 | 93 |
| 95 JavascriptRuntimeError::StackFrame::~StackFrame() { | 94 JavascriptRuntimeError::StackFrame::~StackFrame() { |
| 96 } | 95 } |
| 97 | 96 |
| 98 JavascriptRuntimeError::JavascriptRuntimeError(bool from_incognito, | 97 JavascriptRuntimeError::JavascriptRuntimeError(bool from_incognito, |
| 99 const string16& source, | 98 const string16& source, |
| 100 const string16& message, | 99 const string16& message, |
| 101 logging::LogSeverity level, | 100 logging::LogSeverity level, |
| 102 const string16& details) | 101 const string16& details) |
| 103 : ExtensionError(ExtensionError::JAVASCRIPT_RUNTIME_ERROR, | 102 : ExtensionError(ExtensionError::JAVASCRIPT_RUNTIME_ERROR, |
| 103 std::string(), // We don't know the id yet. |
| 104 from_incognito, | 104 from_incognito, |
| 105 source, | 105 source, |
| 106 message), | 106 message), |
| 107 level_(level) { | 107 level_(level) { |
| 108 ParseDetails(details); | 108 ParseDetails(details); |
| 109 DetermineExtensionID(); | 109 DetermineExtensionID(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 JavascriptRuntimeError::~JavascriptRuntimeError() { | 112 JavascriptRuntimeError::~JavascriptRuntimeError() { |
| 113 } | 113 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 stack_trace_.push_back(StackFrame(line, column, url, function)); | 163 stack_trace_.push_back(StackFrame(line, column, url, function)); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 void JavascriptRuntimeError::DetermineExtensionID() { | 167 void JavascriptRuntimeError::DetermineExtensionID() { |
| 168 if (!GetExtensionIDFromGURL(GURL(source_), &extension_id_)) | 168 if (!GetExtensionIDFromGURL(GURL(source_), &extension_id_)) |
| 169 GetExtensionIDFromGURL(GURL(execution_context_url_), &extension_id_); | 169 GetExtensionIDFromGURL(GURL(execution_context_url_), &extension_id_); |
| 170 } | 170 } |
| 171 | 171 |
| 172 } // namespace extensions | 172 } // namespace extensions |
| OLD | NEW |