Index: chrome/renderer/chrome_render_view_observer.cc |
diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc |
index 45199106a8990bc953138e142db78a79d6b864b9..c24cf29907b9fae33cd8b7f0132cc35c754d46b8 100644 |
--- a/chrome/renderer/chrome_render_view_observer.cc |
+++ b/chrome/renderer/chrome_render_view_observer.cc |
@@ -10,6 +10,7 @@ |
#include "base/debug/trace_event.h" |
#include "base/message_loop/message_loop.h" |
#include "base/metrics/histogram.h" |
+#include "base/strings/string_split.h" |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/common/chrome_constants.h" |
#include "chrome/common/chrome_switches.h" |
@@ -29,6 +30,7 @@ |
#include "content/public/renderer/content_renderer_client.h" |
#include "content/public/renderer/render_view.h" |
#include "extensions/common/constants.h" |
+#include "extensions/common/stack_frame.h" |
#include "net/base/data_url.h" |
#include "skia/ext/image_operations.h" |
#include "skia/ext/platform_canvas.h" |
@@ -55,6 +57,8 @@ |
#include "v8/include/v8-testing.h" |
#include "webkit/glue/webkit_glue.h" |
+using base::string16; |
+using extensions::APIPermission; |
using WebKit::WebAccessibilityObject; |
using WebKit::WebCString; |
using WebKit::WebDataSource; |
@@ -75,7 +79,6 @@ using WebKit::WebURLRequest; |
using WebKit::WebView; |
using WebKit::WebVector; |
using WebKit::WebWindowFeatures; |
-using extensions::APIPermission; |
// Delay in milliseconds that we'll wait before capturing the page contents |
// and thumbnail. |
@@ -166,6 +169,7 @@ static bool isHostInDomain(const std::string& host, const std::string& domain) { |
} |
namespace { |
+ |
GURL StripRef(const GURL& url) { |
GURL::Replacements replacements; |
replacements.ClearRef(); |
@@ -176,9 +180,9 @@ GURL StripRef(const GURL& url) { |
// |thumbnail_min_area_pixels|, we return the image unmodified. Otherwise, we |
// scale down the image so that the width and height do not exceed |
// |thumbnail_max_size_pixels|, preserving the original aspect ratio. |
-static SkBitmap Downscale(WebKit::WebImage image, |
- int thumbnail_min_area_pixels, |
- gfx::Size thumbnail_max_size_pixels) { |
+SkBitmap Downscale(WebKit::WebImage image, |
+ int thumbnail_min_area_pixels, |
+ gfx::Size thumbnail_max_size_pixels) { |
if (image.isNull()) |
return SkBitmap(); |
@@ -207,6 +211,62 @@ static SkBitmap Downscale(WebKit::WebImage image, |
static_cast<int>(scaled_size.width()), |
static_cast<int>(scaled_size.height())); |
} |
+ |
+// The delimiter for a stack trace provided by WebKit. |
+const char kStackFrameDelimiter[] = "\n at "; |
+ |
+// Get a stack trace from a WebKit console message. |
+// There are three possible scenarios: |
+// 1. WebKit gives us a stack trace in |stack_trace|. |
+// 2. The stack trace is embedded in the error |message| by an internal |
+// script. This will be more useful than |stack_trace|, since |stack_trace| |
+// will include the internal bindings trace, instead of a developer's code. |
+// 3. No stack trace is included. In this case, we should mock one up from |
+// the given line number and source. |
+// |message| will be populated with the error message only (i.e., will not |
+// include any stack trace). |
+extensions::StackTrace GetStackTraceFromMessage(string16* message, |
+ const string16& source, |
+ const string16& stack_trace, |
+ int32 line_number) { |
+ extensions::StackTrace result; |
+ std::vector<base::string16> pieces; |
+ size_t index = 0; |
+ |
+ if (message->find(base::UTF8ToUTF16(kStackFrameDelimiter)) != |
+ string16::npos) { |
+ base::SplitStringUsingSubstr(*message, |
+ base::UTF8ToUTF16(kStackFrameDelimiter), |
+ &pieces); |
+ *message = pieces[0]; |
+ index = 1; |
+ } else if (!stack_trace.empty()) { |
+ base::SplitStringUsingSubstr(stack_trace, |
+ base::UTF8ToUTF16(kStackFrameDelimiter), |
+ &pieces); |
+ } |
+ |
+ // If we got a stack trace, parse each frame from the text. |
+ if (index < pieces.size()) { |
+ for (; index < pieces.size(); ++index) { |
+ scoped_ptr<extensions::StackFrame> frame = |
+ extensions::StackFrame::CreateFromText(pieces[index]); |
+ if (frame.get()) |
+ result.push_back(*frame); |
+ } |
+ } |
+ |
+ if (result.empty()) { // If we don't have a stack trace, mock one up. |
+ result.push_back( |
+ extensions::StackFrame(line_number, |
+ 1u, // column number |
+ source, |
+ EmptyString16() /* no function name */ )); |
+ } |
+ |
+ return result; |
+} |
+ |
} // namespace |
ChromeRenderViewObserver::ChromeRenderViewObserver( |
@@ -767,6 +827,25 @@ void ChromeRenderViewObserver::DidHandleGestureEvent( |
text_input_type != WebKit::WebTextInputTypeNone)); |
} |
+void ChromeRenderViewObserver::DetailedConsoleMessageAdded( |
+ const base::string16& message, |
+ const base::string16& source, |
+ const base::string16& stack_trace_string, |
+ int32 line_number, |
+ int32 severity_level) { |
+ string16 trimmed_message = message; |
+ extensions::StackTrace stack_trace = GetStackTraceFromMessage( |
+ &trimmed_message, |
+ source, |
+ stack_trace_string, |
+ line_number); |
+ Send(new ChromeViewHostMsg_DetailedConsoleMessageAdded(routing_id(), |
+ trimmed_message, |
+ source, |
+ stack_trace, |
+ severity_level)); |
+} |
+ |
void ChromeRenderViewObserver::CapturePageInfoLater(int page_id, |
bool preliminary_capture, |
base::TimeDelta delay) { |