Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(593)

Side by Side Diff: chrome/renderer/chrome_render_frame_observer.cc

Issue 321453003: Mark ChromeViewHostMsg_DetailedConsoleMessageAdded as extensions-only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
8 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/common/prerender_messages.h" 8 #include "chrome/common/prerender_messages.h"
10 #include "chrome/common/print_messages.h" 9 #include "chrome/common/print_messages.h"
11 #include "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
12 #include "chrome/renderer/prerender/prerender_helper.h" 11 #include "chrome/renderer/prerender/prerender_helper.h"
13 #include "chrome/renderer/printing/print_web_view_helper.h" 12 #include "chrome/renderer/printing/print_web_view_helper.h"
14 #include "content/public/renderer/render_frame.h" 13 #include "content/public/renderer/render_frame.h"
15 #include "extensions/common/stack_frame.h"
16 #include "skia/ext/image_operations.h" 14 #include "skia/ext/image_operations.h"
17 #include "skia/ext/platform_canvas.h" 15 #include "skia/ext/platform_canvas.h"
18 #include "third_party/WebKit/public/platform/WebImage.h" 16 #include "third_party/WebKit/public/platform/WebImage.h"
19 #include "third_party/WebKit/public/web/WebElement.h" 17 #include "third_party/WebKit/public/web/WebElement.h"
20 #include "third_party/WebKit/public/web/WebFrame.h" 18 #include "third_party/WebKit/public/web/WebFrame.h"
21 #include "third_party/WebKit/public/web/WebNode.h" 19 #include "third_party/WebKit/public/web/WebNode.h"
22 20
23 using blink::WebElement; 21 using blink::WebElement;
24 using blink::WebNode; 22 using blink::WebNode;
25 23
26 namespace { 24 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
83 // If the source image is null or occupies less area than 26 // If the source image is null or occupies less area than
84 // |thumbnail_min_area_pixels|, we return the image unmodified. Otherwise, we 27 // |thumbnail_min_area_pixels|, we return the image unmodified. Otherwise, we
85 // scale down the image so that the width and height do not exceed 28 // scale down the image so that the width and height do not exceed
86 // |thumbnail_max_size_pixels|, preserving the original aspect ratio. 29 // |thumbnail_max_size_pixels|, preserving the original aspect ratio.
87 SkBitmap Downscale(blink::WebImage image, 30 SkBitmap Downscale(blink::WebImage image,
88 int thumbnail_min_area_pixels, 31 int thumbnail_min_area_pixels,
89 gfx::Size thumbnail_max_size_pixels) { 32 gfx::Size thumbnail_max_size_pixels) {
90 if (image.isNull()) 33 if (image.isNull())
91 return SkBitmap(); 34 return SkBitmap();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 91 }
149 92
150 void ChromeRenderFrameObserver::DidChangeName( 93 void ChromeRenderFrameObserver::DidChangeName(
151 const base::string16& name) { 94 const base::string16& name) {
152 Send(new ChromeViewHostMsg_UpdateFrameName( 95 Send(new ChromeViewHostMsg_UpdateFrameName(
153 routing_id(), 96 routing_id(),
154 !render_frame()->GetWebFrame()->parent(), 97 !render_frame()->GetWebFrame()->parent(),
155 base::UTF16ToUTF8(name))); 98 base::UTF16ToUTF8(name)));
156 } 99 }
157 100
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
174 void ChromeRenderFrameObserver::OnSetIsPrerendering(bool is_prerendering) { 101 void ChromeRenderFrameObserver::OnSetIsPrerendering(bool is_prerendering) {
175 if (is_prerendering) { 102 if (is_prerendering) {
176 // If the PrerenderHelper for this frame already exists, don't create it. It 103 // If the PrerenderHelper for this frame already exists, don't create it. It
177 // can already be created for subframes during handling of 104 // can already be created for subframes during handling of
178 // RenderFrameCreated, if the parent frame was prerendering at time of 105 // RenderFrameCreated, if the parent frame was prerendering at time of
179 // subframe creation. 106 // subframe creation.
180 if (prerender::PrerenderHelper::Get(render_frame())) 107 if (prerender::PrerenderHelper::Get(render_frame()))
181 return; 108 return;
182 109
183 // The PrerenderHelper will destroy itself either after recording histograms 110 // The PrerenderHelper will destroy itself either after recording histograms
(...skipping 18 matching lines...) Expand all
202 Send(new ChromeViewHostMsg_RequestThumbnailForContextNode_ACK( 129 Send(new ChromeViewHostMsg_RequestThumbnailForContextNode_ACK(
203 routing_id(), thumbnail, original_size)); 130 routing_id(), thumbnail, original_size));
204 } 131 }
205 132
206 void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() { 133 void ChromeRenderFrameObserver::OnPrintNodeUnderContextMenu() {
207 printing::PrintWebViewHelper* helper = 134 printing::PrintWebViewHelper* helper =
208 printing::PrintWebViewHelper::Get(render_frame()->GetRenderView()); 135 printing::PrintWebViewHelper::Get(render_frame()->GetRenderView());
209 if (helper) 136 if (helper)
210 helper->PrintNode(render_frame()->GetContextMenuNode()); 137 helper->PrintNode(render_frame()->GetContextMenuNode());
211 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698