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/renderer/chrome_render_frame_observer.h" | 5 #include "chrome/renderer/chrome_render_frame_observer.h" |
6 | 6 |
| 7 #include "base/strings/string_split.h" |
7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/common/prerender_messages.h" | 9 #include "chrome/common/prerender_messages.h" |
9 #include "chrome/common/print_messages.h" | 10 #include "chrome/common/print_messages.h" |
10 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
11 #include "chrome/renderer/prerender/prerender_helper.h" | 12 #include "chrome/renderer/prerender/prerender_helper.h" |
12 #include "chrome/renderer/printing/print_web_view_helper.h" | 13 #include "chrome/renderer/printing/print_web_view_helper.h" |
13 #include "content/public/renderer/render_frame.h" | 14 #include "content/public/renderer/render_frame.h" |
| 15 #include "extensions/common/stack_frame.h" |
14 #include "skia/ext/image_operations.h" | 16 #include "skia/ext/image_operations.h" |
15 #include "skia/ext/platform_canvas.h" | 17 #include "skia/ext/platform_canvas.h" |
16 #include "third_party/WebKit/public/platform/WebImage.h" | 18 #include "third_party/WebKit/public/platform/WebImage.h" |
17 #include "third_party/WebKit/public/web/WebElement.h" | 19 #include "third_party/WebKit/public/web/WebElement.h" |
18 #include "third_party/WebKit/public/web/WebFrame.h" | 20 #include "third_party/WebKit/public/web/WebFrame.h" |
19 #include "third_party/WebKit/public/web/WebNode.h" | 21 #include "third_party/WebKit/public/web/WebNode.h" |
20 | 22 |
21 using blink::WebElement; | 23 using blink::WebElement; |
22 using blink::WebNode; | 24 using blink::WebNode; |
23 | 25 |
24 namespace { | 26 namespace { |
| 27 // The delimiter for a stack trace provided by WebKit. |
| 28 const char kStackFrameDelimiter[] = "\n at "; |
| 29 |
| 30 // Get a stack trace from a WebKit console message. |
| 31 // There are three possible scenarios: |
| 32 // 1. WebKit gives us a stack trace in |stack_trace|. |
| 33 // 2. The stack trace is embedded in the error |message| by an internal |
| 34 // script. This will be more useful than |stack_trace|, since |stack_trace| |
| 35 // will include the internal bindings trace, instead of a developer's code. |
| 36 // 3. No stack trace is included. In this case, we should mock one up from |
| 37 // the given line number and source. |
| 38 // |message| will be populated with the error message only (i.e., will not |
| 39 // include any stack trace). |
| 40 extensions::StackTrace GetStackTraceFromMessage( |
| 41 base::string16* message, |
| 42 const base::string16& source, |
| 43 const base::string16& stack_trace, |
| 44 int32 line_number) { |
| 45 extensions::StackTrace result; |
| 46 std::vector<base::string16> pieces; |
| 47 size_t index = 0; |
| 48 |
| 49 if (message->find(base::UTF8ToUTF16(kStackFrameDelimiter)) != |
| 50 base::string16::npos) { |
| 51 base::SplitStringUsingSubstr(*message, |
| 52 base::UTF8ToUTF16(kStackFrameDelimiter), |
| 53 &pieces); |
| 54 *message = pieces[0]; |
| 55 index = 1; |
| 56 } else if (!stack_trace.empty()) { |
| 57 base::SplitStringUsingSubstr(stack_trace, |
| 58 base::UTF8ToUTF16(kStackFrameDelimiter), |
| 59 &pieces); |
| 60 } |
| 61 |
| 62 // If we got a stack trace, parse each frame from the text. |
| 63 if (index < pieces.size()) { |
| 64 for (; index < pieces.size(); ++index) { |
| 65 scoped_ptr<extensions::StackFrame> frame = |
| 66 extensions::StackFrame::CreateFromText(pieces[index]); |
| 67 if (frame.get()) |
| 68 result.push_back(*frame); |
| 69 } |
| 70 } |
| 71 |
| 72 if (result.empty()) { // If we don't have a stack trace, mock one up. |
| 73 result.push_back( |
| 74 extensions::StackFrame(line_number, |
| 75 1u, // column number |
| 76 source, |
| 77 base::string16() /* no function name */ )); |
| 78 } |
| 79 |
| 80 return result; |
| 81 } |
| 82 |
25 // If the source image is null or occupies less area than | 83 // If the source image is null or occupies less area than |
26 // |thumbnail_min_area_pixels|, we return the image unmodified. Otherwise, we | 84 // |thumbnail_min_area_pixels|, we return the image unmodified. Otherwise, we |
27 // scale down the image so that the width and height do not exceed | 85 // scale down the image so that the width and height do not exceed |
28 // |thumbnail_max_size_pixels|, preserving the original aspect ratio. | 86 // |thumbnail_max_size_pixels|, preserving the original aspect ratio. |
29 SkBitmap Downscale(blink::WebImage image, | 87 SkBitmap Downscale(blink::WebImage image, |
30 int thumbnail_min_area_pixels, | 88 int thumbnail_min_area_pixels, |
31 gfx::Size thumbnail_max_size_pixels) { | 89 gfx::Size thumbnail_max_size_pixels) { |
32 if (image.isNull()) | 90 if (image.isNull()) |
33 return SkBitmap(); | 91 return SkBitmap(); |
34 | 92 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 148 } |
91 | 149 |
92 void ChromeRenderFrameObserver::DidChangeName( | 150 void ChromeRenderFrameObserver::DidChangeName( |
93 const base::string16& name) { | 151 const base::string16& name) { |
94 Send(new ChromeViewHostMsg_UpdateFrameName( | 152 Send(new ChromeViewHostMsg_UpdateFrameName( |
95 routing_id(), | 153 routing_id(), |
96 !render_frame()->GetWebFrame()->parent(), | 154 !render_frame()->GetWebFrame()->parent(), |
97 base::UTF16ToUTF8(name))); | 155 base::UTF16ToUTF8(name))); |
98 } | 156 } |
99 | 157 |
| 158 void ChromeRenderFrameObserver::DetailedConsoleMessageAdded( |
| 159 const base::string16& message, |
| 160 const base::string16& source, |
| 161 const base::string16& stack_trace_string, |
| 162 int32 line_number, |
| 163 int32 severity_level) { |
| 164 base::string16 trimmed_message = message; |
| 165 extensions::StackTrace stack_trace = GetStackTraceFromMessage( |
| 166 &trimmed_message, |
| 167 source, |
| 168 stack_trace_string, |
| 169 line_number); |
| 170 Send(new ChromeViewHostMsg_DetailedConsoleMessageAdded( |
| 171 routing_id(), trimmed_message, source, stack_trace, severity_level)); |
| 172 } |
| 173 |
100 void ChromeRenderFrameObserver::OnSetIsPrerendering(bool is_prerendering) { | 174 void ChromeRenderFrameObserver::OnSetIsPrerendering(bool is_prerendering) { |
101 if (is_prerendering) { | 175 if (is_prerendering) { |
102 // If the PrerenderHelper for this frame already exists, don't create it. It | 176 // If the PrerenderHelper for this frame already exists, don't create it. It |
103 // can already be created for subframes during handling of | 177 // can already be created for subframes during handling of |
104 // RenderFrameCreated, if the parent frame was prerendering at time of | 178 // RenderFrameCreated, if the parent frame was prerendering at time of |
105 // subframe creation. | 179 // subframe creation. |
106 if (prerender::PrerenderHelper::Get(render_frame())) | 180 if (prerender::PrerenderHelper::Get(render_frame())) |
107 return; | 181 return; |
108 | 182 |
109 // The PrerenderHelper will destroy itself either after recording histograms | 183 // The PrerenderHelper will destroy itself either after recording histograms |
(...skipping 18 matching lines...) Expand all Loading... |
128 Send(new ChromeViewHostMsg_RequestThumbnailForContextNode_ACK( | 202 Send(new ChromeViewHostMsg_RequestThumbnailForContextNode_ACK( |
129 routing_id(), thumbnail, original_size)); | 203 routing_id(), thumbnail, original_size)); |
130 } | 204 } |
131 | 205 |
132 void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() { | 206 void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() { |
133 printing::PrintWebViewHelper* helper = | 207 printing::PrintWebViewHelper* helper = |
134 printing::PrintWebViewHelper::Get(render_frame()->GetRenderView()); | 208 printing::PrintWebViewHelper::Get(render_frame()->GetRenderView()); |
135 if (helper) | 209 if (helper) |
136 helper->PrintNode(render_frame()->GetContextMenuNode()); | 210 helper->PrintNode(render_frame()->GetContextMenuNode()); |
137 } | 211 } |
OLD | NEW |