| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer/extensions_render_frame_observer.h" | 5 #include "extensions/renderer/extensions_render_frame_observer.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 |
| 7 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/public/renderer/render_frame.h" | 11 #include "content/public/renderer/render_frame.h" |
| 10 #include "extensions/common/extension_messages.h" | 12 #include "extensions/common/extension_messages.h" |
| 11 #include "extensions/common/stack_frame.h" | 13 #include "extensions/common/stack_frame.h" |
| 12 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 14 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 13 | 15 |
| 14 namespace extensions { | 16 namespace extensions { |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 // The delimiter for a stack trace provided by WebKit. | 20 // The delimiter for a stack trace provided by WebKit. |
| 19 const char kStackFrameDelimiter[] = "\n at "; | 21 const char kStackFrameDelimiter[] = "\n at "; |
| 20 | 22 |
| 21 // Get a stack trace from a WebKit console message. | 23 // Get a stack trace from a WebKit console message. |
| 22 // There are three possible scenarios: | 24 // There are three possible scenarios: |
| 23 // 1. WebKit gives us a stack trace in |stack_trace|. | 25 // 1. WebKit gives us a stack trace in |stack_trace|. |
| 24 // 2. The stack trace is embedded in the error |message| by an internal | 26 // 2. The stack trace is embedded in the error |message| by an internal |
| 25 // script. This will be more useful than |stack_trace|, since |stack_trace| | 27 // script. This will be more useful than |stack_trace|, since |stack_trace| |
| 26 // will include the internal bindings trace, instead of a developer's code. | 28 // will include the internal bindings trace, instead of a developer's code. |
| 27 // 3. No stack trace is included. In this case, we should mock one up from | 29 // 3. No stack trace is included. In this case, we should mock one up from |
| 28 // the given line number and source. | 30 // the given line number and source. |
| 29 // |message| will be populated with the error message only (i.e., will not | 31 // |message| will be populated with the error message only (i.e., will not |
| 30 // include any stack trace). | 32 // include any stack trace). |
| 31 StackTrace GetStackTraceFromMessage( | 33 StackTrace GetStackTraceFromMessage(base::string16* message, |
| 32 base::string16* message, | 34 const base::string16& source, |
| 33 const base::string16& source, | 35 const base::string16& stack_trace, |
| 34 const base::string16& stack_trace, | 36 int32_t line_number) { |
| 35 int32 line_number) { | |
| 36 StackTrace result; | 37 StackTrace result; |
| 37 std::vector<base::string16> pieces; | 38 std::vector<base::string16> pieces; |
| 38 size_t index = 0; | 39 size_t index = 0; |
| 39 | 40 |
| 40 if (message->find(base::UTF8ToUTF16(kStackFrameDelimiter)) != | 41 if (message->find(base::UTF8ToUTF16(kStackFrameDelimiter)) != |
| 41 base::string16::npos) { | 42 base::string16::npos) { |
| 42 base::SplitStringUsingSubstr(*message, | 43 base::SplitStringUsingSubstr(*message, |
| 43 base::UTF8ToUTF16(kStackFrameDelimiter), | 44 base::UTF8ToUTF16(kStackFrameDelimiter), |
| 44 &pieces); | 45 &pieces); |
| 45 *message = pieces[0]; | 46 *message = pieces[0]; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 : content::RenderFrameObserver(render_frame) { | 78 : content::RenderFrameObserver(render_frame) { |
| 78 } | 79 } |
| 79 | 80 |
| 80 ExtensionsRenderFrameObserver::~ExtensionsRenderFrameObserver() { | 81 ExtensionsRenderFrameObserver::~ExtensionsRenderFrameObserver() { |
| 81 } | 82 } |
| 82 | 83 |
| 83 void ExtensionsRenderFrameObserver::DetailedConsoleMessageAdded( | 84 void ExtensionsRenderFrameObserver::DetailedConsoleMessageAdded( |
| 84 const base::string16& message, | 85 const base::string16& message, |
| 85 const base::string16& source, | 86 const base::string16& source, |
| 86 const base::string16& stack_trace_string, | 87 const base::string16& stack_trace_string, |
| 87 int32 line_number, | 88 int32_t line_number, |
| 88 int32 severity_level) { | 89 int32_t severity_level) { |
| 89 base::string16 trimmed_message = message; | 90 base::string16 trimmed_message = message; |
| 90 StackTrace stack_trace = GetStackTraceFromMessage( | 91 StackTrace stack_trace = GetStackTraceFromMessage( |
| 91 &trimmed_message, | 92 &trimmed_message, |
| 92 source, | 93 source, |
| 93 stack_trace_string, | 94 stack_trace_string, |
| 94 line_number); | 95 line_number); |
| 95 Send(new ExtensionHostMsg_DetailedConsoleMessageAdded( | 96 Send(new ExtensionHostMsg_DetailedConsoleMessageAdded( |
| 96 routing_id(), trimmed_message, source, stack_trace, severity_level)); | 97 routing_id(), trimmed_message, source, stack_trace, severity_level)); |
| 97 } | 98 } |
| 98 | 99 |
| 99 } // namespace extensions | 100 } // namespace extensions |
| OLD | NEW |